From d152519c823d963a22c422460649844627d1511d Mon Sep 17 00:00:00 2001 From: Jeff Lill Date: Fri, 19 May 2023 19:54:00 -0700 Subject: [PATCH 1/4] Added support for making branches read-only --- .../Clients/RepositoryBranchesClientTests.cs | 2 ++ .../Models/Request/BranchProtectionUpdate.cs | 31 +++++++++++++---- Octokit/Models/Response/BranchProtection.cs | 33 +++++++++++++++++-- 3 files changed, 58 insertions(+), 8 deletions(-) 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..b670ca2d9a 100644 --- a/Octokit/Models/Response/BranchProtection.cs +++ b/Octokit/Models/Response/BranchProtection.cs @@ -18,6 +18,7 @@ public BranchProtectionSettings(BranchProtectionRequiredStatusChecks requiredSta BranchProtectionRequiredReviews requiredPullRequestReviews, BranchProtectionPushRestrictions restrictions, EnforceAdmins enforceAdmins, + EnforceLock lockBranch, BranchProtectionEnabledCommon requiredLinearHistory, BranchProtectionEnabledCommon allowForcePushes, BranchProtectionEnabledCommon allowDeletions, @@ -29,6 +30,7 @@ public BranchProtectionSettings(BranchProtectionRequiredStatusChecks requiredSta RequiredPullRequestReviews = requiredPullRequestReviews; Restrictions = restrictions; EnforceAdmins = enforceAdmins; + LockBranch = lockBranch; RequiredLinearHistory = requiredLinearHistory; AllowForcePushes = allowForcePushes; AllowDeletions = allowDeletions; @@ -37,8 +39,6 @@ public BranchProtectionSettings(BranchProtectionRequiredStatusChecks requiredSta RequiredSignatures = requiredSignatures; } - - /// /// 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 /// From 61fba353f2fb76dfa86374ce4e324f4fcab8a7cc Mon Sep 17 00:00:00 2001 From: Jeff Lill Date: Fri, 19 May 2023 20:25:49 -0700 Subject: [PATCH 2/4] nuget: publishes as: Neon.Octokit --- Octokit/Octokit.csproj | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index a1f0c9075b..7c851cb700 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -2,21 +2,22 @@ An async-based GitHub API client library for .NET and .NET Core - Octokit + Neon.Octokit GitHub 0.0.0-dev true netstandard2.0 Octokit - Octokit + Neon.Octokit embedded - https://github.com/octokit/octokit.net - https://github.com/octokit/octokit.net + https://github.com/neonforge-forks/octokit.net + https://github.com/neonforge-forks/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 + NEONFORGE: This is a temporary Octokit upgrade that supports locking branches. This is currently required by the Neon.GitHub package but we've submitted a pull request, so hopefully that will be accepted and we'll be able to deprecate this package. From ff83eac7549caead1fe73ea3ce7e10df8b07d411 Mon Sep 17 00:00:00 2001 From: Jeff Lill Date: Sat, 20 May 2023 08:25:48 -0700 Subject: [PATCH 3/4] OctoKit.csproj: restored original file. Will publish temporary nugets from the [release] branch going forward --- Octokit/Octokit.csproj | 85 +++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 43 deletions(-) diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 7c851cb700..ebee405f40 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -1,51 +1,50 @@  - - An async-based GitHub API client library for .NET and .NET Core - Neon.Octokit - GitHub - 0.0.0-dev - true - netstandard2.0 - Octokit - Neon.Octokit - embedded - https://github.com/neonforge-forks/octokit.net - https://github.com/neonforge-forks/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 - NEONFORGE: This is a temporary Octokit upgrade that supports locking branches. This is currently required by the Neon.GitHub package but we've submitted a pull request, so hopefully that will be accepted and we'll be able to deprecate this package. - + + 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) + + From 8854ccfa7a30776e6932d0ec4acfe7d914218eb3 Mon Sep 17 00:00:00 2001 From: Jeff Lill Date: Sat, 20 May 2023 08:31:30 -0700 Subject: [PATCH 4/4] Change to branch protection settings is not breaking any more --- Octokit/Models/Response/BranchProtection.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Octokit/Models/Response/BranchProtection.cs b/Octokit/Models/Response/BranchProtection.cs index b670ca2d9a..13202d859e 100644 --- a/Octokit/Models/Response/BranchProtection.cs +++ b/Octokit/Models/Response/BranchProtection.cs @@ -18,25 +18,25 @@ public BranchProtectionSettings(BranchProtectionRequiredStatusChecks requiredSta BranchProtectionRequiredReviews requiredPullRequestReviews, BranchProtectionPushRestrictions restrictions, EnforceAdmins enforceAdmins, - EnforceLock lockBranch, BranchProtectionEnabledCommon requiredLinearHistory, BranchProtectionEnabledCommon allowForcePushes, BranchProtectionEnabledCommon allowDeletions, BranchProtectionEnabledCommon blockCreations, BranchProtectionEnabledCommon requiredConversationResolution, - BranchProtectionEnabledCommon requiredSignatures) + BranchProtectionEnabledCommon requiredSignatures, + EnforceLock lockBranch = null) { RequiredStatusChecks = requiredStatusChecks; RequiredPullRequestReviews = requiredPullRequestReviews; Restrictions = restrictions; EnforceAdmins = enforceAdmins; - LockBranch = lockBranch; RequiredLinearHistory = requiredLinearHistory; AllowForcePushes = allowForcePushes; AllowDeletions = allowDeletions; BlockCreations = blockCreations; RequiredConversationResolution = requiredConversationResolution; RequiredSignatures = requiredSignatures; + LockBranch = lockBranch != null ? lockBranch : new EnforceLock(false); } ///