-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from octokit/haacked/commit-status-api
Commit Status API
- Loading branch information
Showing
21 changed files
with
507 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.