mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-20 06:05:12 +00:00
* Added ApiOptions overloads for RepositoryCommitClient methods * Added overloads to Reactive clients * Integration tests in progress * Integration test addition in progress * More integration tests added * Added Ensure things * Minor changes * Minor changes * Few changes * Tried to fix errors * Tried to fix errors * Fixed a few things * Fixed integration tests * Tidying up * Added public keyword * Added unit tests for GetAll() in normal and reactive methods * Minor changes * Changed the class name * Fixed the unit test
133 lines
5.8 KiB
C#
133 lines
5.8 KiB
C#
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Octokit
|
|
{
|
|
/// <summary>
|
|
/// A client for GitHub's Repository Commits API.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See the <a href="http://developer.github.com/v3/repos/commits/">Repository Commits API documentation</a> for more information.
|
|
/// </remarks>
|
|
public class RepositoryCommitsClient : IRepositoryCommitsClient
|
|
{
|
|
readonly IApiConnection _apiConnection;
|
|
|
|
public RepositoryCommitsClient(IApiConnection apiConnection)
|
|
{
|
|
_apiConnection = apiConnection;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Compare two references in a repository
|
|
/// </summary>
|
|
/// <param name="owner">The owner of the repository</param>
|
|
/// <param name="name">The name of the repository</param>
|
|
/// <param name="base">The reference to use as the base commit</param>
|
|
/// <param name="head">The reference to use as the head commit</param>
|
|
/// <returns></returns>
|
|
public Task<CompareResult> 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<CompareResult>(ApiUrls.RepoCompare(owner, name, @base, head));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets a single commit for a given repository
|
|
/// </summary>
|
|
/// <param name="owner">The owner of the repository</param>
|
|
/// <param name="name">The name of the repository</param>
|
|
/// <param name="reference">The reference for the commit (SHA)</param>
|
|
/// <returns></returns>
|
|
public Task<GitHubCommit> Get(string owner, string name, string reference)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
|
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
|
Ensure.ArgumentNotNullOrEmptyString(reference, "reference");
|
|
|
|
return _apiConnection.Get<GitHubCommit>(ApiUrls.RepositoryCommit(owner, name, reference));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets all commits for a given repository
|
|
/// </summary>
|
|
/// <param name="owner">The owner of the repository</param>
|
|
/// <param name="name">The name of the repository</param>
|
|
/// <returns></returns>
|
|
public Task<IReadOnlyList<GitHubCommit>> GetAll(string owner, string name)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
|
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
|
|
|
return GetAll(owner, name, new CommitRequest(), ApiOptions.None);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets all commits for a given repository
|
|
/// </summary>
|
|
/// <param name="owner">The owner of the repository</param>
|
|
/// <param name="name">The name of the repository</param>
|
|
/// <param name="options">Options for changing the API response</param>
|
|
/// <returns></returns>
|
|
public Task<IReadOnlyList<GitHubCommit>> GetAll(string owner, string name, ApiOptions options)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
|
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
|
|
|
return GetAll(owner, name, new CommitRequest(), options);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets all commits for a given repository
|
|
/// </summary>
|
|
/// <param name="owner">The owner of the repository</param>
|
|
/// <param name="name">The name of the repository</param>
|
|
/// <param name="request">Used to filter list of commits returned</param>
|
|
/// <returns></returns>
|
|
public Task<IReadOnlyList<GitHubCommit>> 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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets all commits for a given repository
|
|
/// </summary>
|
|
/// <param name="owner">The owner of the repository</param>
|
|
/// <param name="name">The name of the repository</param>
|
|
/// <param name="request">Used to filter list of commits returned</param>
|
|
/// <param name="options">Options for changing the API response</param>
|
|
/// <returns></returns>
|
|
public Task<IReadOnlyList<GitHubCommit>> GetAll(string owner, string name, CommitRequest request, ApiOptions options)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
|
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
|
Ensure.ArgumentNotNull(request, "request");
|
|
|
|
return _apiConnection.GetAll<GitHubCommit>(ApiUrls.RepositoryCommits(owner, name), request.ToParametersDictionary(), options);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the SHA-1 of a commit reference
|
|
/// </summary>
|
|
/// <param name="owner">The owner of the repository</param>
|
|
/// <param name="name">The name of the repository</param>
|
|
/// <param name="reference">The repository reference</param>
|
|
/// <returns></returns>
|
|
public Task<string> GetSha1(string owner, string name, string reference)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
|
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
|
Ensure.ArgumentNotNullOrEmptyString(reference, "reference");
|
|
|
|
return _apiConnection.Get<string>(ApiUrls.RepositoryCommit(owner, name, reference), null, AcceptHeaders.CommitReferenceSha1Preview);
|
|
}
|
|
}
|
|
} |