using System.Collections.Generic; using System.Threading.Tasks; namespace Octokit { /// /// A client for GitHub's References API. /// /// /// See the References API documentation for more information. /// public class ReferencesClient : ApiClient, IReferencesClient { /// /// Instantiates a new GitHub References API client /// /// An API connection public ReferencesClient(IApiConnection apiConnection) : base(apiConnection) { } /// /// 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 reference name /// /// The reference 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") /// [ManualRoute("GET", "/repos/{owner}/{repo}/git/refs/{ref}")] public Task Get(string owner, string name, string reference) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); if (reference.StartsWith("refs/")) { reference = reference.Replace("refs/", string.Empty); } return ApiConnection.Get(ApiUrls.Reference(owner, name, reference)); } /// /// 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 reference name /// /// The reference 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") /// [ManualRoute("GET", "/repositories/{id}/git/refs/{ref}")] public Task Get(long repositoryId, string reference) { Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); if (reference.StartsWith("refs/")) { reference = reference.Replace("refs/", string.Empty); } return ApiConnection.Get(ApiUrls.Reference(repositoryId, reference)); } /// /// 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 /// [ManualRoute("GET", "/repos/{owner}/{repo}/git/refs")] public Task> 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 /// [ManualRoute("GET", "/repos/{owner}/{repo}/git/refs")] public Task> GetAll(string owner, string name, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(options, nameof(options)); return ApiConnection.GetAll(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 /// [ManualRoute("GET", "/repositories/{id}/git/refs")] public Task> 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 /// [ManualRoute("GET", "/repositories/{id}/git/refs")] public Task> GetAll(long repositoryId, ApiOptions options) { Ensure.ArgumentNotNull(options, nameof(options)); return ApiConnection.GetAll(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 /// [ManualRoute("GET", "/repos/{owner}/{repo}/git/refs/{ref}")] public Task> 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 reference 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") /// [ManualRoute("GET", "/repos/{owner}/{repo}/git/refs/{ref}")] public Task> 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 ApiConnection.GetAll(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 /// [ManualRoute("GET", "/repositories/{id}/git/refs/{ref}")] public Task> 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") /// [ManualRoute("GET", "/repositories/{id}/git/refs/{ref}")] public Task> 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 ApiConnection.GetAll(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 /// [ManualRoute("POST", "/repos/{owner}/{repo}/git/refs")] public Task Create(string owner, string name, NewReference reference) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(reference, nameof(reference)); return ApiConnection.Post(ApiUrls.Reference(owner, name), reference); } /// /// 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 /// [ManualRoute("POST", "/repositories/{id}/git/refs")] public Task Create(long repositoryId, NewReference reference) { Ensure.ArgumentNotNull(reference, nameof(reference)); return ApiConnection.Post(ApiUrls.Reference(repositoryId), reference); } /// /// 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 reference name /// The updated reference data /// /// The reference 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") /// [ManualRoute("PATCH", "/repos/{owner}/{repo}/git/refs/{ref}")] public Task 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)); if (reference.StartsWith("refs/")) { reference = reference.Replace("refs/", string.Empty); } return ApiConnection.Patch(ApiUrls.Reference(owner, name, reference), referenceUpdate); } /// /// 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 reference name /// The updated reference data /// /// The reference 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") /// [ManualRoute("PATCH", "/repositories/{id}/git/refs/{ref}")] public Task Update(long repositoryId, string reference, ReferenceUpdate referenceUpdate) { Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); Ensure.ArgumentNotNull(referenceUpdate, nameof(referenceUpdate)); if (reference.StartsWith("refs/")) { reference = reference.Replace("refs/", string.Empty); } return ApiConnection.Patch(ApiUrls.Reference(repositoryId, reference), referenceUpdate); } /// /// 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 reference name /// /// The reference 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") /// [ManualRoute("PATCH", "/repos/{owner}/{repo}/git/refs/{ref}")] public Task Delete(string owner, string name, string reference) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); if (reference.StartsWith("refs/")) { reference = reference.Replace("refs/", string.Empty); } return ApiConnection.Delete(ApiUrls.Reference(owner, name, reference)); } /// /// 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 reference name /// /// The reference 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") /// [ManualRoute("DELETE", "/repositories/{id}/git/refs/{ref}")] public Task Delete(long repositoryId, string reference) { Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); if (reference.StartsWith("refs/")) { reference = reference.Replace("refs/", string.Empty); } return ApiConnection.Delete(ApiUrls.Reference(repositoryId, reference)); } } }