mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-03 03:01:31 +00:00
feat: Adds missing properties to the branch protection response object (#2485)
This commit is contained in:
@@ -197,7 +197,6 @@ public class RepositoryBranchesClientTests
|
||||
{
|
||||
IRepositoryBranchesClient _client;
|
||||
RepositoryContext _userRepoContext;
|
||||
OrganizationRepositoryWithTeamContext _orgRepoContext;
|
||||
|
||||
public TheGetBranchProtectionMethod()
|
||||
{
|
||||
@@ -205,7 +204,6 @@ public class RepositoryBranchesClientTests
|
||||
_client = github.Repository.Branch;
|
||||
|
||||
_userRepoContext = github.CreateRepositoryWithProtectedBranch().Result;
|
||||
_orgRepoContext = github.CreateOrganizationRepositoryWithProtectedBranch().Result;
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
@@ -213,7 +211,7 @@ public class RepositoryBranchesClientTests
|
||||
{
|
||||
var repoOwner = _userRepoContext.RepositoryOwner;
|
||||
var repoName = _userRepoContext.RepositoryName;
|
||||
var protection = await _client.GetBranchProtection(repoOwner, repoName, "master");
|
||||
var protection = await _client.GetBranchProtection(repoOwner, repoName, "main");
|
||||
|
||||
Assert.True(protection.RequiredStatusChecks.Strict);
|
||||
Assert.Equal(2, protection.RequiredStatusChecks.Contexts.Count);
|
||||
@@ -225,13 +223,18 @@ public class RepositoryBranchesClientTests
|
||||
Assert.Null(protection.Restrictions);
|
||||
|
||||
Assert.True(protection.EnforceAdmins.Enabled);
|
||||
Assert.True(protection.RequiredLinearHistory.Enabled);
|
||||
Assert.True(protection.AllowForcePushes.Enabled);
|
||||
Assert.True(protection.AllowDeletions.Enabled);
|
||||
Assert.False(protection.BlockCreations.Enabled);
|
||||
Assert.True(protection.RequiredConversationResolution.Enabled);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task GetsBranchProtectionWithRepositoryId()
|
||||
{
|
||||
var repoId = _userRepoContext.RepositoryId;
|
||||
var protection = await _client.GetBranchProtection(repoId, "master");
|
||||
var protection = await _client.GetBranchProtection(repoId, "main");
|
||||
|
||||
Assert.True(protection.RequiredStatusChecks.Strict);
|
||||
Assert.Equal(2, protection.RequiredStatusChecks.Contexts.Count);
|
||||
@@ -243,14 +246,39 @@ public class RepositoryBranchesClientTests
|
||||
Assert.Null(protection.Restrictions);
|
||||
|
||||
Assert.True(protection.EnforceAdmins.Enabled);
|
||||
Assert.True(protection.RequiredLinearHistory.Enabled);
|
||||
Assert.True(protection.AllowForcePushes.Enabled);
|
||||
Assert.True(protection.AllowDeletions.Enabled);
|
||||
Assert.False(protection.BlockCreations.Enabled);
|
||||
Assert.True(protection.RequiredConversationResolution.Enabled);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public void Dispose()
|
||||
{
|
||||
if (_userRepoContext != null)
|
||||
_userRepoContext.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetBranchOrgProtectionMethod : IDisposable
|
||||
{
|
||||
IRepositoryBranchesClient _client;
|
||||
OrganizationRepositoryWithTeamContext _orgRepoContext;
|
||||
|
||||
public TheGetBranchOrgProtectionMethod()
|
||||
{
|
||||
var github = Helper.GetAuthenticatedClient();
|
||||
_client = github.Repository.Branch;
|
||||
|
||||
_orgRepoContext = github.CreateOrganizationRepositoryWithProtectedBranch().Result;
|
||||
}
|
||||
|
||||
[OrganizationTest]
|
||||
public async Task GetsBranchProtectionForOrgRepo()
|
||||
{
|
||||
var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner;
|
||||
var repoName = _orgRepoContext.RepositoryContext.RepositoryName;
|
||||
var protection = await _client.GetBranchProtection(repoOwner, repoName, "master");
|
||||
var protection = await _client.GetBranchProtection(repoOwner, repoName, "main");
|
||||
|
||||
Assert.True(protection.RequiredStatusChecks.Strict);
|
||||
Assert.Equal(2, protection.RequiredStatusChecks.Contexts.Count);
|
||||
@@ -266,11 +294,11 @@ public class RepositoryBranchesClientTests
|
||||
Assert.True(protection.EnforceAdmins.Enabled);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
[OrganizationTest]
|
||||
public async Task GetsBranchProtectionForOrgRepoWithRepositoryId()
|
||||
{
|
||||
var repoId = _orgRepoContext.RepositoryContext.RepositoryId;
|
||||
var protection = await _client.GetBranchProtection(repoId, "master");
|
||||
var protection = await _client.GetBranchProtection(repoId, "main");
|
||||
|
||||
Assert.True(protection.RequiredStatusChecks.Strict);
|
||||
Assert.Equal(2, protection.RequiredStatusChecks.Contexts.Count);
|
||||
@@ -288,9 +316,6 @@ public class RepositoryBranchesClientTests
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_userRepoContext != null)
|
||||
_userRepoContext.Dispose();
|
||||
|
||||
if (_orgRepoContext != null)
|
||||
_orgRepoContext.Dispose();
|
||||
}
|
||||
|
||||
@@ -34,9 +34,14 @@ namespace Octokit.Tests.Integration.Helpers
|
||||
new BranchProtectionRequiredStatusChecksUpdate(true, new[] { "build", "test" }),
|
||||
new BranchProtectionRequiredReviewsUpdate(true, true, 3),
|
||||
null,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
true);
|
||||
|
||||
await client.Repository.Branch.UpdateBranchProtection(contextUserRepo.RepositoryOwner, contextUserRepo.RepositoryName, "master", update);
|
||||
await client.Repository.Branch.UpdateBranchProtection(contextUserRepo.RepositoryOwner, contextUserRepo.RepositoryName, "main", update);
|
||||
|
||||
return contextUserRepo;
|
||||
}
|
||||
|
||||
@@ -121,7 +121,6 @@ namespace Octokit.Tests.Integration
|
||||
{
|
||||
IObservableRepositoryBranchesClient _client;
|
||||
RepositoryContext _userRepoContext;
|
||||
OrganizationRepositoryWithTeamContext _orgRepoContext;
|
||||
|
||||
public TheUpdateBranchProtectionMethod()
|
||||
{
|
||||
@@ -129,7 +128,6 @@ namespace Octokit.Tests.Integration
|
||||
_client = new ObservableRepositoryBranchesClient(github);
|
||||
|
||||
_userRepoContext = github.CreateRepositoryWithProtectedBranch().Result;
|
||||
_orgRepoContext = github.CreateOrganizationRepositoryWithProtectedBranch().Result;
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
@@ -142,7 +140,7 @@ namespace Octokit.Tests.Integration
|
||||
new BranchProtectionRequiredReviewsUpdate(false, true, 2),
|
||||
false);
|
||||
|
||||
var protection = await _client.UpdateBranchProtection(repoOwner, repoName, "master", update);
|
||||
var protection = await _client.UpdateBranchProtection(repoOwner, repoName, "main", update);
|
||||
|
||||
Assert.False(protection.RequiredStatusChecks.Strict);
|
||||
Assert.Equal(1, protection.RequiredStatusChecks.Contexts.Count);
|
||||
@@ -166,7 +164,7 @@ namespace Octokit.Tests.Integration
|
||||
new BranchProtectionRequiredReviewsUpdate(false, true, 2),
|
||||
false);
|
||||
|
||||
var protection = await _client.UpdateBranchProtection(repoId, "master", update);
|
||||
var protection = await _client.UpdateBranchProtection(repoId, "main", update);
|
||||
|
||||
Assert.False(protection.RequiredStatusChecks.Strict);
|
||||
Assert.Equal(1, protection.RequiredStatusChecks.Contexts.Count);
|
||||
@@ -181,7 +179,27 @@ namespace Octokit.Tests.Integration
|
||||
Assert.False(protection.EnforceAdmins.Enabled);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public void Dispose()
|
||||
{
|
||||
if (_userRepoContext != null)
|
||||
_userRepoContext.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public class TheUpdateOrgBranchProtectionMethod : IDisposable
|
||||
{
|
||||
IObservableRepositoryBranchesClient _client;
|
||||
OrganizationRepositoryWithTeamContext _orgRepoContext;
|
||||
|
||||
public TheUpdateOrgBranchProtectionMethod()
|
||||
{
|
||||
var github = Helper.GetAuthenticatedClient();
|
||||
_client = new ObservableRepositoryBranchesClient(github);
|
||||
|
||||
_orgRepoContext = github.CreateOrganizationRepositoryWithProtectedBranch().Result;
|
||||
}
|
||||
|
||||
[OrganizationTest]
|
||||
public async Task UpdatesBranchProtectionForOrgRepo()
|
||||
{
|
||||
var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner;
|
||||
@@ -190,9 +208,14 @@ namespace Octokit.Tests.Integration
|
||||
new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }),
|
||||
new BranchProtectionRequiredReviewsUpdate(new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(false), false, false, 2),
|
||||
new BranchProtectionPushRestrictionsUpdate(),
|
||||
false);
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true);
|
||||
|
||||
var protection = await _client.UpdateBranchProtection(repoOwner, repoName, "master", update);
|
||||
var protection = await _client.UpdateBranchProtection(repoOwner, repoName, "main", update);
|
||||
|
||||
Assert.False(protection.RequiredStatusChecks.Strict);
|
||||
Assert.Equal(1, protection.RequiredStatusChecks.Contexts.Count);
|
||||
@@ -206,9 +229,14 @@ namespace Octokit.Tests.Integration
|
||||
Assert.Empty(protection.Restrictions.Users);
|
||||
|
||||
Assert.False(protection.EnforceAdmins.Enabled);
|
||||
Assert.True(protection.RequiredLinearHistory.Enabled);
|
||||
Assert.True(protection.AllowForcePushes.Enabled);
|
||||
Assert.True(protection.AllowDeletions.Enabled);
|
||||
Assert.True(protection.BlockCreations.Enabled);
|
||||
Assert.True(protection.RequiredConversationResolution.Enabled);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
[OrganizationTest]
|
||||
public async Task UpdatesBranchProtectionForOrgRepoWithRepositoryId()
|
||||
{
|
||||
var repoId = _orgRepoContext.RepositoryContext.RepositoryId;
|
||||
@@ -216,9 +244,14 @@ namespace Octokit.Tests.Integration
|
||||
new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }),
|
||||
new BranchProtectionRequiredReviewsUpdate(new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(false), false, false, 2),
|
||||
new BranchProtectionPushRestrictionsUpdate(),
|
||||
false);
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true);
|
||||
|
||||
var protection = await _client.UpdateBranchProtection(repoId, "master", update);
|
||||
var protection = await _client.UpdateBranchProtection(repoId, "main", update);
|
||||
|
||||
Assert.False(protection.RequiredStatusChecks.Strict);
|
||||
Assert.Equal(1, protection.RequiredStatusChecks.Contexts.Count);
|
||||
@@ -232,13 +265,15 @@ namespace Octokit.Tests.Integration
|
||||
Assert.Empty(protection.Restrictions.Users);
|
||||
|
||||
Assert.False(protection.EnforceAdmins.Enabled);
|
||||
Assert.True(protection.RequiredLinearHistory.Enabled);
|
||||
Assert.True(protection.AllowForcePushes.Enabled);
|
||||
Assert.True(protection.AllowDeletions.Enabled);
|
||||
Assert.True(protection.BlockCreations.Enabled);
|
||||
Assert.True(protection.RequiredConversationResolution.Enabled);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_userRepoContext != null)
|
||||
_userRepoContext.Dispose();
|
||||
|
||||
if (_orgRepoContext != null)
|
||||
_orgRepoContext.Dispose();
|
||||
}
|
||||
|
||||
@@ -85,7 +85,10 @@ namespace Octokit
|
||||
/// <param name="requiredPullRequestReviews">Specifies if reviews are required to merge the pull request. Pass null to disable required reviews</param>
|
||||
/// <param name="restrictions">Specifies the requested push access restrictions (applies only to Organization owned repositories). Pass null to disable push access restrictions</param>
|
||||
/// <param name="enforceAdmins">Specifies whether the protections applied to this branch also apply to repository admins</param>
|
||||
public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate requiredStatusChecks, BranchProtectionRequiredReviewsUpdate requiredPullRequestReviews, BranchProtectionPushRestrictionsUpdate restrictions, bool enforceAdmins)
|
||||
public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate requiredStatusChecks,
|
||||
BranchProtectionRequiredReviewsUpdate requiredPullRequestReviews,
|
||||
BranchProtectionPushRestrictionsUpdate restrictions,
|
||||
bool enforceAdmins)
|
||||
{
|
||||
RequiredStatusChecks = requiredStatusChecks;
|
||||
RequiredPullRequestReviews = requiredPullRequestReviews;
|
||||
@@ -93,6 +96,39 @@ namespace Octokit
|
||||
EnforceAdmins = enforceAdmins;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a BranchProtection update request
|
||||
/// </summary>
|
||||
/// <param name="requiredStatusChecks">Specifies the requested status check settings. Pass null to disable status checks</param>
|
||||
/// <param name="requiredPullRequestReviews">Specifies if reviews are required to merge the pull request. Pass null to disable required reviews</param>
|
||||
/// <param name="restrictions">Specifies the requested push access restrictions (applies only to Organization owned repositories). Pass null to disable push access restrictions</param>
|
||||
/// <param name="enforceAdmins">Specifies whether the protections applied to this branch also apply to repository admins</param>
|
||||
/// <param name="requiredLinearHistory">Enforces a linear commit Git history</param>
|
||||
/// <param name="allowForcePushes">Permits force pushes to the protected branch</param>
|
||||
/// <param name="allowDeletions">Allows deletion of the protected branch</param>
|
||||
/// <param name="blockCreations">The restrictions branch protection settings will also block pushes which create new branches</param>
|
||||
/// <param name="requiredConversationResolution">Requires all conversations on code to be resolved before a pull request can be merged</param>
|
||||
public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate requiredStatusChecks,
|
||||
BranchProtectionRequiredReviewsUpdate requiredPullRequestReviews,
|
||||
BranchProtectionPushRestrictionsUpdate restrictions,
|
||||
bool enforceAdmins,
|
||||
bool requiredLinearHistory,
|
||||
bool? allowForcePushes,
|
||||
bool allowDeletions,
|
||||
bool blockCreations,
|
||||
bool requiredConversationResolution)
|
||||
{
|
||||
RequiredStatusChecks = requiredStatusChecks;
|
||||
RequiredPullRequestReviews = requiredPullRequestReviews;
|
||||
Restrictions = restrictions;
|
||||
EnforceAdmins = enforceAdmins;
|
||||
RequiredLinearHistory = requiredLinearHistory;
|
||||
AllowForcePushes = allowForcePushes;
|
||||
AllowDeletions = allowDeletions;
|
||||
BlockCreations = blockCreations;
|
||||
RequiredConversationResolution = requiredConversationResolution;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Status check settings for the protected branch
|
||||
/// </summary>
|
||||
@@ -116,6 +152,32 @@ namespace Octokit
|
||||
/// </summary>
|
||||
public bool EnforceAdmins { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Enforces a linear commit Git history. Default is false.
|
||||
/// </summary>
|
||||
public bool RequiredLinearHistory { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Permits force pushes to the protected branch by anyone with write access to the repository. Default is false.
|
||||
/// </summary>
|
||||
public bool? AllowForcePushes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Allows deletion of the protected branch by anyone with write access to the repository. Default is false.
|
||||
/// </summary>
|
||||
public bool AllowDeletions { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// If set to true, the restrictions branch protection settings which limits who can push will also block pushes which create new branches, unless the push is initiated by a user, team, or app which has the ability to push. Default is false.
|
||||
/// </summary>
|
||||
public bool BlockCreations { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Requires all conversations on code to be resolved before a pull request can be merged. Default is false.
|
||||
/// </summary>
|
||||
public bool RequiredConversationResolution { get; set; }
|
||||
|
||||
|
||||
internal string DebuggerDisplay
|
||||
{
|
||||
get
|
||||
|
||||
@@ -9,41 +9,85 @@ namespace Octokit
|
||||
/// <summary>
|
||||
/// Protection details for a <see cref="Branch"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Note: this is a PREVIEW api: https://developer.github.com/changes/2016-06-27-protected-branches-api-update/
|
||||
/// </remarks>
|
||||
[DebuggerDisplay("{DebuggerDisplay,nq}")]
|
||||
public class BranchProtectionSettings
|
||||
{
|
||||
public BranchProtectionSettings() { }
|
||||
|
||||
public BranchProtectionSettings(BranchProtectionRequiredStatusChecks requiredStatusChecks, BranchProtectionPushRestrictions restrictions, BranchProtectionRequiredReviews requiredPullRequestReviews, EnforceAdmins enforceAdmins)
|
||||
public BranchProtectionSettings(BranchProtectionRequiredStatusChecks requiredStatusChecks,
|
||||
BranchProtectionRequiredReviews requiredPullRequestReviews,
|
||||
BranchProtectionPushRestrictions restrictions,
|
||||
EnforceAdmins enforceAdmins,
|
||||
BranchProtectionEnabledCommon requiredLinearHistory,
|
||||
BranchProtectionEnabledCommon allowForcePushes,
|
||||
BranchProtectionEnabledCommon allowDeletions,
|
||||
BranchProtectionEnabledCommon blockCreations,
|
||||
BranchProtectionEnabledCommon requiredConversationResolution,
|
||||
BranchProtectionEnabledCommon requiredSignatures)
|
||||
{
|
||||
RequiredStatusChecks = requiredStatusChecks;
|
||||
Restrictions = restrictions;
|
||||
RequiredPullRequestReviews = requiredPullRequestReviews;
|
||||
Restrictions = restrictions;
|
||||
EnforceAdmins = enforceAdmins;
|
||||
RequiredLinearHistory = requiredLinearHistory;
|
||||
AllowForcePushes = allowForcePushes;
|
||||
AllowDeletions = allowDeletions;
|
||||
BlockCreations = blockCreations;
|
||||
RequiredConversationResolution = requiredConversationResolution;
|
||||
RequiredSignatures = requiredSignatures;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Status check settings for the protected branch
|
||||
/// </summary>
|
||||
public BranchProtectionRequiredStatusChecks RequiredStatusChecks { get; protected set; }
|
||||
public BranchProtectionRequiredStatusChecks RequiredStatusChecks { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Required review settings for the protected branch
|
||||
/// </summary>
|
||||
public BranchProtectionRequiredReviews RequiredPullRequestReviews { get; protected set; }
|
||||
public BranchProtectionRequiredReviews RequiredPullRequestReviews { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Push access restrictions for the protected branch
|
||||
/// </summary>
|
||||
public BranchProtectionPushRestrictions Restrictions { get; protected set; }
|
||||
public BranchProtectionPushRestrictions Restrictions { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies whether the protections applied to this branch also apply to repository admins
|
||||
/// </summary>
|
||||
public EnforceAdmins EnforceAdmins { get; protected set; }
|
||||
public EnforceAdmins EnforceAdmins { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies whether a linear history is required
|
||||
/// </summary>
|
||||
public BranchProtectionEnabledCommon RequiredLinearHistory { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies whether force pushes are allowed
|
||||
/// </summary>
|
||||
public BranchProtectionEnabledCommon AllowForcePushes { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies whether deletions are allowed
|
||||
/// </summary>
|
||||
public BranchProtectionEnabledCommon AllowDeletions { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies whether creations can be blocked
|
||||
/// </summary>
|
||||
public BranchProtectionEnabledCommon BlockCreations { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies whether conversation resolution iss required
|
||||
/// </summary>
|
||||
public BranchProtectionEnabledCommon RequiredConversationResolution { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies whether signatures are required
|
||||
/// </summary>
|
||||
public BranchProtectionEnabledCommon RequiredSignatures { get; private set; }
|
||||
|
||||
internal string DebuggerDisplay
|
||||
{
|
||||
@@ -239,4 +283,25 @@ namespace Octokit
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[DebuggerDisplay("{DebuggerDisplay,nq}")]
|
||||
public class BranchProtectionEnabledCommon
|
||||
{
|
||||
public BranchProtectionEnabledCommon() { }
|
||||
|
||||
public BranchProtectionEnabledCommon(bool enabled)
|
||||
{
|
||||
Enabled = enabled;
|
||||
}
|
||||
|
||||
public bool Enabled { get; protected set; }
|
||||
|
||||
internal string DebuggerDisplay
|
||||
{
|
||||
get
|
||||
{
|
||||
return string.Format(CultureInfo.InvariantCulture, "Enabled: {0}", Enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user