diff --git a/Octokit.Reactive/Clients/IObservableCommitStatusClient.cs b/Octokit.Reactive/Clients/IObservableCommitStatusClient.cs index d2168f80..b1a970fb 100644 --- a/Octokit.Reactive/Clients/IObservableCommitStatusClient.cs +++ b/Octokit.Reactive/Clients/IObservableCommitStatusClient.cs @@ -15,6 +15,18 @@ namespace Octokit.Reactive /// IObservable GetAll(string owner, string name, string reference); + /// + /// Retrieves commit statuses for the specified reference. A reference can be a commit SHA, a branch name, or + /// a tag name. + /// + /// Only users with pull access can see this. + /// The owner of the repository + /// The name of the repository + /// The reference (SHA, branch name, or tag name) to list commits for + /// Options for changing the API response + /// + IObservable GetAll(string owner, string name, string reference, ApiOptions options); + /// /// Retrieves a combined view of statuses for the specified reference. A reference can be a commit SHA, a branch name, or /// a tag name. diff --git a/Octokit.Reactive/Clients/ObservableCommitStatusClient.cs b/Octokit.Reactive/Clients/ObservableCommitStatusClient.cs index b6390bc1..cc43773e 100644 --- a/Octokit.Reactive/Clients/ObservableCommitStatusClient.cs +++ b/Octokit.Reactive/Clients/ObservableCommitStatusClient.cs @@ -28,7 +28,31 @@ namespace Octokit.Reactive /// public IObservable GetAll(string owner, string name, string reference) { - return _connection.GetAndFlattenAllPages(ApiUrls.CommitStatuses(owner, name, reference)); + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); + + return GetAll(owner, name ,reference, ApiOptions.None); + } + + /// + /// Retrieves commit statuses for the specified reference. A reference can be a commit SHA, a branch name, or + /// a tag name. + /// + /// Only users with pull access can see this. + /// The owner of the repository + /// The name of the repository + /// The reference (SHA, branch name, or tag name) to list commits for + /// Options for changing the API response + /// + public IObservable GetAll(string owner, string name, string reference, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.CommitStatuses(owner, name, reference),options); } /// diff --git a/Octokit.Reactive/Clients/ObservableReleasesClient.cs b/Octokit.Reactive/Clients/ObservableReleasesClient.cs index 100bd131..880580c1 100644 --- a/Octokit.Reactive/Clients/ObservableReleasesClient.cs +++ b/Octokit.Reactive/Clients/ObservableReleasesClient.cs @@ -33,7 +33,7 @@ namespace Octokit.Reactive Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - return _connection.GetAndFlattenAllPages(ApiUrls.Releases(owner, name)); + return GetAll(owner, name, ApiOptions.None); } /// diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index 4181ab35..960f011e 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -141,6 +141,7 @@ + diff --git a/Octokit.Tests.Integration/Reactive/ObservableCommitStatusClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableCommitStatusClientTests.cs new file mode 100644 index 00000000..f903f896 --- /dev/null +++ b/Octokit.Tests.Integration/Reactive/ObservableCommitStatusClientTests.cs @@ -0,0 +1,85 @@ +using System.Reactive.Linq; +using System.Threading.Tasks; +using Octokit.Reactive; +using Xunit; + +namespace Octokit.Tests.Integration.Reactive +{ + public class ObservableCommitStatusClientTests + { + public class TheGetAllMethod + { + readonly ObservableCommitStatusClient _commitStatusClient; + const string owner = "octokit"; + const string name = "octokit.net"; + const string reference = "1335f37"; + + public TheGetAllMethod() + { + var github = Helper.GetAuthenticatedClient(); + _commitStatusClient = new ObservableCommitStatusClient(github); + } + + [IntegrationTest] + public async Task ReturnCommitStatus() + { + var commitStatus = await _commitStatusClient.GetAll(owner, name, reference).ToList(); + + Assert.NotEmpty(commitStatus); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfCommitStatusWithoutStart() + { + var options = new ApiOptions + { + PageSize = 2, + PageCount = 1 + }; + + var commitStatus = await _commitStatusClient.GetAll(owner, name ,reference , options).ToList(); + + Assert.Equal(2, commitStatus.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfCommitStatusWithStart() + { + var options = new ApiOptions + { + PageSize = 2, + PageCount = 1, + StartPage = 1 + }; + + var commitStatus = await _commitStatusClient.GetAll(owner, name, reference, options).ToList(); + + Assert.Equal(2, commitStatus.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctResultsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 2, + PageCount = 1 + }; + + var firstPage = await _commitStatusClient.GetAll(owner, name, reference, startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 2, + PageCount = 1, + StartPage = 2 + }; + + var secondPage = await _commitStatusClient.GetAll(owner, name, reference,skipStartOptions).ToList(); + + Assert.NotEqual(firstPage[0].Id, secondPage[0].Id); + Assert.NotEqual(firstPage[1].Id, secondPage[1].Id); + } + } + } +} diff --git a/Octokit.Tests/Clients/CommitStatusClientTests.cs b/Octokit.Tests/Clients/CommitStatusClientTests.cs index c7658c83..6dd5689f 100644 --- a/Octokit.Tests/Clients/CommitStatusClientTests.cs +++ b/Octokit.Tests/Clients/CommitStatusClientTests.cs @@ -20,8 +20,27 @@ namespace Octokit.Tests.Clients client.GetAll("fake", "repo", "sha"); connection.Received() - .GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/commits/sha/statuses")); + .GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/commits/sha/statuses"), Arg.Any()); } + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new CommitStatusClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + + client.GetAll("fake", "repo", "sha", options); + + connection.Received() + .GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/commits/sha/statuses"), Args.ApiOptions); + } + [Fact] public async Task EnsuresNonNullArguments() diff --git a/Octokit.Tests/Reactive/ObservableReleasesClientTests.cs b/Octokit.Tests/Reactive/ObservableReleasesClientTests.cs index fd8f94bb..77e09103 100644 --- a/Octokit.Tests/Reactive/ObservableReleasesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableReleasesClientTests.cs @@ -29,7 +29,7 @@ namespace Octokit.Tests.Reactive client.GetAll("fake", "repo"); gitHubClient.Connection.Received(1).Get>( - new Uri("repos/fake/repo/releases", UriKind.Relative), null, null); + new Uri("repos/fake/repo/releases", UriKind.Relative), Args.EmptyDictionary, null); } [Fact] diff --git a/Octokit/Clients/CommitStatusClient.cs b/Octokit/Clients/CommitStatusClient.cs index 6a42091e..b890bdff 100644 --- a/Octokit/Clients/CommitStatusClient.cs +++ b/Octokit/Clients/CommitStatusClient.cs @@ -36,7 +36,29 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); - return ApiConnection.GetAll(ApiUrls.CommitStatuses(owner, name, reference)); + return GetAll(owner,name,reference,ApiOptions.None); + } + + /// + /// Retrieves commit statuses for the specified reference. A reference can be a commit SHA, a branch name, or + /// a tag name. + /// + /// + /// https://developer.github.com/v3/repos/statuses/#list-statuses-for-a-specific-ref + /// + /// The owner of the repository + /// The name of the repository + /// The reference (SHA, branch name, or tag name) to list commits for + /// Options for changing the API response + /// + public Task> GetAll(string owner, string name, string reference, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.CommitStatuses(owner, name, reference),options); } /// diff --git a/Octokit/Clients/ICommitStatusClient.cs b/Octokit/Clients/ICommitStatusClient.cs index e9743ea7..eb3c7209 100644 --- a/Octokit/Clients/ICommitStatusClient.cs +++ b/Octokit/Clients/ICommitStatusClient.cs @@ -24,6 +24,20 @@ namespace Octokit /// Task> GetAll(string owner, string name, string reference); + /// + /// Retrieves commit statuses for the specified reference. A reference can be a commit SHA, a branch name, or + /// a tag name. + /// + /// + /// https://developer.github.com/v3/repos/statuses/#list-statuses-for-a-specific-ref + /// + /// The owner of the repository + /// The name of the repository + /// The reference (SHA, branch name, or tag name) to list commits for + /// Options for changing the API response + /// + Task> GetAll(string owner, string name, string reference, ApiOptions options); + /// /// Retrieves a combined view of statuses for the specified reference. A reference can be a commit SHA, a branch name, or /// a tag name.