mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-06 12:03:19 +00:00
[WIP] Protected branches updates - granular methods (#1443)
* Add get method for required status checks * Add api urls for required status checks * change name of apir url for required status checks * fix xml comment * add update method for required status checks * add delete method for required status checks * fix api url * fix xml comment * add api url for required status cehcks contexts * add get method for required status checks contexts * add replace method for required status checks contexts * add add method for required status checks contexts * add new overload for delete method * add delete method for required status checks contexts; fix overloads for delete * add api url for restrictions * add get method for restrictions * add delete method for restrictions * add api url for teams restrictions * add get method for team restrictions; fix delete method restrictions * fix overhead for get team restrictions * fix httpmethod for update required status checks * add set method for team restrictions * add add method for team restrictions * add delete method for team restrictions * add api url for user restrictions * add get method for user restrictions * add set method for user restrictions * add add method for user restrictions * add delete method for user restrictions * Add unit test; fix api urls * Add ExcludeFromTest class * add exclude attribute to methods * Add attribute usage * Add parameter to interface * add observable unit tests * rename excludefromtest exclude all the tests for the new api endpoints because they broke the pagination and syncobsverable tests. * rename excludefromattribute * refactor observable methods * [WIP] Add integration tests * finish integration test * fix renamed branch protection restrictions * add team and user collections * rename set to update * rename test methods * optimize integration tests * made some tidy ups - fixup comment wording Edit => Replace - remove spurious characters from description - remove un-needed exclude attributes * remove ForOrgRepo tests * remove unused org contexts * dispose contexts * remove obsolete GetRedirect * add clarifying comment to restriction methods
This commit is contained in:
committed by
Ryan Gribble
parent
6a21ce5df6
commit
93ae832311
@@ -151,7 +151,7 @@ namespace Octokit
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the branch protection settings for the specified branch />
|
||||
/// Get the branch protection settings for the specified branch
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#get-branch-protection">API documentation</a> for more details
|
||||
@@ -169,7 +169,7 @@ namespace Octokit
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the branch protection settings for the specified branch />
|
||||
/// Get the branch protection settings for the specified branch
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#get-branch-protection">API documentation</a> for more details
|
||||
@@ -184,7 +184,7 @@ namespace Octokit
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the branch protection settings for the specified branch />
|
||||
/// Update the branch protection settings for the specified branch
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#update-branch-protection">API documentation</a> for more details
|
||||
@@ -199,12 +199,12 @@ namespace Octokit
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
|
||||
Ensure.ArgumentNotNull(update, "update");
|
||||
|
||||
|
||||
return ApiConnection.Put<BranchProtectionSettings>(ApiUrls.RepoBranchProtection(owner, name, branch), update, null, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the branch protection settings for the specified branch />
|
||||
/// Update the branch protection settings for the specified branch
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#update-branch-protection">API documentation</a> for more details
|
||||
@@ -221,7 +221,7 @@ namespace Octokit
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove the branch protection settings for the specified branch />
|
||||
/// Remove the branch protection settings for the specified branch
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#remove-branch-protection">API documentation</a> for more details
|
||||
@@ -248,7 +248,7 @@ namespace Octokit
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove the branch protection settings for the specified branch />
|
||||
/// Remove the branch protection settings for the specified branch
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#remove-branch-protection">API documentation</a> for more details
|
||||
@@ -270,5 +270,646 @@ namespace Octokit
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the required status checks for the specified branch
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#get-required-status-checks-of-protected-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="branch">The name of the branch</param>
|
||||
public Task<BranchProtectionRequiredStatusChecks> GetRequiredStatusChecks(string owner, string name, string branch)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
|
||||
|
||||
return ApiConnection.Get<BranchProtectionRequiredStatusChecks>(ApiUrls.RepoRequiredStatusChecks(owner, name, branch), null, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the required status checks for the specified branch
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#get-required-status-checks-of-protected-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="repositoryId">The Id of the repository</param>
|
||||
/// <param name="branch">The name of the branch</param>
|
||||
public Task<BranchProtectionRequiredStatusChecks> GetRequiredStatusChecks(long repositoryId, string branch)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
|
||||
|
||||
return ApiConnection.Get<BranchProtectionRequiredStatusChecks>(ApiUrls.RepoRequiredStatusChecks(repositoryId, branch), null, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replace required status checks for the specified branch
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#update-required-status-checks-of-protected-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="branch">The name of the branch</param>
|
||||
/// <param name="update">Required status checks</param>
|
||||
public Task<BranchProtectionRequiredStatusChecks> UpdateRequiredStatusChecks(string owner, string name, string branch, BranchProtectionRequiredStatusChecksUpdate update)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
|
||||
Ensure.ArgumentNotNull(update, "update");
|
||||
|
||||
return ApiConnection.Patch<BranchProtectionRequiredStatusChecks>(ApiUrls.RepoRequiredStatusChecks(owner, name, branch), update, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replace required status checks for the specified branch
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#update-required-status-checks-of-protected-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="repositoryId">The Id of the repository</param>
|
||||
/// <param name="branch">The name of the branch</param>
|
||||
/// <param name="update">Required status checks</param>
|
||||
public Task<BranchProtectionRequiredStatusChecks> UpdateRequiredStatusChecks(long repositoryId, string branch, BranchProtectionRequiredStatusChecksUpdate update)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
|
||||
Ensure.ArgumentNotNull(update, "update");
|
||||
|
||||
return ApiConnection.Patch<BranchProtectionRequiredStatusChecks>(ApiUrls.RepoRequiredStatusChecks(repositoryId, branch), update, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove required status checks for the specified branch
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#remove-required-status-checks-of-protected-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="branch">The name of the branch</param>
|
||||
public async Task<bool> DeleteRequiredStatusChecks(string owner, string name, string branch)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
|
||||
|
||||
var endpoint = ApiUrls.RepoRequiredStatusChecks(owner, name, branch);
|
||||
|
||||
try
|
||||
{
|
||||
var httpStatusCode = await Connection.Delete(endpoint, null, AcceptHeaders.ProtectedBranchesApiPreview).ConfigureAwait(false);
|
||||
return httpStatusCode == HttpStatusCode.NoContent;
|
||||
}
|
||||
catch (NotFoundException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove required status checks for the specified branch
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#remove-required-status-checks-of-protected-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="repositoryId">The Id of the repository</param>
|
||||
/// <param name="branch">The name of the branch</param>
|
||||
public async Task<bool> DeleteRequiredStatusChecks(long repositoryId, string branch)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
|
||||
|
||||
var endpoint = ApiUrls.RepoRequiredStatusChecks(repositoryId, branch);
|
||||
|
||||
try
|
||||
{
|
||||
var httpStatusCode = await Connection.Delete(endpoint, null, AcceptHeaders.ProtectedBranchesApiPreview).ConfigureAwait(false);
|
||||
return httpStatusCode == HttpStatusCode.NoContent;
|
||||
}
|
||||
catch (NotFoundException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the required status checks contexts for the specified branch
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#list-required-status-checks-contexts-of-protected-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="branch">The name of the branch</param>
|
||||
public Task<IReadOnlyList<string>> GetRequiredStatusChecksContexts(string owner, string name, string branch)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
|
||||
|
||||
return ApiConnection.Get<IReadOnlyList<string>>(ApiUrls.RepoRequiredStatusChecksContexts(owner, name, branch), null, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the required status checks contexts for the specified branch
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#list-required-status-checks-contexts-of-protected-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="repositoryId">The Id of the repository</param>
|
||||
/// <param name="branch">The name of the branch</param>
|
||||
public Task<IReadOnlyList<string>> GetRequiredStatusChecksContexts(long repositoryId, string branch)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
|
||||
|
||||
return ApiConnection.Get<IReadOnlyList<string>>(ApiUrls.RepoRequiredStatusChecksContexts(repositoryId, branch), null, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replace the required status checks contexts for the specified branch
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#replace-required-status-checks-contexts-of-protected-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="branch">The name of the branch</param>
|
||||
/// <param name="contexts">The contexts to replace</param>
|
||||
public Task<IReadOnlyList<string>> UpdateRequiredStatusChecksContexts(string owner, string name, string branch, IReadOnlyList<string> contexts)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
|
||||
Ensure.ArgumentNotNull(contexts, "contexts");
|
||||
|
||||
return ApiConnection.Put<IReadOnlyList<string>>(ApiUrls.RepoRequiredStatusChecksContexts(owner, name, branch), contexts, null, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replace the required status checks contexts for the specified branch
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#replace-required-status-checks-contexts-of-protected-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="repositoryId">The Id of the repository</param>
|
||||
/// <param name="branch">The name of the branch</param>
|
||||
/// <param name="contexts">The contexts to replace</param>
|
||||
public Task<IReadOnlyList<string>> UpdateRequiredStatusChecksContexts(long repositoryId, string branch, IReadOnlyList<string> contexts)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
|
||||
Ensure.ArgumentNotNull(contexts, "contexts");
|
||||
|
||||
return ApiConnection.Put<IReadOnlyList<string>>(ApiUrls.RepoRequiredStatusChecksContexts(repositoryId, branch), contexts, null, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add the required status checks context for the specified branch
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#add-required-status-checks-contexts-of-protected-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="branch">The name of the branch</param>
|
||||
/// <param name="contexts">The contexts to add</param>
|
||||
public Task<IReadOnlyList<string>> AddRequiredStatusChecksContexts(string owner, string name, string branch, IReadOnlyList<string> contexts)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
|
||||
Ensure.ArgumentNotNull(contexts, "contexts");
|
||||
|
||||
return ApiConnection.Post<IReadOnlyList<string>>(ApiUrls.RepoRequiredStatusChecksContexts(owner, name, branch), contexts, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add the required status checks contexts for the specified branch
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#add-required-status-checks-contexts-of-protected-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="repositoryId">The Id of the repository</param>
|
||||
/// <param name="branch">The name of the branch</param>
|
||||
/// <param name="contexts">The contexts to add</param>
|
||||
public Task<IReadOnlyList<string>> AddRequiredStatusChecksContexts(long repositoryId, string branch, IReadOnlyList<string> contexts)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
|
||||
Ensure.ArgumentNotNull(contexts, "contexts");
|
||||
|
||||
return ApiConnection.Post<IReadOnlyList<string>>(ApiUrls.RepoRequiredStatusChecksContexts(repositoryId, branch), contexts, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove the required status checks context for the specified branch
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#remove-required-status-checks-contexts-of-protected-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="branch">The name of the branch</param>
|
||||
/// <param name="contexts">The contexts to remove</param>
|
||||
public Task<IReadOnlyList<string>> DeleteRequiredStatusChecksContexts(string owner, string name, string branch, IReadOnlyList<string> contexts)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
|
||||
Ensure.ArgumentNotNull(contexts, "contexts");
|
||||
|
||||
return ApiConnection.Delete<IReadOnlyList<string>>(ApiUrls.RepoRequiredStatusChecksContexts(owner, name, branch), contexts, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove the required status checks contexts for the specified branch
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#remove-required-status-checks-contexts-of-protected-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="repositoryId">The Id of the repository</param>
|
||||
/// <param name="branch">The name of the branch</param>
|
||||
/// <param name="contexts">The contexts to remove</param>
|
||||
public Task<IReadOnlyList<string>> DeleteRequiredStatusChecksContexts(long repositoryId, string branch, IReadOnlyList<string> contexts)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
|
||||
Ensure.ArgumentNotNull(contexts, "contexts");
|
||||
|
||||
return ApiConnection.Delete<IReadOnlyList<string>>(ApiUrls.RepoRequiredStatusChecksContexts(repositoryId, branch), contexts, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get restrictions for the specified branch (applies only to Organization owned repositories)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#get-restrictions-of-protected-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="branch">The name of the branch</param>
|
||||
public Task<BranchProtectionPushRestrictions> GetProtectedBranchRestrictions(string owner, string name, string branch)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
|
||||
|
||||
return ApiConnection.Get<BranchProtectionPushRestrictions>(ApiUrls.RepoRestrictions(owner, name, branch), null, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get restrictions for the specified branch (applies only to Organization owned repositories)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#get-restrictions-of-protected-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="repositoryId">The Id of the repository</param>
|
||||
/// <param name="branch">The name of the branch</param>
|
||||
public Task<BranchProtectionPushRestrictions> GetProtectedBranchRestrictions(long repositoryId, string branch)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
|
||||
|
||||
return ApiConnection.Get<BranchProtectionPushRestrictions>(ApiUrls.RepoRestrictions(repositoryId, branch), null, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove restrictions for the specified branch (applies only to Organization owned repositories)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#remove-restrictions-of-protected-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="branch">The name of the branch</param>
|
||||
public async Task<bool> DeleteProtectedBranchRestrictions(string owner, string name, string branch)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
|
||||
|
||||
var endpoint = ApiUrls.RepoRestrictions(owner, name, branch);
|
||||
|
||||
try
|
||||
{
|
||||
var httpStatusCode = await Connection.Delete(endpoint, null, AcceptHeaders.ProtectedBranchesApiPreview).ConfigureAwait(false);
|
||||
return httpStatusCode == HttpStatusCode.NoContent;
|
||||
}
|
||||
catch (NotFoundException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove restrictions for the specified branch (applies only to Organization owned repositories)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#remove-restrictions-of-protected-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="repositoryId">The Id of the repository</param>
|
||||
/// <param name="branch">The name of the branch</param>
|
||||
public async Task<bool> DeleteProtectedBranchRestrictions(long repositoryId, string branch)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
|
||||
|
||||
var endpoint = ApiUrls.RepoRestrictions(repositoryId, branch);
|
||||
|
||||
try
|
||||
{
|
||||
var httpStatusCode = await Connection.Delete(endpoint, null, AcceptHeaders.ProtectedBranchesApiPreview).ConfigureAwait(false);
|
||||
return httpStatusCode == HttpStatusCode.NoContent;
|
||||
}
|
||||
catch (NotFoundException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get team restrictions for the specified branch (applies only to Organization owned repositories)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#list-team-restrictions-of-protected-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="branch">The name of the branch</param>
|
||||
public Task<IReadOnlyList<Team>> GetProtectedBranchTeamRestrictions(string owner, string name, string branch)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
|
||||
|
||||
return ApiConnection.Get<IReadOnlyList<Team>>(ApiUrls.RepoRestrictionsTeams(owner, name, branch), null, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get team restrictions for the specified branch (applies only to Organization owned repositories)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#list-team-restrictions-of-protected-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="repositoryId">The Id of the repository</param>
|
||||
/// <param name="branch">The name of the branch</param>
|
||||
public Task<IReadOnlyList<Team>> GetProtectedBranchTeamRestrictions(long repositoryId, string branch)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
|
||||
|
||||
return ApiConnection.Get<IReadOnlyList<Team>>(ApiUrls.RepoRestrictionsTeams(repositoryId, branch), null, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replace team restrictions for the specified branch (applies only to Organization owned repositories)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#replace-team-restrictions-of-protected-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="branch">The name of the branch</param>
|
||||
/// <param name="teams">List of teams with push access</param>
|
||||
public Task<IReadOnlyList<Team>> UpdateProtectedBranchTeamRestrictions(string owner, string name, string branch, BranchProtectionTeamCollection teams)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
|
||||
Ensure.ArgumentNotNull(teams, "teams");
|
||||
|
||||
return ApiConnection.Put<IReadOnlyList<Team>>(ApiUrls.RepoRestrictionsTeams(owner, name, branch), teams, null, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replace team restrictions for the specified branch (applies only to Organization owned repositories)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#replace-team-restrictions-of-protected-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="repositoryId">The Id of the repository</param>
|
||||
/// <param name="branch">The name of the branch</param>
|
||||
/// <param name="teams">List of teams with push access</param>
|
||||
public Task<IReadOnlyList<Team>> UpdateProtectedBranchTeamRestrictions(long repositoryId, string branch, BranchProtectionTeamCollection teams)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
|
||||
Ensure.ArgumentNotNull(teams, "teams");
|
||||
|
||||
return ApiConnection.Put<IReadOnlyList<Team>>(ApiUrls.RepoRestrictionsTeams(repositoryId, branch), teams, null, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add team restrictions for the specified branch (applies only to Organization owned repositories)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#add-team-restrictions-of-protected-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="branch">The name of the branch</param>
|
||||
/// <param name="teams">List of teams with push access to add</param>
|
||||
public Task<IReadOnlyList<Team>> AddProtectedBranchTeamRestrictions(string owner, string name, string branch, BranchProtectionTeamCollection teams)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
|
||||
Ensure.ArgumentNotNull(teams, "teams");
|
||||
|
||||
return ApiConnection.Post<IReadOnlyList<Team>>(ApiUrls.RepoRestrictionsTeams(owner, name, branch), teams, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add team restrictions for the specified branch (applies only to Organization owned repositories)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#add-team-restrictions-of-protected-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="repositoryId">The Id of the repository</param>
|
||||
/// <param name="branch">The name of the branch</param>
|
||||
/// <param name="teams">List of teams with push access to add</param>
|
||||
public Task<IReadOnlyList<Team>> AddProtectedBranchTeamRestrictions(long repositoryId, string branch, BranchProtectionTeamCollection teams)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
|
||||
Ensure.ArgumentNotNull(teams, "teams");
|
||||
|
||||
return ApiConnection.Post<IReadOnlyList<Team>>(ApiUrls.RepoRestrictionsTeams(repositoryId, branch), teams, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove team restrictions for the specified branch (applies only to Organization owned repositories)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#remove-team-restrictions-of-protected-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="branch">The name of the branch</param>
|
||||
/// <param name="teams">List of teams to remove</param>
|
||||
public Task<IReadOnlyList<Team>> DeleteProtectedBranchTeamRestrictions(string owner, string name, string branch, BranchProtectionTeamCollection teams)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
|
||||
Ensure.ArgumentNotNull(teams, "teams");
|
||||
|
||||
return ApiConnection.Delete<IReadOnlyList<Team>>(ApiUrls.RepoRestrictionsTeams(owner, name, branch), teams, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove team restrictions for the specified branch (applies only to Organization owned repositories)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#remove-team-restrictions-of-protected-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="repositoryId">The Id of the repository</param>
|
||||
/// <param name="branch">The name of the branch</param>
|
||||
/// <param name="teams">List of teams to remove</param>
|
||||
public Task<IReadOnlyList<Team>> DeleteProtectedBranchTeamRestrictions(long repositoryId, string branch, BranchProtectionTeamCollection teams)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
|
||||
Ensure.ArgumentNotNull(teams, "teams");
|
||||
|
||||
return ApiConnection.Delete<IReadOnlyList<Team>>(ApiUrls.RepoRestrictionsTeams(repositoryId, branch), teams, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get user restrictions for the specified branch (applies only to Organization owned repositories)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#list-user-restrictions-of-protected-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="branch">The name of the branch</param>
|
||||
public Task<IReadOnlyList<User>> GetProtectedBranchUserRestrictions(string owner, string name, string branch)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
|
||||
|
||||
return ApiConnection.Get<IReadOnlyList<User>>(ApiUrls.RepoRestrictionsUsers(owner, name, branch), null, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get user restrictions for the specified branch (applies only to Organization owned repositories)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#list-user-restrictions-of-protected-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="repositoryId">The Id of the repository</param>
|
||||
/// <param name="branch">The name of the branch</param>
|
||||
public Task<IReadOnlyList<User>> GetProtectedBranchUserRestrictions(long repositoryId, string branch)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
|
||||
|
||||
return ApiConnection.Get<IReadOnlyList<User>>(ApiUrls.RepoRestrictionsUsers(repositoryId, branch), null, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replace user restrictions for the specified branch (applies only to Organization owned repositories)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#replace-user-restrictions-of-protected-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="branch">The name of the branch</param>
|
||||
/// <param name="users">List of users with push access</param>
|
||||
public Task<IReadOnlyList<User>> UpdateProtectedBranchUserRestrictions(string owner, string name, string branch, BranchProtectionUserCollection users)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
|
||||
Ensure.ArgumentNotNull(users, "users");
|
||||
|
||||
return ApiConnection.Put<IReadOnlyList<User>>(ApiUrls.RepoRestrictionsUsers(owner, name, branch), users, null, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replace user restrictions for the specified branch (applies only to Organization owned repositories)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#replace-user-restrictions-of-protected-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="repositoryId">The Id of the repository</param>
|
||||
/// <param name="branch">The name of the branch</param>
|
||||
/// <param name="users">List of users with push access</param>
|
||||
public Task<IReadOnlyList<User>> UpdateProtectedBranchUserRestrictions(long repositoryId, string branch, BranchProtectionUserCollection users)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
|
||||
Ensure.ArgumentNotNull(users, "users");
|
||||
|
||||
return ApiConnection.Put<IReadOnlyList<User>>(ApiUrls.RepoRestrictionsUsers(repositoryId, branch), users, null, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add user restrictions for the specified branch (applies only to Organization owned repositories)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#add-user-restrictions-of-protected-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="branch">The name of the branch</param>
|
||||
/// <param name="users">List of users with push access to add</param>
|
||||
public Task<IReadOnlyList<User>> AddProtectedBranchUserRestrictions(string owner, string name, string branch, BranchProtectionUserCollection users)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
|
||||
Ensure.ArgumentNotNull(users, "users");
|
||||
|
||||
return ApiConnection.Post<IReadOnlyList<User>>(ApiUrls.RepoRestrictionsUsers(owner, name, branch), users, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add user restrictions for the specified branch (applies only to Organization owned repositories)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#add-user-restrictions-of-protected-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="repositoryId">The Id of the repository</param>
|
||||
/// <param name="branch">The name of the branch</param>
|
||||
/// <param name="users">List of users with push access to add</param>
|
||||
public Task<IReadOnlyList<User>> AddProtectedBranchUserRestrictions(long repositoryId, string branch, BranchProtectionUserCollection users)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
|
||||
Ensure.ArgumentNotNull(users, "users");
|
||||
|
||||
return ApiConnection.Post<IReadOnlyList<User>>(ApiUrls.RepoRestrictionsUsers(repositoryId, branch), users, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove user restrictions for the specified branch (applies only to Organization owned repositories)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#remove-user-restrictions-of-protected-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="branch">The name of the branch</param>
|
||||
/// <param name="users">List of users with push access to remove</param>
|
||||
public Task<IReadOnlyList<User>> DeleteProtectedBranchUserRestrictions(string owner, string name, string branch, BranchProtectionUserCollection users)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
|
||||
Ensure.ArgumentNotNull(users, "users");
|
||||
|
||||
return ApiConnection.Delete<IReadOnlyList<User>>(ApiUrls.RepoRestrictionsUsers(owner, name, branch), users, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove user restrictions for the specified branch (applies only to Organization owned repositories)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/repos/branches/#remove-user-restrictions-of-protected-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="repositoryId">The Id of the repository</param>
|
||||
/// <param name="branch">The name of the branch</param>
|
||||
/// <param name="users">List of users with push access to remove</param>
|
||||
public Task<IReadOnlyList<User>> DeleteProtectedBranchUserRestrictions(long repositoryId, string branch, BranchProtectionUserCollection users)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
|
||||
Ensure.ArgumentNotNull(users, "users");
|
||||
|
||||
return ApiConnection.Delete<IReadOnlyList<User>>(ApiUrls.RepoRestrictionsUsers(repositoryId, branch), users, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user