diff --git a/Octokit.Reactive/Clients/IObservablePullRequestsClient.cs b/Octokit.Reactive/Clients/IObservablePullRequestsClient.cs index d1b46a93..242f5a9d 100644 --- a/Octokit.Reactive/Clients/IObservablePullRequestsClient.cs +++ b/Octokit.Reactive/Clients/IObservablePullRequestsClient.cs @@ -84,5 +84,15 @@ namespace Octokit /// The pull request number /// IObservable Merged(string owner, string name, int number); + + /// + /// Gets the list of commits on a pull request. + /// + /// http://developer.github.com/v3/pulls/#list-commits-on-a-pull-request + /// The owner of the repository + /// The name of the repository + /// The pull request number + /// + IObservable Commits(string owner, string name, int number); } } diff --git a/Octokit.Reactive/Clients/ObservablePullRequestsClient.cs b/Octokit.Reactive/Clients/ObservablePullRequestsClient.cs index 3ce61a60..716eb1f3 100644 --- a/Octokit.Reactive/Clients/ObservablePullRequestsClient.cs +++ b/Octokit.Reactive/Clients/ObservablePullRequestsClient.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Reactive; using System.Reactive.Threading.Tasks; using System.Threading.Tasks; @@ -137,5 +138,21 @@ namespace Octokit.Reactive.Clients return _client.Merged(owner, name, number).ToObservable(); } + + /// + /// Gets the list of commits on a pull request. + /// + /// http://developer.github.com/v3/pulls/#list-commits-on-a-pull-request + /// The owner of the repository + /// The name of the repository + /// The pull request number + /// + public IObservable Commits(string owner, string name, int number) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return _connection.GetAndFlattenAllPages(ApiUrls.PullRequestCommits(owner, name, number)); + } } } \ No newline at end of file diff --git a/Octokit.Tests/Clients/PullRequestsClientTests.cs b/Octokit.Tests/Clients/PullRequestsClientTests.cs index f55c0422..f07e2ce6 100644 --- a/Octokit.Tests/Clients/PullRequestsClientTests.cs +++ b/Octokit.Tests/Clients/PullRequestsClientTests.cs @@ -167,7 +167,7 @@ namespace Octokit.Tests.Clients public class TheMergedMethod { [Fact] - public void PutsToCorrectUrl() + public void RequestsCorrectUrl() { var connection = Substitute.For(); var client = new PullRequestsClient(connection); @@ -183,10 +183,37 @@ namespace Octokit.Tests.Clients var connection = Substitute.For(); var client = new PullRequestsClient(connection); - AssertEx.Throws(async () => await - client.Merged(null, "name", 42)); - AssertEx.Throws(async () => await - client.Merged("owner", null, 42)); + await AssertEx.Throws(async () => await client.Merged(null, "name", 1)); + await AssertEx.Throws(async () => await client.Merged("owner", null, 1)); + await AssertEx.Throws(async () => await client.Merged(null, "", 1)); + await AssertEx.Throws(async () => await client.Merged("", null, 1)); + } + } + + public class TheCommitsMethod + { + [Fact] + public async void RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new PullRequestsClient(connection); + + client.Commits("fake", "repo", 42); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repos/fake/repo/pulls/42/commits")); + } + + [Fact] + public async Task EnsuresArgumentsNotNull() + { + var connection = Substitute.For(); + var client = new PullRequestsClient(connection); + + await AssertEx.Throws(async () => await client.Commits(null, "name", 1)); + await AssertEx.Throws(async () => await client.Commits("owner", null, 1)); + await AssertEx.Throws(async () => await client.Commits(null, "", 1)); + await AssertEx.Throws(async () => await client.Commits("", null, 1)); } } diff --git a/Octokit/Clients/IPullRequestsClient.cs b/Octokit/Clients/IPullRequestsClient.cs index b3fd2d9d..d3248116 100644 --- a/Octokit/Clients/IPullRequestsClient.cs +++ b/Octokit/Clients/IPullRequestsClient.cs @@ -82,5 +82,15 @@ namespace Octokit /// The pull request number /// Task Merged(string owner, string name, int number); + + /// + /// Gets the list of commits on a pull request. + /// + /// http://developer.github.com/v3/pulls/#list-commits-on-a-pull-request + /// The owner of the repository + /// The name of the repository + /// The pull request number + /// + Task> Commits(string owner, string name, int number); } } diff --git a/Octokit/Clients/PullRequestsClient.cs b/Octokit/Clients/PullRequestsClient.cs index ee092ec3..090a0600 100644 --- a/Octokit/Clients/PullRequestsClient.cs +++ b/Octokit/Clients/PullRequestsClient.cs @@ -130,5 +130,21 @@ namespace Octokit return ApiConnection.Get(ApiUrls.MergePullRequest(owner, name, number)); } + + /// + /// Gets the list of commits on a pull request. + /// + /// http://developer.github.com/v3/pulls/#list-commits-on-a-pull-request + /// The owner of the repository + /// The name of the repository + /// The pull request number + /// + public Task> Commits(string owner, string name, int number) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return ApiConnection.GetAll(ApiUrls.PullRequestCommits(owner, name, number)); + } } } diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index d96f96df..f907cb61 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -599,6 +599,17 @@ namespace Octokit return "repos/{0}/{1}/pulls/{2}/merge".FormatUri(owner, name, number); } + /// + /// Returns the that returns the commits on a pull request. + /// + /// The owner of the repository + /// The name of the repository + /// /// The pull request number + public static Uri PullRequestCommits(string owner, string name, int number) + { + return "repos/{0}/{1}/pulls/{2}/commits".FormatUri(owner, name, number); + } + /// /// Returns the for a spesific comment for the specified commit. ///