Skip to content

Commit

Permalink
add RequiredApprovingReview preview functionality to branch protectio…
Browse files Browse the repository at this point in the history
…n calls (#1912)
  • Loading branch information
ryangribble authored Jan 30, 2019
1 parent 64cecbb commit cf44249
Show file tree
Hide file tree
Showing 9 changed files with 213 additions and 163 deletions.
34 changes: 24 additions & 10 deletions Octokit.Tests.Integration/Clients/RepositoryBranchesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public async Task UpdatesBranchProtection()
var repoName = _userRepoContext.RepositoryName;
var update = new BranchProtectionSettingsUpdate(
new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }),
new BranchProtectionRequiredReviewsUpdate(false, true),
new BranchProtectionRequiredReviewsUpdate(false, true, 2),
false);

var protection = await _client.UpdateBranchProtection(repoOwner, repoName, "master", update);
Expand All @@ -329,6 +329,7 @@ public async Task UpdatesBranchProtection()
Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions);
Assert.False(protection.RequiredPullRequestReviews.DismissStaleReviews);
Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews);
Assert.Equal(2, protection.RequiredPullRequestReviews.RequiredApprovingReviewCount);

Assert.Null(protection.Restrictions);

Expand All @@ -341,7 +342,7 @@ public async Task UpdatesBranchProtectionWithRepositoryId()
var repoId = _userRepoContext.RepositoryId;
var update = new BranchProtectionSettingsUpdate(
new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }),
new BranchProtectionRequiredReviewsUpdate(false, true),
new BranchProtectionRequiredReviewsUpdate(false, true, 2),
false);

var protection = await _client.UpdateBranchProtection(repoId, "master", update);
Expand All @@ -352,6 +353,7 @@ public async Task UpdatesBranchProtectionWithRepositoryId()
Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions);
Assert.False(protection.RequiredPullRequestReviews.DismissStaleReviews);
Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews);
Assert.Equal(2, protection.RequiredPullRequestReviews.RequiredApprovingReviewCount);

Assert.Null(protection.Restrictions);

Expand All @@ -365,7 +367,7 @@ public async Task UpdatesBranchProtectionForOrgRepo()
var repoName = _orgRepoContext.RepositoryContext.RepositoryName;
var update = new BranchProtectionSettingsUpdate(
new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }),
new BranchProtectionRequiredReviewsUpdate(new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(false), false, false),
new BranchProtectionRequiredReviewsUpdate(new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(false), false, false, 2),
new BranchProtectionPushRestrictionsUpdate(),
false);

Expand All @@ -377,6 +379,7 @@ public async Task UpdatesBranchProtectionForOrgRepo()
Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions);
Assert.False(protection.RequiredPullRequestReviews.DismissStaleReviews);
Assert.False(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews);
Assert.Equal(2, protection.RequiredPullRequestReviews.RequiredApprovingReviewCount);

Assert.Empty(protection.Restrictions.Teams);
Assert.Empty(protection.Restrictions.Users);
Expand All @@ -390,7 +393,7 @@ public async Task UpdatesBranchProtectionForOrgRepoWithRepositoryId()
var repoId = _orgRepoContext.RepositoryContext.RepositoryId;
var update = new BranchProtectionSettingsUpdate(
new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }),
new BranchProtectionRequiredReviewsUpdate(new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(false), false, false),
new BranchProtectionRequiredReviewsUpdate(new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(false), false, false, 2),
new BranchProtectionPushRestrictionsUpdate(),
false);

Expand All @@ -402,6 +405,7 @@ public async Task UpdatesBranchProtectionForOrgRepoWithRepositoryId()
Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions);
Assert.False(protection.RequiredPullRequestReviews.DismissStaleReviews);
Assert.False(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews);
Assert.Equal(2, protection.RequiredPullRequestReviews.RequiredApprovingReviewCount);

Assert.Empty(protection.Restrictions.Teams);
Assert.Empty(protection.Restrictions.Users);
Expand Down Expand Up @@ -873,26 +877,28 @@ public async Task UpdatesReviewEnforcement()
{
var repoOwner = _userRepoContext.RepositoryOwner;
var repoName = _userRepoContext.RepositoryName;
var update = new BranchProtectionRequiredReviewsUpdate(false, true);
var update = new BranchProtectionRequiredReviewsUpdate(false, true, 2);

var requiredReviews = await _client.UpdateReviewEnforcement(repoOwner, repoName, "master", update);

Assert.Null(requiredReviews.DismissalRestrictions);
Assert.False(requiredReviews.DismissStaleReviews);
Assert.True(requiredReviews.RequireCodeOwnerReviews);
Assert.Equal(2, requiredReviews.RequiredApprovingReviewCount);
}

