using System; using System.Reactive; using System.Reactive.Threading.Tasks; using Octokit.Reactive.Internal; namespace Octokit.Reactive { /// /// A client for GitHub's References API. /// /// /// See the References API documentation for more information. /// public class ObservableReferencesClient : IObservableReferencesClient { readonly IReferencesClient _reference; readonly IConnection _connection; public ObservableReferencesClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, nameof(client)); _reference = client.Git.Reference; _connection = client.Connection; } /// /// Gets a reference for a given repository by reference name /// /// /// http://developer.github.com/v3/git/refs/#get-a-reference /// /// The owner of the repository /// The name of the repository /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/master" or "tags/release-1" /// public IObservable Get(string owner, string name, string reference) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); return _reference.Get(owner, name, reference).ToObservable(); } /// /// Gets a reference for a given repository by reference name /// /// /// http://developer.github.com/v3/git/refs/#get-a-reference /// /// The Id of the repository /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/master" or "tags/release-1" /// public IObservable Get(long repositoryId, string reference) { Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); return _reference.Get(repositoryId, reference).ToObservable(); } /// /// Gets all references for a given repository /// /// /// http://developer.github.com/v3/git/refs/#get-all-references /// /// The owner of the repository /// The name of the repository /// public IObservable GetAll(string owner, string name) { return GetAll(owner, name, ApiOptions.None); } /// /// Gets all references for a given repository /// /// /// http://developer.github.com/v3/git/refs/#get-all-references /// /// 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, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages(ApiUrls.Reference(owner, name), options); } /// /// Gets all references for a given repository /// /// /// http://developer.github.com/v3/git/refs/#get-all-references /// /// The Id of the repository /// public IObservable GetAll(long repositoryId) { return GetAll(repositoryId, ApiOptions.None); } /// /// Gets all references for a given repository /// /// /// http://developer.github.com/v3/git/refs/#get-all-references /// /// The Id of the repository /// Options for changing the API response /// public IObservable GetAll(long repositoryId, ApiOptions options) { Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages(ApiUrls.Reference(repositoryId), options); } /// /// Gets references for a given repository by sub-namespace, i.e. "tags" or "heads" /// /// /// http://developer.github.com/v3/git/refs/#get-all-references /// /// The owner of the repository /// The name of the repository /// The sub-namespace to get references for /// public IObservable GetAllForSubNamespace(string owner, string name, string subNamespace) { return GetAllForSubNamespace(owner, name, subNamespace, ApiOptions.None); } /// /// Gets references for a given repository by sub-namespace, i.e. "tags" or "heads" /// /// /// http://developer.github.com/v3/git/refs/#get-all-references /// /// The owner of the repository /// The name of the repository /// The sub-namespace to get references for /// Options for changing the API response /// /// The subNamespace parameter supports either the fully-qualified ref /// (prefixed with "refs/", e.g. "refs/heads/master" or /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. /// "heads/master" or "tags/release-1") /// public IObservable GetAllForSubNamespace(string owner, string name, string subNamespace, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNullOrEmptyString(subNamespace, nameof(subNamespace)); Ensure.ArgumentNotNull(options, nameof(options)); if (subNamespace.StartsWith("refs/")) { subNamespace = subNamespace.Replace("refs/", string.Empty); } return _connection.GetAndFlattenAllPages(ApiUrls.Reference(owner, name, subNamespace), options); } /// /// Gets references for a given repository by sub-namespace, i.e. "tags" or "heads" /// /// /// http://developer.github.com/v3/git/refs/#get-all-references /// /// The Id of the repository /// The sub-namespace to get references for /// public IObservable GetAllForSubNamespace(long repositoryId, string subNamespace) { return GetAllForSubNamespace(repositoryId, subNamespace, ApiOptions.None); } /// /// Gets references for a given repository by sub-namespace, i.e. "tags" or "heads" /// /// /// http://developer.github.com/v3/git/refs/#get-all-references /// /// The Id of the repository /// The sub-namespace to get references for /// Options for changing the API response /// /// The subNamespace parameter supports either the fully-qualified ref /// (prefixed with "refs/", e.g. "refs/heads/master" or /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. /// "heads/master" or "tags/release-1") /// public IObservable GetAllForSubNamespace(long repositoryId, string subNamespace, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(subNamespace, nameof(subNamespace)); Ensure.ArgumentNotNull(options, nameof(options)); if (subNamespace.StartsWith("refs/")) { subNamespace = subNamespace.Replace("refs/", string.Empty); } return _connection.GetAndFlattenAllPages(ApiUrls.Reference(repositoryId, subNamespace), options); } /// /// Creates a reference for a given repository /// /// /// http://developer.github.com/v3/git/refs/#create-a-reference /// /// The owner of the repository /// The name of the repository /// The reference to create /// public IObservable Create(string owner, string name, NewReference reference) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(reference, nameof(reference)); return _reference.Create(owner, name, reference).ToObservable(); } /// /// Creates a reference for a given repository /// /// /// http://developer.github.com/v3/git/refs/#create-a-reference /// /// The Id of the repository /// The reference to create /// public IObservable Create(long repositoryId, NewReference reference) { Ensure.ArgumentNotNull(reference, nameof(reference)); return _reference.Create(repositoryId, reference).ToObservable(); } /// /// Updates a reference for a given repository by reference name /// /// /// http://developer.github.com/v3/git/refs/#update-a-reference /// /// The owner of the repository /// The name of the repository /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/master" or "tags/release-1" /// The updated reference data /// public IObservable Update(string owner, string name, string reference, ReferenceUpdate referenceUpdate) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); Ensure.ArgumentNotNull(referenceUpdate, nameof(referenceUpdate)); return _reference.Update(owner, name, reference, referenceUpdate).ToObservable(); } /// /// Updates a reference for a given repository by reference name /// /// /// http://developer.github.com/v3/git/refs/#update-a-reference /// /// The Id of the repository /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/master" or "tags/release-1" /// The updated reference data /// public IObservable Update(long repositoryId, string reference, ReferenceUpdate referenceUpdate) { Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); Ensure.ArgumentNotNull(referenceUpdate, nameof(referenceUpdate)); return _reference.Update(repositoryId, reference, referenceUpdate).ToObservable(); } /// /// Deletes a reference for a given repository by reference name /// /// /// http://developer.github.com/v3/git/refs/#delete-a-reference /// /// The owner of the repository /// The name of the repository /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/master" or "tags/release-1" /// public IObservable Delete(string owner, string name, string reference) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); return _reference.Delete(owner, name, reference).ToObservable(); } /// /// Deletes a reference for a given repository by reference name /// /// /// http://developer.github.com/v3/git/refs/#delete-a-reference /// /// The Id of the repository /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/master" or "tags/release-1" /// public IObservable Delete(long repositoryId, string reference) { Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); return _reference.Delete(repositoryId, reference).ToObservable(); } } }