mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-07 12:26:18 +00:00
[feat] Adds support for making branches read-only (#2715)
This commit is contained in:
@@ -26,6 +26,7 @@ namespace Octokit
|
||||
RequiredPullRequestReviews = null;
|
||||
Restrictions = null;
|
||||
EnforceAdmins = false;
|
||||
LockBranch = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -38,6 +39,7 @@ namespace Octokit
|
||||
RequiredPullRequestReviews = requiredPullRequestReviews;
|
||||
Restrictions = null;
|
||||
EnforceAdmins = false;
|
||||
LockBranch = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -50,18 +52,21 @@ namespace Octokit
|
||||
RequiredPullRequestReviews = null;
|
||||
Restrictions = restrictions;
|
||||
EnforceAdmins = false;
|
||||
LockBranch = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a BranchProtection update request
|
||||
/// </summary>
|
||||
/// <param name="enforceAdmins">Specifies whether the protections applied to this branch also apply to repository admins</param>
|
||||
public BranchProtectionSettingsUpdate(bool enforceAdmins)
|
||||
/// <param name="lockBranch">Optionally specfies that the branch should be read-only.</param>
|
||||
public BranchProtectionSettingsUpdate(bool enforceAdmins, bool lockBranch = false)
|
||||
{
|
||||
RequiredStatusChecks = null;
|
||||
RequiredPullRequestReviews = null;
|
||||
Restrictions = null;
|
||||
EnforceAdmins = enforceAdmins;
|
||||
LockBranch = lockBranch;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -70,12 +75,14 @@ namespace Octokit
|
||||
/// <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="enforceAdmins">Specifies whether the protections applied to this branch also apply to repository admins</param>
|
||||
public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate requiredStatusChecks, BranchProtectionRequiredReviewsUpdate requiredPullRequestReviews, bool enforceAdmins)
|
||||
/// <param name="lockBranch">Optionally specfies that the branch should be read-only.</param>
|
||||
public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate requiredStatusChecks, BranchProtectionRequiredReviewsUpdate requiredPullRequestReviews, bool enforceAdmins, bool lockBranch = false)
|
||||
{
|
||||
RequiredStatusChecks = requiredStatusChecks;
|
||||
RequiredPullRequestReviews = requiredPullRequestReviews;
|
||||
Restrictions = null;
|
||||
EnforceAdmins = enforceAdmins;
|
||||
LockBranch = lockBranch;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -85,15 +92,18 @@ 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>
|
||||
/// <param name="lockBranch">Optionally specfies that the branch should be read-only.</param>
|
||||
public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate requiredStatusChecks,
|
||||
BranchProtectionRequiredReviewsUpdate requiredPullRequestReviews,
|
||||
BranchProtectionPushRestrictionsUpdate restrictions,
|
||||
bool enforceAdmins)
|
||||
bool enforceAdmins,
|
||||
bool lockBranch = false)
|
||||
{
|
||||
RequiredStatusChecks = requiredStatusChecks;
|
||||
RequiredPullRequestReviews = requiredPullRequestReviews;
|
||||
Restrictions = restrictions;
|
||||
EnforceAdmins = enforceAdmins;
|
||||
LockBranch = lockBranch;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -108,6 +118,7 @@ namespace Octokit
|
||||
/// <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>
|
||||
/// <param name="lockBranch">Optionally specfies that the branch should be read-only.</param>
|
||||
public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate requiredStatusChecks,
|
||||
BranchProtectionRequiredReviewsUpdate requiredPullRequestReviews,
|
||||
BranchProtectionPushRestrictionsUpdate restrictions,
|
||||
@@ -116,12 +127,14 @@ namespace Octokit
|
||||
bool? allowForcePushes,
|
||||
bool allowDeletions,
|
||||
bool blockCreations,
|
||||
bool requiredConversationResolution)
|
||||
bool requiredConversationResolution,
|
||||
bool lockBranch = false)
|
||||
{
|
||||
RequiredStatusChecks = requiredStatusChecks;
|
||||
RequiredPullRequestReviews = requiredPullRequestReviews;
|
||||
Restrictions = restrictions;
|
||||
EnforceAdmins = enforceAdmins;
|
||||
LockBranch = lockBranch;
|
||||
RequiredLinearHistory = requiredLinearHistory;
|
||||
AllowForcePushes = allowForcePushes;
|
||||
AllowDeletions = allowDeletions;
|
||||
@@ -152,6 +165,11 @@ namespace Octokit
|
||||
/// </summary>
|
||||
public bool EnforceAdmins { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies whether this branch should be read-only.
|
||||
/// </summary>
|
||||
public bool LockBranch { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Enforces a linear commit Git history. Default is false.
|
||||
/// </summary>
|
||||
@@ -183,11 +201,12 @@ namespace Octokit
|
||||
get
|
||||
{
|
||||
return string.Format(CultureInfo.InvariantCulture,
|
||||
"RequiredStatusChecks: {0} RequiredPullRequestReviews: {1} Restrictions: {2} EnforceAdmins: {3}",
|
||||
"RequiredStatusChecks: {0} RequiredPullRequestReviews: {1} Restrictions: {2} EnforceAdmins: {3} LockBranch: {4}",
|
||||
RequiredStatusChecks?.DebuggerDisplay ?? "disabled",
|
||||
RequiredPullRequestReviews?.DebuggerDisplay ?? "disabled",
|
||||
Restrictions?.DebuggerDisplay ?? "disabled",
|
||||
EnforceAdmins);
|
||||
EnforceAdmins,
|
||||
LockBranch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,8 @@ namespace Octokit
|
||||
BranchProtectionEnabledCommon allowDeletions,
|
||||
BranchProtectionEnabledCommon blockCreations,
|
||||
BranchProtectionEnabledCommon requiredConversationResolution,
|
||||
BranchProtectionEnabledCommon requiredSignatures)
|
||||
BranchProtectionEnabledCommon requiredSignatures,
|
||||
EnforceLock lockBranch = null)
|
||||
{
|
||||
RequiredStatusChecks = requiredStatusChecks;
|
||||
RequiredPullRequestReviews = requiredPullRequestReviews;
|
||||
@@ -35,10 +36,9 @@ namespace Octokit
|
||||
BlockCreations = blockCreations;
|
||||
RequiredConversationResolution = requiredConversationResolution;
|
||||
RequiredSignatures = requiredSignatures;
|
||||
LockBranch = lockBranch != null ? lockBranch : new EnforceLock(false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Status check settings for the protected branch
|
||||
/// </summary>
|
||||
@@ -59,6 +59,11 @@ namespace Octokit
|
||||
/// </summary>
|
||||
public EnforceAdmins EnforceAdmins { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether this branch is read-only.
|
||||
/// </summary>
|
||||
public EnforceLock LockBranch { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies whether a linear history is required
|
||||
/// </summary>
|
||||
@@ -127,6 +132,30 @@ namespace Octokit
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies whether the this branch also should be read-only.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{DebuggerDisplay,nq}")]
|
||||
public class EnforceLock
|
||||
{
|
||||
public EnforceLock() { }
|
||||
|
||||
public EnforceLock(bool enabled)
|
||||
{
|
||||
Enabled = enabled;
|
||||
}
|
||||
|
||||
public bool Enabled { get; private set; }
|
||||
|
||||
internal string DebuggerDisplay
|
||||
{
|
||||
get
|
||||
{
|
||||
return string.Format(CultureInfo.InvariantCulture, "Enabled: {0}", Enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies settings for status checks which must pass before branches can be merged into the protected branch
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user