Skip to content

Commit

Permalink
Add missing ctors and fix naming
Browse files Browse the repository at this point in the history
Tests where updated to use the minimum nesseccary constructor
  • Loading branch information
M-Zuber committed Apr 6, 2017
1 parent 321f3ba commit 7551029
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ public async Task UpdatesBranchProtection()
var repoOwner = _userRepoContext.RepositoryOwner;
var repoName = _userRepoContext.RepositoryName;
var update = new BranchProtectionSettingsUpdate(
new BranchProtectionRequiredStatusChecksUpdate(false, false, new[] { "new" }), new BranchProtectionRequiredPullRequestReviewsUpdate(false));
new BranchProtectionRequiredStatusChecksUpdate(false, false, new[] { "new" }));

var protection = await _client.UpdateBranchProtection(repoOwner, repoName, "master", update);

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

var protection = await _client.UpdateBranchProtection(repoId, "master", update);

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

var protection = await _client.UpdateBranchProtection(repoOwner, repoName, "master", update);

Expand All @@ -461,7 +461,7 @@ public async Task UpdatesBranchProtectionForOrgRepoWithRepositoryId()
var repoId = _orgRepoContext.RepositoryContext.RepositoryId;
var update = new BranchProtectionSettingsUpdate(
new BranchProtectionRequiredStatusChecksUpdate(false, false, new[] { "new" }),
new BranchProtectionPushRestrictionsUpdate(), new BranchProtectionRequiredPullRequestReviewsUpdate(false));
new BranchProtectionPushRestrictionsUpdate());

var protection = await _client.UpdateBranchProtection(repoId, "master", update);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal async static Task<RepositoryContext> CreateRepositoryWithProtectedBranc

// Protect master branch
var update = new BranchProtectionSettingsUpdate(
new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "build", "test" }), new BranchProtectionRequiredPullRequestReviewsUpdate(false));
new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "build", "test" }));

await client.Repository.Branch.UpdateBranchProtection(contextUserRepo.RepositoryOwner, contextUserRepo.RepositoryName, "master", update);

Expand All @@ -57,7 +57,7 @@ await client.Organization.Team.AddRepository(
// Protect master branch
var protection = new BranchProtectionSettingsUpdate(
new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "build", "test" }),
new BranchProtectionPushRestrictionsUpdate(new BranchProtectionTeamCollection { contextOrgTeam.TeamName }), new BranchProtectionRequiredPullRequestReviewsUpdate(false));
new BranchProtectionPushRestrictionsUpdate(new BranchProtectionTeamCollection { contextOrgTeam.TeamName }));
await client.Repository.Branch.UpdateBranchProtection(contextOrgRepo.RepositoryOwner, contextOrgRepo.RepositoryName, "master", protection);

