Module scm provides a unified interface to multiple source code management systems including GitHub, GitHub Enterprise, Bitbucket, Bitbucket Server, Gitee, Gitea and Gogs.
Create a GitHub client:
use amp_common::scm::client::Client;
use amp_common::scm::driver::github;
fn main() {
let client = Client::new(github::default());
}
Create a GitHub Enterprise client:
use amp_common::scm::client::Client;
use amp_common::scm::driver::github;
fn main() {
let client = Client::new(github::new("https://github.company.com/api/v3"));
}
Create a Bitbucket client:
use amp_common::scm::client::Client;
use amp_common::scm::driver::bitbucket;
fn main() {
let client = Client::new(bitbucket::default());
}
Create a Bitbucket Server (Stash) client:
use amp_common::scm::client::Client;
use amp_common::scm::driver::bitbucket;
fn main() {
let client = Client::new(bitbucket::new("https://stash.company.com"));
}
Create a Gitea client:
use amp_common::scm::client::Client;
use amp_common::scm::driver::gitea;
fn main() {
let client = Client::new(gitea::new("https://gitea.company.com"));
}
Create a Gitee client:
use amp_common::scm::client::Client;
use amp_common::scm::driver::gitee;
fn main() {
let client = Client::new(gitee::new("https://gitee.com/api/v5"));
}
The scm client does not directly handle authentication. Instead, when creating
a new client, provide an http.Client
that can handle authentication for you.
For convenience, this library includes oauth1 and oauth2 implementations that
can be used to authenticate requests.
use amp_common::scm::client::Client;
use amp_common::scm::driver::github;
use amp_common::scm::transport;
use amp_common::scm::transport::oauth2;
fn main() {
let mut client = Client::new(github::default());
// provide a custom http.Client with a transport
// that injects the oauth2 token.
client.client = http.Client{
transport: oauth2.Transport{
source: oauth2.StaticTokenSource(
scm.Token{
token: "ecf4c1f9869f59758e679ab54b4",
},
),
},
};
// provide a custom http.Client with a transport
// that injects the private GitLab token through
// the PRIVATE_TOKEN header variable.
client.client = http.Client{
transport: transport.PrivateToken{
token: "ecf4c1f9869f59758e679ab54b4",
},
};
}
The scm client exposes dozens of endpoints for working with repositories, issues, comments, files and more.
Example code to get a commit:
use amp_common::scm::client::Client;
use amp_common::scm::driver::github;
use amp_common::scm::git::GitService;
fn main() {
let client = Client::new(github::default());
let commit = client.git().find_commit("octocat/Hello-World", "master");
assert!(commit.is_ok());
}
Here are some useful links to providers API documentation:
- Azure DevOps
- Bitbucket cloud API
- Bitbucket server/Stash API
- Gitea API
- Gitee API
- Github API
- Gitlab API
- Gogs API
Heavily inspired by drone/go-scm