using System; using System.Reactive.Threading.Tasks; using Octokit.Reactive.Internal; namespace Octokit.Reactive { 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) { return _commit.Compare(owner, name, @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 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 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 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 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"); return _connection.GetAndFlattenAllPages(ApiUrls.RepositoryCommits(owner, name), 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(); } } }