return new OrganizationRepositoryWithTeamContext
Expand Down
6 changes: 3 additions & 3 deletions Octokit.Tests/Clients/RepositoryBranchesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public void RequestsTheCorrectUrl()
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryBranchesClient(connection);
var update = new BranchProtectionSettingsUpdate(
new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" }), new BranchProtectionRequiredPullRequestReviewsUpdate(false));
new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" }));
const string previewAcceptsHeader = "application/vnd.github.loki-preview+json";

client.UpdateBranchProtection("owner", "repo", "branch", update);
Expand All @@ -272,7 +272,7 @@ public void RequestsTheCorrectUrlWithRepositoryId()
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryBranchesClient(connection);
var update = new BranchProtectionSettingsUpdate(
new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" }), new BranchProtectionRequiredPullRequestReviewsUpdate(false));
new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" }));
const string previewAcceptsHeader = "application/vnd.github.loki-preview+json";

client.UpdateBranchProtection(1, "branch", update);
Expand All @@ -286,7 +286,7 @@ public async Task EnsuresNonNullArguments()
{
var client = new RepositoryBranchesClient(Substitute.For<IApiConnection>());
var update = new BranchProtectionSettingsUpdate(
new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" }), new BranchProtectionRequiredPullRequestReviewsUpdate(false));
new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" }));

await Assert.ThrowsAsync<ArgumentNullException>(() => client.UpdateBranchProtection(null, "repo", "branch", update));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.UpdateBranchProtection("owner", null, "branch", update));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public void RequestsTheCorrectUrl()
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableRepositoryBranchesClient(gitHubClient);
var update = new BranchProtectionSettingsUpdate(
new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" }), new BranchProtectionRequiredPullRequestReviewsUpdate(false));
new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" }));

client.UpdateBranchProtection("owner", "repo", "branch", update);

Expand All @@ -264,7 +264,7 @@ public void RequestsTheCorrectUrlWithRepositoryId()
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableRepositoryBranchesClient(gitHubClient);
var update = new BranchProtectionSettingsUpdate(
new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" }), new BranchProtectionRequiredPullRequestReviewsUpdate(false));
new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" }));

client.UpdateBranchProtection(1, "branch", update);

Expand All @@ -277,7 +277,7 @@ public async Task EnsuresNonNullArguments()
{
var client = new ObservableRepositoryBranchesClient(Substitute.For<IGitHubClient>());
var update = new BranchProtectionSettingsUpdate(
new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" }), new BranchProtectionRequiredPullRequestReviewsUpdate(false));
new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" }));

Assert.Throws<ArgumentNullException>(() => client.UpdateBranchProtection(null, "repo", "branch", update));
Assert.Throws<ArgumentNullException>(() => client.UpdateBranchProtection("owner", null, "branch", update));
Expand Down
69 changes: 55 additions & 14 deletions Octokit/Models/Request/BranchProtectionUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,53 @@ public class BranchProtectionSettingsUpdate
/// Create a BranchProtection update request
/// </summary>
/// <param name="requiredStatusChecks">Specifies the requested status check settings. Pass null to disable status checks</param>
/// <param name="requiredPullRequestReviews">Specifies whether repository administrators need to pass pull requests checks before being able to merge a pull request</param>
public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate requiredStatusChecks, BranchProtectionRequiredPullRequestReviewsUpdate requiredPullRequestReviews)
public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate requiredStatusChecks)
{
RequiredStatusChecks = requiredStatusChecks;
Restrictions = null;
RequiredPullRequestReviews = null;
}

/// <summary>
/// Create a BranchProtection update request
/// </summary>
/// <param name="restrictions">Specifies the requested push access restrictions (applies only to Organization owned repositories). Pass null to disable push access restrictions</param>
public BranchProtectionSettingsUpdate(BranchProtectionPushRestrictionsUpdate restrictions)
{
RequiredStatusChecks = null;
Restrictions = restrictions;
RequiredPullRequestReviews = null;
}

/// <summary>
/// Create a BranchProtection update request
/// </summary>
/// <param name="requiredPullRequestReviews">Specifies if reviews are required to merge the pull request. Pass null to disable restrictions</param>
public BranchProtectionSettingsUpdate(BranchProtectionRequiredReviewsUpdate requiredPullRequestReviews)
{
RequiredStatusChecks = null;
Restrictions = null;
RequiredPullRequestReviews = requiredPullRequestReviews;
}

/// <summary>
/// Create a BranchProtection update request
/// </summary>
/// <param name="requiredStatusChecks">Specifies the requested status check settings. Pass null to disable status checks</param>
/// <param name="restrictions">Specifies the requested push access restrictions (applies only to Organization owned repositories). Pass null to disable push access restrictions</param>
public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate requiredStatusChecks, BranchProtectionPushRestrictionsUpdate restrictions)
{
RequiredStatusChecks = requiredStatusChecks;
Restrictions = restrictions;
RequiredPullRequestReviews = null;
}

/// <summary>
/// Create a BranchProtection update request
/// </summary>
/// <param name="requiredStatusChecks">Specifies the requested status check settings. Pass null to disable status checks</param>
/// <param name="requiredPullRequestReviews">Specifies if reviews are required to merge the pull request. Pass null to disable restrictions</param>
public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate requiredStatusChecks, BranchProtectionRequiredReviewsUpdate requiredPullRequestReviews)
{
RequiredStatusChecks = requiredStatusChecks;
RequiredPullRequestReviews = requiredPullRequestReviews;
Expand All @@ -32,8 +77,8 @@ public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate
/// Create a BranchProtection update request
/// </summary>
/// <param name="restrictions">Specifies the requested push access restrictions (applies only to Organization owned repositories). Pass null to disable push access restrictions</param>
/// <param name="requiredPullRequestReviews">Specifies whether repository administrators need to pass pull requests checks before being able to merge a pull request</param>
public BranchProtectionSettingsUpdate(BranchProtectionPushRestrictionsUpdate restrictions, BranchProtectionRequiredPullRequestReviewsUpdate requiredPullRequestReviews)
/// <param name="requiredPullRequestReviews">Specifies if reviews are required to merge the pull request. Pass null to disable restrictions</param>
public BranchProtectionSettingsUpdate(BranchProtectionPushRestrictionsUpdate restrictions, BranchProtectionRequiredReviewsUpdate requiredPullRequestReviews)
{
RequiredStatusChecks = null;
RequiredPullRequestReviews = requiredPullRequestReviews;
Expand All @@ -45,8 +90,8 @@ public BranchProtectionSettingsUpdate(BranchProtectionPushRestrictionsUpdate res
/// </summary>
/// <param name="requiredStatusChecks">Specifies the requested status check settings. Pass null to disable status checks</param>
/// <param name="restrictions">Specifies the requested push access restrictions (applies only to Organization owned repositories). Pass null to disable push access restrictions</param>
/// <param name="requiredPullRequestReviews">Specifies whether repository administrators need to pass pull request reviews before being able to merge a pull request</param>
public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate requiredStatusChecks, BranchProtectionPushRestrictionsUpdate restrictions, BranchProtectionRequiredPullRequestReviewsUpdate requiredPullRequestReviews)
/// <param name="requiredPullRequestReviews">Specifies if reviews are required to merge the pull request. Pass null to disable restrictions</param>
public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate requiredStatusChecks, BranchProtectionPushRestrictionsUpdate restrictions, BranchProtectionRequiredReviewsUpdate requiredPullRequestReviews)
{
RequiredStatusChecks = requiredStatusChecks;
Restrictions = restrictions;
Expand All @@ -62,7 +107,7 @@ public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate
/// <summary>
/// Pull Request review settings for the protected branch
/// </summary>
public BranchProtectionRequiredPullRequestReviewsUpdate RequiredPullRequestReviews { get; protected set; }
public BranchProtectionRequiredReviewsUpdate RequiredPullRequestReviews { get; protected set; }

/// <summary>
/// Push access restrictions for the protected branch
Expand Down Expand Up @@ -238,16 +283,12 @@ internal string DebuggerDisplay
}

/// <summary>
/// Specifies whether repository administrators need to pass pull request reviews before being able to merge a pull request
/// Specifies if pull request reviews are required before merging a pull request. Can optionally enforce the policy on repository administrators also.
/// </summary>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class BranchProtectionRequiredPullRequestReviewsUpdate
public class BranchProtectionRequiredReviewsUpdate
{
/// <summary>
/// Sets whether repository administrators are allowed to merge a pull request without going through the review status checks
/// </summary>
/// <param name="includeAdmins">Enforce pull request reviews for repository administrators</param>
public BranchProtectionRequiredPullRequestReviewsUpdate(bool includeAdmins)
public BranchProtectionRequiredReviewsUpdate(bool includeAdmins)
{
IncludeAdmins = includeAdmins;
}
Expand Down
12 changes: 6 additions & 6 deletions Octokit/Models/Response/BranchProtection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public class BranchProtectionSettings
{
public BranchProtectionSettings() { }

public BranchProtectionSettings(BranchProtectionRequiredStatusChecks requiredStatusChecks, BranchProtectionPushRestrictions restrictions, BranchProtectionRequiredPullRequestReviews requiredPullRequestReviews)
public BranchProtectionSettings(BranchProtectionRequiredStatusChecks requiredStatusChecks, BranchProtectionPushRestrictions restrictions, BranchProtectionRequiredReviews requiredPullRequestReviews)
{
RequiredStatusChecks = requiredStatusChecks;
Restrictions = restrictions;
Expand All @@ -128,7 +128,7 @@ public BranchProtectionSettings(BranchProtectionRequiredStatusChecks requiredSta
/// <summary>
/// Pull Request Review required settings for the protected branch
/// </summary>
public BranchProtectionRequiredPullRequestReviews RequiredPullRequestReviews { get; protected set; }
public BranchProtectionRequiredReviews RequiredPullRequestReviews { get; protected set; }

internal string DebuggerDisplay
{
Expand Down Expand Up @@ -223,14 +223,14 @@ internal string DebuggerDisplay
}

/// <summary>
/// Specifies if pull request reviews are required before merging a pull request made by a repository administrator.
/// Specifies if pull request reviews are required before merging a pull request. Can optionally enforce the policy on repository administrators also.
/// </summary>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class BranchProtectionRequiredPullRequestReviews
public class BranchProtectionRequiredReviews
{
public BranchProtectionRequiredPullRequestReviews() { }
public BranchProtectionRequiredReviews() { }

public BranchProtectionRequiredPullRequestReviews(bool includeAdmins)
public BranchProtectionRequiredReviews(bool includeAdmins)
{
IncludeAdmins = includeAdmins;
}
Expand Down

0 comments on commit 7551029

Please sign in to comment.