using System.Collections.Generic; using System.Threading.Tasks; namespace Octokit { /// /// A client for GitHub's Repository Commits API. /// /// /// See the Repository Commits API documentation for more information. /// public class RepositoryCommitsClient : ApiClient, IRepositoryCommitsClient { public RepositoryCommitsClient(IApiConnection apiConnection) : base(apiConnection) { } /// /// Compare two references in a repository /// /// The owner of the repository /// The name of the repository /// The reference to use as the base commit /// The reference to use as the head commit /// public Task Compare(string owner, string name, string @base, string head) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(@base, "base"); Ensure.ArgumentNotNullOrEmptyString(head, "head"); return ApiConnection.Get(ApiUrls.RepoCompare(owner, name, @base, head)); } /// /// Compare two references in a repository /// /// The ID of the repository /// The reference to use as the base commit /// The reference to use as the head commit /// public Task Compare(int repositoryId, string @base, string head) { Ensure.ArgumentNotNullOrEmptyString(@base, "base"); Ensure.ArgumentNotNullOrEmptyString(head, "head"); return ApiConnection.Get(ApiUrls.RepoCompare(repositoryId, @base, head)); } /// /// Gets a single commit for a given repository /// /// The owner of the repository /// The name of the repository /// The reference for the commit (SHA) /// public Task Get(string owner, string name, string reference) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); return ApiConnection.Get(ApiUrls.RepositoryCommit(owner, name, reference)); } /// /// Gets a single commit for a given repository /// /// The ID of the repository /// The reference for the commit (SHA) /// public Task Get(int repositoryId, string reference) { Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); return ApiConnection.Get(ApiUrls.RepositoryCommit(repositoryId, reference)); } /// /// Gets all commits for a given repository /// /// The owner of the repository /// The name of the repository /// public Task> GetAll(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); return GetAll(owner, name, new CommitRequest(), ApiOptions.None); } /// /// Gets all commits for a given repository /// /// The ID of the repository /// public Task> GetAll(int repositoryId) { return GetAll(repositoryId, new CommitRequest(), ApiOptions.None); } /// /// Gets all commits for a given repository /// /// The owner of the repository /// The name of the repository /// Options for changing the API response /// public Task> GetAll(string owner, string name, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); return GetAll(owner, name, new CommitRequest(), options); } /// /// Gets all commits for a given repository /// /// The ID of the repository /// Options for changing the API response /// public Task> GetAll(int repositoryId, ApiOptions options) { return GetAll(repositoryId, new CommitRequest(), options); } /// /// Gets all commits for a given repository /// /// The owner of the repository /// The name of the repository /// Used to filter list of commits returned /// public Task> GetAll(string owner, string name, CommitRequest request) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(request, "request"); return GetAll(owner, name, request, ApiOptions.None); } /// /// Gets all commits for a given repository /// /// The ID of the repository /// Used to filter list of commits returned /// public Task> GetAll(int repositoryId, CommitRequest request) { Ensure.ArgumentNotNull(request, "request"); return GetAll(repositoryId, request, ApiOptions.None); } /// /// Gets all commits for a given repository /// /// The owner of the repository /// The name of the repository /// Used to filter list of commits returned /// Options for changing the API response /// public Task> GetAll(string owner, string name, CommitRequest request, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(request, "request"); Ensure.ArgumentNotNull(options, "options"); return ApiConnection.GetAll(ApiUrls.RepositoryCommits(owner, name), request.ToParametersDictionary(), options); } /// /// Gets all commits for a given repository /// /// The ID of the repository /// Used to filter list of commits returned /// Options for changing the API response /// public Task> GetAll(int repositoryId, CommitRequest request, ApiOptions options) { Ensure.ArgumentNotNull(request, "request"); Ensure.ArgumentNotNull(options, "options"); return ApiConnection.GetAll(ApiUrls.RepositoryCommits(repositoryId), request.ToParametersDictionary(), options); } /// /// Get the SHA-1 of a commit reference /// /// The owner of the repository /// The name of the repository /// The repository reference /// public Task GetSha1(string owner, string name, string reference) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); return ApiConnection.Get(ApiUrls.RepositoryCommit(owner, name, reference), null, AcceptHeaders.CommitReferenceSha1Preview); } /// /// Get the SHA-1 of a commit reference /// /// The ID of the repository /// The repository reference /// public Task GetSha1(int repositoryId, string reference) { Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); return ApiConnection.Get(ApiUrls.RepositoryCommit(repositoryId, reference), null, AcceptHeaders.CommitReferenceSha1Preview); } } }