using System.Threading.Tasks;
namespace Octokit
{
///
/// A client for GitHub's Git Commits API.
///
///
/// See the Git Commits API documentation for more information.
///
public class CommitsClient : ApiClient, ICommitsClient
{
///
/// Instantiates a new GitHub Git Commits API client.
///
/// An API connection
public CommitsClient(IApiConnection apiConnection) :
base(apiConnection)
{
}
///
/// Gets a commit for a given repository by sha reference
///
///
/// http://developer.github.com/v3/git/commits/#get-a-commit
///
/// The owner of the repository
/// The name of the repository
/// Tha sha reference of the commit
[ManualRoute("GET", "/repos/{owner}/{repo}/git/commits/{commit_sha}")]
public Task Get(string owner, string name, string reference)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference));
return ApiConnection.Get(ApiUrls.Commit(owner, name, reference));
}
///
/// Gets a commit for a given repository by sha reference
///
///
/// http://developer.github.com/v3/git/commits/#get-a-commit
///
/// The Id of the repository
/// Tha sha reference of the commit
[ManualRoute("GET", "/repositories/{id}/git/commits/{commit_sha}")]
public Task Get(long repositoryId, string reference)
{
Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference));
return ApiConnection.Get(ApiUrls.Commit(repositoryId, reference));
}
///
/// Create a commit for a given repository
///
///
/// http://developer.github.com/v3/git/commits/#create-a-commit
///
/// The owner of the repository
/// The name of the repository
/// The commit to create
[ManualRoute("POST", "/repos/{owner}/{repo}/git/commits")]
public Task Create(string owner, string name, NewCommit commit)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(commit, nameof(commit));
return ApiConnection.Post(ApiUrls.CreateCommit(owner, name), commit);
}
///
/// Create a commit for a given repository
///
///
/// http://developer.github.com/v3/git/commits/#create-a-commit
///
/// The Id of the repository
/// The commit to create
[ManualRoute("POST", "/repositories/{id}/git/commits")]
public Task Create(long repositoryId, NewCommit commit)
{
Ensure.ArgumentNotNull(commit, nameof(commit));
return ApiConnection.Post(ApiUrls.CreateCommit(repositoryId), commit);
}
}
}