using System;
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
namespace Octokit
{
///
/// A client for GitHub's Repository Branches API.
///
///
/// See the Repository Branches API documentation for more details.
///
public class RepositoryBranchesClient : ApiClient, IRepositoryBranchesClient
{
///
/// Initializes a new GitHub Repository Branches API client.
///
/// An API connection
public RepositoryBranchesClient(IApiConnection apiConnection)
: base(apiConnection)
{
}
///
/// Gets all the branches for the specified repository.
///
///
/// See the API documentation for more details
///
/// The owner of the repository
/// The name of the repository
[ManualRoute("GET", "/repos/{owner}/{repo}/branches")]
public Task> GetAll(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
return GetAll(owner, name, ApiOptions.None);
}
///
/// Gets all the branches for the specified repository.
///
///
/// See the API documentation for more details
///
/// The Id of the repository
[ManualRoute("GET", "/repositories/{id}/branches")]
public Task> GetAll(long repositoryId)
{
return GetAll(repositoryId, ApiOptions.None);
}
///
/// Gets all the branches for the specified repository.
///
///
/// See the API documentation for more details
///
/// The owner of the repository
/// The name of the repository
/// Options for changing the API response
/// Thrown when a general API error occurs.
[Preview("luke-cage")]
[ManualRoute("GET", "/repos/{owner}/{repo}/branches")]
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.RepoBranches(owner, name), null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview, options);
}
///
/// Gets all the branches for the specified repository.
///
///
/// See the API documentation for more details
///
/// The Id of the repository
/// Options for changing the API response
[Preview("luke-cage")]
[ManualRoute("GET", "/repositories/{id}/branches")]
public Task> GetAll(long repositoryId, ApiOptions options)
{
Ensure.ArgumentNotNull(options, nameof(options));
return ApiConnection.GetAll(ApiUrls.RepoBranches(repositoryId), null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview, options);
}
///
/// Gets the specified branch.
///
///
/// See the API documentation for more details
///
/// The owner of the repository
/// The name of the repository
/// The name of the branch
[Preview("luke-cage")]
[ManualRoute("GET", "/repos/{owner}/{repo}/branches/{branch}")]
public Task Get(string owner, string name, string branch)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
return ApiConnection.Get(ApiUrls.RepoBranch(owner, name, branch), null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Gets the specified branch.
///
///
/// See the API documentation for more details
///
/// The Id of the repository
/// The name of the branch
[Preview("luke-cage")]
[ManualRoute("GET", "/repositories/{id}/branches/{branch}")]
public Task Get(long repositoryId, string branch)
{
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
return ApiConnection.Get(ApiUrls.RepoBranch(repositoryId, branch), null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Get the branch protection settings for the specified branch
///
///
/// See the API documentation for more details
///
/// The owner of the repository
/// The name of the repository
/// The name of the branch
[Preview("luke-cage")]
[ManualRoute("GET", "/repos/{owner}/{repo}/branches/{branch}/protection")]
public Task GetBranchProtection(string owner, string name, string branch)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
return ApiConnection.Get(ApiUrls.RepoBranchProtection(owner, name, branch), null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Get the branch protection settings for the specified branch
///
///
/// See the API documentation for more details
///
/// The Id of the repository
/// The name of the branch
[Preview("luke-cage")]
[ManualRoute("GET", "/repositories/{id}/branches/{branch}/protection")]
public Task GetBranchProtection(long repositoryId, string branch)
{
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
return ApiConnection.Get(ApiUrls.RepoBranchProtection(repositoryId, branch), null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Update the branch protection settings for the specified branch
///
///
/// See the API documentation for more details
///
/// The owner of the repository
/// The name of the repository
/// The name of the branch
/// Branch protection settings
[Preview("luke-cage")]
[ManualRoute("PUT", "/repos/{owner}/{repo}/branches/{branch}/protection")]
public Task UpdateBranchProtection(string owner, string name, string branch, BranchProtectionSettingsUpdate update)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
Ensure.ArgumentNotNull(update, nameof(update));
return ApiConnection.Put(ApiUrls.RepoBranchProtection(owner, name, branch), update, null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Update the branch protection settings for the specified branch
///
///
/// See the API documentation for more details
///
/// The Id of the repository
/// The name of the branch
/// Branch protection settings
[Preview("luke-cage")]
[ManualRoute("PUT", "/repositories/{id}/branches/{branch}/protection")]
public Task UpdateBranchProtection(long repositoryId, string branch, BranchProtectionSettingsUpdate update)
{
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
Ensure.ArgumentNotNull(update, nameof(update));
return ApiConnection.Put(ApiUrls.RepoBranchProtection(repositoryId, branch), update, null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Remove the branch protection settings for the specified branch
///
///
/// See the API documentation for more details
///
/// The owner of the repository
/// The name of the repository
/// The name of the branch
[Preview("luke-cage")]
[ManualRoute("DELETE", "/repos/{owner}/{repo}/branches/{branch}/protection")]
public async Task DeleteBranchProtection(string owner, string name, string branch)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
var endpoint = ApiUrls.RepoBranchProtection(owner, name, branch);
try
{
var httpStatusCode = await Connection.Delete(endpoint, null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview).ConfigureAwait(false);
return httpStatusCode == HttpStatusCode.NoContent;
}
catch (NotFoundException)
{
return false;
}
}
///
/// Remove the branch protection settings for the specified branch
///
///
/// See the API documentation for more details
///
/// The Id of the repository
/// The name of the branch
[Preview("luke-cage")]
[ManualRoute("DELETE", "/repositories/{id}/branches/{branch}/protection")]
public async Task DeleteBranchProtection(long repositoryId, string branch)
{
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
var endpoint = ApiUrls.RepoBranchProtection(repositoryId, branch);
try
{
var httpStatusCode = await Connection.Delete(endpoint, null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview).ConfigureAwait(false);
return httpStatusCode == HttpStatusCode.NoContent;
}
catch (NotFoundException)
{
return false;
}
}
///
/// Get the required status checks for the specified branch
///
///
/// See the API documentation for more details
///
/// The owner of the repository
/// The name of the repository
/// The name of the branch
[Preview("luke-cage")]
[ManualRoute("GET", "/repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks")]
public Task GetRequiredStatusChecks(string owner, string name, string branch)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
return ApiConnection.Get(ApiUrls.RepoRequiredStatusChecks(owner, name, branch), null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Get the required status checks for the specified branch
///
///
/// See the API documentation for more details
///
/// The Id of the repository
/// The name of the branch
[Preview("luke-cage")]
[ManualRoute("GET", "/repositories/{id}/branches/{branch}/protection/required_status_checks")]
public Task GetRequiredStatusChecks(long repositoryId, string branch)
{
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
return ApiConnection.Get(ApiUrls.RepoRequiredStatusChecks(repositoryId, branch), null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Replace required status checks for the specified branch
///
///
/// See the API documentation for more details
///
/// The owner of the repository
/// The name of the repository
/// The name of the branch
/// Required status checks
[Preview("luke-cage")]
[ManualRoute("PATCH", "/repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks")]
public Task UpdateRequiredStatusChecks(string owner, string name, string branch, BranchProtectionRequiredStatusChecksUpdate update)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
Ensure.ArgumentNotNull(update, nameof(update));
return ApiConnection.Patch(ApiUrls.RepoRequiredStatusChecks(owner, name, branch), update, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Replace required status checks for the specified branch
///
///
/// See the API documentation for more details
///
/// The Id of the repository
/// The name of the branch
/// Required status checks
[Preview("luke-cage")]
[ManualRoute("PATCH", "/repositories/{id}/branches/{branch}/protection/required_status_checks")]
public Task UpdateRequiredStatusChecks(long repositoryId, string branch, BranchProtectionRequiredStatusChecksUpdate update)
{
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
Ensure.ArgumentNotNull(update, nameof(update));
return ApiConnection.Patch(ApiUrls.RepoRequiredStatusChecks(repositoryId, branch), update, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Remove required status checks for the specified branch
///
///
/// See the API documentation for more details
///
/// The owner of the repository
/// The name of the repository
/// The name of the branch
[Preview("luke-cage")]
[ManualRoute("DELETE", "/repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks")]
public async Task DeleteRequiredStatusChecks(string owner, string name, string branch)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
var endpoint = ApiUrls.RepoRequiredStatusChecks(owner, name, branch);
try
{
var httpStatusCode = await Connection.Delete(endpoint, null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview).ConfigureAwait(false);
return httpStatusCode == HttpStatusCode.NoContent;
}
catch (NotFoundException)
{
return false;
}
}
///
/// Remove required status checks for the specified branch
///
///
/// See the API documentation for more details
///
/// The Id of the repository
/// The name of the branch
[Preview("luke-cage")]
[ManualRoute("DELETE", "/repositories/{id}/branches/{branch}/protection/required_status_checks")]
public async Task DeleteRequiredStatusChecks(long repositoryId, string branch)
{
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
var endpoint = ApiUrls.RepoRequiredStatusChecks(repositoryId, branch);
try
{
var httpStatusCode = await Connection.Delete(endpoint, null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview).ConfigureAwait(false);
return httpStatusCode == HttpStatusCode.NoContent;
}
catch (NotFoundException)
{
return false;
}
}
///
/// Get the required status checks contexts for the specified branch
///
///
/// See the API documentation for more details
///
/// The owner of the repository
/// The name of the repository
/// The name of the branch
[Preview("luke-cage")]
[ManualRoute("GET", "/repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks/contexts")]
public Task> GetAllRequiredStatusChecksContexts(string owner, string name, string branch)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
return ApiConnection.Get>(ApiUrls.RepoRequiredStatusChecksContexts(owner, name, branch), null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Get the required status checks contexts for the specified branch
///
///
/// See the API documentation for more details
///
/// The Id of the repository
/// The name of the branch
[Preview("luke-cage")]
[ManualRoute("GET", "/repositories/{id}/branches/{branch}/protection/required_status_checks/contexts")]
public Task> GetAllRequiredStatusChecksContexts(long repositoryId, string branch)
{
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
return ApiConnection.Get>(ApiUrls.RepoRequiredStatusChecksContexts(repositoryId, branch), null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Replace the required status checks contexts for the specified branch
///
///
/// See the API documentation for more details
///
/// The owner of the repository
/// The name of the repository
/// The name of the branch
/// The contexts to replace
[Preview("luke-cage")]
[ManualRoute("PUT", "/repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks/contexts")]
public Task> UpdateRequiredStatusChecksContexts(string owner, string name, string branch, IReadOnlyList contexts)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
Ensure.ArgumentNotNull(contexts, nameof(contexts));
return ApiConnection.Put>(ApiUrls.RepoRequiredStatusChecksContexts(owner, name, branch), contexts, null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Replace the required status checks contexts for the specified branch
///
///
/// See the API documentation for more details
///
/// The Id of the repository
/// The name of the branch
/// The contexts to replace
[Preview("luke-cage")]
[ManualRoute("PUT", "/repositories/{id}/branches/{branch}/protection/required_status_checks/contexts")]
public Task> UpdateRequiredStatusChecksContexts(long repositoryId, string branch, IReadOnlyList contexts)
{
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
Ensure.ArgumentNotNull(contexts, nameof(contexts));
return ApiConnection.Put>(ApiUrls.RepoRequiredStatusChecksContexts(repositoryId, branch), contexts, null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Add the required status checks context for the specified branch
///
///
/// See the API documentation for more details
///
/// The owner of the repository
/// The name of the repository
/// The name of the branch
/// The contexts to add
[Preview("luke-cage")]
[ManualRoute("POST", "/repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks/contexts")]
public Task> AddRequiredStatusChecksContexts(string owner, string name, string branch, IReadOnlyList contexts)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
Ensure.ArgumentNotNull(contexts, nameof(contexts));
return ApiConnection.Post>(ApiUrls.RepoRequiredStatusChecksContexts(owner, name, branch), contexts, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Add the required status checks contexts for the specified branch
///
///
/// See the API documentation for more details
///
/// The Id of the repository
/// The name of the branch
/// The contexts to add
[Preview("luke-cage")]
[ManualRoute("POST", "/repositories/{id}/branches/{branch}/protection/required_status_checks/contexts")]
public Task> AddRequiredStatusChecksContexts(long repositoryId, string branch, IReadOnlyList contexts)
{
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
Ensure.ArgumentNotNull(contexts, nameof(contexts));
return ApiConnection.Post>(ApiUrls.RepoRequiredStatusChecksContexts(repositoryId, branch), contexts, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Remove the required status checks context for the specified branch
///
///
/// See the API documentation for more details
///
/// The owner of the repository
/// The name of the repository
/// The name of the branch
/// The contexts to remove
[Preview("luke-cage")]
[ManualRoute("DELETE", "/repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks/contexts")]
public Task> DeleteRequiredStatusChecksContexts(string owner, string name, string branch, IReadOnlyList contexts)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
Ensure.ArgumentNotNull(contexts, nameof(contexts));
return ApiConnection.Delete>(ApiUrls.RepoRequiredStatusChecksContexts(owner, name, branch), contexts, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Remove the required status checks contexts for the specified branch
///
///
/// See the API documentation for more details
///
/// The Id of the repository
/// The name of the branch
/// The contexts to remove
[Preview("luke-cage")]
[ManualRoute("DELETE", "/repositories/{id}/branches/{branch}/protection/required_status_checks/contexts")]
public Task> DeleteRequiredStatusChecksContexts(long repositoryId, string branch, IReadOnlyList contexts)
{
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
Ensure.ArgumentNotNull(contexts, nameof(contexts));
return ApiConnection.Delete>(ApiUrls.RepoRequiredStatusChecksContexts(repositoryId, branch), contexts, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Get required pull request review enforcement of protected branch
///
///
/// See the API documentation for more details
///
/// The owner of the repository
/// The name of the repository
/// The name of the branch
[Preview("luke-cage")]
[ManualRoute("GET", "/repos/{owner}/{repo}/branches/{branch}/protection/required_pull_request_reviews")]
public Task GetReviewEnforcement(string owner, string name, string branch)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
return ApiConnection.Get(ApiUrls.RepoProtectedBranchReviewEnforcement(owner, name, branch), null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Get required pull request review enforcement of protected branch
///
///
/// See the API documentation for more details
///
/// The Id of the repository
/// The name of the branch
[Preview("luke-cage")]
[ManualRoute("GET", "/repositories/{id}/branches/{branch}/protection/required_pull_request_reviews")]
public Task GetReviewEnforcement(long repositoryId, string branch)
{
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
return ApiConnection.Get(ApiUrls.RepoProtectedBranchReviewEnforcement(repositoryId, branch), null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Update required pull request review enforcement of protected branch
///
///
/// See the API documentation for more details
///
/// The owner of the repository
/// The name of the repository
/// The name of the branch
/// The required pull request review settings
[Preview("luke-cage")]
[ManualRoute("PATCH", "/repos/{owner}/{repo}/branches/{branch}/protection/required_pull_request_reviews")]
public Task UpdateReviewEnforcement(string owner, string name, string branch, BranchProtectionRequiredReviewsUpdate update)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
Ensure.ArgumentNotNull(update, nameof(update));
return ApiConnection.Patch(ApiUrls.RepoProtectedBranchReviewEnforcement(owner, name, branch), update, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Update required pull request review enforcement of protected branch
///
///
/// See the API documentation for more details
///
/// The Id of the repository
/// The name of the branch
/// The required pull request review settings
[Preview("luke-cage")]
[ManualRoute("GET", "/repositories/{id}/branches/{branch}/protection/required_pull_request_reviews")]
public Task UpdateReviewEnforcement(long repositoryId, string branch, BranchProtectionRequiredReviewsUpdate update)
{
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
Ensure.ArgumentNotNull(update, nameof(update));
return ApiConnection.Patch(ApiUrls.RepoProtectedBranchReviewEnforcement(repositoryId, branch), update, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Remove required pull request review enforcement of protected branch
///
///
/// See the API documentation for more details
///
/// The owner of the repository
/// The name of the repository
/// The name of the branch
[Preview("luke-cage")]
[ManualRoute("DELETE", "/repos/{owner}/{repo}/branches/{branch}/protection/required_pull_request_reviews")]
public async Task RemoveReviewEnforcement(string owner, string name, string branch)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
var endpoint = ApiUrls.RepoProtectedBranchReviewEnforcement(owner, name, branch);
try
{
var httpStatusCode = await Connection.Delete(endpoint, null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview).ConfigureAwait(false);
return httpStatusCode == HttpStatusCode.NoContent;
}
catch (NotFoundException)
{
return false;
}
}
///
/// Remove required pull request review enforcement of protected branch
///
///
/// See the API documentation for more details
///
/// The Id of the repository
/// The name of the branch
[Preview("luke-cage")]
[ManualRoute("DELETE", "/repositories/{id}/branches/{branch}/protection/required_pull_request_reviews")]
public async Task RemoveReviewEnforcement(long repositoryId, string branch)
{
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
var endpoint = ApiUrls.RepoProtectedBranchReviewEnforcement(repositoryId, branch);
try
{
var httpStatusCode = await Connection.Delete(endpoint, null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview).ConfigureAwait(false);
return httpStatusCode == HttpStatusCode.NoContent;
}
catch (NotFoundException)
{
return false;
}
}
///
/// Get admin enforcement of protected branch
///
///
/// See the API documentation for more details
///
/// The owner of the repository
/// The name of the repository
/// The name of the branch
[Preview("luke-cage")]
[ManualRoute("GET", "/repos/{owner}/{repo}/branches/{branch}/protection/enforce_admins")]
public Task GetAdminEnforcement(string owner, string name, string branch)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
return ApiConnection.Get(ApiUrls.RepoProtectedBranchAdminEnforcement(owner, name, branch), null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Get admin enforcement of protected branch
///
///
/// See the API documentation for more details
///
/// The Id of the repository
/// The name of the branch
[Preview("luke-cage")]
[ManualRoute("GET", "/repositories/{id}/branches/{branch}/protection/enforce_admins")]
public Task GetAdminEnforcement(long repositoryId, string branch)
{
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
return ApiConnection.Get(ApiUrls.RepoProtectedBranchAdminEnforcement(repositoryId, branch), null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Add admin enforcement to protected branch
///
///
/// See the API documentation for more details
///
/// The owner of the repository
/// The name of the repository
/// The name of the branch
[Preview("luke-cage")]
[ManualRoute("POST", "/repos/{owner}/{repo}/branches/{branch}/protection/enforce_admins")]
public Task AddAdminEnforcement(string owner, string name, string branch)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
return ApiConnection.Post(ApiUrls.RepoProtectedBranchAdminEnforcement(owner, name, branch), new object(), AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Add admin enforcement to protected branch
///
///
/// See the API documentation for more details
///
/// The Id of the repository
/// The name of the branch
[Preview("luke-cage")]
[ManualRoute("POST", "/repositories/{id}/branches/{branch}/protection/enforce_admins")]
public Task AddAdminEnforcement(long repositoryId, string branch)
{
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
return ApiConnection.Post(ApiUrls.RepoProtectedBranchAdminEnforcement(repositoryId, branch), new object(), AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Remove admin enforcement on protected branch
///
///
/// See the API documentation for more details
///
/// The owner of the repository
/// The name of the repository
/// The name of the branch
[Preview("luke-cage")]
[ManualRoute("DELETE", "/repos/{owner}/{repo}/branches/{branch}/protection/enforce_admins")]
public async Task RemoveAdminEnforcement(string owner, string name, string branch)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
var endpoint = ApiUrls.RepoProtectedBranchAdminEnforcement(owner, name, branch);
try
{
var httpStatusCode = await Connection.Delete(endpoint, null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview).ConfigureAwait(false);
return httpStatusCode == HttpStatusCode.NoContent;
}
catch (NotFoundException)
{
return false;
}
}
///
/// Remove admin enforcement on protected branch
///
///
/// See the API documentation for more details
///
/// The Id of the repository
/// The name of the branch
[Preview("luke-cage")]
[ManualRoute("DELETE", "/repositories/{id}/branches/{branch}/protection/enforce_admins")]
public async Task RemoveAdminEnforcement(long repositoryId, string branch)
{
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
var endpoint = ApiUrls.RepoProtectedBranchAdminEnforcement(repositoryId, branch);
try
{
var httpStatusCode = await Connection.Delete(endpoint, null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview).ConfigureAwait(false);
return httpStatusCode == HttpStatusCode.NoContent;
}
catch (NotFoundException)
{
return false;
}
}
///
/// Get restrictions for the specified branch (applies only to Organization owned repositories)
///
///
/// See the API documentation for more details
///
/// The owner of the repository
/// The name of the repository
/// The name of the branch
[Preview("luke-cage")]
[ManualRoute("GET", "/repos/{owner}/{repo}/branches/{branch}/protection/restrictions")]
public Task GetProtectedBranchRestrictions(string owner, string name, string branch)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
return ApiConnection.Get(ApiUrls.RepoRestrictions(owner, name, branch), null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Get restrictions for the specified branch (applies only to Organization owned repositories)
///
///
/// See the API documentation for more details
///
/// The Id of the repository
/// The name of the branch
[Preview("luke-cage")]
[ManualRoute("GET", "/repositories/{id}/branches/{branch}/protection/restrictions")]
public Task GetProtectedBranchRestrictions(long repositoryId, string branch)
{
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
return ApiConnection.Get(ApiUrls.RepoRestrictions(repositoryId, branch), null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Remove restrictions for the specified branch (applies only to Organization owned repositories)
///
///
/// See the API documentation for more details
///
/// The owner of the repository
/// The name of the repository
/// The name of the branch
[Preview("luke-cage")]
[ManualRoute("DELETE", "/repos/{owner}/{repo}/branches/{branch}/protection/restrictions")]
public async Task DeleteProtectedBranchRestrictions(string owner, string name, string branch)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
var endpoint = ApiUrls.RepoRestrictions(owner, name, branch);
try
{
var httpStatusCode = await Connection.Delete(endpoint, null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview).ConfigureAwait(false);
return httpStatusCode == HttpStatusCode.NoContent;
}
catch (NotFoundException)
{
return false;
}
}
///
/// Remove restrictions for the specified branch (applies only to Organization owned repositories)
///
///
/// See the API documentation for more details
///
/// The Id of the repository
/// The name of the branch
[Preview("luke-cage")]
[ManualRoute("DELETE", "/repositories/{id}/branches/{branch}/protection/restrictions")]
public async Task DeleteProtectedBranchRestrictions(long repositoryId, string branch)
{
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
var endpoint = ApiUrls.RepoRestrictions(repositoryId, branch);
try
{
var httpStatusCode = await Connection.Delete(endpoint, null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview).ConfigureAwait(false);
return httpStatusCode == HttpStatusCode.NoContent;
}
catch (NotFoundException)
{
return false;
}
}
///
/// Get team restrictions for the specified branch (applies only to Organization owned repositories)
///
///
/// See the API documentation for more details
///
/// The owner of the repository
/// The name of the repository
/// The name of the branch
[Preview("luke-cage")]
[ManualRoute("GET", "/repos/{owner}/{repo}/branches/{branch}/protection/restrictions/teams")]
public Task> GetAllProtectedBranchTeamRestrictions(string owner, string name, string branch)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
return ApiConnection.Get>(ApiUrls.RepoRestrictionsTeams(owner, name, branch), null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Get team restrictions for the specified branch (applies only to Organization owned repositories)
///
///
/// See the API documentation for more details
///
/// The Id of the repository
/// The name of the branch
[Preview("luke-cage")]
[ManualRoute("GET", "/repositories/{id}/branches/{branch}/protection/restrictions/teams")]
public Task> GetAllProtectedBranchTeamRestrictions(long repositoryId, string branch)
{
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
return ApiConnection.Get>(ApiUrls.RepoRestrictionsTeams(repositoryId, branch), null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Replace team restrictions for the specified branch (applies only to Organization owned repositories)
///
///
/// See the API documentation for more details
///
/// The owner of the repository
/// The name of the repository
/// The name of the branch
/// List of teams with push access
[Preview("luke-cage")]
[ManualRoute("PUT", "/repos/{owner}/{repo}/branches/{branch}/protection/restrictions/teams")]
public Task> UpdateProtectedBranchTeamRestrictions(string owner, string name, string branch, BranchProtectionTeamCollection teams)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
Ensure.ArgumentNotNull(teams, nameof(teams));
return ApiConnection.Put>(ApiUrls.RepoRestrictionsTeams(owner, name, branch), teams, null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Replace team restrictions for the specified branch (applies only to Organization owned repositories)
///
///
/// See the API documentation for more details
///
/// The Id of the repository
/// The name of the branch
/// List of teams with push access
[Preview("luke-cage")]
[ManualRoute("PUT", "/repositories/{id}/branches/{branch}/protection/restrictions/teams")]
public Task> UpdateProtectedBranchTeamRestrictions(long repositoryId, string branch, BranchProtectionTeamCollection teams)
{
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
Ensure.ArgumentNotNull(teams, nameof(teams));
return ApiConnection.Put>(ApiUrls.RepoRestrictionsTeams(repositoryId, branch), teams, null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Add team restrictions for the specified branch (applies only to Organization owned repositories)
///
///
/// See the API documentation for more details
///
/// The owner of the repository
/// The name of the repository
/// The name of the branch
/// List of teams with push access to add
[Preview("luke-cage")]
[ManualRoute("POST", "/repos/{owner}/{repo}/branches/{branch}/protection/restrictions/teams")]
public Task> AddProtectedBranchTeamRestrictions(string owner, string name, string branch, BranchProtectionTeamCollection teams)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
Ensure.ArgumentNotNull(teams, nameof(teams));
return ApiConnection.Post>(ApiUrls.RepoRestrictionsTeams(owner, name, branch), teams, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Add team restrictions for the specified branch (applies only to Organization owned repositories)
///
///
/// See the API documentation for more details
///
/// The Id of the repository
/// The name of the branch
/// List of teams with push access to add
[Preview("luke-cage")]
[ManualRoute("POST", "/repositories/{id}/branches/{branch}/protection/restrictions/teams")]
public Task> AddProtectedBranchTeamRestrictions(long repositoryId, string branch, BranchProtectionTeamCollection teams)
{
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
Ensure.ArgumentNotNull(teams, nameof(teams));
return ApiConnection.Post>(ApiUrls.RepoRestrictionsTeams(repositoryId, branch), teams, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Remove team restrictions for the specified branch (applies only to Organization owned repositories)
///
///
/// See the API documentation for more details
///
/// The owner of the repository
/// The name of the repository
/// The name of the branch
/// List of teams to remove
[Preview("luke-cage")]
[ManualRoute("DELETE", "/repos/{owner}/{repo}/branches/{branch}/protection/restrictions/teams")]
public Task> DeleteProtectedBranchTeamRestrictions(string owner, string name, string branch, BranchProtectionTeamCollection teams)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
Ensure.ArgumentNotNull(teams, nameof(teams));
return ApiConnection.Delete>(ApiUrls.RepoRestrictionsTeams(owner, name, branch), teams, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Remove team restrictions for the specified branch (applies only to Organization owned repositories)
///
///
/// See the API documentation for more details
///
/// The Id of the repository
/// The name of the branch
/// List of teams to remove
[Preview("luke-cage")]
[ManualRoute("DELETE", "/repositories/{id}/branches/{branch}/protection/restrictions/teams")]
public Task> DeleteProtectedBranchTeamRestrictions(long repositoryId, string branch, BranchProtectionTeamCollection teams)
{
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
Ensure.ArgumentNotNull(teams, nameof(teams));
return ApiConnection.Delete>(ApiUrls.RepoRestrictionsTeams(repositoryId, branch), teams, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Get user restrictions for the specified branch (applies only to Organization owned repositories)
///
///
/// See the API documentation for more details
///
/// The owner of the repository
/// The name of the repository
/// The name of the branch
[Preview("luke-cage")]
[ManualRoute("GET", "/repos/{owner}/{repo}/branches/{branch}/protection/restrictions/users")]
public Task> GetAllProtectedBranchUserRestrictions(string owner, string name, string branch)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
return ApiConnection.Get>(ApiUrls.RepoRestrictionsUsers(owner, name, branch), null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Get user restrictions for the specified branch (applies only to Organization owned repositories)
///
///
/// See the API documentation for more details
///
/// The Id of the repository
/// The name of the branch
[Preview("luke-cage")]
[ManualRoute("GET", "/repositories/{id}/branches/{branch}/protection/restrictions/users")]
public Task> GetAllProtectedBranchUserRestrictions(long repositoryId, string branch)
{
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
return ApiConnection.Get>(ApiUrls.RepoRestrictionsUsers(repositoryId, branch), null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Replace user restrictions for the specified branch (applies only to Organization owned repositories)
///
///
/// See the API documentation for more details
///
/// The owner of the repository
/// The name of the repository
/// The name of the branch
/// List of users with push access
[Preview("luke-cage")]
[ManualRoute("UPDATE", "/repos/{owner}/{repo}/branches/{branch}/protection/restrictions/users")]
public Task> UpdateProtectedBranchUserRestrictions(string owner, string name, string branch, BranchProtectionUserCollection users)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
Ensure.ArgumentNotNull(users, nameof(users));
return ApiConnection.Put>(ApiUrls.RepoRestrictionsUsers(owner, name, branch), users, null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Replace user restrictions for the specified branch (applies only to Organization owned repositories)
///
///
/// See the API documentation for more details
///
/// The Id of the repository
/// The name of the branch
/// List of users with push access
[Preview("luke-cage")]
[ManualRoute("PUT", "/repositories/{id}/branches/{branch}/protection/restrictions/users")]
public Task> UpdateProtectedBranchUserRestrictions(long repositoryId, string branch, BranchProtectionUserCollection users)
{
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
Ensure.ArgumentNotNull(users, nameof(users));
return ApiConnection.Put>(ApiUrls.RepoRestrictionsUsers(repositoryId, branch), users, null, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Add user restrictions for the specified branch (applies only to Organization owned repositories)
///
///
/// See the API documentation for more details
///
/// The owner of the repository
/// The name of the repository
/// The name of the branch
/// List of users with push access to add
[Preview("luke-cage")]
[ManualRoute("POST", "/repos/{owner}/{repo}/branches/{branch}/protection/restrictions/users")]
public Task> AddProtectedBranchUserRestrictions(string owner, string name, string branch, BranchProtectionUserCollection users)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
Ensure.ArgumentNotNull(users, nameof(users));
return ApiConnection.Post>(ApiUrls.RepoRestrictionsUsers(owner, name, branch), users, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Add user restrictions for the specified branch (applies only to Organization owned repositories)
///
///
/// See the API documentation for more details
///
/// The Id of the repository
/// The name of the branch
/// List of users with push access to add
[Preview("luke-cage")]
[ManualRoute("POST", "/repositories/{id}/branches/{branch}/protection/restrictions/users")]
public Task> AddProtectedBranchUserRestrictions(long repositoryId, string branch, BranchProtectionUserCollection users)
{
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
Ensure.ArgumentNotNull(users, nameof(users));
return ApiConnection.Post>(ApiUrls.RepoRestrictionsUsers(repositoryId, branch), users, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Remove user restrictions for the specified branch (applies only to Organization owned repositories)
///
///
/// See the API documentation for more details
///
/// The owner of the repository
/// The name of the repository
/// The name of the branch
/// List of users with push access to remove
[Preview("luke-cage")]
[ManualRoute("DELETE", "/repos/{owner}/{repo}/branches/{branch}/protection/restrictions/users")]
public Task> DeleteProtectedBranchUserRestrictions(string owner, string name, string branch, BranchProtectionUserCollection users)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
Ensure.ArgumentNotNull(users, nameof(users));
return ApiConnection.Delete>(ApiUrls.RepoRestrictionsUsers(owner, name, branch), users, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
///
/// Remove user restrictions for the specified branch (applies only to Organization owned repositories)
///
///
/// See the API documentation for more details
///
/// The Id of the repository
/// The name of the branch
/// List of users with push access to remove
[Preview("luke-cage")]
[ManualRoute("DELETE", "/repositories/{id}/branches/{branch}/protection/restrictions/users")]
public Task> DeleteProtectedBranchUserRestrictions(long repositoryId, string branch, BranchProtectionUserCollection users)
{
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
Ensure.ArgumentNotNull(users, nameof(users));
return ApiConnection.Delete>(ApiUrls.RepoRestrictionsUsers(repositoryId, branch), users, AcceptHeaders.ProtectedBranchesRequiredApprovingApiPreview);
}
}
}