using System.Collections.Generic;
using System.Threading.Tasks;
namespace Octokit
{
///
/// A client for GitHub's Git Repository Status API.
///
///
/// See the Repository Statuses API documentation for more information.
///
public class CommitStatusClient : ApiClient, ICommitStatusClient
{
///
/// Initializes a new Commit Status API client.
///
/// An API connection
public CommitStatusClient(IApiConnection apiConnection) : base(apiConnection)
{
}
///
/// Retrieves commit statuses for the specified reference. A reference can be a commit SHA, a branch name, or
/// a tag name.
///
///
/// https://developer.github.com/v3/repos/statuses/#list-statuses-for-a-specific-ref
///
/// The owner of the repository
/// The name of the repository
/// The reference (SHA, branch name, or tag name) to list commits for
[ManualRoute("GET", "/repos/{owner}/{repo}/commits/{ref}/statuses")]
public Task> GetAll(string owner, string name, string reference)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference));
return GetAll(owner, name, reference, ApiOptions.None);
}
///
/// Retrieves commit statuses for the specified reference. A reference can be a commit SHA, a branch name, or
/// a tag name.
///
///
/// https://developer.github.com/v3/repos/statuses/#list-statuses-for-a-specific-ref
///
/// The Id of the repository
/// The reference (SHA, branch name, or tag name) to list commits for
[ManualRoute("GET", "/repositories/{id}/commits/{ref}/statuses")]
public Task> GetAll(long repositoryId, string reference)
{
Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference));
return GetAll(repositoryId, reference, ApiOptions.None);
}
///
/// Retrieves commit statuses for the specified reference. A reference can be a commit SHA, a branch name, or
/// a tag name.
///
///
/// https://developer.github.com/v3/repos/statuses/#list-statuses-for-a-specific-ref
///
/// The owner of the repository
/// The name of the repository
/// The reference (SHA, branch name, or tag name) to list commits for
/// Options for changing the API response
[ManualRoute("GET", "/repos/{owner}/{repo}/commits/{ref}/statuses")]
public Task> GetAll(string owner, string name, string reference, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference));
Ensure.ArgumentNotNull(options, nameof(options));
return ApiConnection.GetAll(ApiUrls.CommitStatuses(owner, name, reference), options);
}
///
/// Retrieves commit statuses for the specified reference. A reference can be a commit SHA, a branch name, or
/// a tag name.
///
///
/// https://developer.github.com/v3/repos/statuses/#list-statuses-for-a-specific-ref
///
/// The Id of the repository
/// The reference (SHA, branch name, or tag name) to list commits for
/// Options for changing the API response
[ManualRoute("GET", "/repositories/{id}/commits/{ref}/statuses")]
public Task> GetAll(long repositoryId, string reference, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference));
Ensure.ArgumentNotNull(options, nameof(options));
return ApiConnection.GetAll(ApiUrls.CommitStatuses(repositoryId, reference), options);
}
///
/// Retrieves a combined view of statuses for the specified reference. A reference can be a commit SHA, a branch name, or
/// a tag name.
///
///
/// https://developer.github.com/v3/repos/statuses/#get-the-combined-status-for-a-specific-ref
///
/// The owner of the repository
/// The name of the repository
/// The reference (SHA, branch name, or tag name) to list commits for
[ManualRoute("GET", "/repos/{owner}/{repo}/commits/{ref}/status")]
public Task GetCombined(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.CombinedCommitStatus(owner, name, reference));
}
///
/// Retrieves a combined view of statuses for the specified reference. A reference can be a commit SHA, a branch name, or
/// a tag name.
///
///
/// https://developer.github.com/v3/repos/statuses/#get-the-combined-status-for-a-specific-ref
///
/// The Id of the repository
/// The reference (SHA, branch name, or tag name) to list commits for
[ManualRoute("GET", "/repositories/{id}/commits/{ref}/status")]
public Task GetCombined(long repositoryId, string reference)
{
Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference));
return ApiConnection.Get(ApiUrls.CombinedCommitStatus(repositoryId, reference));
}
///
/// Creates a commit status for the specified ref.
///
///
/// https://developer.github.com/v3/repos/statuses/#create-a-status
///
/// The owner of the repository
/// The name of the repository
/// The reference (SHA, branch name, or tag name) to list commits for
/// The commit status to create
[ManualRoute("POST", "/repos/{owner}/{repo}/statuses/{sha}")]
public Task Create(string owner, string name, string reference, NewCommitStatus newCommitStatus)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference));
Ensure.ArgumentNotNull(newCommitStatus, nameof(newCommitStatus));
return ApiConnection.Post(ApiUrls.CreateCommitStatus(owner, name, reference), newCommitStatus);
}
///
/// Creates a commit status for the specified ref.
///
///
/// https://developer.github.com/v3/repos/statuses/#create-a-status
///
/// The Id of the repository
/// The reference (SHA, branch name, or tag name) to list commits for
/// The commit status to create
[ManualRoute("POST", "/repositories/{id}/statuses/{sha}")]
public Task Create(long repositoryId, string reference, NewCommitStatus newCommitStatus)
{
Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference));
Ensure.ArgumentNotNull(newCommitStatus, nameof(newCommitStatus));
return ApiConnection.Post(ApiUrls.CreateCommitStatus(repositoryId, reference), newCommitStatus);
}
}
}