diff --git a/Octokit.Tests.Integration/Clients/RepositoryBranchesClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryBranchesClientTests.cs index 682fe7f3c5..038cf74d87 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryBranchesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryBranchesClientTests.cs @@ -296,6 +296,7 @@ public async Task GetsBranchProtection() Assert.Null(protection.Restrictions); Assert.True(protection.EnforceAdmins.Enabled); + Assert.True(protection.LockBranch.Enabled); Assert.True(protection.RequiredLinearHistory.Enabled); Assert.True(protection.AllowForcePushes.Enabled); Assert.True(protection.AllowDeletions.Enabled); @@ -323,6 +324,7 @@ public async Task GetsBranchProtectionWithRepositoryId() Assert.Null(protection.Restrictions); Assert.True(protection.EnforceAdmins.Enabled); + Assert.True(protection.LockBranch.Enabled); Assert.True(protection.RequiredLinearHistory.Enabled); Assert.True(protection.AllowForcePushes.Enabled); Assert.True(protection.AllowDeletions.Enabled); diff --git a/Octokit/Models/Request/BranchProtectionUpdate.cs b/Octokit/Models/Request/BranchProtectionUpdate.cs index 1c2424cdf7..74d43d3610 100644 --- a/Octokit/Models/Request/BranchProtectionUpdate.cs +++ b/Octokit/Models/Request/BranchProtectionUpdate.cs @@ -26,6 +26,7 @@ public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate RequiredPullRequestReviews = null; Restrictions = null; EnforceAdmins = false; + LockBranch = false; } /// @@ -38,6 +39,7 @@ public BranchProtectionSettingsUpdate(BranchProtectionRequiredReviewsUpdate requ RequiredPullRequestReviews = requiredPullRequestReviews; Restrictions = null; EnforceAdmins = false; + LockBranch = false; } /// @@ -50,18 +52,21 @@ public BranchProtectionSettingsUpdate(BranchProtectionPushRestrictionsUpdate res RequiredPullRequestReviews = null; Restrictions = restrictions; EnforceAdmins = false; + LockBranch = false; } /// /// Create a BranchProtection update request /// /// Specifies whether the protections applied to this branch also apply to repository admins - public BranchProtectionSettingsUpdate(bool enforceAdmins) + /// Optionally specfies that the branch should be read-only. + public BranchProtectionSettingsUpdate(bool enforceAdmins, bool lockBranch = false) { RequiredStatusChecks = null; RequiredPullRequestReviews = null; Restrictions = null; EnforceAdmins = enforceAdmins; + LockBranch = lockBranch; } /// @@ -70,12 +75,14 @@ public BranchProtectionSettingsUpdate(bool enforceAdmins) /// Specifies the requested status check settings. Pass null to disable status checks /// Specifies if reviews are required to merge the pull request. Pass null to disable required reviews /// Specifies whether the protections applied to this branch also apply to repository admins - public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate requiredStatusChecks, BranchProtectionRequiredReviewsUpdate requiredPullRequestReviews, bool enforceAdmins) + /// Optionally specfies that the branch should be read-only. + public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate requiredStatusChecks, BranchProtectionRequiredReviewsUpdate requiredPullRequestReviews, bool enforceAdmins, bool lockBranch = false) { RequiredStatusChecks = requiredStatusChecks; RequiredPullRequestReviews = requiredPullRequestReviews; Restrictions = null; EnforceAdmins = enforceAdmins; + LockBranch = lockBranch; } /// @@ -85,15 +92,18 @@ public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate /// Specifies if reviews are required to merge the pull request. Pass null to disable required reviews /// Specifies the requested push access restrictions (applies only to Organization owned repositories). Pass null to disable push access restrictions /// Specifies whether the protections applied to this branch also apply to repository admins + /// Optionally specfies that the branch should be read-only. 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; } /// @@ -108,6 +118,7 @@ public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate /// Allows deletion of the protected branch /// The restrictions branch protection settings will also block pushes which create new branches /// Requires all conversations on code to be resolved before a pull request can be merged + /// Optionally specfies that the branch should be read-only. public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate requiredStatusChecks, BranchProtectionRequiredReviewsUpdate requiredPullRequestReviews, BranchProtectionPushRestrictionsUpdate restrictions, @@ -116,12 +127,14 @@ public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate 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 @@ public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate /// public bool EnforceAdmins { get; set; } + /// + /// Specifies whether this branch should be read-only. + /// + public bool LockBranch { get; set; } + /// /// Enforces a linear commit Git history. Default is false. /// @@ -183,11 +201,12 @@ internal string DebuggerDisplay 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); } } } diff --git a/Octokit/Models/Response/BranchProtection.cs b/Octokit/Models/Response/BranchProtection.cs index cc73b69e3e..13202d859e 100644 --- a/Octokit/Models/Response/BranchProtection.cs +++ b/Octokit/Models/Response/BranchProtection.cs @@ -23,7 +23,8 @@ public BranchProtectionSettings(BranchProtectionRequiredStatusChecks requiredSta BranchProtectionEnabledCommon allowDeletions, BranchProtectionEnabledCommon blockCreations, BranchProtectionEnabledCommon requiredConversationResolution, - BranchProtectionEnabledCommon requiredSignatures) + BranchProtectionEnabledCommon requiredSignatures, + EnforceLock lockBranch = null) { RequiredStatusChecks = requiredStatusChecks; RequiredPullRequestReviews = requiredPullRequestReviews; @@ -35,10 +36,9 @@ public BranchProtectionSettings(BranchProtectionRequiredStatusChecks requiredSta BlockCreations = blockCreations; RequiredConversationResolution = requiredConversationResolution; RequiredSignatures = requiredSignatures; + LockBranch = lockBranch != null ? lockBranch : new EnforceLock(false); } - - /// /// Status check settings for the protected branch /// @@ -59,6 +59,11 @@ public BranchProtectionSettings(BranchProtectionRequiredStatusChecks requiredSta /// public EnforceAdmins EnforceAdmins { get; private set; } + /// + /// Indicates whether this branch is read-only. + /// + public EnforceLock LockBranch { get; private set; } + /// /// Specifies whether a linear history is required /// @@ -127,6 +132,30 @@ internal string DebuggerDisplay } } + /// + /// Specifies whether the this branch also should be read-only. + /// + [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); + } + } + } + /// /// Specifies settings for status checks which must pass before branches can be merged into the protected branch /// diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index a1f0c9075b..ebee405f40 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -1,50 +1,50 @@  - - An async-based GitHub API client library for .NET and .NET Core - Octokit - GitHub - 0.0.0-dev - true - netstandard2.0 - Octokit - Octokit - embedded - https://github.com/octokit/octokit.net - https://github.com/octokit/octokit.net - https://f.cloud.github.com/assets/19977/1510987/64af2b26-4a9d-11e3-89fc-96a185171c75.png - octokit.png - MIT - GitHub API Octokit linqpad-samples dotnetcore - Copyright GitHub 2017 - + + An async-based GitHub API client library for .NET and .NET Core + Octokit + GitHub + 0.0.0-dev + true + netstandard2.0 + Octokit + Octokit + embedded + https://github.com/octokit/octokit.net + https://github.com/octokit/octokit.net + https://f.cloud.github.com/assets/19977/1510987/64af2b26-4a9d-11e3-89fc-96a185171c75.png + octokit.png + MIT + GitHub API Octokit linqpad-samples dotnetcore + Copyright GitHub 2017 + - - $(DefineConstants);SIMPLE_JSON_INTERNAL;SIMPLE_JSON_OBJARRAYINTERNAL;SIMPLE_JSON_READONLY_COLLECTIONS;SIMPLE_JSON_TYPEINFO - $(NoWarn);1591;1701;1702;1705 - true - + + $(DefineConstants);SIMPLE_JSON_INTERNAL;SIMPLE_JSON_OBJARRAYINTERNAL;SIMPLE_JSON_READONLY_COLLECTIONS;SIMPLE_JSON_TYPEINFO + $(NoWarn);1591;1701;1702;1705 + true + - - - true - - true - - $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb - + + + true + + true + + $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb + - - - + + + - - - + + + - - - <_Parameter1>Octokit.Tests$(StrongNameSuffix) - - + + + <_Parameter1>Octokit.Tests$(StrongNameSuffix) + +