Files
octokit.net/Octokit.Tests.Integration/Helpers/OrganizationRepositoryWithTeamContext.cs
Mordechai Zuber a2b48a66a4 ProtectedBranches API changes for Required Review Enforcement (#1523)
* Add `BranchProtectionRequiredPullRequestReviews` and `BranchProtectionRequiredPullRequestReviewsUpdate` models

* Add missing ctors and fix naming

Tests where updated to use the minimum nesseccary constructor

* Fix debugger display

* Update BranchProtection response model to include new dismissal restrictions fields and tidy up existing properties ctors and DebuggerDisplay

* Update BranchProtectionUpdate request model to include new dismissal restrictions fields/classes and tidy up existing properties and DebuggerDisplay

* Update BranchProtection tests to use new RequiredReviews and dismissal restrictions options

* Add specific client endpoints for GetReviewEnforcement UpdateReviewEnforcement and RemoveReviewEnforcement

* Add unit and integration tests for new client methods

* Implement Observable client methods and unit tests

* Add integration tests for Observable client

* Run CodeFormatter to fix up whitespace

* Clarify review dismissal restriction behaviour in code comments
2017-08-30 21:12:42 +10:00

76 lines
3.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Octokit.Tests.Integration.Helpers
{
internal class OrganizationRepositoryWithTeamContext : IDisposable
{
internal RepositoryContext RepositoryContext { get; set; }
internal TeamContext TeamContext { get; set; }
public void Dispose()
{
if (RepositoryContext != null)
RepositoryContext.Dispose();
if (TeamContext != null)
TeamContext.Dispose();
}
}
internal static class RepositoryProtectedBranchHelperExtensions
{
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
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);
return contextUserRepo;
}
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);
// Create team in org
var contextOrgTeam = await client.CreateTeamContext(Helper.Organization, new NewTeam(Helper.MakeNameWithTimestamp("team")));
// Grant team push access to repo
await client.Organization.Team.AddRepository(
contextOrgTeam.TeamId,
contextOrgRepo.RepositoryOwner,
contextOrgRepo.RepositoryName,
new RepositoryPermissionRequest(Permission.Push));
// 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);
return new OrganizationRepositoryWithTeamContext
{
RepositoryContext = contextOrgRepo,
TeamContext = contextOrgTeam
};
}
}
}