mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-05 11:40:42 +00:00
feat: Fixing master > main in integration tests (#2489)
This commit is contained in:
@@ -4,6 +4,17 @@ namespace Octokit.Tests.Integration.Helpers
|
||||
{
|
||||
internal static class GithubClientExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a public repository with the timestamped name public-repo
|
||||
/// </summary>
|
||||
internal static async Task<RepositoryContext> CreateRepositoryContext(this IGitHubClient client)
|
||||
{
|
||||
var repoName = Helper.MakeNameWithTimestamp("public-repo");
|
||||
var repo = await client.Repository.Create(new NewRepository(repoName) { AutoInit = true });
|
||||
|
||||
return new RepositoryContext(client.Connection, repo);
|
||||
}
|
||||
|
||||
internal static async Task<RepositoryContext> CreateRepositoryContext(this IGitHubClient client, string repositoryName)
|
||||
{
|
||||
var repoName = Helper.MakeNameWithTimestamp(repositoryName);
|
||||
@@ -12,16 +23,30 @@ namespace Octokit.Tests.Integration.Helpers
|
||||
return new RepositoryContext(client.Connection, repo);
|
||||
}
|
||||
|
||||
internal static async Task<RepositoryContext> CreateRepositoryContext(this IGitHubClient client, string organizationLogin, NewRepository newRepository)
|
||||
internal static async Task<RepositoryContext> CreateRepositoryContext(this IGitHubClient client, NewRepository newRepository)
|
||||
{
|
||||
var repo = await client.Repository.Create(organizationLogin, newRepository);
|
||||
var repo = await client.Repository.Create(newRepository);
|
||||
|
||||
return new RepositoryContext(client.Connection, repo);
|
||||
}
|
||||
|
||||
internal static async Task<RepositoryContext> CreateRepositoryContext(this IGitHubClient client, NewRepository newRepository)
|
||||
/// <summary>
|
||||
/// Creates an organisationrepository with the timestamped name organisation-repo
|
||||
/// </summary>
|
||||
internal static async Task<RepositoryContext> CreateOrganizationRepositoryContext(this IGitHubClient client)
|
||||
{
|
||||
var repo = await client.Repository.Create(newRepository);
|
||||
var repoName = Helper.MakeNameWithTimestamp("organization-repo");
|
||||
var repo = await client.Repository.Create(Helper.Organization, new NewRepository(repoName) { AutoInit = true });
|
||||
|
||||
return new RepositoryContext(client.Connection, repo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an organization repository
|
||||
/// </summary>
|
||||
internal static async Task<RepositoryContext> CreateOrganizationRepositoryContext(this IGitHubClient client, string organizationLogin, NewRepository newRepository)
|
||||
{
|
||||
var repo = await client.Repository.Create(organizationLogin, newRepository);
|
||||
|
||||
return new RepositoryContext(client.Connection, repo);
|
||||
}
|
||||
|
||||
@@ -23,13 +23,30 @@ namespace Octokit.Tests.Integration.Helpers
|
||||
|
||||
internal static class RepositoryProtectedBranchHelperExtensions
|
||||
{
|
||||
internal async static Task ProtectDefaultBranch(this IGitHubClient client, RepositoryContext repoContext)
|
||||
{
|
||||
// Protect default branch
|
||||
var update = new BranchProtectionSettingsUpdate(
|
||||
new BranchProtectionRequiredStatusChecksUpdate(true, new[] { "build", "test" }),
|
||||
new BranchProtectionRequiredReviewsUpdate(true, true, 3),
|
||||
null,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
true);
|
||||
|
||||
await client.Repository.Branch.UpdateBranchProtection(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch, update);
|
||||
}
|
||||
|
||||
internal async static Task<RepositoryContext> CreateRepositoryWithProtectedBranch(this IGitHubClient client)
|
||||
{
|
||||
// Create user owned repo
|
||||
var userRepo = new NewRepository(Helper.MakeNameWithTimestamp("protected-repo")) { AutoInit = true };
|
||||
var contextUserRepo = await client.CreateRepositoryContext(userRepo);
|
||||
|
||||
// Protect master branch
|
||||
// Protect default branch
|
||||
var update = new BranchProtectionSettingsUpdate(
|
||||
new BranchProtectionRequiredStatusChecksUpdate(true, new[] { "build", "test" }),
|
||||
new BranchProtectionRequiredReviewsUpdate(true, true, 3),
|
||||
@@ -46,11 +63,34 @@ namespace Octokit.Tests.Integration.Helpers
|
||||
return contextUserRepo;
|
||||
}
|
||||
|
||||
internal async static Task<TeamContext> ProtectDefaultBranchWithTeam(this IGitHubClient client, RepositoryContext repoContext)
|
||||
{
|
||||
// Create team in org
|
||||
var team = await client.CreateTeamContext(Helper.Organization, new NewTeam(Helper.MakeNameWithTimestamp("team")));
|
||||
|
||||
// Grant team push access to repo
|
||||
await client.Organization.Team.AddRepository(
|
||||
team.TeamId,
|
||||
repoContext.RepositoryOwner,
|
||||
repoContext.RepositoryName,
|
||||
new RepositoryPermissionRequest(Permission.Push));
|
||||
|
||||
// Protect default branch
|
||||
var protection = new BranchProtectionSettingsUpdate(
|
||||
new BranchProtectionRequiredStatusChecksUpdate(true, new[] { "build", "test" }),
|
||||
new BranchProtectionRequiredReviewsUpdate(new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(new BranchProtectionTeamCollection { team.TeamName }), true, true, 3),
|
||||
new BranchProtectionPushRestrictionsUpdate(new BranchProtectionTeamCollection { team.TeamName }),
|
||||
true);
|
||||
await client.Repository.Branch.UpdateBranchProtection(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch, protection);
|
||||
|
||||
return team;
|
||||
}
|
||||
|
||||
internal async static Task<OrganizationRepositoryWithTeamContext> CreateOrganizationRepositoryWithProtectedBranch(this IGitHubClient client)
|
||||
{
|
||||
// Create organization owned repo
|
||||
var orgRepo = new NewRepository(Helper.MakeNameWithTimestamp("protected-org-repo")) { AutoInit = true };
|
||||
var contextOrgRepo = await client.CreateRepositoryContext(Helper.Organization, orgRepo);
|
||||
var contextOrgRepo = await client.CreateOrganizationRepositoryContext(Helper.Organization, orgRepo);
|
||||
|
||||
// Create team in org
|
||||
var contextOrgTeam = await client.CreateTeamContext(Helper.Organization, new NewTeam(Helper.MakeNameWithTimestamp("team")));
|
||||
@@ -62,13 +102,13 @@ namespace Octokit.Tests.Integration.Helpers
|
||||
contextOrgRepo.RepositoryName,
|
||||
new RepositoryPermissionRequest(Permission.Push));
|
||||
|
||||
// Protect master branch
|
||||
// Protect default branch
|
||||
var protection = new BranchProtectionSettingsUpdate(
|
||||
new BranchProtectionRequiredStatusChecksUpdate(true, new[] { "build", "test" }),
|
||||
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);
|
||||
await client.Repository.Branch.UpdateBranchProtection(contextOrgRepo.RepositoryOwner, contextOrgRepo.RepositoryName, "main", protection);
|
||||
|
||||
return new OrganizationRepositoryWithTeamContext
|
||||
{
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Octokit.Tests.Integration
|
||||
|
||||
public IEnumerable<IXunitTestCase> Discover(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute)
|
||||
{
|
||||
if (Helper.Organization == null)
|
||||
if (Helper.HasNoOrganization)
|
||||
{
|
||||
return Enumerable.Empty<IXunitTestCase>();
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Octokit.Tests.Integration.Helpers
|
||||
|
||||
using (var context = await client.CreateRepositoryContext("public-repo"))
|
||||
{
|
||||
var branchFromMaster = await fixture.CreateBranch(context.RepositoryOwner, context.RepositoryName, "patch-1");
|
||||
var branchFromMaster = await fixture.CreateBranch(context.RepositoryOwner, context.RepositoryName, "patch-1", context.Repository.DefaultBranch);
|
||||
|
||||
var branchFromPath = await fixture.CreateBranch(context.RepositoryOwner, context.RepositoryName, "patch-2", branchFromMaster);
|
||||
|
||||
|
||||
@@ -16,12 +16,14 @@ namespace Octokit.Tests.Integration.Helpers
|
||||
RepositoryId = repo.Id;
|
||||
RepositoryOwner = repo.Owner.Login;
|
||||
RepositoryName = repo.Name;
|
||||
RepositoryDefaultBranch = repo.DefaultBranch;
|
||||
}
|
||||
|
||||
private IConnection _connection;
|
||||
internal long RepositoryId { get; private set; }
|
||||
internal string RepositoryOwner { get; private set; }
|
||||
internal string RepositoryName { get; private set; }
|
||||
internal string RepositoryDefaultBranch { get; private set; }
|
||||
|
||||
internal Repository Repository { get; private set; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user