using System; using System.Reactive.Threading.Tasks; using Octokit.Reactive.Internal; namespace Octokit.Reactive { /// /// A client for GitHub's Git Repository Status API. /// /// /// See the Repository Statuses API documentation for more information. /// public class ObservableCommitStatusClient : IObservableCommitStatusClient { readonly ICommitStatusClient _client; readonly IConnection _connection; public ObservableCommitStatusClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, "client"); _client = client.Repository.Status; _connection = client.Connection; } /// /// Retrieves commit statuses for the specified reference. A reference can be a commit SHA, a branch name, or /// a tag name. /// /// Only users with pull access can see this. /// The owner of the repository /// The name of the repository /// The reference (SHA, branch name, or tag name) to list commits for public IObservable GetAll(string owner, string name, string reference) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(reference, "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. /// /// Only users with pull access can see this. /// The ID of the repository /// The reference (SHA, branch name, or tag name) to list commits for public IObservable GetAll(int repositoryId, string reference) { Ensure.ArgumentNotNullOrEmptyString(reference, "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. /// /// Only users with pull access can see this. /// 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 public IObservable GetAll(string owner, string name, string reference, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); Ensure.ArgumentNotNull(options, "options"); return _connection.GetAndFlattenAllPages(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. /// /// Only users with pull access can see this. /// The ID of the repository /// The reference (SHA, branch name, or tag name) to list commits for /// Options for changing the API response public IObservable GetAll(int repositoryId, string reference, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); Ensure.ArgumentNotNull(options, "options"); return _connection.GetAndFlattenAllPages(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. /// /// Only users with pull access can see this. /// The owner of the repository /// The name of the repository /// The reference (SHA, branch name, or tag name) to list commits for public IObservable GetCombined(string owner, string name, string reference) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); return _client.GetCombined(owner, name, reference).ToObservable(); } /// /// Retrieves a combined view of statuses for the specified reference. A reference can be a commit SHA, a branch name, or /// a tag name. /// /// Only users with pull access can see this. /// The ID of the repository /// The reference (SHA, branch name, or tag name) to list commits for public IObservable GetCombined(int repositoryId, string reference) { Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); return _client.GetCombined(repositoryId, reference).ToObservable(); } /// /// Creates a commit status for the specified ref. /// /// 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 public IObservable Create(string owner, string name, string reference, NewCommitStatus newCommitStatus) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); Ensure.ArgumentNotNull(newCommitStatus, "newCommitStatus"); return _client.Create(owner, name, reference, newCommitStatus).ToObservable(); } /// /// Creates a commit status for the specified ref. /// /// The ID of the repository /// The reference (SHA, branch name, or tag name) to list commits for /// The commit status to create public IObservable Create(int repositoryId, string reference, NewCommitStatus newCommitStatus) { Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); Ensure.ArgumentNotNull(newCommitStatus, "newCommitStatus"); return _client.Create(repositoryId, reference, newCommitStatus).ToObservable(); } } }