mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-04 03:16:11 +00:00
Remove the obsolete branch protection methods and classes as they are now no longer supported (#1620)
This commit is contained in:
@@ -1478,12 +1478,6 @@ public class RepositoriesClientTests
|
||||
var branches = await github.Repository.GetAllBranches(7528679);
|
||||
|
||||
Assert.NotEmpty(branches);
|
||||
|
||||
// Ensure Protection attribute is deserialized
|
||||
foreach (var branch in branches)
|
||||
{
|
||||
Assert.NotNull(branch.Protection);
|
||||
}
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
@@ -1798,102 +1792,4 @@ public class RepositoriesClientTests
|
||||
Assert.NotEqual(firstPage[4].Name, secondPage[4].Name);
|
||||
}
|
||||
}
|
||||
|
||||
public class TheEditBranchMethod
|
||||
{
|
||||
private readonly IRepositoriesClient _fixture;
|
||||
private readonly RepositoryContext _context;
|
||||
|
||||
public TheEditBranchMethod()
|
||||
{
|
||||
var github = Helper.GetAuthenticatedClient();
|
||||
_context = github.CreateRepositoryContext("source-repo").Result;
|
||||
_fixture = github.Repository;
|
||||
}
|
||||
|
||||
public async Task CreateTheWorld()
|
||||
{
|
||||
// Set master branch to be protected, with some status checks
|
||||
var requiredStatusChecks = new RequiredStatusChecks(EnforcementLevel.Everyone, new List<string> { "check1", "check2" });
|
||||
|
||||
var update = new BranchUpdate();
|
||||
update.Protection = new BranchProtection(true, requiredStatusChecks);
|
||||
|
||||
var newBranch = await _fixture.EditBranch(_context.Repository.Owner.Login, _context.Repository.Name, "master", update);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task ProtectsBranch()
|
||||
{
|
||||
// Set master branch to be protected, with some status checks
|
||||
var requiredStatusChecks = new RequiredStatusChecks(EnforcementLevel.Everyone, new List<string> { "check1", "check2", "check3" });
|
||||
|
||||
var update = new BranchUpdate();
|
||||
update.Protection = new BranchProtection(true, requiredStatusChecks);
|
||||
|
||||
var branch = await _fixture.EditBranch(_context.Repository.Owner.Login, _context.Repository.Name, "master", update);
|
||||
|
||||
// Ensure a branch object was returned
|
||||
Assert.NotNull(branch);
|
||||
|
||||
// Retrieve master branch
|
||||
branch = await _fixture.GetBranch(_context.Repository.Owner.Login, _context.Repository.Name, "master");
|
||||
|
||||
// Assert the changes were made
|
||||
Assert.Equal(branch.Protection.Enabled, true);
|
||||
Assert.Equal(branch.Protection.RequiredStatusChecks.EnforcementLevel, EnforcementLevel.Everyone);
|
||||
Assert.Equal(branch.Protection.RequiredStatusChecks.Contexts.Count, 3);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task RemoveStatusCheckEnforcement()
|
||||
{
|
||||
await CreateTheWorld();
|
||||
|
||||
// Remove status check enforcement
|
||||
var requiredStatusChecks = new RequiredStatusChecks(EnforcementLevel.Off, new List<string> { "check1" });
|
||||
|
||||
var update = new BranchUpdate();
|
||||
update.Protection = new BranchProtection(true, requiredStatusChecks);
|
||||
|
||||
var branch = await _fixture.EditBranch(_context.Repository.Owner.Login, _context.Repository.Name, "master", update);
|
||||
|
||||
// Ensure a branch object was returned
|
||||
Assert.NotNull(branch);
|
||||
|
||||
// Retrieve master branch
|
||||
branch = await _fixture.GetBranch(_context.Repository.Owner.Login, _context.Repository.Name, "master");
|
||||
|
||||
// Assert the changes were made
|
||||
Assert.Equal(branch.Protection.Enabled, true);
|
||||
Assert.Equal(branch.Protection.RequiredStatusChecks.EnforcementLevel, EnforcementLevel.Off);
|
||||
Assert.Equal(branch.Protection.RequiredStatusChecks.Contexts.Count, 1);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task UnprotectsBranch()
|
||||
{
|
||||
await CreateTheWorld();
|
||||
|
||||
// Unprotect branch
|
||||
// Deliberately set Enforcement and Contexts to some values (these should be ignored)
|
||||
var requiredStatusChecks = new RequiredStatusChecks(EnforcementLevel.Everyone, new List<string> { "check1" });
|
||||
|
||||
var update = new BranchUpdate();
|
||||
update.Protection = new BranchProtection(false, requiredStatusChecks);
|
||||
|
||||
var branch = await _fixture.EditBranch(_context.Repository.Owner.Login, _context.Repository.Name, "master", update);
|
||||
|
||||
// Ensure a branch object was returned
|
||||
Assert.NotNull(branch);
|
||||
|
||||
// Retrieve master branch
|
||||
branch = await _fixture.GetBranch(_context.Repository.Owner.Login, _context.Repository.Name, "master");
|
||||
|
||||
// Assert the branch is unprotected, and enforcement/contexts are cleared
|
||||
Assert.Equal(branch.Protection.Enabled, false);
|
||||
Assert.Equal(branch.Protection.RequiredStatusChecks.EnforcementLevel, EnforcementLevel.Off);
|
||||
Assert.Equal(branch.Protection.RequiredStatusChecks.Contexts.Count, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,11 +20,6 @@ public class RepositoryBranchesClientTests
|
||||
|
||||
Assert.NotEmpty(branches);
|
||||
|
||||
foreach (var branch in branches)
|
||||
{
|
||||
Assert.NotNull(branch.Protection);
|
||||
}
|
||||
|
||||
Assert.True(branches.First(x => x.Name == "master").Protected);
|
||||
}
|
||||
|
||||
@@ -37,11 +32,6 @@ public class RepositoryBranchesClientTests
|
||||
|
||||
Assert.NotEmpty(branches);
|
||||
|
||||
foreach (var branch in branches)
|
||||
{
|
||||
Assert.NotNull(branch.Protection);
|
||||
}
|
||||
|
||||
Assert.True(branches.First(x => x.Name == "master").Protected);
|
||||
}
|
||||
|
||||
@@ -189,7 +179,6 @@ public class RepositoryBranchesClientTests
|
||||
|
||||
Assert.NotNull(branch);
|
||||
Assert.Equal("master", branch.Name);
|
||||
Assert.NotNull(branch.Protection);
|
||||
|
||||
Assert.True(branch.Protected);
|
||||
}
|
||||
@@ -204,109 +193,10 @@ public class RepositoryBranchesClientTests
|
||||
Assert.NotNull(branch);
|
||||
Assert.Equal("master", branch.Name);
|
||||
|
||||
Assert.NotNull(branch.Protection);
|
||||
Assert.True(branch.Protected);
|
||||
}
|
||||
}
|
||||
|
||||
public class TheEditMethod
|
||||
{
|
||||
private readonly IRepositoryBranchesClient _fixture;
|
||||
private readonly RepositoryContext _context;
|
||||
|
||||
public TheEditMethod()
|
||||
{
|
||||
var github = Helper.GetAuthenticatedClient();
|
||||
_context = github.CreateRepositoryContext("source-repo").Result;
|
||||
_fixture = github.Repository.Branch;
|
||||
}
|
||||
|
||||
public async Task CreateTheWorld()
|
||||
{
|
||||
// Set master branch to be protected, with some status checks
|
||||
var requiredStatusChecks = new RequiredStatusChecks(EnforcementLevel.Everyone, new List<string> { "check1", "check2" });
|
||||
|
||||
var update = new BranchUpdate();
|
||||
update.Protection = new BranchProtection(true, requiredStatusChecks);
|
||||
|
||||
var newBranch = await _fixture.Edit(_context.Repository.Owner.Login, _context.Repository.Name, "master", update);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task ProtectsBranch()
|
||||
{
|
||||
// Set master branch to be protected, with some status checks
|
||||
var requiredStatusChecks = new RequiredStatusChecks(EnforcementLevel.Everyone, new List<string> { "check1", "check2", "check3" });
|
||||
|
||||
var update = new BranchUpdate();
|
||||
update.Protection = new BranchProtection(true, requiredStatusChecks);
|
||||
|
||||
var branch = await _fixture.Edit(_context.Repository.Owner.Login, _context.Repository.Name, "master", update);
|
||||
|
||||
// Ensure a branch object was returned
|
||||
Assert.NotNull(branch);
|
||||
|
||||
// Retrieve master branch
|
||||
branch = await _fixture.Get(_context.Repository.Owner.Login, _context.Repository.Name, "master");
|
||||
|
||||
// Assert the changes were made
|
||||
Assert.Equal(branch.Protection.Enabled, true);
|
||||
Assert.Equal(branch.Protection.RequiredStatusChecks.EnforcementLevel, EnforcementLevel.Everyone);
|
||||
Assert.Equal(branch.Protection.RequiredStatusChecks.Contexts.Count, 3);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task RemoveStatusCheckEnforcement()
|
||||
{
|
||||
await CreateTheWorld();
|
||||
|
||||
// Remove status check enforcement
|
||||
var requiredStatusChecks = new RequiredStatusChecks(EnforcementLevel.Off, new List<string> { "check1" });
|
||||
|
||||
var update = new BranchUpdate();
|
||||
update.Protection = new BranchProtection(true, requiredStatusChecks);
|
||||
|
||||
var branch = await _fixture.Edit(_context.Repository.Owner.Login, _context.Repository.Name, "master", update);
|
||||
|
||||
// Ensure a branch object was returned
|
||||
Assert.NotNull(branch);
|
||||
|
||||
// Retrieve master branch
|
||||
branch = await _fixture.Get(_context.Repository.Owner.Login, _context.Repository.Name, "master");
|
||||
|
||||
// Assert the changes were made
|
||||
Assert.Equal(branch.Protection.Enabled, true);
|
||||
Assert.Equal(branch.Protection.RequiredStatusChecks.EnforcementLevel, EnforcementLevel.Off);
|
||||
Assert.Equal(branch.Protection.RequiredStatusChecks.Contexts.Count, 1);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task UnprotectsBranch()
|
||||
{
|
||||
await CreateTheWorld();
|
||||
|
||||
// Unprotect branch
|
||||
// Deliberately set Enforcement and Contexts to some values (these should be ignored)
|
||||
var requiredStatusChecks = new RequiredStatusChecks(EnforcementLevel.Everyone, new List<string> { "check1" });
|
||||
|
||||
var update = new BranchUpdate();
|
||||
update.Protection = new BranchProtection(false, requiredStatusChecks);
|
||||
|
||||
var branch = await _fixture.Edit(_context.Repository.Owner.Login, _context.Repository.Name, "master", update);
|
||||
|
||||
// Ensure a branch object was returned
|
||||
Assert.NotNull(branch);
|
||||
|
||||
// Retrieve master branch
|
||||
branch = await _fixture.Get(_context.Repository.Owner.Login, _context.Repository.Name, "master");
|
||||
|
||||
// Assert the branch is unprotected, and enforcement/contexts are cleared
|
||||
Assert.Equal(branch.Protection.Enabled, false);
|
||||
Assert.Equal(branch.Protection.RequiredStatusChecks.EnforcementLevel, EnforcementLevel.Off);
|
||||
Assert.Equal(branch.Protection.RequiredStatusChecks.Contexts.Count, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetBranchProtectionMethod : IDisposable
|
||||
{
|
||||
IRepositoryBranchesClient _client;
|
||||
|
||||
Reference in New Issue
Block a user