diff --git a/Octokit.Reactive/Clients/IObservableRepositoryPagesClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryPagesClient.cs index d62daa706a..1293eb31a9 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoryPagesClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoryPagesClient.cs @@ -16,6 +16,7 @@ public interface IObservableRepositoryPagesClient /// [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")] IObservable Get(string owner, string repositoryName); + /// /// Gets all build metadata for a given repository /// @@ -26,6 +27,19 @@ public interface IObservableRepositoryPagesClient /// /// IObservable GetAll(string owner, string repositoryName); + + /// + /// Gets all build metadata for a given repository + /// + /// The owner of the repository + /// The name of the repository + /// Options to change the API response + /// + /// See the API documentation for more information. + /// + /// + IObservable GetAll(string owner, string repositoryName, ApiOptions options); + /// /// Gets the build metadata for the last build for a given repository /// diff --git a/Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs index ebcd3af70f..28d06ccc35 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs @@ -50,7 +50,26 @@ public IObservable GetAll(string owner, string repositoryName) Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); - return _connection.GetAndFlattenAllPages(ApiUrls.RepositoryPageBuilds(owner, repositoryName)); + return GetAll(owner, repositoryName, ApiOptions.None); + } + + /// + /// Gets all build metadata for a given repository + /// + /// The owner of the repository + /// The name of the repository + /// Options to change the API response + /// + /// See the API documentation for more information. + /// + /// + public IObservable GetAll(string owner, string repositoryName, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.RepositoryPageBuilds(owner, repositoryName), options); } /// diff --git a/Octokit.Tests.Integration/Clients/RepositoryPagesClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryPagesClientTests.cs new file mode 100644 index 0000000000..ba2d614c88 --- /dev/null +++ b/Octokit.Tests.Integration/Clients/RepositoryPagesClientTests.cs @@ -0,0 +1,27 @@ +using System.Threading.Tasks; +using Octokit; +using Octokit.Tests.Integration; +using Xunit; + +public class RepositoryPagesClientTests +{ + public class TheGetMethod + { + readonly IRepositoryPagesClient _repositoryPagesClient; + const string owner = "octokit"; + const string name = "octokit.net"; + + public TheGetMethod() + { + var github = Helper.GetAuthenticatedClient(); + _repositoryPagesClient = github.Repository.Page; + } + + [IntegrationTest(Skip= "These tests require repository admin rights - see https://github.com/octokit/octokit.net/issues/1263 for discussion")] + public async Task ReturnsMetadata() + { + var data = await _repositoryPagesClient.Get(owner, name); + Assert.Equal("https://api.github.com/repos/octokit/octokit.net/pages", data.Url); + } + } +} \ No newline at end of file diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index 54e5e0407c..d954107000 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -101,6 +101,7 @@ + @@ -155,6 +156,7 @@ + diff --git a/Octokit.Tests.Integration/Reactive/ObservableRepositoryDeployKeysClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableRepositoryDeployKeysClientTests.cs index 41b142567f..1cf8b6067e 100644 --- a/Octokit.Tests.Integration/Reactive/ObservableRepositoryDeployKeysClientTests.cs +++ b/Octokit.Tests.Integration/Reactive/ObservableRepositoryDeployKeysClientTests.cs @@ -103,4 +103,4 @@ public void Dispose() { Helper.DeleteRepo(_repository); } -} +} \ No newline at end of file diff --git a/Octokit.Tests.Integration/Reactive/ObservableRepositoryPagesClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableRepositoryPagesClientTests.cs new file mode 100644 index 0000000000..0bb66f59ed --- /dev/null +++ b/Octokit.Tests.Integration/Reactive/ObservableRepositoryPagesClientTests.cs @@ -0,0 +1,46 @@ +using System.Reactive.Linq; +using System.Threading.Tasks; +using Octokit.Reactive; +using Xunit; + +namespace Octokit.Tests.Integration.Reactive +{ + public class ObservableRepositoryPagesClientTests + { + public class TheGetAllMethod + { + readonly ObservableRepositoryPagesClient _repositoryPagesClient; + const string owner = "octokit"; + const string name = "octokit.net"; + + public TheGetAllMethod() + { + var github = Helper.GetAuthenticatedClient(); + + _repositoryPagesClient = new ObservableRepositoryPagesClient(github); + } + + [IntegrationTest(Skip = "These tests require repository admin rights - see https://github.com/octokit/octokit.net/issues/1263 for discussion")] + public async Task ReturnsAllRepositoryPagesBuilds() + { + var pages = await _repositoryPagesClient.GetAll(owner, name).ToList(); + + Assert.NotEmpty(pages); + } + + [IntegrationTest(Skip = "These tests require repository admin rights - see https://github.com/octokit/octokit.net/issues/1263 for discussion")] + public async Task ReturnsPageOfRepositoryBuilds() + { + var options = new ApiOptions + { + PageSize= 5, + PageCount = 1 + }; + + var pages = await _repositoryPagesClient.GetAll(owner, name, options).ToList(); + + Assert.Equal(5, pages.Count); + } + } + } +} diff --git a/Octokit.Tests/Clients/RepositoryPagesClientTests.cs b/Octokit.Tests/Clients/RepositoryPagesClientTests.cs index 1bc0578ba9..7afe1f7af4 100644 --- a/Octokit.Tests/Clients/RepositoryPagesClientTests.cs +++ b/Octokit.Tests/Clients/RepositoryPagesClientTests.cs @@ -41,7 +41,7 @@ public async Task EnsuresNonNullArguments() } } - public class TheGetBuildsMethod + public class TheGetAllMethod { [Fact] public void RequestsCorrectUrl() @@ -51,7 +51,7 @@ public void RequestsCorrectUrl() client.GetAll("fake", "repo"); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/pages/builds")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/pages/builds"), Args.ApiOptions); } [Fact] @@ -60,8 +60,19 @@ public async Task EnsuresNonNullArguments() var connection = Substitute.For(); var client = new RepositoryPagesClient(connection); - await Assert.ThrowsAsync(() => client.Get(null, "name")); - await Assert.ThrowsAsync(() => client.Get("owner", null)); + await Assert.ThrowsAsync(() => client.GetAll(null, "name", new ApiOptions())); + await Assert.ThrowsAsync(() => client.GetAll("owner", null, new ApiOptions())); + await Assert.ThrowsAsync(() => client.GetAll("owner", "name", null)); + } + + [Fact] + public async Task EnsuresNonEmptyArguments() + { + var connection = Substitute.For(); + var client = new RepositoryPagesClient(connection); + + await Assert.ThrowsAsync(() => client.GetAll("", "name", new ApiOptions())); + await Assert.ThrowsAsync(() => client.GetAll("owner", "", new ApiOptions())); } } diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index 0ee78a27d0..2a8e7c325e 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -220,6 +220,7 @@ + diff --git a/Octokit.Tests/Reactive/ObservableRepositoryPagesClientTests.cs b/Octokit.Tests/Reactive/ObservableRepositoryPagesClientTests.cs new file mode 100644 index 0000000000..35311d7cf4 --- /dev/null +++ b/Octokit.Tests/Reactive/ObservableRepositoryPagesClientTests.cs @@ -0,0 +1,54 @@ +using System; +using NSubstitute; +using Octokit.Reactive; +using Xunit; + +namespace Octokit.Tests.Reactive +{ + public class ObservableRepositoryPagesClientTests + { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => new ObservableRepositoryPagesClient(null)); + } + } + + public class TheGetAllMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var githubClient = Substitute.For(); + var client = new ObservableRepositoryPagesClient(githubClient); + var options = new ApiOptions(); + + client.GetAll("fake", "repo", options); + githubClient.Received().Repository.Page.GetAll("fake", "repo", options); + } + + [Fact] + public void EnsuresNonNullArguments() + { + var githubClient = Substitute.For(); + var client = new ObservableRepositoryPagesClient(githubClient); + + Assert.Throws(() => client.GetAll(null, "repo", new ApiOptions())); + Assert.Throws(() => client.GetAll("owner", null, new ApiOptions())); + Assert.Throws(() => client.GetAll("owner", "repo", null)); + } + + [Fact] + public void EnsuresNonEmptyArguments() + { + var githubClient = Substitute.For(); + var client = new ObservableRepositoryPagesClient(githubClient); + + Assert.Throws(() => client.GetAll("", "repo", new ApiOptions())); + Assert.Throws(() => client.GetAll("owner", "", new ApiOptions())); + } + } + } +} diff --git a/Octokit/Clients/IRepositoryPagesClient.cs b/Octokit/Clients/IRepositoryPagesClient.cs index 579b263326..0716152ae9 100644 --- a/Octokit/Clients/IRepositoryPagesClient.cs +++ b/Octokit/Clients/IRepositoryPagesClient.cs @@ -23,16 +23,30 @@ public interface IRepositoryPagesClient /// [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")] Task Get(string owner, string repositoryName); + /// /// Gets all build metadata for a given repository /// /// The owner of the repository /// The name of the repository - /// + /// /// See the API documentation for more information. /// /// Task> GetAll(string owner, string repositoryName); + + /// + /// Gets all build metadata for a given repository + /// + /// The owner of the repository + /// The name of the repository + /// Options to change the API response + /// + /// See the API documentation for more information. + /// + /// + Task> GetAll(string owner, string repositoryName, ApiOptions options); + /// /// Gets the build metadata for the last build for a given repository /// diff --git a/Octokit/Clients/RepositoryPagesClient.cs b/Octokit/Clients/RepositoryPagesClient.cs index 04ed5c2a5a..9958daefb1 100644 --- a/Octokit/Clients/RepositoryPagesClient.cs +++ b/Octokit/Clients/RepositoryPagesClient.cs @@ -41,7 +41,7 @@ public Task Get(string owner, string repositoryName) /// /// The owner of the repository /// The name of the repository - /// + /// /// See the API documentation for more information. /// /// @@ -50,7 +50,27 @@ public Task> GetAll(string owner, string repositoryNam Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); - return ApiConnection.GetAll(ApiUrls.RepositoryPageBuilds(owner, repositoryName)); + return GetAll(owner, repositoryName, ApiOptions.None); + } + + /// + /// Gets all build metadata for a given repository + /// + /// The owner of the repository + /// The name of the repository + /// Options to change the API response + /// + /// See the API documentation for more information. + /// + /// + public Task> GetAll(string owner, string repositoryName, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); + Ensure.ArgumentNotNull(options, "options"); + + var endpoint = ApiUrls.RepositoryPageBuilds(owner, repositoryName); + return ApiConnection.GetAll(endpoint, options); } ///