diff --git a/Octokit.Reactive/Clients/IObservableRepositoryBranchesClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryBranchesClient.cs
index 5bf66450..b7836177 100644
--- a/Octokit.Reactive/Clients/IObservableRepositoryBranchesClient.cs
+++ b/Octokit.Reactive/Clients/IObservableRepositoryBranchesClient.cs
@@ -295,6 +295,69 @@ namespace Octokit.Reactive
/// The contexts to remove
IObservable DeleteRequiredStatusChecksContexts(long repositoryId, string branch, IReadOnlyList contexts);
+ ///
+ /// Get required pull request review enforcement of protected branch
+ ///
+ ///
+ /// See the API documentation for more details
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The name of the branch
+ IObservable GetReviewEnforcement(string owner, string name, string branch);
+
+ ///
+ /// Get required pull request review enforcement of protected branch
+ ///
+ ///
+ /// See the API documentation for more details
+ ///
+ /// The Id of the repository
+ /// The name of the branch
+ IObservable GetReviewEnforcement(long repositoryId, string branch);
+
+ ///
+ /// Update required pull request review enforcement of protected branch
+ ///
+ ///
+ /// See the API documentation for more details
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The name of the branch
+ IObservable UpdateReviewEnforcement(string owner, string name, string branch, BranchProtectionRequiredReviewsUpdate update);
+
+ ///
+ /// Update required pull request review enforcement of protected branch
+ ///
+ ///
+ /// See the API documentation for more details
+ ///
+ /// The Id of the repository
+ /// The name of the branch
+ IObservable UpdateReviewEnforcement(long repositoryId, string branch, BranchProtectionRequiredReviewsUpdate update);
+
+ ///
+ /// Remove required pull request review enforcement of protected branch
+ ///
+ ///
+ /// See the API documentation for more details
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The name of the branch
+ IObservable RemoveReviewEnforcement(string owner, string name, string branch);
+
+ ///
+ /// Remove required pull request review enforcement of protected branch
+ ///
+ ///
+ /// See the API documentation for more details
+ ///
+ /// The Id of the repository
+ /// The name of the branch
+ IObservable RemoveReviewEnforcement(long repositoryId, string branch);
+
///
/// Get admin enforcement of protected branch
///
diff --git a/Octokit.Reactive/Clients/ObservableRepositoryBranchesClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryBranchesClient.cs
index b3080a21..6b800dd9 100644
--- a/Octokit.Reactive/Clients/ObservableRepositoryBranchesClient.cs
+++ b/Octokit.Reactive/Clients/ObservableRepositoryBranchesClient.cs
@@ -466,6 +466,107 @@ namespace Octokit.Reactive
return _client.DeleteRequiredStatusChecksContexts(repositoryId, branch, contexts).ToObservable().SelectMany(x => x);
}
+ ///
+ /// Get required pull request review enforcement of protected branch
+ ///
+ ///
+ /// See the API documentation for more details
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The name of the branch
+ public IObservable GetReviewEnforcement(string owner, string name, string branch)
+ {
+ Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
+ Ensure.ArgumentNotNullOrEmptyString(name, "name");
+ Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
+
+ return _client.GetReviewEnforcement(owner, name, branch).ToObservable();
+ }
+
+ ///
+ /// Get required pull request review enforcement of protected branch
+ ///
+ ///
+ /// See the API documentation for more details
+ ///
+ /// The Id of the repository
+ /// The name of the branch
+ public IObservable GetReviewEnforcement(long repositoryId, string branch)
+ {
+ Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
+
+ return _client.GetReviewEnforcement(repositoryId, branch).ToObservable();
+ }
+
+ ///
+ /// Update required pull request review enforcement of protected branch
+ ///
+ ///
+ /// See the API documentation for more details
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The name of the branch
+ public IObservable UpdateReviewEnforcement(string owner, string name, string branch, BranchProtectionRequiredReviewsUpdate update)
+ {
+ Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
+ Ensure.ArgumentNotNullOrEmptyString(name, "name");
+ Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
+ Ensure.ArgumentNotNull(update, nameof(update));
+
+ return _client.UpdateReviewEnforcement(owner, name, branch, update).ToObservable();
+ }
+
+ ///
+ /// Update required pull request review enforcement of protected branch
+ ///
+ ///
+ /// See the API documentation for more details
+ ///
+ /// The Id of the repository
+ /// The name of the branch
+ public IObservable UpdateReviewEnforcement(long repositoryId, string branch, BranchProtectionRequiredReviewsUpdate update)
+ {
+ Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
+ Ensure.ArgumentNotNull(update, nameof(update));
+
+ return _client.UpdateReviewEnforcement(repositoryId, branch, update).ToObservable();
+ }
+
+ ///
+ /// Remove required pull request review enforcement of protected branch
+ ///
+ ///
+ /// See the API documentation for more details
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The name of the branch
+ public IObservable RemoveReviewEnforcement(string owner, string name, string branch)
+ {
+ Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
+ Ensure.ArgumentNotNullOrEmptyString(name, "name");
+ Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
+
+ return _client.RemoveReviewEnforcement(owner, name, branch).ToObservable();
+ }
+
+ ///
+ /// Remove required pull request review enforcement of protected branch
+ ///
+ ///
+ /// See the API documentation for more details
+ ///
+ /// The Id of the repository
+ /// The name of the branch
+ public IObservable RemoveReviewEnforcement(long repositoryId, string branch)
+ {
+ Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
+
+ return _client.RemoveReviewEnforcement(repositoryId, branch).ToObservable();
+ }
+
///
/// Get admin enforcement of protected branch
///
@@ -517,6 +618,14 @@ namespace Octokit.Reactive
return _client.AddAdminEnforcement(owner, name, branch).ToObservable();
}
+ ///
+ /// Add admin enforcement to protected branch
+ ///
+ ///
+ /// See the API documentation for more details
+ ///
+ /// The Id of the repository
+ /// The name of the branch
public IObservable AddAdminEnforcement(long repositoryId, string branch)
{
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
diff --git a/Octokit.Tests.Integration/Clients/RepositoryBranchesClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryBranchesClientTests.cs
index 6b72a8d6..75414753 100644
--- a/Octokit.Tests.Integration/Clients/RepositoryBranchesClientTests.cs
+++ b/Octokit.Tests.Integration/Clients/RepositoryBranchesClientTests.cs
@@ -219,11 +219,16 @@ public class RepositoryBranchesClientTests
var repoName = _userRepoContext.RepositoryName;
var protection = await _client.GetBranchProtection(repoOwner, repoName, "master");
- Assert.True(protection.EnforceAdmins.Enabled);
Assert.True(protection.RequiredStatusChecks.Strict);
Assert.Equal(2, protection.RequiredStatusChecks.Contexts.Count);
+ Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions);
+ Assert.True(protection.RequiredPullRequestReviews.DismissStaleReviews);
+ Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews);
+
Assert.Null(protection.Restrictions);
+
+ Assert.True(protection.EnforceAdmins.Enabled);
}
[IntegrationTest]
@@ -232,11 +237,16 @@ public class RepositoryBranchesClientTests
var repoId = _userRepoContext.RepositoryId;
var protection = await _client.GetBranchProtection(repoId, "master");
- Assert.True(protection.EnforceAdmins.Enabled);
Assert.True(protection.RequiredStatusChecks.Strict);
Assert.Equal(2, protection.RequiredStatusChecks.Contexts.Count);
+ Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions);
+ Assert.True(protection.RequiredPullRequestReviews.DismissStaleReviews);
+ Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews);
+
Assert.Null(protection.Restrictions);
+
+ Assert.True(protection.EnforceAdmins.Enabled);
}
[IntegrationTest]
@@ -246,12 +256,18 @@ public class RepositoryBranchesClientTests
var repoName = _orgRepoContext.RepositoryContext.RepositoryName;
var protection = await _client.GetBranchProtection(repoOwner, repoName, "master");
- Assert.True(protection.EnforceAdmins.Enabled);
Assert.True(protection.RequiredStatusChecks.Strict);
Assert.Equal(2, protection.RequiredStatusChecks.Contexts.Count);
+ Assert.Equal(1, protection.RequiredPullRequestReviews.DismissalRestrictions.Teams.Count);
+ Assert.Equal(0, protection.RequiredPullRequestReviews.DismissalRestrictions.Users.Count);
+ Assert.True(protection.RequiredPullRequestReviews.DismissStaleReviews);
+ Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews);
+
Assert.Equal(1, protection.Restrictions.Teams.Count);
Assert.Equal(0, protection.Restrictions.Users.Count);
+
+ Assert.True(protection.EnforceAdmins.Enabled);
}
[IntegrationTest]
@@ -260,12 +276,18 @@ public class RepositoryBranchesClientTests
var repoId = _orgRepoContext.RepositoryContext.RepositoryId;
var protection = await _client.GetBranchProtection(repoId, "master");
- Assert.True(protection.EnforceAdmins.Enabled);
Assert.True(protection.RequiredStatusChecks.Strict);
Assert.Equal(2, protection.RequiredStatusChecks.Contexts.Count);
+ Assert.Equal(1, protection.RequiredPullRequestReviews.DismissalRestrictions.Teams.Count);
+ Assert.Equal(0, protection.RequiredPullRequestReviews.DismissalRestrictions.Users.Count);
+ Assert.True(protection.RequiredPullRequestReviews.DismissStaleReviews);
+ Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews);
+
Assert.Equal(1, protection.Restrictions.Teams.Count);
Assert.Equal(0, protection.Restrictions.Users.Count);
+
+ Assert.True(protection.EnforceAdmins.Enabled);
}
public void Dispose()
@@ -299,15 +321,22 @@ public class RepositoryBranchesClientTests
var repoOwner = _userRepoContext.RepositoryOwner;
var repoName = _userRepoContext.RepositoryName;
var update = new BranchProtectionSettingsUpdate(
- new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }));
+ new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }),
+ new BranchProtectionRequiredReviewsUpdate(false, true),
+ false);
var protection = await _client.UpdateBranchProtection(repoOwner, repoName, "master", update);
- Assert.False(protection.EnforceAdmins.Enabled);
Assert.False(protection.RequiredStatusChecks.Strict);
Assert.Equal(1, protection.RequiredStatusChecks.Contexts.Count);
+ Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions);
+ Assert.False(protection.RequiredPullRequestReviews.DismissStaleReviews);
+ Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews);
+
Assert.Null(protection.Restrictions);
+
+ Assert.False(protection.EnforceAdmins.Enabled);
}
[IntegrationTest]
@@ -315,15 +344,22 @@ public class RepositoryBranchesClientTests
{
var repoId = _userRepoContext.RepositoryId;
var update = new BranchProtectionSettingsUpdate(
- new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }));
+ new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }),
+ new BranchProtectionRequiredReviewsUpdate(false, true),
+ false);
var protection = await _client.UpdateBranchProtection(repoId, "master", update);
- Assert.False(protection.EnforceAdmins.Enabled);
Assert.False(protection.RequiredStatusChecks.Strict);
Assert.Equal(1, protection.RequiredStatusChecks.Contexts.Count);
+ Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions);
+ Assert.False(protection.RequiredPullRequestReviews.DismissStaleReviews);
+ Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews);
+
Assert.Null(protection.Restrictions);
+
+ Assert.False(protection.EnforceAdmins.Enabled);
}
[IntegrationTest]
@@ -333,17 +369,23 @@ public class RepositoryBranchesClientTests
var repoName = _orgRepoContext.RepositoryContext.RepositoryName;
var update = new BranchProtectionSettingsUpdate(
new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }),
+ new BranchProtectionRequiredReviewsUpdate(new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(false), false, false),
new BranchProtectionPushRestrictionsUpdate(),
false);
var protection = await _client.UpdateBranchProtection(repoOwner, repoName, "master", update);
- Assert.False(protection.EnforceAdmins.Enabled);
Assert.False(protection.RequiredStatusChecks.Strict);
Assert.Equal(1, protection.RequiredStatusChecks.Contexts.Count);
+ Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions);
+ Assert.False(protection.RequiredPullRequestReviews.DismissStaleReviews);
+ Assert.False(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews);
+
Assert.Empty(protection.Restrictions.Teams);
Assert.Empty(protection.Restrictions.Users);
+
+ Assert.False(protection.EnforceAdmins.Enabled);
}
[IntegrationTest]
@@ -352,17 +394,23 @@ public class RepositoryBranchesClientTests
var repoId = _orgRepoContext.RepositoryContext.RepositoryId;
var update = new BranchProtectionSettingsUpdate(
new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }),
+ new BranchProtectionRequiredReviewsUpdate(new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(false), false, false),
new BranchProtectionPushRestrictionsUpdate(),
false);
var protection = await _client.UpdateBranchProtection(repoId, "master", update);
- Assert.False(protection.EnforceAdmins.Enabled);
Assert.False(protection.RequiredStatusChecks.Strict);
Assert.Equal(1, protection.RequiredStatusChecks.Contexts.Count);
+ Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions);
+ Assert.False(protection.RequiredPullRequestReviews.DismissStaleReviews);
+ Assert.False(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews);
+
Assert.Empty(protection.Restrictions.Teams);
Assert.Empty(protection.Restrictions.Users);
+
+ Assert.False(protection.EnforceAdmins.Enabled);
}
public void Dispose()
@@ -736,6 +784,261 @@ public class RepositoryBranchesClientTests
}
}
+ public class TheGetReviewEnforcementMethod : IDisposable
+ {
+ IRepositoryBranchesClient _client;
+ RepositoryContext _userRepoContext;
+ OrganizationRepositoryWithTeamContext _orgRepoContext;
+
+ public TheGetReviewEnforcementMethod()
+ {
+ var github = Helper.GetAuthenticatedClient();
+ _client = github.Repository.Branch;
+
+ _userRepoContext = github.CreateRepositoryWithProtectedBranch().Result;
+ _orgRepoContext = github.CreateOrganizationRepositoryWithProtectedBranch().Result;
+ }
+
+ [IntegrationTest]
+ public async Task GetsReviewEnforcement()
+ {
+ var repoOwner = _userRepoContext.RepositoryOwner;
+ var repoName = _userRepoContext.RepositoryName;
+ var requiredReviews = await _client.GetReviewEnforcement(repoOwner, repoName, "master");
+
+ Assert.Null(requiredReviews.DismissalRestrictions);
+ Assert.True(requiredReviews.DismissStaleReviews);
+ Assert.True(requiredReviews.RequireCodeOwnerReviews);
+ }
+
+ [IntegrationTest]
+ public async Task GetsReviewEnforcementWithRepositoryId()
+ {
+ var repoId = _userRepoContext.RepositoryId;
+ var requiredReviews = await _client.GetReviewEnforcement(repoId, "master");
+
+ Assert.Null(requiredReviews.DismissalRestrictions);
+ Assert.True(requiredReviews.DismissStaleReviews);
+ Assert.True(requiredReviews.RequireCodeOwnerReviews);
+ }
+
+ [IntegrationTest]
+ public async Task GetsReviewEnforcementForOrgRepo()
+ {
+ var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner;
+ var repoName = _orgRepoContext.RepositoryContext.RepositoryName;
+ var requiredReviews = await _client.GetReviewEnforcement(repoOwner, repoName, "master");
+
+ Assert.Equal(1, requiredReviews.DismissalRestrictions.Teams.Count);
+ Assert.Equal(0, requiredReviews.DismissalRestrictions.Users.Count);
+ Assert.True(requiredReviews.DismissStaleReviews);
+ Assert.True(requiredReviews.RequireCodeOwnerReviews);
+ }
+
+ [IntegrationTest]
+ public async Task GetsReviewEnforcementForOrgRepoWithRepositoryId()
+ {
+ var repoId = _orgRepoContext.RepositoryContext.RepositoryId;
+ var requiredReviews = await _client.GetReviewEnforcement(repoId, "master");
+
+ Assert.Equal(1, requiredReviews.DismissalRestrictions.Teams.Count);
+ Assert.Equal(0, requiredReviews.DismissalRestrictions.Users.Count);
+ Assert.True(requiredReviews.DismissStaleReviews);
+ Assert.True(requiredReviews.RequireCodeOwnerReviews);
+ }
+
+ public void Dispose()
+ {
+ if (_userRepoContext != null)
+ _userRepoContext.Dispose();
+
+ if (_orgRepoContext != null)
+ _orgRepoContext.Dispose();
+ }
+ }
+
+ public class TheUpdateReviewEnforcementMethod : IDisposable
+ {
+ IRepositoryBranchesClient _client;
+ RepositoryContext _userRepoContext;
+ OrganizationRepositoryWithTeamContext _orgRepoContext;
+
+ public TheUpdateReviewEnforcementMethod()
+ {
+ var github = Helper.GetAuthenticatedClient();
+ _client = github.Repository.Branch;
+
+ _userRepoContext = github.CreateRepositoryWithProtectedBranch().Result;
+ _orgRepoContext = github.CreateOrganizationRepositoryWithProtectedBranch().Result;
+ }
+
+ [IntegrationTest]
+ public async Task UpdatesReviewEnforcement()
+ {
+ var repoOwner = _userRepoContext.RepositoryOwner;
+ var repoName = _userRepoContext.RepositoryName;
+ var update = new BranchProtectionRequiredReviewsUpdate(false, true);
+
+ var requiredReviews = await _client.UpdateReviewEnforcement(repoOwner, repoName, "master", update);
+
+ Assert.Null(requiredReviews.DismissalRestrictions);
+ Assert.False(requiredReviews.DismissStaleReviews);
+ Assert.True(requiredReviews.RequireCodeOwnerReviews);
+ }
+
+ [IntegrationTest]
+ public async Task UpdatesReviewEnforcementWithRepositoryId()
+ {
+ var repoId = _userRepoContext.RepositoryId;
+ var update = new BranchProtectionRequiredReviewsUpdate(false, true);
+
+ var requiredReviews = await _client.UpdateReviewEnforcement(repoId, "master", update);
+
+ Assert.Null(requiredReviews.DismissalRestrictions);
+ Assert.False(requiredReviews.DismissStaleReviews);
+ Assert.True(requiredReviews.RequireCodeOwnerReviews);
+ }
+
+ [IntegrationTest]
+ public async Task UpdatesReviewEnforcementForOrgRepo()
+ {
+ var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner;
+ var repoName = _orgRepoContext.RepositoryContext.RepositoryName;
+ var update = new BranchProtectionRequiredReviewsUpdate(
+ new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(false),
+ false,
+ false);
+
+ var requiredReviews = await _client.UpdateReviewEnforcement(repoOwner, repoName, "master", update);
+
+ Assert.Null(requiredReviews.DismissalRestrictions);
+ Assert.False(requiredReviews.DismissStaleReviews);
+ Assert.False(requiredReviews.RequireCodeOwnerReviews);
+ }
+
+ [IntegrationTest]
+ public async Task UpdatesReviewEnforcementForOrgRepoWithRepositoryId()
+ {
+ var repoId = _orgRepoContext.RepositoryContext.RepositoryId;
+ var update = new BranchProtectionRequiredReviewsUpdate(
+ new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(false),
+ false,
+ false);
+
+ var requiredReviews = await _client.UpdateReviewEnforcement(repoId, "master", update);
+
+ Assert.Null(requiredReviews.DismissalRestrictions);
+ Assert.False(requiredReviews.DismissStaleReviews);
+ Assert.False(requiredReviews.RequireCodeOwnerReviews);
+ }
+
+ [IntegrationTest]
+ public async Task UpdatesReviewEnforcementForOrgRepoWithAdminOnly()
+ {
+ var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner;
+ var repoName = _orgRepoContext.RepositoryContext.RepositoryName;
+ var update = new BranchProtectionRequiredReviewsUpdate(
+ new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(true),
+ false,
+ false);
+
+ 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);
+ }
+
+ [IntegrationTest]
+ public async Task UpdatesReviewEnforcementForOrgRepoWithAdminOnlyWithRepositoryId()
+ {
+ var repoId = _orgRepoContext.RepositoryContext.RepositoryId;
+ var update = new BranchProtectionRequiredReviewsUpdate(
+ new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(true),
+ false,
+ false);
+
+ 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);
+ }
+
+ public void Dispose()
+ {
+ if (_userRepoContext != null)
+ _userRepoContext.Dispose();
+
+ if (_orgRepoContext != null)
+ _orgRepoContext.Dispose();
+ }
+ }
+
+ public class TheRemoveReviewEnforcementMethod
+ {
+ IGitHubClient _github;
+ IRepositoryBranchesClient _client;
+
+ public TheRemoveReviewEnforcementMethod()
+ {
+ _github = Helper.GetAuthenticatedClient();
+ _client = _github.Repository.Branch;
+ }
+
+ [IntegrationTest]
+ public async Task RemovesReviewEnforcement()
+ {
+ using (var context = await _github.CreateRepositoryWithProtectedBranch())
+ {
+ var repoOwner = context.RepositoryOwner;
+ var repoName = context.RepositoryName;
+ var deleted = await _client.RemoveReviewEnforcement(repoOwner, repoName, "master");
+
+ Assert.True(deleted);
+ }
+ }
+
+ [IntegrationTest]
+ public async Task RemovesReviewEnforcementWithRepositoryId()
+ {
+ using (var context = await _github.CreateRepositoryWithProtectedBranch())
+ {
+ var repoId = context.RepositoryId;
+ var deleted = await _client.RemoveReviewEnforcement(repoId, "master");
+
+ Assert.True(deleted);
+ }
+ }
+
+ [IntegrationTest]
+ public async Task RemovesReviewEnforcementForOrgRepo()
+ {
+ using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch())
+ {
+ var repoOwner = context.RepositoryContext.RepositoryOwner;
+ var repoName = context.RepositoryContext.RepositoryName;
+ var deleted = await _client.RemoveReviewEnforcement(repoOwner, repoName, "master");
+
+ Assert.True(deleted);
+ }
+ }
+
+ [IntegrationTest]
+ public async Task RemovesReviewEnforcementForOrgRepoWithRepositoryId()
+ {
+ using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch())
+ {
+ var repoId = context.RepositoryContext.RepositoryId;
+ var deleted = await _client.RemoveReviewEnforcement(repoId, "master");
+
+ Assert.True(deleted);
+ }
+ }
+ }
+
public class TheGetAdminEnforcementMethod : IDisposable
{
private readonly IRepositoryBranchesClient _client;
diff --git a/Octokit.Tests.Integration/Helpers/OrganizationRepositoryWithTeamContext.cs b/Octokit.Tests.Integration/Helpers/OrganizationRepositoryWithTeamContext.cs
index 4211ef93..7322913b 100644
--- a/Octokit.Tests.Integration/Helpers/OrganizationRepositoryWithTeamContext.cs
+++ b/Octokit.Tests.Integration/Helpers/OrganizationRepositoryWithTeamContext.cs
@@ -30,7 +30,11 @@ namespace Octokit.Tests.Integration.Helpers
var contextUserRepo = await client.CreateRepositoryContext(userRepo);
// Protect master branch
- var update = new BranchProtectionSettingsUpdate(new BranchProtectionRequiredStatusChecksUpdate(true, new[] { "build", "test" }), null, true);
+ var update = new BranchProtectionSettingsUpdate(
+ new BranchProtectionRequiredStatusChecksUpdate(true, new[] { "build", "test" }),
+ new BranchProtectionRequiredReviewsUpdate(true, true),
+ null,
+ true);
await client.Repository.Branch.UpdateBranchProtection(contextUserRepo.RepositoryOwner, contextUserRepo.RepositoryName, "master", update);
@@ -56,6 +60,7 @@ namespace Octokit.Tests.Integration.Helpers
// Protect master branch
var protection = new BranchProtectionSettingsUpdate(
new BranchProtectionRequiredStatusChecksUpdate(true, new[] { "build", "test" }),
+ new BranchProtectionRequiredReviewsUpdate(new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(new BranchProtectionTeamCollection { contextOrgTeam.TeamName }), true, true),
new BranchProtectionPushRestrictionsUpdate(new BranchProtectionTeamCollection { contextOrgTeam.TeamName }),
true);
await client.Repository.Branch.UpdateBranchProtection(contextOrgRepo.RepositoryOwner, contextOrgRepo.RepositoryName, "master", protection);
diff --git a/Octokit.Tests.Integration/Reactive/ObservableRepositoryBranchesClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableRepositoryBranchesClientTests.cs
new file mode 100644
index 00000000..db4ea1b5
--- /dev/null
+++ b/Octokit.Tests.Integration/Reactive/ObservableRepositoryBranchesClientTests.cs
@@ -0,0 +1,556 @@
+using System;
+using System.Linq;
+using System.Reactive.Linq;
+using System.Threading.Tasks;
+using Octokit.Reactive;
+using Octokit.Tests.Integration.Helpers;
+using Xunit;
+
+namespace Octokit.Tests.Integration
+{
+ public class ObservableRepositoryBranchesClientTests
+ {
+ public class TheGetBranchProtectionMethod : IDisposable
+ {
+ IObservableRepositoryBranchesClient _client;
+ RepositoryContext _userRepoContext;
+ OrganizationRepositoryWithTeamContext _orgRepoContext;
+
+ public TheGetBranchProtectionMethod()
+ {
+ var github = Helper.GetAuthenticatedClient();
+ _client = new ObservableRepositoryBranchesClient(github);
+
+ _userRepoContext = github.CreateRepositoryWithProtectedBranch().Result;
+ _orgRepoContext = github.CreateOrganizationRepositoryWithProtectedBranch().Result;
+ }
+
+ [IntegrationTest]
+ public async Task GetsBranchProtection()
+ {
+ var repoOwner = _userRepoContext.RepositoryOwner;
+ var repoName = _userRepoContext.RepositoryName;
+ var protection = await _client.GetBranchProtection(repoOwner, repoName, "master");
+
+ Assert.True(protection.RequiredStatusChecks.Strict);
+ Assert.Equal(2, protection.RequiredStatusChecks.Contexts.Count);
+
+ Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions);
+ Assert.True(protection.RequiredPullRequestReviews.DismissStaleReviews);
+ Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews);
+
+ Assert.Null(protection.Restrictions);
+
+ Assert.True(protection.EnforceAdmins.Enabled);
+ }
+
+ [IntegrationTest]
+ public async Task GetsBranchProtectionWithRepositoryId()
+ {
+ var repoId = _userRepoContext.RepositoryId;
+ var protection = await _client.GetBranchProtection(repoId, "master");
+
+ Assert.True(protection.RequiredStatusChecks.Strict);
+ Assert.Equal(2, protection.RequiredStatusChecks.Contexts.Count);
+
+ Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions);
+ Assert.True(protection.RequiredPullRequestReviews.DismissStaleReviews);
+ Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews);
+
+ Assert.Null(protection.Restrictions);
+
+ Assert.True(protection.EnforceAdmins.Enabled);
+ }
+
+ [IntegrationTest]
+ public async Task GetsBranchProtectionForOrgRepo()
+ {
+ var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner;
+ var repoName = _orgRepoContext.RepositoryContext.RepositoryName;
+ var protection = await _client.GetBranchProtection(repoOwner, repoName, "master");
+
+ Assert.True(protection.RequiredStatusChecks.Strict);
+ Assert.Equal(2, protection.RequiredStatusChecks.Contexts.Count);
+
+ Assert.Equal(1, protection.RequiredPullRequestReviews.DismissalRestrictions.Teams.Count);
+ Assert.Equal(0, protection.RequiredPullRequestReviews.DismissalRestrictions.Users.Count);
+ Assert.True(protection.RequiredPullRequestReviews.DismissStaleReviews);
+ Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews);
+
+ Assert.Equal(1, protection.Restrictions.Teams.Count);
+ Assert.Equal(0, protection.Restrictions.Users.Count);
+
+ Assert.True(protection.EnforceAdmins.Enabled);
+ }
+
+ [IntegrationTest]
+ public async Task GetsBranchProtectionForOrgRepoWithRepositoryId()
+ {
+ var repoId = _orgRepoContext.RepositoryContext.RepositoryId;
+ var protection = await _client.GetBranchProtection(repoId, "master");
+
+ Assert.True(protection.RequiredStatusChecks.Strict);
+ Assert.Equal(2, protection.RequiredStatusChecks.Contexts.Count);
+
+ Assert.Equal(1, protection.RequiredPullRequestReviews.DismissalRestrictions.Teams.Count);
+ Assert.Equal(0, protection.RequiredPullRequestReviews.DismissalRestrictions.Users.Count);
+ Assert.True(protection.RequiredPullRequestReviews.DismissStaleReviews);
+ Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews);
+
+ Assert.Equal(1, protection.Restrictions.Teams.Count);
+ Assert.Equal(0, protection.Restrictions.Users.Count);
+
+ Assert.True(protection.EnforceAdmins.Enabled);
+ }
+
+ public void Dispose()
+ {
+ if (_userRepoContext != null)
+ _userRepoContext.Dispose();
+
+ if (_orgRepoContext != null)
+ _orgRepoContext.Dispose();
+ }
+ }
+
+ public class TheUpdateBranchProtectionMethod : IDisposable
+ {
+ IObservableRepositoryBranchesClient _client;
+ RepositoryContext _userRepoContext;
+ OrganizationRepositoryWithTeamContext _orgRepoContext;
+
+ public TheUpdateBranchProtectionMethod()
+ {
+ var github = Helper.GetAuthenticatedClient();
+ _client = new ObservableRepositoryBranchesClient(github);
+
+ _userRepoContext = github.CreateRepositoryWithProtectedBranch().Result;
+ _orgRepoContext = github.CreateOrganizationRepositoryWithProtectedBranch().Result;
+ }
+
+ [IntegrationTest]
+ public async Task UpdatesBranchProtection()
+ {
+ var repoOwner = _userRepoContext.RepositoryOwner;
+ var repoName = _userRepoContext.RepositoryName;
+ var update = new BranchProtectionSettingsUpdate(
+ new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }),
+ new BranchProtectionRequiredReviewsUpdate(false, true),
+ false);
+
+ var protection = await _client.UpdateBranchProtection(repoOwner, repoName, "master", update);
+
+ Assert.False(protection.RequiredStatusChecks.Strict);
+ Assert.Equal(1, protection.RequiredStatusChecks.Contexts.Count);
+
+ Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions);
+ Assert.False(protection.RequiredPullRequestReviews.DismissStaleReviews);
+ Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews);
+
+ Assert.Null(protection.Restrictions);
+
+ Assert.False(protection.EnforceAdmins.Enabled);
+ }
+
+ [IntegrationTest]
+ public async Task UpdatesBranchProtectionWithRepositoryId()
+ {
+ var repoId = _userRepoContext.RepositoryId;
+ var update = new BranchProtectionSettingsUpdate(
+ new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }),
+ new BranchProtectionRequiredReviewsUpdate(false, true),
+ false);
+
+ var protection = await _client.UpdateBranchProtection(repoId, "master", update);
+
+ Assert.False(protection.RequiredStatusChecks.Strict);
+ Assert.Equal(1, protection.RequiredStatusChecks.Contexts.Count);
+
+ Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions);
+ Assert.False(protection.RequiredPullRequestReviews.DismissStaleReviews);
+ Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews);
+
+ Assert.Null(protection.Restrictions);
+
+ Assert.False(protection.EnforceAdmins.Enabled);
+ }
+
+ [IntegrationTest]
+ public async Task UpdatesBranchProtectionForOrgRepo()
+ {
+ var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner;
+ var repoName = _orgRepoContext.RepositoryContext.RepositoryName;
+ var update = new BranchProtectionSettingsUpdate(
+ new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }),
+ new BranchProtectionRequiredReviewsUpdate(new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(false), false, false),
+ new BranchProtectionPushRestrictionsUpdate(),
+ false);
+
+ var protection = await _client.UpdateBranchProtection(repoOwner, repoName, "master", update);
+
+ Assert.False(protection.RequiredStatusChecks.Strict);
+ Assert.Equal(1, protection.RequiredStatusChecks.Contexts.Count);
+
+ Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions);
+ Assert.False(protection.RequiredPullRequestReviews.DismissStaleReviews);
+ Assert.False(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews);
+
+ Assert.Empty(protection.Restrictions.Teams);
+ Assert.Empty(protection.Restrictions.Users);
+
+ Assert.False(protection.EnforceAdmins.Enabled);
+ }
+
+ [IntegrationTest]
+ 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 BranchProtectionPushRestrictionsUpdate(),
+ false);
+
+ var protection = await _client.UpdateBranchProtection(repoId, "master", update);
+
+ Assert.False(protection.RequiredStatusChecks.Strict);
+ Assert.Equal(1, protection.RequiredStatusChecks.Contexts.Count);
+
+ Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions);
+ Assert.False(protection.RequiredPullRequestReviews.DismissStaleReviews);
+ Assert.False(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews);
+
+ Assert.Empty(protection.Restrictions.Teams);
+ Assert.Empty(protection.Restrictions.Users);
+
+ Assert.False(protection.EnforceAdmins.Enabled);
+ }
+
+ public void Dispose()
+ {
+ if (_userRepoContext != null)
+ _userRepoContext.Dispose();
+
+ if (_orgRepoContext != null)
+ _orgRepoContext.Dispose();
+ }
+ }
+
+ public class TheDeleteBranchProtectionMethod
+ {
+ IGitHubClient _github;
+ IObservableRepositoryBranchesClient _client;
+
+ public TheDeleteBranchProtectionMethod()
+ {
+ _github = Helper.GetAuthenticatedClient();
+ _client = new ObservableRepositoryBranchesClient(_github);
+ }
+
+ [IntegrationTest]
+ public async Task DeletesBranchProtection()
+ {
+ using (var context = await _github.CreateRepositoryWithProtectedBranch())
+ {
+ var repoOwner = context.RepositoryOwner;
+ var repoName = context.RepositoryName;
+ var deleted = await _client.DeleteBranchProtection(repoOwner, repoName, "master");
+
+ Assert.True(deleted);
+ }
+ }
+
+ [IntegrationTest]
+ public async Task DeletesBranchProtectionWithRepositoryId()
+ {
+ using (var context = await _github.CreateRepositoryWithProtectedBranch())
+ {
+ var repoId = context.RepositoryId;
+ var deleted = await _client.DeleteBranchProtection(repoId, "master");
+
+ Assert.True(deleted);
+ }
+ }
+
+ [IntegrationTest]
+ public async Task DeletesBranchProtectionForOrgRepo()
+ {
+ using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch())
+ {
+ var repoOwner = context.RepositoryContext.RepositoryOwner;
+ var repoName = context.RepositoryContext.RepositoryName;
+ var deleted = await _client.DeleteBranchProtection(repoOwner, repoName, "master");
+
+ Assert.True(deleted);
+ }
+ }
+
+ [IntegrationTest]
+ public async Task DeletesBranchProtectionForOrgRepoWithRepositoryId()
+ {
+ using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch())
+ {
+ var repoId = context.RepositoryContext.RepositoryId;
+ var deleted = await _client.DeleteBranchProtection(repoId, "master");
+
+ Assert.True(deleted);
+ }
+ }
+ }
+
+ public class TheGetReviewEnforcementMethod : IDisposable
+ {
+ IObservableRepositoryBranchesClient _client;
+ RepositoryContext _userRepoContext;
+ OrganizationRepositoryWithTeamContext _orgRepoContext;
+
+ public TheGetReviewEnforcementMethod()
+ {
+ var github = Helper.GetAuthenticatedClient();
+ _client = new ObservableRepositoryBranchesClient(github);
+
+ _userRepoContext = github.CreateRepositoryWithProtectedBranch().Result;
+ _orgRepoContext = github.CreateOrganizationRepositoryWithProtectedBranch().Result;
+ }
+
+ [IntegrationTest]
+ public async Task GetsReviewEnforcement()
+ {
+ var repoOwner = _userRepoContext.RepositoryOwner;
+ var repoName = _userRepoContext.RepositoryName;
+ var requiredReviews = await _client.GetReviewEnforcement(repoOwner, repoName, "master");
+
+ Assert.Null(requiredReviews.DismissalRestrictions);
+ Assert.True(requiredReviews.DismissStaleReviews);
+ Assert.True(requiredReviews.RequireCodeOwnerReviews);
+ }
+
+ [IntegrationTest]
+ public async Task GetsReviewEnforcementWithRepositoryId()
+ {
+ var repoId = _userRepoContext.RepositoryId;
+ var requiredReviews = await _client.GetReviewEnforcement(repoId, "master");
+
+ Assert.Null(requiredReviews.DismissalRestrictions);
+ Assert.True(requiredReviews.DismissStaleReviews);
+ Assert.True(requiredReviews.RequireCodeOwnerReviews);
+ }
+
+ [IntegrationTest]
+ public async Task GetsReviewEnforcementForOrgRepo()
+ {
+ var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner;
+ var repoName = _orgRepoContext.RepositoryContext.RepositoryName;
+ var requiredReviews = await _client.GetReviewEnforcement(repoOwner, repoName, "master");
+
+ Assert.Equal(1, requiredReviews.DismissalRestrictions.Teams.Count);
+ Assert.Equal(0, requiredReviews.DismissalRestrictions.Users.Count);
+ Assert.True(requiredReviews.DismissStaleReviews);
+ Assert.True(requiredReviews.RequireCodeOwnerReviews);
+ }
+
+ [IntegrationTest]
+ public async Task GetsReviewEnforcementForOrgRepoWithRepositoryId()
+ {
+ var repoId = _orgRepoContext.RepositoryContext.RepositoryId;
+ var requiredReviews = await _client.GetReviewEnforcement(repoId, "master");
+
+ Assert.Equal(1, requiredReviews.DismissalRestrictions.Teams.Count);
+ Assert.Equal(0, requiredReviews.DismissalRestrictions.Users.Count);
+ Assert.True(requiredReviews.DismissStaleReviews);
+ Assert.True(requiredReviews.RequireCodeOwnerReviews);
+ }
+
+ public void Dispose()
+ {
+ if (_userRepoContext != null)
+ _userRepoContext.Dispose();
+
+ if (_orgRepoContext != null)
+ _orgRepoContext.Dispose();
+ }
+ }
+
+ public class TheUpdateReviewEnforcementMethod : IDisposable
+ {
+ IObservableRepositoryBranchesClient _client;
+ RepositoryContext _userRepoContext;
+ OrganizationRepositoryWithTeamContext _orgRepoContext;
+
+ public TheUpdateReviewEnforcementMethod()
+ {
+ var github = Helper.GetAuthenticatedClient();
+ _client = new ObservableRepositoryBranchesClient(github);
+
+ _userRepoContext = github.CreateRepositoryWithProtectedBranch().Result;
+ _orgRepoContext = github.CreateOrganizationRepositoryWithProtectedBranch().Result;
+ }
+
+ [IntegrationTest]
+ public async Task UpdatesReviewEnforcement()
+ {
+ var repoOwner = _userRepoContext.RepositoryOwner;
+ var repoName = _userRepoContext.RepositoryName;
+ var update = new BranchProtectionRequiredReviewsUpdate(false, true);
+
+ var requiredReviews = await _client.UpdateReviewEnforcement(repoOwner, repoName, "master", update);
+
+ Assert.Null(requiredReviews.DismissalRestrictions);
+ Assert.False(requiredReviews.DismissStaleReviews);
+ Assert.True(requiredReviews.RequireCodeOwnerReviews);
+ }
+
+ [IntegrationTest]
+ public async Task UpdatesReviewEnforcementWithRepositoryId()
+ {
+ var repoId = _userRepoContext.RepositoryId;
+ var update = new BranchProtectionRequiredReviewsUpdate(false, true);
+
+ var requiredReviews = await _client.UpdateReviewEnforcement(repoId, "master", update);
+
+ Assert.Null(requiredReviews.DismissalRestrictions);
+ Assert.False(requiredReviews.DismissStaleReviews);
+ Assert.True(requiredReviews.RequireCodeOwnerReviews);
+ }
+
+ [IntegrationTest]
+ public async Task UpdatesReviewEnforcementForOrgRepo()
+ {
+ var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner;
+ var repoName = _orgRepoContext.RepositoryContext.RepositoryName;
+ var update = new BranchProtectionRequiredReviewsUpdate(
+ new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(false),
+ false,
+ false);
+
+ var requiredReviews = await _client.UpdateReviewEnforcement(repoOwner, repoName, "master", update);
+
+ Assert.Null(requiredReviews.DismissalRestrictions);
+ Assert.False(requiredReviews.DismissStaleReviews);
+ Assert.False(requiredReviews.RequireCodeOwnerReviews);
+ }
+
+ [IntegrationTest]
+ public async Task UpdatesReviewEnforcementForOrgRepoWithRepositoryId()
+ {
+ var repoId = _orgRepoContext.RepositoryContext.RepositoryId;
+ var update = new BranchProtectionRequiredReviewsUpdate(
+ new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(false),
+ false,
+ false);
+
+ var requiredReviews = await _client.UpdateReviewEnforcement(repoId, "master", update);
+
+ Assert.Null(requiredReviews.DismissalRestrictions);
+ Assert.False(requiredReviews.DismissStaleReviews);
+ Assert.False(requiredReviews.RequireCodeOwnerReviews);
+ }
+
+ [IntegrationTest]
+ public async Task UpdatesReviewEnforcementForOrgRepoWithAdminOnly()
+ {
+ var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner;
+ var repoName = _orgRepoContext.RepositoryContext.RepositoryName;
+ var update = new BranchProtectionRequiredReviewsUpdate(
+ new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(true),
+ false,
+ false);
+
+ 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);
+ }
+
+ [IntegrationTest]
+ public async Task UpdatesReviewEnforcementForOrgRepoWithAdminOnlyWithRepositoryId()
+ {
+ var repoId = _orgRepoContext.RepositoryContext.RepositoryId;
+ var update = new BranchProtectionRequiredReviewsUpdate(
+ new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(true),
+ false,
+ false);
+
+ 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);
+ }
+
+ public void Dispose()
+ {
+ if (_userRepoContext != null)
+ _userRepoContext.Dispose();
+
+ if (_orgRepoContext != null)
+ _orgRepoContext.Dispose();
+ }
+ }
+
+ public class TheRemoveReviewEnforcementMethod
+ {
+ IGitHubClient _github;
+ IObservableRepositoryBranchesClient _client;
+
+ public TheRemoveReviewEnforcementMethod()
+ {
+ _github = Helper.GetAuthenticatedClient();
+ _client = new ObservableRepositoryBranchesClient(_github);
+ }
+
+ [IntegrationTest]
+ public async Task RemovesReviewEnforcement()
+ {
+ using (var context = await _github.CreateRepositoryWithProtectedBranch())
+ {
+ var repoOwner = context.RepositoryOwner;
+ var repoName = context.RepositoryName;
+ var deleted = await _client.RemoveReviewEnforcement(repoOwner, repoName, "master");
+
+ Assert.True(deleted);
+ }
+ }
+
+ [IntegrationTest]
+ public async Task RemovesReviewEnforcementWithRepositoryId()
+ {
+ using (var context = await _github.CreateRepositoryWithProtectedBranch())
+ {
+ var repoId = context.RepositoryId;
+ var deleted = await _client.RemoveReviewEnforcement(repoId, "master");
+
+ Assert.True(deleted);
+ }
+ }
+
+ [IntegrationTest]
+ public async Task RemovesReviewEnforcementForOrgRepo()
+ {
+ using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch())
+ {
+ var repoOwner = context.RepositoryContext.RepositoryOwner;
+ var repoName = context.RepositoryContext.RepositoryName;
+ var deleted = await _client.RemoveReviewEnforcement(repoOwner, repoName, "master");
+
+ Assert.True(deleted);
+ }
+ }
+
+ [IntegrationTest]
+ public async Task RemovesReviewEnforcementForOrgRepoWithRepositoryId()
+ {
+ using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch())
+ {
+ var repoId = context.RepositoryContext.RepositoryId;
+ var deleted = await _client.RemoveReviewEnforcement(repoId, "master");
+
+ Assert.True(deleted);
+ }
+ }
+ }
+ }
+}
diff --git a/Octokit.Tests/Clients/RepositoryBranchesClientTests.cs b/Octokit.Tests/Clients/RepositoryBranchesClientTests.cs
index 2650890e..5ad8a378 100644
--- a/Octokit.Tests/Clients/RepositoryBranchesClientTests.cs
+++ b/Octokit.Tests/Clients/RepositoryBranchesClientTests.cs
@@ -648,6 +648,153 @@ namespace Octokit.Tests.Clients
}
}
+ public class TheGetReviewEnforcementMethod
+ {
+ [Fact]
+ public void RequestsTheCorrectUrl()
+ {
+ var connection = Substitute.For();
+ var client = new RepositoryBranchesClient(connection);
+ const string previewAcceptsHeader = "application/vnd.github.loki-preview+json";
+
+ client.GetReviewEnforcement("owner", "repo", "branch");
+
+ connection.Received()
+ .Get(Arg.Is(u => u.ToString() == "repos/owner/repo/branches/branch/protection/required_pull_request_reviews"), null, previewAcceptsHeader);
+ }
+
+ [Fact]
+ public void RequestsTheCorrectUrlWithRepositoryId()
+ {
+ var connection = Substitute.For();
+ var client = new RepositoryBranchesClient(connection);
+ const string previewAcceptsHeader = "application/vnd.github.loki-preview+json";
+
+ client.GetReviewEnforcement(1, "branch");
+
+ connection.Received()
+ .Get(Arg.Is(u => u.ToString() == "repositories/1/branches/branch/protection/required_pull_request_reviews"), null, previewAcceptsHeader);
+ }
+
+ [Fact]
+ public async Task EnsuresNonNullArguments()
+ {
+ var client = new RepositoryBranchesClient(Substitute.For());
+
+ await Assert.ThrowsAsync(() => client.GetReviewEnforcement(null, "repo", "branch"));
+ await Assert.ThrowsAsync(() => client.GetReviewEnforcement("owner", null, "branch"));
+ await Assert.ThrowsAsync(() => client.GetReviewEnforcement("owner", "repo", null));
+
+ await Assert.ThrowsAsync(() => client.GetReviewEnforcement(1, null));
+
+ await Assert.ThrowsAsync(() => client.GetReviewEnforcement("", "repo", "branch"));
+ await Assert.ThrowsAsync(() => client.GetReviewEnforcement("owner", "", "branch"));
+ await Assert.ThrowsAsync(() => client.GetReviewEnforcement("owner", "repo", ""));
+
+ await Assert.ThrowsAsync(() => client.GetReviewEnforcement(1, ""));
+ }
+ }
+
+ public class TheUpdateReviewEnforcementMethod
+ {
+ [Fact]
+ public void RequestsTheCorrectUrl()
+ {
+ var connection = Substitute.For();
+ var client = new RepositoryBranchesClient(connection);
+ var update = new BranchProtectionRequiredReviewsUpdate(false, false);
+ const string previewAcceptsHeader = "application/vnd.github.loki-preview+json";
+
+ client.UpdateReviewEnforcement("owner", "repo", "branch", update);
+
+ connection.Received()
+ .Patch(Arg.Is(u => u.ToString() == "repos/owner/repo/branches/branch/protection/required_pull_request_reviews"), Arg.Any(), previewAcceptsHeader);
+ }
+
+ [Fact]
+ public void RequestsTheCorrectUrlWithRepositoryId()
+ {
+ var connection = Substitute.For();
+ var client = new RepositoryBranchesClient(connection);
+ var update = new BranchProtectionRequiredReviewsUpdate(false, false);
+ const string previewAcceptsHeader = "application/vnd.github.loki-preview+json";
+
+ client.UpdateReviewEnforcement(1, "branch", update);
+
+ connection.Received()
+ .Patch(Arg.Is(u => u.ToString() == "repositories/1/branches/branch/protection/required_pull_request_reviews"), Arg.Any(), previewAcceptsHeader);
+ }
+
+ [Fact]
+ public async Task EnsuresNonNullArguments()
+ {
+ var client = new RepositoryBranchesClient(Substitute.For());
+
+ var update = new BranchProtectionRequiredReviewsUpdate(false, false);
+
+ await Assert.ThrowsAsync(() => client.UpdateReviewEnforcement(null, "repo", "branch", update));
+ await Assert.ThrowsAsync(() => client.UpdateReviewEnforcement("owner", null, "branch", update));
+ await Assert.ThrowsAsync(() => client.UpdateReviewEnforcement("owner", "repo", null, update));
+ await Assert.ThrowsAsync(() => client.UpdateReviewEnforcement("owner", "repo", "branch", null));
+
+ await Assert.ThrowsAsync(() => client.UpdateReviewEnforcement(1, null, update));
+ await Assert.ThrowsAsync(() => client.UpdateReviewEnforcement(1, "branch", null));
+
+ await Assert.ThrowsAsync(() => client.UpdateReviewEnforcement("", "repo", "branch", update));
+ await Assert.ThrowsAsync(() => client.UpdateReviewEnforcement("owner", "", "branch", update));
+ await Assert.ThrowsAsync(() => client.UpdateReviewEnforcement("owner", "repo", "", update));
+
+ await Assert.ThrowsAsync(() => client.UpdateReviewEnforcement(1, "", update));
+ }
+ }
+
+ public class TheRemoveReviewEnforcementMethod
+ {
+ [Fact]
+ public void RequestsTheCorrectUrl()
+ {
+ var connection = Substitute.For();
+ var client = new RepositoryBranchesClient(connection);
+ const string previewAcceptsHeader = "application/vnd.github.loki-preview+json";
+
+ client.RemoveReviewEnforcement("owner", "repo", "branch");
+
+ connection.Connection.Received()
+ .Delete(Arg.Is(u => u.ToString() == "repos/owner/repo/branches/branch/protection/required_pull_request_reviews"), Arg.Any