mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-05 11:40:42 +00:00
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
This commit is contained in:
committed by
Ryan Gribble
parent
d1b0ff485f
commit
cf4c78c900
@@ -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
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace Octokit.Tests.Clients
|
||||
|
||||
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]
|
||||
@@ -52,7 +52,7 @@ namespace Octokit.Tests.Clients
|
||||
|
||||
client.Create(newRepository);
|
||||
|
||||
connection.Received().Post<Repository>(Args.Uri, newRepository);
|
||||
connection.Received().Post<Repository>(Args.Uri, newRepository, "application/vnd.github.polaris-preview+json");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -68,7 +68,7 @@ namespace Octokit.Tests.Clients
|
||||
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);
|
||||
|
||||
@@ -95,7 +95,7 @@ namespace Octokit.Tests.Clients
|
||||
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);
|
||||
|
||||
@@ -127,7 +127,8 @@ namespace Octokit.Tests.Clients
|
||||
|
||||
connection.Received().Post<Repository>(
|
||||
Arg.Is<Uri>(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<Repository>(Args.Uri, newRepository);
|
||||
connection.Received().Post<Repository>(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<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);
|
||||
|
||||
@@ -178,7 +179,7 @@ namespace Octokit.Tests.Clients
|
||||
+ @"""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);
|
||||
|
||||
@@ -199,7 +200,7 @@ namespace Octokit.Tests.Clients
|
||||
+ @"""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);
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace Octokit
|
||||
{
|
||||
try
|
||||
{
|
||||
return await ApiConnection.Post<Repository>(url, newRepository).ConfigureAwait(false);
|
||||
return await ApiConnection.Post<Repository>(url, newRepository, AcceptHeaders.SquashCommitPreview).ConfigureAwait(false);
|
||||
}
|
||||
catch (ApiValidationException e)
|
||||
{
|
||||
|
||||
@@ -82,6 +82,21 @@ namespace Octokit
|
||||
/// </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
|
||||
|
||||
Reference in New Issue
Block a user