From cf4c78c9001da4f08dcb3adbb3a84578b2401d4a Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Sat, 1 Oct 2016 23:25:18 +1000 Subject: [PATCH] Add new fields to NewRepository request and update RepositoriesClient.Create() method to specify preview accepts header and fix impacted unit tests Add integration test for Create Repository with merge method specified --- .../Clients/RepositoriesClientTests.cs | 30 +++++++++++++++++++ .../Clients/RepositoriesClientTests.cs | 19 ++++++------ Octokit/Clients/RepositoriesClient.cs | 2 +- Octokit/Models/Request/NewRepository.cs | 15 ++++++++++ 4 files changed, 56 insertions(+), 10 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs index 17dfc16c..545d14bd 100644 --- a/Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs @@ -268,6 +268,36 @@ public class RepositoriesClientTests Task.WhenAll(deleteRepos).Wait(); } } + + [IntegrationTest] + public async Task CreatesARepositoryWithRequestedMergeMethod() + { + var github = Helper.GetAuthenticatedClient(); + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + + var newRepository = new NewRepository(repoName) + { + AllowMergeCommit = false, + AllowSquashMerge = true, + AllowRebaseMerge = false + }; + + using (var context = await github.CreateRepositoryContext(newRepository)) + { + var createdRepository = context.Repository; + + Assert.Equal(repoName, createdRepository.Name); + Assert.False(createdRepository.AllowMergeCommit); + Assert.True(createdRepository.AllowSquashMerge); + Assert.False(createdRepository.AllowRebaseMerge); + + var repository = await github.Repository.Get(Helper.UserName, repoName); + Assert.Equal(repoName, repository.Name); + Assert.False(repository.AllowMergeCommit); + Assert.True(repository.AllowSquashMerge); + Assert.False(repository.AllowRebaseMerge); + } + } } public class TheCreateMethodForOrganization diff --git a/Octokit.Tests/Clients/RepositoriesClientTests.cs b/Octokit.Tests/Clients/RepositoriesClientTests.cs index d8c6c958..aff6d913 100644 --- a/Octokit.Tests/Clients/RepositoriesClientTests.cs +++ b/Octokit.Tests/Clients/RepositoriesClientTests.cs @@ -40,7 +40,7 @@ namespace Octokit.Tests.Clients client.Create(new NewRepository("aName")); - connection.Received().Post(Arg.Is(u => u.ToString() == "user/repos"), Arg.Any()); + connection.Received().Post(Arg.Is(u => u.ToString() == "user/repos"), Arg.Any(), "application/vnd.github.polaris-preview+json"); } [Fact] @@ -52,7 +52,7 @@ namespace Octokit.Tests.Clients client.Create(newRepository); - connection.Received().Post(Args.Uri, newRepository); + connection.Received().Post(Args.Uri, newRepository, "application/vnd.github.polaris-preview+json"); } [Fact] @@ -68,7 +68,7 @@ namespace Octokit.Tests.Clients var connection = Substitute.For(); connection.Connection.BaseAddress.Returns(GitHubClient.GitHubApiUrl); connection.Connection.Credentials.Returns(credentials); - connection.Post(Args.Uri, newRepository) + connection.Post(Args.Uri, newRepository, "application/vnd.github.polaris-preview+json") .Returns>(_ => { throw new ApiValidationException(response); }); var client = new RepositoriesClient(connection); @@ -95,7 +95,7 @@ namespace Octokit.Tests.Clients var connection = Substitute.For(); connection.Connection.BaseAddress.Returns(GitHubClient.GitHubApiUrl); connection.Connection.Credentials.Returns(credentials); - connection.Post(Args.Uri, newRepository) + connection.Post(Args.Uri, newRepository, "application/vnd.github.polaris-preview+json") .Returns>(_ => { throw new ApiValidationException(response); }); var client = new RepositoriesClient(connection); @@ -127,7 +127,8 @@ namespace Octokit.Tests.Clients connection.Received().Post( Arg.Is(u => u.ToString() == "orgs/theLogin/repos"), - Args.NewRepository); + Args.NewRepository, + "application/vnd.github.polaris-preview+json"); } [Fact] @@ -139,7 +140,7 @@ namespace Octokit.Tests.Clients await client.Create("aLogin", newRepository); - connection.Received().Post(Args.Uri, newRepository); + connection.Received().Post(Args.Uri, newRepository, "application/vnd.github.polaris-preview+json"); } [Fact] @@ -153,7 +154,7 @@ namespace Octokit.Tests.Clients + @"""code"":""custom"",""field"":""name"",""message"":""name already exists on this account""}]}"); var connection = Substitute.For(); connection.Connection.BaseAddress.Returns(GitHubClient.GitHubApiUrl); - connection.Post(Args.Uri, newRepository) + connection.Post(Args.Uri, newRepository, "application/vnd.github.polaris-preview+json") .Returns>(_ => { throw new ApiValidationException(response); }); var client = new RepositoriesClient(connection); @@ -178,7 +179,7 @@ namespace Octokit.Tests.Clients + @"""http://developer.github.com/v3/repos/#create"",""errors"":[]}"); var connection = Substitute.For(); connection.Connection.BaseAddress.Returns(GitHubClient.GitHubApiUrl); - connection.Post(Args.Uri, newRepository) + connection.Post(Args.Uri, newRepository, "application/vnd.github.polaris-preview+json") .Returns>(_ => { throw new ApiValidationException(response); }); var client = new RepositoriesClient(connection); @@ -199,7 +200,7 @@ namespace Octokit.Tests.Clients + @"""code"":""custom"",""field"":""name"",""message"":""name already exists on this account""}]}"); var connection = Substitute.For(); connection.Connection.BaseAddress.Returns(new Uri("https://example.com")); - connection.Post(Args.Uri, newRepository) + connection.Post(Args.Uri, newRepository, "application/vnd.github.polaris-preview+json") .Returns>(_ => { throw new ApiValidationException(response); }); var client = new RepositoriesClient(connection); diff --git a/Octokit/Clients/RepositoriesClient.cs b/Octokit/Clients/RepositoriesClient.cs index 3e9b8026..eafbaffa 100644 --- a/Octokit/Clients/RepositoriesClient.cs +++ b/Octokit/Clients/RepositoriesClient.cs @@ -82,7 +82,7 @@ namespace Octokit { try { - return await ApiConnection.Post(url, newRepository).ConfigureAwait(false); + return await ApiConnection.Post(url, newRepository, AcceptHeaders.SquashCommitPreview).ConfigureAwait(false); } catch (ApiValidationException e) { diff --git a/Octokit/Models/Request/NewRepository.cs b/Octokit/Models/Request/NewRepository.cs index 7d09ead6..12e54c73 100644 --- a/Octokit/Models/Request/NewRepository.cs +++ b/Octokit/Models/Request/NewRepository.cs @@ -82,6 +82,21 @@ namespace Octokit /// public int? TeamId { get; set; } + /// + /// Optional. Allows the "Rebase and Merge" method to be used. + /// + public bool? AllowRebaseMerge { get; set; } + + /// + /// Optional. Allows the "Squash Merge" merge method to be used. + /// + public bool? AllowSquashMerge { get; set; } + + /// + /// Optional. Allows the "Create a merge commit" merge method to be used. + /// + public bool? AllowMergeCommit { get; set; } + internal string DebuggerDisplay { get