Files
octokit.net/Octokit/Clients/ReferencesClient.cs
aedampir@gmail.com 2244baf53d added new overloads
2016-06-16 15:32:27 +07:00

237 lines
9.9 KiB
C#

using System.Collections.Generic;
using System.Threading.Tasks;
namespace Octokit
{
/// <summary>
/// A client for GitHub's References API.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/git/refs/">References API documentation</a> for more information.
/// </remarks>
public class ReferencesClient : ApiClient, IReferencesClient
{
/// <summary>
/// Instantiates a new GitHub References API client
/// </summary>
/// <param name="apiConnection">An API connection</param>
public ReferencesClient(IApiConnection apiConnection) :
base(apiConnection)
{
}
/// <summary>
/// Gets a reference for a given repository by reference name
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/refs/#get-a-reference
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="reference">The name of the reference</param>
/// <returns></returns>
public Task<Reference> Get(string owner, string name, string reference)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(reference, "reference");
return ApiConnection.Get<Reference>(ApiUrls.Reference(owner, name, reference));
}
/// <summary>
/// Gets a reference for a given repository by reference name
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/refs/#get-a-reference
/// </remarks>
/// <param name="repositoryId">The ID of the repository</param>
/// <param name="reference">The name of the reference</param>
/// <returns></returns>
public Task<Reference> Get(int repositoryId, string reference)
{
Ensure.ArgumentNotNullOrEmptyString(reference, "reference");
return ApiConnection.Get<Reference>(ApiUrls.Reference(repositoryId, reference));
}
/// <summary>
/// Gets all references for a given repository
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/refs/#get-all-references
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns></returns>
public Task<IReadOnlyList<Reference>> GetAll(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return ApiConnection.GetAll<Reference>(ApiUrls.Reference(owner, name));
}
/// <summary>
/// Gets all references for a given repository
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/refs/#get-all-references
/// </remarks>
/// <param name="repositoryId">The ID of the repository</param>
/// <returns></returns>
public Task<IReadOnlyList<Reference>> GetAll(int repositoryId)
{
return ApiConnection.GetAll<Reference>(ApiUrls.Reference(repositoryId));
}
/// <summary>
/// Gets references for a given repository by sub-namespace, i.e. "tags" or "heads"
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/refs/#get-all-references
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="subNamespace">The sub-namespace to get references for</param>
/// <returns></returns>
public Task<IReadOnlyList<Reference>> 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<Reference>(ApiUrls.Reference(owner, name, subNamespace));
}
/// <summary>
/// Gets references for a given repository by sub-namespace, i.e. "tags" or "heads"
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/refs/#get-all-references
/// </remarks>
/// <param name="repositoryId">The ID of the repository</param>
/// <param name="subNamespace">The sub-namespace to get references for</param>
/// <returns></returns>
public Task<IReadOnlyList<Reference>> GetAllForSubNamespace(int repositoryId, string subNamespace)
{
Ensure.ArgumentNotNullOrEmptyString(subNamespace, "subNamespace");
// TODO: Handle 404 when subNamespace cannot be found
return ApiConnection.GetAll<Reference>(ApiUrls.Reference(repositoryId, subNamespace));
}
/// <summary>
/// Creates a reference for a given repository
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/refs/#create-a-reference
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="reference">The reference to create</param>
/// <returns></returns>
public Task<Reference> Create(string owner, string name, NewReference reference)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(reference, "reference");
return ApiConnection.Post<Reference>(ApiUrls.Reference(owner, name), reference);
}
/// <summary>
/// Creates a reference for a given repository
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/refs/#create-a-reference
/// </remarks>
/// <param name="repositoryId">The ID of the repository</param>
/// <param name="reference">The reference to create</param>
/// <returns></returns>
public Task<Reference> Create(int repositoryId, NewReference reference)
{
Ensure.ArgumentNotNull(reference, "reference");
return ApiConnection.Post<Reference>(ApiUrls.Reference(repositoryId), reference);
}
/// <summary>
/// Updates a reference for a given repository by reference name
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/refs/#update-a-reference
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="reference">The name of the reference</param>
/// <param name="referenceUpdate">The updated reference data</param>
/// <returns></returns>
public Task<Reference> 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<Reference>(ApiUrls.Reference(owner, name, reference), referenceUpdate);
}
/// <summary>
/// Updates a reference for a given repository by reference name
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/refs/#update-a-reference
/// </remarks>
/// <param name="repositoryId">The ID of the repository</param>
/// <param name="reference">The name of the reference</param>
/// <param name="referenceUpdate">The updated reference data</param>
/// <returns></returns>
public Task<Reference> Update(int repositoryId, string reference, ReferenceUpdate referenceUpdate)
{
Ensure.ArgumentNotNullOrEmptyString(reference, "reference");
Ensure.ArgumentNotNull(referenceUpdate, "update");
return ApiConnection.Patch<Reference>(ApiUrls.Reference(repositoryId, reference), referenceUpdate);
}
/// <summary>
/// Deletes a reference for a given repository by reference name
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/refs/#delete-a-reference
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="reference">The name of the reference</param>
/// <returns></returns>
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));
}
/// <summary>
/// Deletes a reference for a given repository by reference name
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/refs/#delete-a-reference
/// </remarks>
/// <param name="repositoryId">The ID of the repository</param>
/// <param name="reference">The name of the reference</param>
/// <returns></returns>
public Task Delete(int repositoryId, string reference)
{
Ensure.ArgumentNotNullOrEmptyString(reference, "reference");
return ApiConnection.Delete(ApiUrls.Reference(repositoryId, reference));
}
}
}