diff --git a/Octokit.Tests.Integration/Clients/RepositoryBranchesClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryBranchesClientTests.cs index f732d8b8fb..5e300efeba 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryBranchesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryBranchesClientTests.cs @@ -409,7 +409,7 @@ public async Task UpdatesBranchProtection() var repoOwner = _userRepoContext.RepositoryOwner; var repoName = _userRepoContext.RepositoryName; var update = new BranchProtectionSettingsUpdate( - new BranchProtectionRequiredStatusChecksUpdate(false, false, new[] { "new" }), new BranchProtectionRequiredPullRequestReviewsUpdate(false)); + new BranchProtectionRequiredStatusChecksUpdate(false, false, new[] { "new" })); var protection = await _client.UpdateBranchProtection(repoOwner, repoName, "master", update); @@ -425,7 +425,7 @@ public async Task UpdatesBranchProtectionWithRepositoryId() { var repoId = _userRepoContext.RepositoryId; var update = new BranchProtectionSettingsUpdate( - new BranchProtectionRequiredStatusChecksUpdate(false, false, new[] { "new" }), new BranchProtectionRequiredPullRequestReviewsUpdate(false)); + new BranchProtectionRequiredStatusChecksUpdate(false, false, new[] { "new" })); var protection = await _client.UpdateBranchProtection(repoId, "master", update); @@ -443,7 +443,7 @@ public async Task UpdatesBranchProtectionForOrgRepo() var repoName = _orgRepoContext.RepositoryContext.RepositoryName; var update = new BranchProtectionSettingsUpdate( new BranchProtectionRequiredStatusChecksUpdate(false, false, new[] { "new" }), - new BranchProtectionPushRestrictionsUpdate(), new BranchProtectionRequiredPullRequestReviewsUpdate(false)); + new BranchProtectionPushRestrictionsUpdate()); var protection = await _client.UpdateBranchProtection(repoOwner, repoName, "master", update); @@ -461,7 +461,7 @@ public async Task UpdatesBranchProtectionForOrgRepoWithRepositoryId() var repoId = _orgRepoContext.RepositoryContext.RepositoryId; var update = new BranchProtectionSettingsUpdate( new BranchProtectionRequiredStatusChecksUpdate(false, false, new[] { "new" }), - new BranchProtectionPushRestrictionsUpdate(), new BranchProtectionRequiredPullRequestReviewsUpdate(false)); + new BranchProtectionPushRestrictionsUpdate()); var protection = await _client.UpdateBranchProtection(repoId, "master", update); diff --git a/Octokit.Tests.Integration/Helpers/OrganizationRepositoryWithTeamContext.cs b/Octokit.Tests.Integration/Helpers/OrganizationRepositoryWithTeamContext.cs index 515f2e2af0..6760060679 100644 --- a/Octokit.Tests.Integration/Helpers/OrganizationRepositoryWithTeamContext.cs +++ b/Octokit.Tests.Integration/Helpers/OrganizationRepositoryWithTeamContext.cs @@ -31,7 +31,7 @@ internal async static Task CreateRepositoryWithProtectedBranc // Protect master branch var update = new BranchProtectionSettingsUpdate( - new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "build", "test" }), new BranchProtectionRequiredPullRequestReviewsUpdate(false)); + new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "build", "test" })); await client.Repository.Branch.UpdateBranchProtection(contextUserRepo.RepositoryOwner, contextUserRepo.RepositoryName, "master", update); @@ -57,7 +57,7 @@ await client.Organization.Team.AddRepository( // Protect master branch var protection = new BranchProtectionSettingsUpdate( new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "build", "test" }), - new BranchProtectionPushRestrictionsUpdate(new BranchProtectionTeamCollection { contextOrgTeam.TeamName }), new BranchProtectionRequiredPullRequestReviewsUpdate(false)); + new BranchProtectionPushRestrictionsUpdate(new BranchProtectionTeamCollection { contextOrgTeam.TeamName })); await client.Repository.Branch.UpdateBranchProtection(contextOrgRepo.RepositoryOwner, contextOrgRepo.RepositoryName, "master", protection); return new OrganizationRepositoryWithTeamContext diff --git a/Octokit.Tests/Clients/RepositoryBranchesClientTests.cs b/Octokit.Tests/Clients/RepositoryBranchesClientTests.cs index 0d91e970ce..846a77bcbe 100644 --- a/Octokit.Tests/Clients/RepositoryBranchesClientTests.cs +++ b/Octokit.Tests/Clients/RepositoryBranchesClientTests.cs @@ -257,7 +257,7 @@ public void RequestsTheCorrectUrl() var connection = Substitute.For(); var client = new RepositoryBranchesClient(connection); var update = new BranchProtectionSettingsUpdate( - new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" }), new BranchProtectionRequiredPullRequestReviewsUpdate(false)); + new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" })); const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; client.UpdateBranchProtection("owner", "repo", "branch", update); @@ -272,7 +272,7 @@ public void RequestsTheCorrectUrlWithRepositoryId() var connection = Substitute.For(); var client = new RepositoryBranchesClient(connection); var update = new BranchProtectionSettingsUpdate( - new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" }), new BranchProtectionRequiredPullRequestReviewsUpdate(false)); + new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" })); const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; client.UpdateBranchProtection(1, "branch", update); @@ -286,7 +286,7 @@ public async Task EnsuresNonNullArguments() { var client = new RepositoryBranchesClient(Substitute.For()); var update = new BranchProtectionSettingsUpdate( - new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" }), new BranchProtectionRequiredPullRequestReviewsUpdate(false)); + new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" })); await Assert.ThrowsAsync(() => client.UpdateBranchProtection(null, "repo", "branch", update)); await Assert.ThrowsAsync(() => client.UpdateBranchProtection("owner", null, "branch", update)); diff --git a/Octokit.Tests/Reactive/ObservableRepositoryBranchesClientTests.cs b/Octokit.Tests/Reactive/ObservableRepositoryBranchesClientTests.cs index 0f116a84fd..a4dd6a66c7 100644 --- a/Octokit.Tests/Reactive/ObservableRepositoryBranchesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableRepositoryBranchesClientTests.cs @@ -250,7 +250,7 @@ public void RequestsTheCorrectUrl() var gitHubClient = Substitute.For(); var client = new ObservableRepositoryBranchesClient(gitHubClient); var update = new BranchProtectionSettingsUpdate( - new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" }), new BranchProtectionRequiredPullRequestReviewsUpdate(false)); + new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" })); client.UpdateBranchProtection("owner", "repo", "branch", update); @@ -264,7 +264,7 @@ public void RequestsTheCorrectUrlWithRepositoryId() var gitHubClient = Substitute.For(); var client = new ObservableRepositoryBranchesClient(gitHubClient); var update = new BranchProtectionSettingsUpdate( - new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" }), new BranchProtectionRequiredPullRequestReviewsUpdate(false)); + new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" })); client.UpdateBranchProtection(1, "branch", update); @@ -277,7 +277,7 @@ public async Task EnsuresNonNullArguments() { var client = new ObservableRepositoryBranchesClient(Substitute.For()); var update = new BranchProtectionSettingsUpdate( - new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" }), new BranchProtectionRequiredPullRequestReviewsUpdate(false)); + new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" })); Assert.Throws(() => client.UpdateBranchProtection(null, "repo", "branch", update)); Assert.Throws(() => client.UpdateBranchProtection("owner", null, "branch", update)); diff --git a/Octokit/Models/Request/BranchProtectionUpdate.cs b/Octokit/Models/Request/BranchProtectionUpdate.cs index 27cc4f9955..8f047268cc 100644 --- a/Octokit/Models/Request/BranchProtectionUpdate.cs +++ b/Octokit/Models/Request/BranchProtectionUpdate.cs @@ -20,8 +20,53 @@ public class BranchProtectionSettingsUpdate /// Create a BranchProtection update request /// /// Specifies the requested status check settings. Pass null to disable status checks - /// Specifies whether repository administrators need to pass pull requests checks before being able to merge a pull request - public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate requiredStatusChecks, BranchProtectionRequiredPullRequestReviewsUpdate requiredPullRequestReviews) + public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate requiredStatusChecks) + { + RequiredStatusChecks = requiredStatusChecks; + Restrictions = null; + RequiredPullRequestReviews = null; + } + + /// + /// Create a BranchProtection update request + /// + /// Specifies the requested push access restrictions (applies only to Organization owned repositories). Pass null to disable push access restrictions + public BranchProtectionSettingsUpdate(BranchProtectionPushRestrictionsUpdate restrictions) + { + RequiredStatusChecks = null; + Restrictions = restrictions; + RequiredPullRequestReviews = null; + } + + /// + /// Create a BranchProtection update request + /// + /// Specifies if reviews are required to merge the pull request. Pass null to disable restrictions + public BranchProtectionSettingsUpdate(BranchProtectionRequiredReviewsUpdate requiredPullRequestReviews) + { + RequiredStatusChecks = null; + Restrictions = null; + RequiredPullRequestReviews = requiredPullRequestReviews; + } + + /// + /// Create a BranchProtection update request + /// + /// Specifies the requested status check settings. Pass null to disable status checks + /// Specifies the requested push access restrictions (applies only to Organization owned repositories). Pass null to disable push access restrictions + public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate requiredStatusChecks, BranchProtectionPushRestrictionsUpdate restrictions) + { + RequiredStatusChecks = requiredStatusChecks; + Restrictions = restrictions; + RequiredPullRequestReviews = null; + } + + /// + /// Create a BranchProtection update request + /// + /// 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 restrictions + public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate requiredStatusChecks, BranchProtectionRequiredReviewsUpdate requiredPullRequestReviews) { RequiredStatusChecks = requiredStatusChecks; RequiredPullRequestReviews = requiredPullRequestReviews; @@ -32,8 +77,8 @@ public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate /// Create a BranchProtection update request /// /// Specifies the requested push access restrictions (applies only to Organization owned repositories). Pass null to disable push access restrictions - /// Specifies whether repository administrators need to pass pull requests checks before being able to merge a pull request - public BranchProtectionSettingsUpdate(BranchProtectionPushRestrictionsUpdate restrictions, BranchProtectionRequiredPullRequestReviewsUpdate requiredPullRequestReviews) + /// Specifies if reviews are required to merge the pull request. Pass null to disable restrictions + public BranchProtectionSettingsUpdate(BranchProtectionPushRestrictionsUpdate restrictions, BranchProtectionRequiredReviewsUpdate requiredPullRequestReviews) { RequiredStatusChecks = null; RequiredPullRequestReviews = requiredPullRequestReviews; @@ -45,8 +90,8 @@ public BranchProtectionSettingsUpdate(BranchProtectionPushRestrictionsUpdate res /// /// Specifies the requested status check settings. Pass null to disable status checks /// Specifies the requested push access restrictions (applies only to Organization owned repositories). Pass null to disable push access restrictions - /// Specifies whether repository administrators need to pass pull request reviews before being able to merge a pull request - public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate requiredStatusChecks, BranchProtectionPushRestrictionsUpdate restrictions, BranchProtectionRequiredPullRequestReviewsUpdate requiredPullRequestReviews) + /// Specifies if reviews are required to merge the pull request. Pass null to disable restrictions + public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate requiredStatusChecks, BranchProtectionPushRestrictionsUpdate restrictions, BranchProtectionRequiredReviewsUpdate requiredPullRequestReviews) { RequiredStatusChecks = requiredStatusChecks; Restrictions = restrictions; @@ -62,7 +107,7 @@ public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate /// /// Pull Request review settings for the protected branch /// - public BranchProtectionRequiredPullRequestReviewsUpdate RequiredPullRequestReviews { get; protected set; } + public BranchProtectionRequiredReviewsUpdate RequiredPullRequestReviews { get; protected set; } /// /// Push access restrictions for the protected branch @@ -238,16 +283,12 @@ internal string DebuggerDisplay } /// - /// Specifies whether repository administrators need to pass pull request reviews before being able to merge a pull request + /// Specifies if pull request reviews are required before merging a pull request. Can optionally enforce the policy on repository administrators also. /// [DebuggerDisplay("{DebuggerDisplay,nq}")] - public class BranchProtectionRequiredPullRequestReviewsUpdate + public class BranchProtectionRequiredReviewsUpdate { - /// - /// Sets whether repository administrators are allowed to merge a pull request without going through the review status checks - /// - /// Enforce pull request reviews for repository administrators - public BranchProtectionRequiredPullRequestReviewsUpdate(bool includeAdmins) + public BranchProtectionRequiredReviewsUpdate(bool includeAdmins) { IncludeAdmins = includeAdmins; } diff --git a/Octokit/Models/Response/BranchProtection.cs b/Octokit/Models/Response/BranchProtection.cs index 0053925f25..483d3c06c7 100644 --- a/Octokit/Models/Response/BranchProtection.cs +++ b/Octokit/Models/Response/BranchProtection.cs @@ -108,7 +108,7 @@ public class BranchProtectionSettings { public BranchProtectionSettings() { } - public BranchProtectionSettings(BranchProtectionRequiredStatusChecks requiredStatusChecks, BranchProtectionPushRestrictions restrictions, BranchProtectionRequiredPullRequestReviews requiredPullRequestReviews) + public BranchProtectionSettings(BranchProtectionRequiredStatusChecks requiredStatusChecks, BranchProtectionPushRestrictions restrictions, BranchProtectionRequiredReviews requiredPullRequestReviews) { RequiredStatusChecks = requiredStatusChecks; Restrictions = restrictions; @@ -128,7 +128,7 @@ public BranchProtectionSettings(BranchProtectionRequiredStatusChecks requiredSta /// /// Pull Request Review required settings for the protected branch /// - public BranchProtectionRequiredPullRequestReviews RequiredPullRequestReviews { get; protected set; } + public BranchProtectionRequiredReviews RequiredPullRequestReviews { get; protected set; } internal string DebuggerDisplay { @@ -223,14 +223,14 @@ internal string DebuggerDisplay } /// - /// Specifies if pull request reviews are required before merging a pull request made by a repository administrator. + /// Specifies if pull request reviews are required before merging a pull request. Can optionally enforce the policy on repository administrators also. /// [DebuggerDisplay("{DebuggerDisplay,nq}")] - public class BranchProtectionRequiredPullRequestReviews + public class BranchProtectionRequiredReviews { - public BranchProtectionRequiredPullRequestReviews() { } + public BranchProtectionRequiredReviews() { } - public BranchProtectionRequiredPullRequestReviews(bool includeAdmins) + public BranchProtectionRequiredReviews(bool includeAdmins) { IncludeAdmins = includeAdmins; }