mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-21 14:45:11 +00:00
Implement Create commit method
This commit is contained in:
@@ -18,5 +18,18 @@ namespace Octokit.Reactive
|
|||||||
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get",
|
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get",
|
||||||
Justification = "Method makes a network request")]
|
Justification = "Method makes a network request")]
|
||||||
IObservable<Commit> Get(string owner, string name, string reference);
|
IObservable<Commit> Get(string owner, string name, string reference);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a commit for a given repository
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// http://developer.github.com/v3/git/commits/#create-a-commit
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="owner">The owner of the repository</param>
|
||||||
|
/// <param name="name">The name of the repository</param>
|
||||||
|
/// <param name="commit">The commit to create</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
IObservable<Commit> Create(string owner, string name, NewCommit commit);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -21,5 +21,14 @@ namespace Octokit.Reactive
|
|||||||
|
|
||||||
return _client.Get(owner, name, reference).ToObservable();
|
return _client.Get(owner, name, reference).ToObservable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IObservable<Commit> Create(string owner, string name, NewCommit commit)
|
||||||
|
{
|
||||||
|
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||||
|
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||||
|
Ensure.ArgumentNotNull(commit, "commit");
|
||||||
|
|
||||||
|
return _client.Create(owner, name, commit).ToObservable();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using NSubstitute;
|
using NSubstitute;
|
||||||
using Octokit;
|
using Octokit;
|
||||||
using Octokit.Tests.Helpers;
|
using Octokit.Tests.Helpers;
|
||||||
@@ -33,6 +35,38 @@ public class CommitsClientTests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class TheCreateMethod
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void PostsToTheCorrectUrl()
|
||||||
|
{
|
||||||
|
var connection = Substitute.For<IApiConnection>();
|
||||||
|
var client = new CommitsClient(connection);
|
||||||
|
|
||||||
|
var parents = new List<string> { "sha-reference1", "sha-reference2" };
|
||||||
|
var newCommit = new NewCommit("message", "tree", parents);
|
||||||
|
client.Create("owner", "repo", newCommit);
|
||||||
|
|
||||||
|
connection.Received().Post<Commit>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/git/commits"),
|
||||||
|
Arg.Is<NewCommit>(nc => nc.Message == "message"
|
||||||
|
&& nc.Tree == "tree"
|
||||||
|
&& nc.Parents.Count() == 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void EnsuresNonNullArguments()
|
||||||
|
{
|
||||||
|
var client = new CommitsClient(Substitute.For<IApiConnection>());
|
||||||
|
|
||||||
|
var newCommit = new NewCommit("message", "tree", new[]{"parent1", "parent2"});
|
||||||
|
await AssertEx.Throws<ArgumentNullException>(async () => await client.Create(null, "name", newCommit));
|
||||||
|
await AssertEx.Throws<ArgumentNullException>(async () => await client.Create("owner", null, newCommit));
|
||||||
|
await AssertEx.Throws<ArgumentNullException>(async () => await client.Create("owner", "name", null));
|
||||||
|
await AssertEx.Throws<ArgumentException>(async () => await client.Create("", "name", newCommit));
|
||||||
|
await AssertEx.Throws<ArgumentException>(async () => await client.Create("owner", "", newCommit));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class TheCtor
|
public class TheCtor
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Reactive.Linq;
|
using System.Reactive.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using NSubstitute;
|
using NSubstitute;
|
||||||
@@ -21,6 +22,7 @@ namespace Octokit.Tests.Reactive
|
|||||||
|
|
||||||
public class TheGetMethod
|
public class TheGetMethod
|
||||||
{
|
{
|
||||||
|
[Fact]
|
||||||
public async Task EnsureNonNullArguments()
|
public async Task EnsureNonNullArguments()
|
||||||
{
|
{
|
||||||
var client = new ObservableCommitsClient(Substitute.For<IGitHubClient>());
|
var client = new ObservableCommitsClient(Substitute.For<IGitHubClient>());
|
||||||
@@ -32,6 +34,46 @@ namespace Octokit.Tests.Reactive
|
|||||||
await AssertEx.Throws<ArgumentException>(async () => await client.Get("owner", "", "reference"));
|
await AssertEx.Throws<ArgumentException>(async () => await client.Get("owner", "", "reference"));
|
||||||
await AssertEx.Throws<ArgumentException>(async () => await client.Get("owner", "name", ""));
|
await AssertEx.Throws<ArgumentException>(async () => await client.Get("owner", "name", ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task RequestsCorrectUrl()
|
||||||
|
{
|
||||||
|
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||||
|
var client = new ObservableCommitsClient(gitHubClient);
|
||||||
|
|
||||||
|
client.Get("owner", "name", "reference");
|
||||||
|
|
||||||
|
gitHubClient.Connection.GetAsync<IReadOnlyList<GitHubClient>>(
|
||||||
|
new Uri("repos/owner/name/commits/reference", UriKind.Relative), null, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TheCreateMethod
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public async Task EnsureNonNullArguments()
|
||||||
|
{
|
||||||
|
var client = new ObservableCommitsClient(Substitute.For<IGitHubClient>());
|
||||||
|
var newCommit = new NewCommit("message", "tree", new[] { "parent1", "parent2" });
|
||||||
|
|
||||||
|
await AssertEx.Throws<ArgumentNullException>(async () => await client.Create(null, "name", newCommit));
|
||||||
|
await AssertEx.Throws<ArgumentNullException>(async () => await client.Create("owner", null, newCommit));
|
||||||
|
await AssertEx.Throws<ArgumentNullException>(async () => await client.Create("owner", "name", null));
|
||||||
|
await AssertEx.Throws<ArgumentException>(async () => await client.Create("", "name", newCommit));
|
||||||
|
await AssertEx.Throws<ArgumentException>(async () => await client.Create("owner", "", newCommit));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task RequestsCorrectUrl()
|
||||||
|
{
|
||||||
|
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||||
|
var client = new ObservableCommitsClient(gitHubClient);
|
||||||
|
var newCommit = new NewCommit("message", "tree", new[] { "parent1", "parent2" });
|
||||||
|
|
||||||
|
client.Create("owner", "name", newCommit);
|
||||||
|
|
||||||
|
gitHubClient.GitDatabase.Commit.Received().Create("owner", "name", newCommit);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,5 +17,14 @@ namespace Octokit
|
|||||||
|
|
||||||
return ApiConnection.Get<Commit>(ApiUrls.Commit(owner, name, reference));
|
return ApiConnection.Get<Commit>(ApiUrls.Commit(owner, name, reference));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task<Commit> Create(string owner, string name, NewCommit commit)
|
||||||
|
{
|
||||||
|
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||||
|
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||||
|
Ensure.ArgumentNotNull(commit, "commit");
|
||||||
|
|
||||||
|
return ApiConnection.Post<Commit>(ApiUrls.CreateCommit(owner, name), commit);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,16 +19,16 @@ namespace Octokit
|
|||||||
Justification = "Method makes a network request")]
|
Justification = "Method makes a network request")]
|
||||||
Task<Commit> Get(string owner, string name, string reference);
|
Task<Commit> Get(string owner, string name, string reference);
|
||||||
|
|
||||||
///// <summary>
|
/// <summary>
|
||||||
///// Create a commit for a given repository
|
/// Create a commit for a given repository
|
||||||
///// </summary>
|
/// </summary>
|
||||||
///// <remarks>
|
/// <remarks>
|
||||||
///// http://developer.github.com/v3/git/commits/#create-a-commit
|
/// http://developer.github.com/v3/git/commits/#create-a-commit
|
||||||
///// </remarks>
|
/// </remarks>
|
||||||
///// <param name="owner">The owner of the repository</param>
|
/// <param name="owner">The owner of the repository</param>
|
||||||
///// <param name="name">The name of the repository</param>
|
/// <param name="name">The name of the repository</param>
|
||||||
///// <param name="tag">The commit to create</param>
|
/// <param name="commit">The commit to create</param>
|
||||||
///// <returns></returns>
|
/// <returns></returns>
|
||||||
//Task<Commit> Create(string owner, string name, NewTag tag);
|
Task<Commit> Create(string owner, string name, NewCommit commit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -42,8 +42,10 @@
|
|||||||
<Link>Properties\SolutionInfo.cs</Link>
|
<Link>Properties\SolutionInfo.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Clients\AssigneesClient.cs" />
|
<Compile Include="Clients\AssigneesClient.cs" />
|
||||||
|
<Compile Include="Clients\CommitsClient.cs" />
|
||||||
<Compile Include="Clients\CommitStatusClient.cs" />
|
<Compile Include="Clients\CommitStatusClient.cs" />
|
||||||
<Compile Include="Clients\GitDatabaseClient.cs" />
|
<Compile Include="Clients\GitDatabaseClient.cs" />
|
||||||
|
<Compile Include="Clients\ICommitsClient.cs" />
|
||||||
<Compile Include="Clients\ICommitStatusClient.cs" />
|
<Compile Include="Clients\ICommitStatusClient.cs" />
|
||||||
<Compile Include="Clients\IGitDatabaseClient.cs" />
|
<Compile Include="Clients\IGitDatabaseClient.cs" />
|
||||||
<Compile Include="Clients\IIssueCommentsClient.cs" />
|
<Compile Include="Clients\IIssueCommentsClient.cs" />
|
||||||
@@ -61,10 +63,12 @@
|
|||||||
<Compile Include="Helpers\ParameterAttribute.cs" />
|
<Compile Include="Helpers\ParameterAttribute.cs" />
|
||||||
<Compile Include="Helpers\ReflectionExtensions.cs" />
|
<Compile Include="Helpers\ReflectionExtensions.cs" />
|
||||||
<Compile Include="Models\Request\MilestoneUpdate.cs" />
|
<Compile Include="Models\Request\MilestoneUpdate.cs" />
|
||||||
|
<Compile Include="Models\Request\NewCommit.cs" />
|
||||||
<Compile Include="Models\Request\NewCommitStatus.cs" />
|
<Compile Include="Models\Request\NewCommitStatus.cs" />
|
||||||
<Compile Include="Models\Request\NewMilestone.cs" />
|
<Compile Include="Models\Request\NewMilestone.cs" />
|
||||||
<Compile Include="Models\Request\NewTag.cs" />
|
<Compile Include="Models\Request\NewTag.cs" />
|
||||||
<Compile Include="Models\Request\RequestParameters.cs" />
|
<Compile Include="Models\Request\RequestParameters.cs" />
|
||||||
|
<Compile Include="Models\Response\Commit.cs" />
|
||||||
<Compile Include="Models\Response\CommitStatus.cs" />
|
<Compile Include="Models\Response\CommitStatus.cs" />
|
||||||
<Compile Include="Models\Response\EventInfo.cs" />
|
<Compile Include="Models\Response\EventInfo.cs" />
|
||||||
<Compile Include="Models\Response\GitTag.cs" />
|
<Compile Include="Models\Response\GitTag.cs" />
|
||||||
|
|||||||
@@ -140,6 +140,7 @@
|
|||||||
<Compile Include="Models\Request\MilestoneRequest.cs" />
|
<Compile Include="Models\Request\MilestoneRequest.cs" />
|
||||||
<Compile Include="Models\Request\MilestoneUpdate.cs" />
|
<Compile Include="Models\Request\MilestoneUpdate.cs" />
|
||||||
<Compile Include="Models\Request\NewAuthorization.cs" />
|
<Compile Include="Models\Request\NewAuthorization.cs" />
|
||||||
|
<Compile Include="Models\Request\NewCommit.cs" />
|
||||||
<Compile Include="Models\Request\NewCommitStatus.cs" />
|
<Compile Include="Models\Request\NewCommitStatus.cs" />
|
||||||
<Compile Include="Models\Request\NewIssue.cs" />
|
<Compile Include="Models\Request\NewIssue.cs" />
|
||||||
<Compile Include="Models\Request\NewMilestone.cs" />
|
<Compile Include="Models\Request\NewMilestone.cs" />
|
||||||
|
|||||||
@@ -74,6 +74,7 @@
|
|||||||
<Compile Include="Helpers\ParameterAttribute.cs" />
|
<Compile Include="Helpers\ParameterAttribute.cs" />
|
||||||
<Compile Include="Helpers\ReflectionExtensions.cs" />
|
<Compile Include="Helpers\ReflectionExtensions.cs" />
|
||||||
<Compile Include="Models\Request\MilestoneUpdate.cs" />
|
<Compile Include="Models\Request\MilestoneUpdate.cs" />
|
||||||
|
<Compile Include="Models\Request\NewCommit.cs" />
|
||||||
<Compile Include="Models\Request\NewCommitStatus.cs" />
|
<Compile Include="Models\Request\NewCommitStatus.cs" />
|
||||||
<Compile Include="Models\Request\NewMilestone.cs" />
|
<Compile Include="Models\Request\NewMilestone.cs" />
|
||||||
<Compile Include="Models\Request\RequestParameters.cs" />
|
<Compile Include="Models\Request\RequestParameters.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user