mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-20 22:25:12 +00:00
118 lines
5.0 KiB
C#
118 lines
5.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Octokit
|
|
{
|
|
/// <summary>
|
|
/// A client for GitHub's repository deploy keys API.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See the <a href="https://developer.github.com/v3/repos/keys/">Repository deploy keys API documentation</a> for more information.
|
|
/// </remarks>
|
|
public class RepositoryDeployKeysClient : ApiClient, IRepositoryDeployKeysClient
|
|
{
|
|
/// <summary>
|
|
/// Instantiates a new GitHub repository deploy keys API client.
|
|
/// </summary>
|
|
/// <param name="apiConnection">The API connection.</param>
|
|
public RepositoryDeployKeysClient(IApiConnection apiConnection)
|
|
: base(apiConnection)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get a single deploy key by number for a repository.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See the <a href="https://developer.github.com/v3/repos/keys/#get"> API documentation</a> for more information.
|
|
/// </remarks>
|
|
/// <param name="owner">The owner of the repository.</param>
|
|
/// <param name="name">The name of the repository.</param>
|
|
/// <param name="number">The id of the deploy key.</param>
|
|
public Task<DeployKey> Get(string owner, string name, int number)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
|
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
|
Ensure.ArgumentNotNull(number, "number");
|
|
|
|
return ApiConnection.Get<DeployKey>(ApiUrls.RepositoryDeployKey(owner, name, number));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get all deploy keys for a repository.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See the <a href="https://developer.github.com/v3/repos/keys/#list"> API documentation</a> for more information.
|
|
/// </remarks>
|
|
/// <param name="owner">The owner of the repository.</param>
|
|
/// <param name="name">The name of the repository.</param>
|
|
public Task<IReadOnlyList<DeployKey>> GetForRepository(string owner, string name)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
|
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
|
|
|
return ApiConnection.Get<IReadOnlyList<DeployKey>>(ApiUrls.RepositoryDeployKeys(owner, name));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a new deploy key for a repository.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See the <a href="https://developer.github.com/v3/repos/keys/#create"> API documentation</a> for more information.
|
|
/// </remarks>
|
|
/// <param name="owner">The owner of the repository.</param>
|
|
/// <param name="name">The name of the repository.</param>
|
|
/// <param name="newDeployKey">The deploy key to create for the repository.</param>
|
|
/// <returns></returns>
|
|
public Task<DeployKey> Create(string owner, string name, NewDeployKey newDeployKey)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
|
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
|
Ensure.ArgumentNotNull(newDeployKey, "newDeployKey");
|
|
|
|
if (string.IsNullOrWhiteSpace(newDeployKey.Title))
|
|
throw new ArgumentException("The new deploy key's title must not be null.");
|
|
|
|
if (string.IsNullOrWhiteSpace(newDeployKey.Key))
|
|
throw new ArgumentException("The new deploy key's key must not be null.");
|
|
|
|
return ApiConnection.Post<DeployKey>(ApiUrls.RepositoryDeployKeys(owner, name), newDeployKey);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Deploy keys are immutable. If you need to update a key, remove the key and create a new one instead.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// https://developer.github.com/v3/repos/keys/#edit
|
|
/// </remarks>
|
|
/// <param name="owner"></param>
|
|
/// <param name="name"></param>
|
|
/// <param name="number"></param>
|
|
/// <param name="newDeployKey"></param>
|
|
/// <returns></returns>
|
|
/// Task<DeployKey> Update(string owner, string name, int number, NewDeployKey newDeployKey);
|
|
|
|
/// <summary>
|
|
/// Deletes a deploy key from a repository.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See the <a href="https://developer.github.com/v3/repos/keys/#delete"> API documentation</a> for more information.
|
|
/// </remarks>
|
|
/// <param name="owner">The owner of the repository.</param>
|
|
/// <param name="name">The name of the repository.</param>
|
|
/// <param name="number">The id of the deploy key to delete.</param>
|
|
/// <returns></returns>
|
|
public Task Delete(string owner, string name, int number)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
|
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
|
Ensure.ArgumentNotNull(number, "number");
|
|
|
|
return ApiConnection.Delete(ApiUrls.RepositoryDeployKey(owner, name, number));
|
|
}
|
|
}
|
|
}
|