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 name of the reference /// public Task Get(string owner, string name, string reference) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); 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 name of the reference /// public Task Get(int repositoryId, string reference) { Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); 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 /// public Task> GetAll(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); return ApiConnection.GetAll(ApiUrls.Reference(owner, name)); } /// /// Gets all references for a given repository /// /// /// http://developer.github.com/v3/git/refs/#get-all-references /// /// The ID of the repository /// public Task> GetAll(int repositoryId) { return ApiConnection.GetAll(ApiUrls.Reference(repositoryId)); } /// /// 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 Task> GetAllForSubNamespace(string owner, string name, string subNamespace) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(subNamespace, "subNamespace"); // TODO: Handle 404 when subNamespace cannot be found return ApiConnection.GetAll(ApiUrls.Reference(owner, name, subNamespace)); } /// /// 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 Task> GetAllForSubNamespace(int repositoryId, string subNamespace) { Ensure.ArgumentNotNullOrEmptyString(subNamespace, "subNamespace"); // TODO: Handle 404 when subNamespace cannot be found return ApiConnection.GetAll(ApiUrls.Reference(repositoryId, subNamespace)); } /// /// 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 Task Create(string owner, string name, NewReference reference) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(reference, "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 /// public Task Create(int repositoryId, NewReference reference) { Ensure.ArgumentNotNull(reference, "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 name of the reference /// The updated reference data /// public Task Update(string owner, string name, string reference, ReferenceUpdate referenceUpdate) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); Ensure.ArgumentNotNull(referenceUpdate, "update"); 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 name of the reference /// The updated reference data /// public Task Update(int repositoryId, string reference, ReferenceUpdate referenceUpdate) { Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); Ensure.ArgumentNotNull(referenceUpdate, "update"); 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 name of the reference /// public Task Delete(string owner, string name, string reference) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); 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 name of the reference /// public Task Delete(int repositoryId, string reference) { Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); return ApiConnection.Delete(ApiUrls.Reference(repositoryId, reference)); } } }