mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-07 12:26:18 +00:00
Merge pull request #104 from octokit/haacked/commit-status-api
Commit Status API
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
|
||||
namespace Octokit.Reactive
|
||||
{
|
||||
public interface IObservableCommitStatusClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Retrieves commit statuses for the specified reference. A reference can be a commit SHA, a branch name, or
|
||||
/// a tag name.
|
||||
/// </summary>
|
||||
/// <remarks>Only users with pull access can see this.</remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="reference">The reference (SHA, branch name, or tag name) to list commits for.</param>
|
||||
/// <returns></returns>
|
||||
IObservable<CommitStatus> GetAll(string owner, string name, string reference);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a commit status for the specified ref.
|
||||
/// </summary>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="reference">The reference (SHA, branch name, or tag name) to list commits for.</param>
|
||||
/// <param name="commitStatus">The commit status to create.</param>
|
||||
/// <returns></returns>
|
||||
IObservable<CommitStatus> Create(string owner, string name, string reference, NewCommitStatus commitStatus);
|
||||
}
|
||||
}
|
||||
@@ -88,5 +88,15 @@ namespace Octokit.Reactive
|
||||
/// <param name="name">The name of the repository.</param>
|
||||
/// <returns></returns>
|
||||
IObservable<string> GetReadmeHtml(string owner, string name);
|
||||
|
||||
/// <summary>
|
||||
/// A client for GitHub's Commit Status API.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/repos/statuses/">Commit Status API documentation</a> for more
|
||||
/// details. Also check out the <a href="https://github.com/blog/1227-commit-status-api">blog post</a>
|
||||
/// that announced this feature.
|
||||
/// </remarks>
|
||||
IObservableCommitStatusClient CommitStatus { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Reactive.Threading.Tasks;
|
||||
using Octokit.Reactive.Internal;
|
||||
|
||||
namespace Octokit.Reactive
|
||||
{
|
||||
public class ObservableCommitStatusClient : IObservableCommitStatusClient
|
||||
{
|
||||
readonly ICommitStatusClient _client;
|
||||
readonly IConnection _connection;
|
||||
|
||||
public ObservableCommitStatusClient(IGitHubClient client)
|
||||
{
|
||||
Ensure.ArgumentNotNull(client, "client");
|
||||
|
||||
_client = client.Repository.CommitStatus;
|
||||
_connection = client.Connection;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves commit statuses for the specified reference. A reference can be a commit SHA, a branch name, or
|
||||
/// a tag name.
|
||||
/// </summary>
|
||||
/// <remarks>Only users with pull access can see this.</remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="reference">The reference (SHA, branch name, or tag name) to list commits for.</param>
|
||||
/// <returns></returns>
|
||||
public IObservable<CommitStatus> GetAll(string owner, string name, string reference)
|
||||
{
|
||||
return _connection.GetAndFlattenAllPages<CommitStatus>(ApiUrls.CommitStatus(owner, name, reference));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a commit status for the specified ref.
|
||||
/// </summary>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="reference">The reference (SHA, branch name, or tag name) to list commits for.</param>
|
||||
/// <param name="commitStatus">The commit status to create.</param>
|
||||
/// <returns></returns>
|
||||
public IObservable<CommitStatus> Create(string owner, string name, string reference, NewCommitStatus commitStatus)
|
||||
{
|
||||
return _client.Create(owner, name, reference, commitStatus).ToObservable();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ namespace Octokit.Reactive
|
||||
readonly IOrganizationsClient _client;
|
||||
readonly IConnection _connection;
|
||||
|
||||
|
||||
public ObservableOrganizationsClient(IGitHubClient client)
|
||||
{
|
||||
Ensure.ArgumentNotNull(client, "client");
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace Octokit.Reactive
|
||||
|
||||
_client = client.Repository;
|
||||
_connection = client.Connection;
|
||||
CommitStatus = new ObservableCommitStatusClient(client);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -105,5 +106,7 @@ namespace Octokit.Reactive
|
||||
|
||||
return _client.GetReadmeHtml(owner, name).ToObservable();
|
||||
}
|
||||
|
||||
public IObservableCommitStatusClient CommitStatus { get; private set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,6 +85,8 @@
|
||||
<Compile Include="..\SolutionInfo.cs">
|
||||
<Link>Properties\SolutionInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Clients\IObservableCommitStatusClient.cs" />
|
||||
<Compile Include="Clients\ObservableCommitStatusClient.cs" />
|
||||
<Compile Include="Clients\ObservableNotificationsClient.cs" />
|
||||
<Compile Include="Clients\ObservableAuthorizationsClient.cs" />
|
||||
<Compile Include="Clients\ObservableMiscellaneousClient.cs" />
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
using System.Net.Http.Headers;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace Octokit.Tests.Integration
|
||||
{
|
||||
public class CommitStatusClientTests
|
||||
{
|
||||
public class TheGetAllMethod
|
||||
{
|
||||
[IntegrationTest]
|
||||
public async Task CanRetrieveStatuses()
|
||||
{
|
||||
// Figured it was easier to grab the public status of a public repository for now than
|
||||
// to go through the rigamarole of creating it all. But ideally, that's exactly what we'd do.
|
||||
|
||||
var githubClient = new GitHubClient(new ProductHeaderValue("OctokitTests"))
|
||||
{
|
||||
Credentials = Helper.Credentials
|
||||
};
|
||||
var statuses = await githubClient.Repository.CommitStatus.GetAll(
|
||||
"rails",
|
||||
"rails",
|
||||
"94b857899506612956bb542e28e292308accb908");
|
||||
Assert.Equal(2, statuses.Count);
|
||||
Assert.Equal(CommitState.Failure, statuses[0].State);
|
||||
Assert.Equal(CommitState.Pending, statuses[1].State);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,6 +56,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AssigneesClientTests.cs" />
|
||||
<Compile Include="CommitStatusClientTests.cs" />
|
||||
<Compile Include="MilestonesClientTests.cs" />
|
||||
<Compile Include="IntegrationTestAttribute.cs" />
|
||||
<Compile Include="IssuesClientTests.cs" />
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using NSubstitute;
|
||||
using Octokit.Tests.Helpers;
|
||||
using Xunit;
|
||||
|
||||
namespace Octokit.Tests.Clients
|
||||
{
|
||||
public class CommitStatusClientTests
|
||||
{
|
||||
public class TheGetMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new CommitStatusClient(connection);
|
||||
|
||||
client.GetAll("fake", "repo", "sha");
|
||||
|
||||
connection.Received()
|
||||
.GetAll<CommitStatus>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/statuses/sha"), null);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new CommitStatusClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await AssertEx.Throws<ArgumentException>(async () =>
|
||||
await client.GetAll("", "name", "sha"));
|
||||
await AssertEx.Throws<ArgumentException>(async () =>
|
||||
await client.GetAll("owner", "", "sha"));
|
||||
await AssertEx.Throws<ArgumentException>(async () =>
|
||||
await client.GetAll("owner", "name", ""));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () =>
|
||||
await client.GetAll(null, "name", "sha"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () =>
|
||||
await client.GetAll("owner", null, "sha"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () =>
|
||||
await client.GetAll("owner", "name", null));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCreateMethodForUser
|
||||
{
|
||||
[Fact]
|
||||
public void PostsToTheCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new CommitStatusClient(connection);
|
||||
|
||||
client.Create("owner", "repo", "sha", new NewCommitStatus { State = CommitState.Success });
|
||||
|
||||
connection.Received().Post<CommitStatus>(Arg.Is<Uri>(u =>
|
||||
u.ToString() == "repos/owner/repo/statuses/sha"),
|
||||
Arg.Is<NewCommitStatus>(s => s.State == CommitState.Success));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new CommitStatusClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await AssertEx.Throws<ArgumentException>(async () =>
|
||||
await client.Create("", "name", "sha", new NewCommitStatus()));
|
||||
await AssertEx.Throws<ArgumentException>(async () =>
|
||||
await client.Create("owner", "", "sha", new NewCommitStatus()));
|
||||
await AssertEx.Throws<ArgumentException>(async () =>
|
||||
await client.Create("owner", "name", "", new NewCommitStatus()));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () =>
|
||||
await client.Create(null, "name", "sha", new NewCommitStatus()));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () =>
|
||||
await client.Create("owner", null, "sha", new NewCommitStatus()));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () =>
|
||||
await client.Create("owner", "name", null, new NewCommitStatus()));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () =>
|
||||
await client.Create("owner", "name", "sha", null));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheConstructor
|
||||
{
|
||||
[Fact]
|
||||
public void EnsuresNonNullArguments()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new CommitStatusClient(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,33 +27,33 @@ namespace Octokit.Tests.Clients
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var repositoriesClient = new RepositoriesClient(Substitute.For<IApiConnection>());
|
||||
var client = new RepositoriesClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await repositoriesClient.Create(null));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await repositoriesClient.Create(new NewRepository { Name = null }));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Create(null));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.Create(new NewRepository { Name = null }));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UsesTheUserReposUrl()
|
||||
{
|
||||
var client = Substitute.For<IApiConnection>();
|
||||
var repositoriesClient = new RepositoriesClient(client);
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoriesClient(connection);
|
||||
|
||||
repositoriesClient.Create(new NewRepository { Name = "aName" });
|
||||
client.Create(new NewRepository { Name = "aName" });
|
||||
|
||||
client.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>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheNewRepositoryDescription()
|
||||
{
|
||||
var client = Substitute.For<IApiConnection>();
|
||||
var repositoriesClient = new RepositoriesClient(client);
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoriesClient(connection);
|
||||
var newRepository = new NewRepository { Name = "aName" };
|
||||
|
||||
repositoriesClient.Create(newRepository);
|
||||
client.Create(newRepository);
|
||||
|
||||
client.Received().Post<Repository>(Arg.Any<Uri>(), newRepository);
|
||||
connection.Received().Post<Repository>(Arg.Any<Uri>(), newRepository);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,22 +62,22 @@ namespace Octokit.Tests.Clients
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var repositoriesClient = new RepositoriesClient(Substitute.For<IApiConnection>());
|
||||
var client = new RepositoriesClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await repositoriesClient.Create(null, new NewRepository { Name = "aName" }));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await repositoriesClient.Create("aLogin", null));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await repositoriesClient.Create("aLogin", new NewRepository { Name = null }));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Create(null, new NewRepository { Name = "aName" }));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.Create("aLogin", null));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.Create("aLogin", new NewRepository { Name = null }));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UsesTheOrganizatinosReposUrl()
|
||||
{
|
||||
var client = Substitute.For<IApiConnection>();
|
||||
var repositoriesClient = new RepositoriesClient(client);
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoriesClient(connection);
|
||||
|
||||
await repositoriesClient.Create("theLogin", new NewRepository { Name = "aName" });
|
||||
await client.Create("theLogin", new NewRepository { Name = "aName" });
|
||||
|
||||
client.Received().Post<Repository>(
|
||||
connection.Received().Post<Repository>(
|
||||
Arg.Is<Uri>(u => u.ToString() == "orgs/theLogin/repos"),
|
||||
Args.NewRepository);
|
||||
}
|
||||
@@ -85,13 +85,13 @@ namespace Octokit.Tests.Clients
|
||||
[Fact]
|
||||
public async Task TheNewRepositoryDescription()
|
||||
{
|
||||
var client = Substitute.For<IApiConnection>();
|
||||
var repositoriesClient = new RepositoriesClient(client);
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoriesClient(connection);
|
||||
var newRepository = new NewRepository { Name = "aName" };
|
||||
|
||||
await repositoriesClient.Create("aLogin", newRepository);
|
||||
await client.Create("aLogin", newRepository);
|
||||
|
||||
client.Received().Post<Repository>(Arg.Any<Uri>(), newRepository);
|
||||
connection.Received().Post<Repository>(Arg.Any<Uri>(), newRepository);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,21 +100,21 @@ namespace Octokit.Tests.Clients
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var repositoriesClient = new RepositoriesClient(Substitute.For<IApiConnection>());
|
||||
var client = new RepositoriesClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await repositoriesClient.Delete(null, "aRepoName"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await repositoriesClient.Delete("anOwner", null));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Delete(null, "aRepoName"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Delete("anOwner", null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrl()
|
||||
{
|
||||
var client = Substitute.For<IApiConnection>();
|
||||
var repositoriesClient = new RepositoriesClient(client);
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoriesClient(connection);
|
||||
|
||||
await repositoriesClient.Delete("theOwner", "theRepoName");
|
||||
await client.Delete("theOwner", "theRepoName");
|
||||
|
||||
client.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "repos/theOwner/theRepoName"));
|
||||
connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "repos/theOwner/theRepoName"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,21 +123,21 @@ namespace Octokit.Tests.Clients
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var client = Substitute.For<IApiConnection>();
|
||||
var repositoriesClient = new RepositoriesClient(client);
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoriesClient(connection);
|
||||
|
||||
repositoriesClient.Get("fake", "repo");
|
||||
client.Get("fake", "repo");
|
||||
|
||||
client.Received().Get<Repository>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo"), null);
|
||||
connection.Received().Get<Repository>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo"), null);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var repositoriesClient = new RepositoriesClient(Substitute.For<IApiConnection>());
|
||||
var client = new RepositoriesClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await repositoriesClient.Get(null, "name"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await repositoriesClient.Get("owner", null));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Get(null, "name"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Get("owner", null));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,12 +146,12 @@ namespace Octokit.Tests.Clients
|
||||
[Fact]
|
||||
public void RequestsTheCorrectUrlAndReturnsOrganizations()
|
||||
{
|
||||
var client = Substitute.For<IApiConnection>();
|
||||
var repositoriesClient = new RepositoriesClient(client);
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoriesClient(connection);
|
||||
|
||||
repositoriesClient.GetAllForCurrent();
|
||||
client.GetAllForCurrent();
|
||||
|
||||
client.Received()
|
||||
connection.Received()
|
||||
.GetAll<Repository>(Arg.Is<Uri>(u => u.ToString() == "user/repos"));
|
||||
}
|
||||
}
|
||||
@@ -161,12 +161,12 @@ namespace Octokit.Tests.Clients
|
||||
[Fact]
|
||||
public void RequestsTheCorrectUrlAndReturnsOrganizations()
|
||||
{
|
||||
var client = Substitute.For<IApiConnection>();
|
||||
var repositoriesClient = new RepositoriesClient(client);
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoriesClient(connection);
|
||||
|
||||
repositoriesClient.GetAllForUser("username");
|
||||
client.GetAllForUser("username");
|
||||
|
||||
client.Received()
|
||||
connection.Received()
|
||||
.GetAll<Repository>(Arg.Is<Uri>(u => u.ToString() == "users/username/repos"));
|
||||
}
|
||||
|
||||
@@ -184,12 +184,12 @@ namespace Octokit.Tests.Clients
|
||||
[Fact]
|
||||
public void RequestsTheCorrectUrlAndReturnsOrganizations()
|
||||
{
|
||||
var client = Substitute.For<IApiConnection>();
|
||||
var repositoriesClient = new RepositoriesClient(client);
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoriesClient(connection);
|
||||
|
||||
repositoriesClient.GetAllForOrg("orgname");
|
||||
client.GetAllForOrg("orgname");
|
||||
|
||||
client.Received()
|
||||
connection.Received()
|
||||
.GetAll<Repository>(Arg.Is<Uri>(u => u.ToString() == "orgs/orgname/repos"));
|
||||
}
|
||||
|
||||
@@ -216,21 +216,21 @@ namespace Octokit.Tests.Clients
|
||||
Url = "https://github.example.com/readme.md",
|
||||
HtmlUrl = "https://github.example.com/readme"
|
||||
};
|
||||
var client = Substitute.For<IApiConnection>();
|
||||
client.Get<ReadmeResponse>(Args.Uri, null).Returns(Task.FromResult(readmeInfo));
|
||||
client.GetHtml(Args.Uri, null).Returns(Task.FromResult("<html>README</html>"));
|
||||
var reposEndpoint = new RepositoriesClient(client);
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
connection.Get<ReadmeResponse>(Args.Uri, null).Returns(Task.FromResult(readmeInfo));
|
||||
connection.GetHtml(Args.Uri, null).Returns(Task.FromResult("<html>README</html>"));
|
||||
var reposEndpoint = new RepositoriesClient(connection);
|
||||
|
||||
var readme = await reposEndpoint.GetReadme("fake", "repo");
|
||||
|
||||
Assert.Equal("README.md", readme.Name);
|
||||
client.Received().Get<ReadmeResponse>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/readme"),
|
||||
connection.Received().Get<ReadmeResponse>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/readme"),
|
||||
null);
|
||||
client.DidNotReceive().GetHtml(Arg.Is<Uri>(u => u.ToString() == "https://github.example.com/readme"),
|
||||
connection.DidNotReceive().GetHtml(Arg.Is<Uri>(u => u.ToString() == "https://github.example.com/readme"),
|
||||
null);
|
||||
var htmlReadme = await readme.GetHtmlContent();
|
||||
Assert.Equal("<html>README</html>", htmlReadme);
|
||||
client.Received().GetHtml(Arg.Is<Uri>(u => u.ToString() == "https://github.example.com/readme"), null);
|
||||
connection.Received().GetHtml(Arg.Is<Uri>(u => u.ToString() == "https://github.example.com/readme"), null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,13 +239,13 @@ namespace Octokit.Tests.Clients
|
||||
[Fact]
|
||||
public async Task ReturnsReadmeHtml()
|
||||
{
|
||||
var client = Substitute.For<IApiConnection>();
|
||||
client.GetHtml(Args.Uri, null).Returns(Task.FromResult("<html>README</html>"));
|
||||
var reposEndpoint = new RepositoriesClient(client);
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
connection.GetHtml(Args.Uri, null).Returns(Task.FromResult("<html>README</html>"));
|
||||
var reposEndpoint = new RepositoriesClient(connection);
|
||||
|
||||
var readme = await reposEndpoint.GetReadmeHtml("fake", "repo");
|
||||
|
||||
client.Received().GetHtml(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/readme"), null);
|
||||
connection.Received().GetHtml(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/readme"), null);
|
||||
Assert.Equal("<html>README</html>", readme);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Authentication\CredentialsTests.cs" />
|
||||
<Compile Include="Clients\AssigneesClientTests.cs" />
|
||||
<Compile Include="Clients\CommitStatusClientTests.cs" />
|
||||
<Compile Include="Clients\MilestonesClientTests.cs" />
|
||||
<Compile Include="Clients\IssuesClientTests.cs" />
|
||||
<Compile Include="Clients\NotificationsClientTests.cs" />
|
||||
|
||||
@@ -52,6 +52,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Authentication\CredentialsTests.cs" />
|
||||
<Compile Include="Clients\AssigneesClientTests.cs" />
|
||||
<Compile Include="Clients\CommitStatusClientTests.cs" />
|
||||
<Compile Include="Clients\IssuesClientTests.cs" />
|
||||
<Compile Include="Clients\MilestonesClientTests.cs" />
|
||||
<Compile Include="Clients\MiscellaneousClientTests.cs" />
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
#if NETFX_CORE
|
||||
using System.Collections.Generic;
|
||||
#endif
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
/// <summary>
|
||||
/// A client for GitHub's Commit Status API.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/repos/statuses/">Commit Status API documentation</a> for more
|
||||
/// details. Also check out the <a href="https://github.com/blog/1227-commit-status-api">blog post</a>
|
||||
/// that announced this feature.
|
||||
/// </remarks>
|
||||
public class CommitStatusClient : ApiClient, ICommitStatusClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new Commit Status API client.
|
||||
/// </summary>
|
||||
/// <param name="apiConnection">An API connection.</param>
|
||||
public CommitStatusClient(IApiConnection apiConnection) : base(apiConnection)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves commit statuses for the specified reference. A reference can be a commit SHA, a branch name, or
|
||||
/// a tag name.
|
||||
/// </summary>
|
||||
/// <remarks>Only users with pull access can see this.</remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="reference">The reference (SHA, branch name, or tag name) to list commits for.</param>
|
||||
/// <returns></returns>
|
||||
public Task<IReadOnlyList<CommitStatus>> GetAll(string owner, string name, string reference)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNullOrEmptyString(reference, "reference");
|
||||
|
||||
return ApiConnection.GetAll<CommitStatus>(ApiUrls.CommitStatus(owner, name, reference), null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a commit status for the specified ref.
|
||||
/// </summary>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="reference">The reference (SHA, branch name, or tag name) to list commits for.</param>
|
||||
/// <param name="commitStatus">The commit status to create.</param>
|
||||
/// <returns></returns>
|
||||
public Task<CommitStatus> Create(string owner, string name, string reference, NewCommitStatus commitStatus)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNullOrEmptyString(reference, "reference");
|
||||
Ensure.ArgumentNotNull(commitStatus, "commitStatus");
|
||||
|
||||
return ApiConnection.Post<CommitStatus>(ApiUrls.CommitStatus(owner, name, reference), commitStatus);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#if NETFX_CORE
|
||||
using System.Collections.Generic;
|
||||
#endif
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
public interface ICommitStatusClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Retrieves commit statuses for the specified reference. A reference can be a commit SHA, a branch name, or
|
||||
/// a tag name.
|
||||
/// </summary>
|
||||
/// <remarks>Only users with pull access can see this.</remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="reference">The reference (SHA, branch name, or tag name) to list commits for.</param>
|
||||
/// <returns></returns>
|
||||
Task<IReadOnlyList<CommitStatus>> GetAll(string owner, string name, string reference);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a commit status for the specified ref.
|
||||
/// </summary>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="reference">The reference (SHA, branch name, or tag name) to list commits for.</param>
|
||||
/// <param name="commitStatus">The commit status to create.</param>
|
||||
/// <returns></returns>
|
||||
Task<CommitStatus> Create(string owner, string name, string reference, NewCommitStatus commitStatus);
|
||||
}
|
||||
}
|
||||
@@ -125,5 +125,15 @@ namespace Octokit
|
||||
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
||||
/// <returns></returns>
|
||||
Task<string> GetReadmeHtml(string owner, string name);
|
||||
|
||||
/// <summary>
|
||||
/// A client for GitHub's Commit Status API.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/repos/statuses/">Commit Status API documentation</a> for more
|
||||
/// details. Also check out the <a href="https://github.com/blog/1227-commit-status-api">blog post</a>
|
||||
/// that announced this feature.
|
||||
/// </remarks>
|
||||
ICommitStatusClient CommitStatus { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ namespace Octokit
|
||||
/// <param name="apiConnection">An API connection.</param>
|
||||
public RepositoriesClient(IApiConnection apiConnection) : base(apiConnection)
|
||||
{
|
||||
CommitStatus = new CommitStatusClient(apiConnection);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -183,5 +184,15 @@ namespace Octokit
|
||||
var endpoint = "repos/{0}/{1}/readme".FormatUri(owner, name);
|
||||
return await ApiConnection.GetHtml(endpoint, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A client for GitHub's Commit Status API.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/repos/statuses/">Commit Status API documentation</a> for more
|
||||
/// details. Also check out the <a href="https://github.com/blog/1227-commit-status-api">blog post</a>
|
||||
/// that announced this feature.
|
||||
/// </remarks>
|
||||
public ICommitStatusClient CommitStatus { get; private set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,5 +234,17 @@ namespace Octokit
|
||||
{
|
||||
return "repos/{0}/{1}/milestones".FormatUri(owner, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="Uri"/> that lists the commit statuses for the specified reference.
|
||||
/// </summary>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="reference">The reference (SHA, branch name, or tag name) to list commits for.</param>
|
||||
/// <returns></returns>
|
||||
public static Uri CommitStatus(string owner, string name, string reference)
|
||||
{
|
||||
return "repos/{0}/{1}/statuses/{2}".FormatUri(owner, name, reference);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
public class NewCommitStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// The state of the commit.
|
||||
/// </summary>
|
||||
public CommitState State { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// URL associated with this status. GitHub.com displays this URL as a link to allow users to easily see the
|
||||
/// ‘source’ of the Status. For example, if your Continuous Integration system is posting build status,
|
||||
/// you would want to provide the deep link for the build output for this specific sha.
|
||||
/// </summary>
|
||||
public Uri TargetUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Short description of the status.
|
||||
/// </summary>
|
||||
public string Description { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
public class CommitStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// The date the commit status was created.
|
||||
/// </summary>
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The date the commit status was updated.
|
||||
/// </summary>
|
||||
public DateTimeOffset UpdatedAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The state of the commit
|
||||
/// </summary>
|
||||
public CommitState State { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// URL associated with this status. GitHub.com displays this URL as a link to allow users to easily see the
|
||||
/// ‘source’ of the Status.
|
||||
/// </summary>
|
||||
public Uri TargetUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Short description of the status.
|
||||
/// </summary>
|
||||
public string Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The unique identifier of the status.
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The URL of the status.
|
||||
/// </summary>
|
||||
public Uri Url { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The user that created the status.
|
||||
/// </summary>
|
||||
public User Creator { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents the state of a commit.
|
||||
/// </summary>
|
||||
public enum CommitState
|
||||
{
|
||||
/// <summary>
|
||||
/// The commit state is still being determined. A build server might set this when it starts a build.
|
||||
/// </summary>
|
||||
Pending,
|
||||
|
||||
/// <summary>
|
||||
/// The build was successful for the commit.
|
||||
/// </summary>
|
||||
Success,
|
||||
|
||||
/// <summary>
|
||||
/// There was some error with the build.
|
||||
/// </summary>
|
||||
Error,
|
||||
|
||||
/// <summary>
|
||||
/// The build completed and reports a failure.
|
||||
/// </summary>
|
||||
Failure
|
||||
}
|
||||
}
|
||||
@@ -82,6 +82,8 @@
|
||||
<Link>Properties\SolutionInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Clients\AssigneesClient.cs" />
|
||||
<Compile Include="Clients\CommitStatusClient.cs" />
|
||||
<Compile Include="Clients\ICommitStatusClient.cs" />
|
||||
<Compile Include="Clients\IssuesClient.cs" />
|
||||
<Compile Include="Clients\MilestonesClient.cs" />
|
||||
<Compile Include="Exceptions\NotFoundException.cs" />
|
||||
@@ -91,8 +93,10 @@
|
||||
<Compile Include="Helpers\ParameterAttribute.cs" />
|
||||
<Compile Include="Helpers\ReflectionExtensions.cs" />
|
||||
<Compile Include="Models\Request\MilestoneUpdate.cs" />
|
||||
<Compile Include="Models\Request\NewCommitStatus.cs" />
|
||||
<Compile Include="Models\Request\NewMilestone.cs" />
|
||||
<Compile Include="Models\Request\RequestParameters.cs" />
|
||||
<Compile Include="Models\Response\CommitStatus.cs" />
|
||||
<Compile Include="Models\Response\Issue.cs" />
|
||||
<Compile Include="Models\Request\IssueRequest.cs" />
|
||||
<Compile Include="Models\Request\IssueUpdate.cs" />
|
||||
|
||||
@@ -112,8 +112,10 @@
|
||||
<Compile Include="Clients\ApiPagination.cs" />
|
||||
<Compile Include="Clients\AssigneesClient.cs" />
|
||||
<Compile Include="Clients\AuthorizationsClient.cs" />
|
||||
<Compile Include="Clients\CommitStatusClient.cs" />
|
||||
<Compile Include="Clients\IAssigneesClient.cs" />
|
||||
<Compile Include="Clients\IAuthorizationsClient.cs" />
|
||||
<Compile Include="Clients\ICommitStatusClient.cs" />
|
||||
<Compile Include="Clients\IIssuesClient.cs" />
|
||||
<Compile Include="Clients\IMilestonesClient.cs" />
|
||||
<Compile Include="Clients\IMiscellaneousClient.cs" />
|
||||
@@ -188,6 +190,7 @@
|
||||
<Compile Include="Models\Request\MilestoneRequest.cs" />
|
||||
<Compile Include="Models\Request\MilestoneUpdate.cs" />
|
||||
<Compile Include="Models\Request\NewAuthorization.cs" />
|
||||
<Compile Include="Models\Request\NewCommitStatus.cs" />
|
||||
<Compile Include="Models\Request\NewIssue.cs" />
|
||||
<Compile Include="Models\Request\NewMilestone.cs" />
|
||||
<Compile Include="Models\Request\NewRepository.cs" />
|
||||
@@ -201,6 +204,7 @@
|
||||
<Compile Include="Models\Response\ApiErrorDetail.cs" />
|
||||
<Compile Include="Models\Response\Application.cs" />
|
||||
<Compile Include="Models\Response\Authorization.cs" />
|
||||
<Compile Include="Models\Response\CommitStatus.cs" />
|
||||
<Compile Include="Models\Response\EmailAddress.cs" />
|
||||
<Compile Include="Models\Response\Issue.cs" />
|
||||
<Compile Include="Models\Response\Label.cs" />
|
||||
|
||||
Reference in New Issue
Block a user