Skip to content

Commit

Permalink
Add new fields to NewRepository request and update RepositoriesClient…
Browse files Browse the repository at this point in the history
….Create() method to specify preview accepts header and fix impacted unit tests
  • Loading branch information
ryangribble committed Oct 1, 2016
1 parent d1b0ff4 commit aedcdb6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
19 changes: 10 additions & 9 deletions Octokit.Tests/Clients/RepositoriesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void UsesTheUserReposUrl()

client.Create(new NewRepository("aName"));

connection.Received().Post<Repository>(Arg.Is<Uri>(u => u.ToString() == "user/repos"), Arg.Any<NewRepository>());
connection.Received().Post<Repository>(Arg.Is<Uri>(u => u.ToString() == "user/repos"), Arg.Any<NewRepository>(), "application/vnd.github.polaris-preview+json");
}

[Fact]
Expand All @@ -52,7 +52,7 @@ public void TheNewRepositoryDescription()

client.Create(newRepository);

connection.Received().Post<Repository>(Args.Uri, newRepository);
connection.Received().Post<Repository>(Args.Uri, newRepository, "application/vnd.github.polaris-preview+json");
}

[Fact]
Expand All @@ -68,7 +68,7 @@ public async Task ThrowsRepositoryExistsExceptionWhenRepositoryExistsForCurrentU
var connection = Substitute.For<IApiConnection>();
connection.Connection.BaseAddress.Returns(GitHubClient.GitHubApiUrl);
connection.Connection.Credentials.Returns(credentials);
connection.Post<Repository>(Args.Uri, newRepository)
connection.Post<Repository>(Args.Uri, newRepository, "application/vnd.github.polaris-preview+json")
.Returns<Task<Repository>>(_ => { throw new ApiValidationException(response); });
var client = new RepositoriesClient(connection);

Expand All @@ -95,7 +95,7 @@ public async Task ThrowsExceptionWhenPrivateRepositoryQuotaExceeded()
var connection = Substitute.For<IApiConnection>();
connection.Connection.BaseAddress.Returns(GitHubClient.GitHubApiUrl);
connection.Connection.Credentials.Returns(credentials);
connection.Post<Repository>(Args.Uri, newRepository)
connection.Post<Repository>(Args.Uri, newRepository, "application/vnd.github.polaris-preview+json")
.Returns<Task<Repository>>(_ => { throw new ApiValidationException(response); });
var client = new RepositoriesClient(connection);

Expand Down Expand Up @@ -127,7 +127,8 @@ public async Task UsesTheOrganizationsReposUrl()

connection.Received().Post<Repository>(
Arg.Is<Uri>(u => u.ToString() == "orgs/theLogin/repos"),
Args.NewRepository);
Args.NewRepository,
"application/vnd.github.polaris-preview+json");
}

[Fact]
Expand All @@ -139,7 +140,7 @@ public async Task TheNewRepositoryDescription()

await client.Create("aLogin", newRepository);

connection.Received().Post<Repository>(Args.Uri, newRepository);
connection.Received().Post<Repository>(Args.Uri, newRepository, "application/vnd.github.polaris-preview+json");
}

[Fact]
Expand All @@ -153,7 +154,7 @@ public async Task ThrowsRepositoryExistsExceptionWhenRepositoryExistsForSpecifie
+ @"""code"":""custom"",""field"":""name"",""message"":""name already exists on this account""}]}");
var connection = Substitute.For<IApiConnection>();
connection.Connection.BaseAddress.Returns(GitHubClient.GitHubApiUrl);
connection.Post<Repository>(Args.Uri, newRepository)
connection.Post<Repository>(Args.Uri, newRepository, "application/vnd.github.polaris-preview+json")
.Returns<Task<Repository>>(_ => { throw new ApiValidationException(response); });
var client = new RepositoriesClient(connection);

Expand All @@ -178,7 +179,7 @@ public async Task ThrowsValidationException()
+ @"""http://developer.github.com/v3/repos/#create"",""errors"":[]}");
var connection = Substitute.For<IApiConnection>();
connection.Connection.BaseAddress.Returns(GitHubClient.GitHubApiUrl);
connection.Post<Repository>(Args.Uri, newRepository)
connection.Post<Repository>(Args.Uri, newRepository, "application/vnd.github.polaris-preview+json")
.Returns<Task<Repository>>(_ => { throw new ApiValidationException(response); });
var client = new RepositoriesClient(connection);

Expand All @@ -199,7 +200,7 @@ public async Task ThrowsRepositoryExistsExceptionForEnterpriseInstance()
+ @"""code"":""custom"",""field"":""name"",""message"":""name already exists on this account""}]}");
var connection = Substitute.For<IApiConnection>();
connection.Connection.BaseAddress.Returns(new Uri("https://example.com"));
connection.Post<Repository>(Args.Uri, newRepository)
connection.Post<Repository>(Args.Uri, newRepository, "application/vnd.github.polaris-preview+json")
.Returns<Task<Repository>>(_ => { throw new ApiValidationException(response); });
var client = new RepositoriesClient(connection);

Expand Down
2 changes: 1 addition & 1 deletion Octokit/Clients/RepositoriesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async Task<Repository> Create(Uri url, string organizationLogin, NewRepository n
{
try
{
return await ApiConnection.Post<Repository>(url, newRepository).ConfigureAwait(false);
return await ApiConnection.Post<Repository>(url, newRepository, AcceptHeaders.SquashCommitPreview).ConfigureAwait(false);
}
catch (ApiValidationException e)
{
Expand Down
15 changes: 15 additions & 0 deletions Octokit/Models/Request/NewRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ public NewRepository(string name)
/// </summary>
public int? TeamId { get; set; }

/// <summary>
/// Optional. Allows the "Rebase and Merge" method to be used.
/// </summary>
public bool? AllowRebaseMerge { get; set; }

/// <summary>
/// Optional. Allows the "Squash Merge" merge method to be used.
/// </summary>
public bool? AllowSquashMerge { get; set; }

/// <summary>
/// Optional. Allows the "Create a merge commit" merge method to be used.
/// </summary>
public bool? AllowMergeCommit { get; set; }

internal string DebuggerDisplay
{
get
Expand Down

0 comments on commit aedcdb6

Please sign in to comment.