[IntegrationTest]
public async Task UpdatesReviewEnforcementWithRepositoryId()
{
var repoId = _userRepoContext.RepositoryId;
var update = new BranchProtectionRequiredReviewsUpdate(false, true);
var update = new BranchProtectionRequiredReviewsUpdate(false, true, 2);

var requiredReviews = await _client.UpdateReviewEnforcement(repoId, "master", update);

Assert.Null(requiredReviews.DismissalRestrictions);
Assert.False(requiredReviews.DismissStaleReviews);
Assert.True(requiredReviews.RequireCodeOwnerReviews);
Assert.Equal(2, requiredReviews.RequiredApprovingReviewCount);
}

[IntegrationTest]
Expand All @@ -903,13 +909,15 @@ public async Task UpdatesReviewEnforcementForOrgRepo()
var update = new BranchProtectionRequiredReviewsUpdate(
new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(false),
false,
false);
false,
2);

var requiredReviews = await _client.UpdateReviewEnforcement(repoOwner, repoName, "master", update);

Assert.Null(requiredReviews.DismissalRestrictions);
Assert.False(requiredReviews.DismissStaleReviews);
Assert.False(requiredReviews.RequireCodeOwnerReviews);
Assert.Equal(2, requiredReviews.RequiredApprovingReviewCount);
}

[IntegrationTest]
Expand All @@ -919,13 +927,15 @@ public async Task UpdatesReviewEnforcementForOrgRepoWithRepositoryId()
var update = new BranchProtectionRequiredReviewsUpdate(
new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(false),
false,
false);
false,
2);

var requiredReviews = await _client.UpdateReviewEnforcement(repoId, "master", update);

Assert.Null(requiredReviews.DismissalRestrictions);
Assert.False(requiredReviews.DismissStaleReviews);
Assert.False(requiredReviews.RequireCodeOwnerReviews);
Assert.Equal(2, requiredReviews.RequiredApprovingReviewCount);
}

[IntegrationTest]
Expand All @@ -936,14 +946,16 @@ public async Task UpdatesReviewEnforcementForOrgRepoWithAdminOnly()
var update = new BranchProtectionRequiredReviewsUpdate(
new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(true),
false,
false);
false,
2);

var requiredReviews = await _client.UpdateReviewEnforcement(repoOwner, repoName, "master", update);

Assert.Empty(requiredReviews.DismissalRestrictions.Teams);
Assert.Empty(requiredReviews.DismissalRestrictions.Users);
Assert.False(requiredReviews.DismissStaleReviews);
Assert.False(requiredReviews.RequireCodeOwnerReviews);
Assert.Equal(2, requiredReviews.RequiredApprovingReviewCount);
}

[IntegrationTest]
Expand All @@ -953,14 +965,16 @@ public async Task UpdatesReviewEnforcementForOrgRepoWithAdminOnlyWithRepositoryI
var update = new BranchProtectionRequiredReviewsUpdate(
new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(true),
false,
false);
false,
2);

var requiredReviews = await _client.UpdateReviewEnforcement(repoId, "master", update);

Assert.Empty(requiredReviews.DismissalRestrictions.Teams);
Assert.Empty(requiredReviews.DismissalRestrictions.Users);
Assert.False(requiredReviews.DismissStaleReviews);
Assert.False(requiredReviews.RequireCodeOwnerReviews);
Assert.Equal(2, requiredReviews.RequiredApprovingReviewCount);
}

public void Dispose()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal async static Task<RepositoryContext> CreateRepositoryWithProtectedBranc
// Protect master branch
var update = new BranchProtectionSettingsUpdate(
new BranchProtectionRequiredStatusChecksUpdate(true, new[] { "build", "test" }),
new BranchProtectionRequiredReviewsUpdate(true, true),
new BranchProtectionRequiredReviewsUpdate(true, true, 3),
null,
true);

Expand Down Expand Up @@ -60,7 +60,7 @@ await client.Organization.Team.AddRepository(
// Protect master branch
var protection = new BranchProtectionSettingsUpdate(
new BranchProtectionRequiredStatusChecksUpdate(true, new[] { "build", "test" }),
new BranchProtectionRequiredReviewsUpdate(new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(new BranchProtectionTeamCollection { contextOrgTeam.TeamName }), true, true),
new BranchProtectionRequiredReviewsUpdate(new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(new BranchProtectionTeamCollection { contextOrgTeam.TeamName }), true, true, 3),
new BranchProtectionPushRestrictionsUpdate(new BranchProtectionTeamCollection { contextOrgTeam.TeamName }),
true);
await client.Repository.Branch.UpdateBranchProtection(contextOrgRepo.RepositoryOwner, contextOrgRepo.RepositoryName, "master", protection);
Expand Down
Loading

0 comments on commit cf44249

Please sign in to comment.