using System; using System.Reactive.Threading.Tasks; using Octokit.Reactive.Internal; namespace Octokit.Reactive { /// /// A client for GitHub's Repository Commits API. /// /// /// See the Repository Commits API documentation for more information. /// public class ObservableRepositoryCommitsClient : IObservableRepositoryCommitsClient { readonly IConnection _connection; readonly IRepositoryCommitsClient _commit; public ObservableRepositoryCommitsClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, "client"); _connection = client.Connection; _commit = client.Repository.Commit; } /// /// 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 IObservable 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 _commit.Compare(owner, name, @base, head).ToObservable(); } /// /// 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 IObservable Compare(int repositoryId, string @base, string head) { Ensure.ArgumentNotNullOrEmptyString(@base, "base"); Ensure.ArgumentNotNullOrEmptyString(head, "head"); return _commit.Compare(repositoryId, @base, head).ToObservable(); } /// /// Gets all commits for a given repository /// /// The owner of the repository /// The name of the repository /// The reference for the commit public IObservable Get(string owner, string name, string reference) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); return _commit.Get(owner, name, reference).ToObservable(); } /// /// Gets all commits for a given repository /// /// The Id of the repository /// The reference for the commit public IObservable Get(int repositoryId, string reference) { Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); return _commit.Get(repositoryId, reference).ToObservable(); } /// /// Gets all commits for a given repository /// /// The owner of the repository /// The name of the repository public IObservable 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 IObservable 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 IObservable GetAll(string owner, string name, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(options, "options"); 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 IObservable GetAll(int repositoryId, ApiOptions options) { Ensure.ArgumentNotNull(options, "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 IObservable 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 IObservable 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 IObservable 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 _connection.GetAndFlattenAllPages(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 IObservable GetAll(int repositoryId, CommitRequest request, ApiOptions options) { Ensure.ArgumentNotNull(request, "request"); Ensure.ArgumentNotNull(options, "options"); return _connection.GetAndFlattenAllPages(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 IObservable GetSha1(string owner, string name, string reference) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); return _commit.GetSha1(owner, name, reference).ToObservable(); } /// /// Get the SHA-1 of a commit reference /// /// The Id of the repository /// The repository reference public IObservable GetSha1(int repositoryId, string reference) { Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); return _commit.GetSha1(repositoryId, reference).ToObservable(); } } }