diff --git a/Octokit.Reactive/Clients/IObservableRepositoriesClient.cs b/Octokit.Reactive/Clients/IObservableRepositoriesClient.cs index 8f47b4fe..023fbb74 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoriesClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoriesClient.cs @@ -74,6 +74,14 @@ namespace Octokit.Reactive Justification = "Makes a network request")] IObservable GetAllForCurrent(); + /// + /// Retrieves every that belongs to the current user. + /// + /// Options for changing the API response + /// Thrown if the client is not authenticated. + /// A of . + IObservable GetAllForCurrent(ApiOptions options); + /// /// Retrieves every that belongs to the current user. /// @@ -83,21 +91,32 @@ namespace Octokit.Reactive /// Search parameters to filter results on /// Thrown if the client is not authenticated. /// A of . - [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", - Justification = "Makes a network request")] IObservable GetAllForCurrent(RepositoryRequest request); + /// + /// Retrieves every that belongs to the current user. + /// + /// Search parameters to filter results on + /// Options for changing the API response + /// Thrown if the client is not authenticated. + /// A of . + IObservable GetAllForCurrent(RepositoryRequest request, ApiOptions options); + /// /// Retrieves every that belongs to the specified user. /// - /// - /// The default page size on GitHub.com is 30. - /// + /// The account name to search for /// A of . - [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", - Justification = "Makes a network request")] IObservable GetAllForUser(string login); + /// + /// Retrieves every that belongs to the specified user. + /// + /// The account name to search for + /// Options for changing the API response + /// A of . + IObservable GetAllForUser(string login, ApiOptions options); + /// /// Retrieves every that belongs to the specified organization. /// @@ -105,10 +124,16 @@ namespace Octokit.Reactive /// The default page size on GitHub.com is 30. /// /// A of . - [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", - Justification = "Makes a network request")] IObservable GetAllForOrg(string organization); + /// + /// Retrieves every that belongs to the specified organization. + /// + /// The organization name to search for + /// Options for changing the API response + /// A of . + IObservable GetAllForOrg(string organization, ApiOptions options); + /// /// A client for GitHub's Commit Status API. /// @@ -203,6 +228,19 @@ namespace Octokit.Reactive /// All es of the repository IObservable GetAllBranches(string owner, string name); + /// + /// Gets all the branches for the specified repository. + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// Thrown when a general API error occurs. + /// All es of the repository + IObservable GetAllBranches(string owner, string name, ApiOptions options); + /// /// Gets all contributors for the specified repository. Does not include anonymous contributors. /// @@ -214,6 +252,18 @@ namespace Octokit.Reactive /// All contributors of the repository. IObservable GetAllContributors(string owner, string name); + /// + /// Gets all contributors for the specified repository. Does not include anonymous contributors. + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// All contributors of the repository. + IObservable GetAllContributors(string owner, string name, ApiOptions options); + /// /// Gets all contributors for the specified repository. With the option to include anonymous contributors. /// @@ -226,6 +276,20 @@ namespace Octokit.Reactive /// All contributors of the repository. IObservable GetAllContributors(string owner, string name, bool includeAnonymous); + + /// + /// Gets all contributors for the specified repository. With the option to include anonymous contributors. + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// True if anonymous contributors should be included in result; Otherwise false + /// Options for changing the API response + /// All contributors of the repository. + IObservable GetAllContributors(string owner, string name, bool includeAnonymous, ApiOptions options); + /// /// Gets all languages for the specified repository. /// @@ -248,6 +312,18 @@ namespace Octokit.Reactive /// All s associated with the repository IObservable GetAllTeams(string owner, string name); + /// + /// Gets all teams for the specified repository. + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// All s associated with the repository + IObservable GetAllTeams(string owner, string name, ApiOptions options); + /// /// Gets all tags for the specified repository. /// @@ -259,6 +335,18 @@ namespace Octokit.Reactive /// All of the repositories tags. IObservable GetAllTags(string owner, string name); + /// + /// Gets all tags for the specified repository. + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// All of the repositories tags. + IObservable GetAllTags(string owner, string name, ApiOptions options); + /// /// Gets the specified branch. /// diff --git a/Octokit.Reactive/Clients/ObservableRepositoriesClient.cs b/Octokit.Reactive/Clients/ObservableRepositoriesClient.cs index d7d7d4cd..26a4ddfe 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoriesClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoriesClient.cs @@ -142,7 +142,20 @@ namespace Octokit.Reactive /// A of . public IObservable GetAllForCurrent() { - return _connection.GetAndFlattenAllPages(ApiUrls.Repositories()); + return GetAllForCurrent(ApiOptions.None); + } + + /// + /// Retrieves every that belongs to the current user. + /// + /// Options for changing the API response + /// Thrown if the client is not authenticated. + /// A of . + public IObservable GetAllForCurrent(ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.Repositories(), options); } /// @@ -158,21 +171,48 @@ namespace Octokit.Reactive { Ensure.ArgumentNotNull(request, "request"); + return GetAllForCurrent(request, ApiOptions.None); + } + + /// + /// Retrieves every that belongs to the current user. + /// + /// Search parameters to filter results on + /// Options for changing the API response + /// Thrown if the client is not authenticated. + /// A of . + public IObservable GetAllForCurrent(RepositoryRequest request, ApiOptions options) + { + Ensure.ArgumentNotNull(request, "request"); + Ensure.ArgumentNotNull(options, "options"); + return _connection.GetAndFlattenAllPages(ApiUrls.Repositories(), request.ToParametersDictionary()); } /// /// Retrieves every that belongs to the specified user. /// - /// - /// The default page size on GitHub.com is 30. - /// + /// The account name to search for /// A of . public IObservable GetAllForUser(string login) { Ensure.ArgumentNotNullOrEmptyString(login, "login"); - return _connection.GetAndFlattenAllPages(ApiUrls.Repositories(login)); + return GetAllForUser(login, ApiOptions.None); + } + + /// + /// Retrieves every that belongs to the specified user. + /// + /// The account name to search for + /// Options for changing the API response + /// A of . + public IObservable GetAllForUser(string login, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(login, "login"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.Repositories(login), options); } /// @@ -186,7 +226,21 @@ namespace Octokit.Reactive { Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); - return _connection.GetAndFlattenAllPages(ApiUrls.OrganizationRepositories(organization)); + return GetAllForOrg(organization, ApiOptions.None); + } + + /// + /// Retrieves every that belongs to the specified organization. + /// + /// The organization name to search for + /// Options for changing the API response + /// A of . + public IObservable GetAllForOrg(string organization, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.OrganizationRepositories(organization), options); } /// @@ -287,8 +341,27 @@ namespace Octokit.Reactive Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - var endpoint = ApiUrls.RepoBranches(owner, name); - return _connection.GetAndFlattenAllPages(endpoint); + return GetAllBranches(owner, name, ApiOptions.None); + } + + /// + /// Gets all the branches for the specified repository. + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// Thrown when a general API error occurs. + /// All es of the repository + public IObservable GetAllBranches(string owner, string name, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.RepoBranches(owner, name), options); } /// @@ -302,7 +375,29 @@ namespace Octokit.Reactive /// All contributors of the repository. public IObservable GetAllContributors(string owner, string name) { - return GetAllContributors(owner, name, false); + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return GetAllContributors(owner, name, ApiOptions.None); + } + + /// + /// Gets all contributors for the specified repository. Does not include anonymous contributors. + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// All contributors of the repository. + public IObservable GetAllContributors(string owner, string name, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(options, "options"); + + return GetAllContributors(owner, name, false, ApiOptions.None); } /// @@ -320,6 +415,15 @@ namespace Octokit.Reactive Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); + return GetAllContributors(owner, name, false, ApiOptions.None); + } + + public IObservable GetAllContributors(string owner, string name, bool includeAnonymous, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(options, "options"); + var endpoint = ApiUrls.RepositoryContributors(owner, name); var parameters = new Dictionary(); if (includeAnonymous) @@ -362,8 +466,26 @@ namespace Octokit.Reactive Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - var endpoint = ApiUrls.RepositoryTeams(owner, name); - return _connection.GetAndFlattenAllPages(endpoint); + return GetAllTeams(owner, name, ApiOptions.None); + } + + /// + /// Gets all teams for the specified repository. + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// All s associated with the repository + public IObservable GetAllTeams(string owner, string name, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.RepositoryTeams(owner, name), options); } /// @@ -380,8 +502,26 @@ namespace Octokit.Reactive Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - var endpoint = ApiUrls.RepositoryTags(owner, name); - return _connection.GetAndFlattenAllPages(endpoint); + return GetAllTags(owner, name, ApiOptions.None); + } + + /// + /// Gets all tags for the specified repository. + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// All of the repositories tags. + public IObservable GetAllTags(string owner, string name, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.RepositoryTags(owner, name), options); } /// diff --git a/Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs index f0bf9972..38c8ceb9 100644 --- a/Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs @@ -523,13 +523,106 @@ public class RepositoriesClientTests public class TheGetAllForOrgMethod { [IntegrationTest] - public async Task ReturnsAllRepositoriesForOrganization() + public async Task ReturnsRepositoriesForOrganization() + { + var github = Helper.GetAuthenticatedClient(); + + var options = new ApiOptions + { + PageSize = 20, + StartPage = 1, + PageCount = 1 + }; + + var repositories = await github.Repository.GetAllForOrg("github", options); + + Assert.Equal(20, repositories.Count); + } + + [IntegrationTest] + public async Task GetsPagesOfRepositories() { var github = Helper.GetAuthenticatedClient(); - var repositories = await github.Repository.GetAllForOrg("github"); + var firstPageOptions = new ApiOptions + { + PageSize = 5, + StartPage = 1, + PageCount = 1 + }; - Assert.True(repositories.Count > 80); + var firstPage = await github.Repository.GetAllForOrg("github", firstPageOptions); + + var secondPageOptions = new ApiOptions + { + PageSize = 5, + StartPage = 2, + PageCount = 1 + }; + + var secondPage = await github.Repository.GetAllForOrg("github", secondPageOptions); + + Assert.Equal(5, firstPage.Count); + Assert.Equal(5, secondPage.Count); + + Assert.NotEqual(firstPage[0].Name, secondPage[0].Name); + Assert.NotEqual(firstPage[1].Name, secondPage[1].Name); + Assert.NotEqual(firstPage[2].Name, secondPage[2].Name); + Assert.NotEqual(firstPage[3].Name, secondPage[3].Name); + Assert.NotEqual(firstPage[4].Name, secondPage[4].Name); + } + } + + public class TheGetAllForUserMethod + { + [IntegrationTest] + public async Task ReturnsRepositoriesForOrganization() + { + var github = Helper.GetAuthenticatedClient(); + + var options = new ApiOptions + { + PageSize = 20, + StartPage = 1, + PageCount = 1 + }; + + var repositories = await github.Repository.GetAllForUser("shiftkey", options); + + Assert.Equal(20, repositories.Count); + } + + [IntegrationTest] + public async Task GetsPagesOfRepositories() + { + var github = Helper.GetAuthenticatedClient(); + + var firstPageOptions = new ApiOptions + { + PageSize = 5, + StartPage = 1, + PageCount = 1 + }; + + var firstPage = await github.Repository.GetAllForUser("shiftkey", firstPageOptions); + + var secondPageOptions = new ApiOptions + { + PageSize = 5, + StartPage = 2, + PageCount = 1 + }; + + var secondPage = await github.Repository.GetAllForUser("shiftkey", secondPageOptions); + + Assert.Equal(5, firstPage.Count); + Assert.Equal(5, secondPage.Count); + + Assert.NotEqual(firstPage[0].Name, secondPage[0].Name); + Assert.NotEqual(firstPage[1].Name, secondPage[1].Name); + Assert.NotEqual(firstPage[2].Name, secondPage[2].Name); + Assert.NotEqual(firstPage[3].Name, secondPage[3].Name); + Assert.NotEqual(firstPage[4].Name, secondPage[4].Name); } } @@ -544,6 +637,39 @@ public class RepositoriesClientTests Assert.True(contributors.Any(c => c.Login == "pmacn")); } + + [IntegrationTest] + public async Task GetsPagesOfContributors() + { + var github = Helper.GetAuthenticatedClient(); + + var firstPageOptions = new ApiOptions + { + PageSize = 5, + StartPage = 1, + PageCount = 1 + }; + + var firstPage = await github.Repository.GetAllContributors("octokit", "octokit.net", firstPageOptions); + + var secondPageOptions = new ApiOptions + { + PageSize = 5, + StartPage = 2, + PageCount = 1 + }; + + var secondPage = await github.Repository.GetAllContributors("octokit", "octokit.net", secondPageOptions); + + Assert.Equal(5, firstPage.Count); + Assert.Equal(5, secondPage.Count); + + Assert.NotEqual(firstPage[0].Login, secondPage[0].Login); + Assert.NotEqual(firstPage[1].Login, secondPage[1].Login); + Assert.NotEqual(firstPage[2].Login, secondPage[2].Login); + Assert.NotEqual(firstPage[3].Login, secondPage[3].Login); + Assert.NotEqual(firstPage[4].Login, secondPage[4].Login); + } } public class TheGetAllForCurrentMethod @@ -558,6 +684,39 @@ public class RepositoriesClientTests Assert.NotEmpty(repositories); } + [IntegrationTest] + public async Task GetsPagesOfRepositories() + { + var github = Helper.GetAuthenticatedClient(); + + var firstPageOptions = new ApiOptions + { + PageSize = 5, + StartPage = 1, + PageCount = 1 + }; + + var firstPage = await github.Repository.GetAllForCurrent(firstPageOptions); + + var secondPageOptions = new ApiOptions + { + PageSize = 5, + StartPage = 2, + PageCount = 1 + }; + + var secondPage = await github.Repository.GetAllForCurrent(secondPageOptions); + + Assert.Equal(5, firstPage.Count); + Assert.Equal(5, secondPage.Count); + + Assert.NotEqual(firstPage[0].Name, secondPage[0].Name); + Assert.NotEqual(firstPage[1].Name, secondPage[1].Name); + Assert.NotEqual(firstPage[2].Name, secondPage[2].Name); + Assert.NotEqual(firstPage[3].Name, secondPage[3].Name); + Assert.NotEqual(firstPage[4].Name, secondPage[4].Name); + } + [IntegrationTest] public async Task CanSortResults() { @@ -627,6 +786,87 @@ public class RepositoriesClientTests Assert.True(tags.Any(t => t.Name == "v0.1.0")); } + + + [IntegrationTest] + public async Task GetsPagesOfTags() + { + var github = Helper.GetAuthenticatedClient(); + + var firstPageOptions = new ApiOptions + { + PageSize = 5, + StartPage = 1, + PageCount = 1 + }; + + var firstPage = await github.Repository.GetAllTags("octokit", "octokit.net", firstPageOptions); + + var secondPageOptions = new ApiOptions + { + PageSize = 5, + StartPage = 2, + PageCount = 1 + }; + + var secondPage = await github.Repository.GetAllTags("octokit", "octokit.net", secondPageOptions); + + Assert.Equal(5, firstPage.Count); + Assert.Equal(5, secondPage.Count); + + Assert.NotEqual(firstPage[0].Name, secondPage[0].Name); + Assert.NotEqual(firstPage[1].Name, secondPage[1].Name); + Assert.NotEqual(firstPage[2].Name, secondPage[2].Name); + Assert.NotEqual(firstPage[3].Name, secondPage[3].Name); + Assert.NotEqual(firstPage[4].Name, secondPage[4].Name); + } + + } + + public class TheGetAllBranchesMethod + { + [IntegrationTest] + public async Task GetsAllBranches() + { + var github = Helper.GetAuthenticatedClient(); + + var branches = await github.Repository.GetAllBranches("octokit", "octokit.net"); + + Assert.NotEmpty(branches); + } + + [IntegrationTest] + public async Task GetsPagesOfBranches() + { + var github = Helper.GetAuthenticatedClient(); + + var firstPageOptions = new ApiOptions + { + PageSize = 5, + StartPage = 1, + PageCount = 1 + }; + + var firstPage = await github.Repository.GetAllBranches("octokit", "octokit.net", firstPageOptions); + + var secondPageOptions = new ApiOptions + { + PageSize = 5, + StartPage = 1, + PageCount = 1 + }; + + var secondPage = await github.Repository.GetAllBranches("octokit", "octokit.net", secondPageOptions); + + Assert.Equal(5, firstPage.Count); + Assert.Equal(5, secondPage.Count); + + Assert.NotEqual(firstPage[0].Name, secondPage[0].Name); + Assert.NotEqual(firstPage[1].Name, secondPage[1].Name); + Assert.NotEqual(firstPage[2].Name, secondPage[2].Name); + Assert.NotEqual(firstPage[3].Name, secondPage[3].Name); + Assert.NotEqual(firstPage[4].Name, secondPage[4].Name); + } } public class TheGetBranchMethod @@ -642,4 +882,50 @@ public class RepositoriesClientTests Assert.Equal("master", branch.Name); } } + + public class TheGetAllTeamsMethod + { + [IntegrationTest(Skip="Test requires administration rights to access this endpoint")] + public async Task GetsAllTeams() + { + var github = Helper.GetAuthenticatedClient(); + + var branches = await github.Repository.GetAllTeams("octokit", "octokit.net"); + + Assert.NotEmpty(branches); + } + + [IntegrationTest(Skip = "Test requires administration rights to access this endpoint")] + public async Task GetsPagesOfBranches() + { + var github = Helper.GetAuthenticatedClient(); + + var firstPageOptions = new ApiOptions + { + PageSize = 5, + StartPage = 1, + PageCount = 1 + }; + + var firstPage = await github.Repository.GetAllTeams("octokit", "octokit.net", firstPageOptions); + + var secondPageOptions = new ApiOptions + { + PageSize = 5, + StartPage = 1, + PageCount = 1 + }; + + var secondPage = await github.Repository.GetAllTeams("octokit", "octokit.net", secondPageOptions); + + Assert.Equal(5, firstPage.Count); + Assert.Equal(5, secondPage.Count); + + Assert.NotEqual(firstPage[0].Name, secondPage[0].Name); + Assert.NotEqual(firstPage[1].Name, secondPage[1].Name); + Assert.NotEqual(firstPage[2].Name, secondPage[2].Name); + Assert.NotEqual(firstPage[3].Name, secondPage[3].Name); + Assert.NotEqual(firstPage[4].Name, secondPage[4].Name); + } + } } diff --git a/Octokit.Tests/Clients/RepositoriesClientTests.cs b/Octokit.Tests/Clients/RepositoriesClientTests.cs index 833045aa..610832bb 100644 --- a/Octokit.Tests/Clients/RepositoriesClientTests.cs +++ b/Octokit.Tests/Clients/RepositoriesClientTests.cs @@ -311,7 +311,7 @@ namespace Octokit.Tests.Clients client.GetAllForCurrent(); connection.Received() - .GetAll(Arg.Is(u => u.ToString() == "user/repos")); + .GetAll(Arg.Is(u => u.ToString() == "user/repos"), Args.ApiOptions); } [Fact] @@ -330,7 +330,8 @@ namespace Octokit.Tests.Clients connection.Received() .GetAll( Arg.Is(u => u.ToString() == "user/repos"), - Arg.Is>(d => d["type"] == "all")); + Arg.Is>(d => d["type"] == "all"), + Args.ApiOptions); } [Fact] @@ -351,7 +352,8 @@ namespace Octokit.Tests.Clients .GetAll( Arg.Is(u => u.ToString() == "user/repos"), Arg.Is>(d => - d["type"] == "private" && d["sort"] == "full_name")); + d["type"] == "private" && d["sort"] == "full_name"), + Args.ApiOptions); } [Fact] @@ -373,7 +375,8 @@ namespace Octokit.Tests.Clients .GetAll( Arg.Is(u => u.ToString() == "user/repos"), Arg.Is>(d => - d["type"] == "member" && d["sort"] == "updated" && d["direction"] == "asc")); + d["type"] == "member" && d["sort"] == "updated" && d["direction"] == "asc"), + Args.ApiOptions); } [Fact] @@ -392,7 +395,8 @@ namespace Octokit.Tests.Clients .GetAll( Arg.Is(u => u.ToString() == "user/repos"), Arg.Is>(d => - d["visibility"] == "private")); + d["visibility"] == "private"), + Args.ApiOptions); } [Fact] @@ -413,22 +417,23 @@ namespace Octokit.Tests.Clients .GetAll( Arg.Is(u => u.ToString() == "user/repos"), Arg.Is>(d => - d["affiliation"] == "owner" && d["sort"] == "full_name")); + d["affiliation"] == "owner" && d["sort"] == "full_name"), + Args.ApiOptions); } } public class TheGetAllForUserMethod { [Fact] - public void RequestsTheCorrectUrlAndReturnsRepositories() + public async Task RequestsTheCorrectUrlAndReturnsRepositories() { var connection = Substitute.For(); var client = new RepositoriesClient(connection); - client.GetAllForUser("username"); + await client.GetAllForUser("username"); connection.Received() - .GetAll(Arg.Is(u => u.ToString() == "users/username/repos")); + .GetAll(Arg.Is(u => u.ToString() == "users/username/repos"), Args.ApiOptions); } [Fact] @@ -437,13 +442,19 @@ namespace Octokit.Tests.Clients var reposEndpoint = new RepositoriesClient(Substitute.For()); await Assert.ThrowsAsync(() => reposEndpoint.GetAllForUser(null)); + await Assert.ThrowsAsync(() => reposEndpoint.GetAllForUser("")); + + await Assert.ThrowsAsync(() => reposEndpoint.GetAllForUser(null, ApiOptions.None)); + await Assert.ThrowsAsync(() => reposEndpoint.GetAllForUser("user", null)); + + await Assert.ThrowsAsync(() => reposEndpoint.GetAllForUser("", ApiOptions.None)); } } public class TheGetAllForOrgMethod { [Fact] - public void RequestsTheCorrectUrlAndReturnsRepositories() + public void RequestsTheCorrectUrl() { var connection = Substitute.For(); var client = new RepositoriesClient(connection); @@ -451,7 +462,7 @@ namespace Octokit.Tests.Clients client.GetAllForOrg("orgname"); connection.Received() - .GetAll(Arg.Is(u => u.ToString() == "orgs/orgname/repos")); + .GetAll(Arg.Is(u => u.ToString() == "orgs/orgname/repos"), Args.ApiOptions); } [Fact] @@ -460,13 +471,18 @@ namespace Octokit.Tests.Clients var reposEndpoint = new RepositoriesClient(Substitute.For()); await Assert.ThrowsAsync(() => reposEndpoint.GetAllForOrg(null)); + await Assert.ThrowsAsync(() => reposEndpoint.GetAllForOrg("")); + + await Assert.ThrowsAsync(() => reposEndpoint.GetAllForOrg(null, ApiOptions.None)); + await Assert.ThrowsAsync(() => reposEndpoint.GetAllForOrg("org", null)); + await Assert.ThrowsAsync(() => reposEndpoint.GetAllForOrg("", ApiOptions.None)); } } public class TheGetAllBranchesMethod { [Fact] - public void ReturnsBranches() + public void RequestsTheCorrectUrl() { var connection = Substitute.For(); var client = new RepositoriesClient(connection); @@ -474,7 +490,7 @@ namespace Octokit.Tests.Clients client.GetAllBranches("owner", "name"); connection.Received() - .GetAll(Arg.Is(u => u.ToString() == "repos/owner/name/branches"), null, "application/vnd.github.loki-preview+json"); + .GetAll(Arg.Is(u => u.ToString() == "repos/owner/name/branches"), null, "application/vnd.github.loki-preview+json", Args.ApiOptions); } [Fact] @@ -500,7 +516,7 @@ namespace Octokit.Tests.Clients client.GetAllContributors("owner", "name"); connection.Received() - .GetAll(Arg.Is(u => u.ToString() == "repos/owner/name/contributors"), Arg.Any>()); + .GetAll(Arg.Is(u => u.ToString() == "repos/owner/name/contributors"), Arg.Any>(), Args.ApiOptions); } [Fact] @@ -508,6 +524,20 @@ namespace Octokit.Tests.Clients { var client = new RepositoriesClient(Substitute.For()); + await Assert.ThrowsAsync(() => client.GetAllContributors(null, "repo", ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllContributors("owner", null, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllContributors("owner", "repo", null)); + + await Assert.ThrowsAsync(() => client.GetAllContributors("", "repo", ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllContributors("owner", "", ApiOptions.None)); + + await Assert.ThrowsAsync(() => client.GetAllContributors(null, "repo", false, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllContributors("owner", null, false, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllContributors("owner", "repo", false, null)); + + await Assert.ThrowsAsync(() => client.GetAllContributors("", "repo", false, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllContributors("owner", "", false, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllContributors(null, "repo")); await Assert.ThrowsAsync(() => client.GetAllContributors("owner", null)); await Assert.ThrowsAsync(() => client.GetAllContributors("", "repo")); @@ -552,7 +582,9 @@ namespace Octokit.Tests.Clients client.GetAllTeams("owner", "name"); connection.Received() - .GetAll(Arg.Is(u => u.ToString() == "repos/owner/name/teams")); + .GetAll( + Arg.Is(u => u.ToString() == "repos/owner/name/teams"), + Args.ApiOptions); } [Fact] @@ -562,8 +594,16 @@ namespace Octokit.Tests.Clients await Assert.ThrowsAsync(() => client.GetAllTeams(null, "repo")); await Assert.ThrowsAsync(() => client.GetAllTeams("owner", null)); + + await Assert.ThrowsAsync(() => client.GetAllTeams(null, "repo", ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllTeams("owner", null, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllTeams("owner", "repo", null)); + await Assert.ThrowsAsync(() => client.GetAllTeams("", "repo")); await Assert.ThrowsAsync(() => client.GetAllTeams("owner", "")); + + await Assert.ThrowsAsync(() => client.GetAllTeams("", "repo", ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllTeams("owner", "", ApiOptions.None)); } } @@ -578,7 +618,7 @@ namespace Octokit.Tests.Clients client.GetAllTags("owner", "name"); connection.Received() - .GetAll(Arg.Is(u => u.ToString() == "repos/owner/name/tags")); + .GetAll(Arg.Is(u => u.ToString() == "repos/owner/name/tags"), Args.ApiOptions); } [Fact] @@ -588,8 +628,16 @@ namespace Octokit.Tests.Clients await Assert.ThrowsAsync(() => client.GetAllTags(null, "repo")); await Assert.ThrowsAsync(() => client.GetAllTags("owner", null)); + + await Assert.ThrowsAsync(() => client.GetAllTags(null, "repo", ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllTags("owner", null, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllTags("owner", "repo", null)); + await Assert.ThrowsAsync(() => client.GetAllTags("", "repo")); await Assert.ThrowsAsync(() => client.GetAllTags("owner", "")); + + await Assert.ThrowsAsync(() => client.GetAllTags("", "repo", ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllTags("owner", "", ApiOptions.None)); } } diff --git a/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs b/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs index fa359b0d..52fc219c 100644 --- a/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs @@ -83,21 +83,22 @@ namespace Octokit.Tests.Reactive { new Repository(7) }); + var gitHubClient = Substitute.For(); - gitHubClient.Connection.GetResponse>(firstPageUrl) + gitHubClient.Connection.Get>(firstPageUrl, Arg.Any>(), null) .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); - gitHubClient.Connection.GetResponse>(secondPageUrl) + gitHubClient.Connection.Get>(secondPageUrl, Arg.Any>(), null) .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); - gitHubClient.Connection.GetResponse>(thirdPageUrl) + gitHubClient.Connection.Get>(thirdPageUrl, Arg.Any>(), null) .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); var repositoriesClient = new ObservableRepositoriesClient(gitHubClient); var results = await repositoriesClient.GetAllForCurrent().ToArray(); Assert.Equal(7, results.Length); - gitHubClient.Connection.Received(1).Get>(firstPageUrl, null, null); - gitHubClient.Connection.Received(1).Get>(secondPageUrl, null, null); - gitHubClient.Connection.Received(1).Get>(thirdPageUrl, null, null); + gitHubClient.Connection.Received(1).Get>(firstPageUrl, Arg.Any>(), null); + gitHubClient.Connection.Received(1).Get>(secondPageUrl, Arg.Any>(), null); + gitHubClient.Connection.Received(1).Get>(thirdPageUrl, Arg.Any>(), null); } [Fact(Skip = "See https://github.com/octokit/octokit.net/issues/1011 for issue to investigate this further")] @@ -245,7 +246,7 @@ namespace Octokit.Tests.Reactive client.GetAllBranches("owner", "repo"); - github.Connection.Received(1).GetResponse>(expected); + github.Connection.Received(1).Get>(expected, Args.EmptyDictionary, null); } } @@ -382,7 +383,9 @@ namespace Octokit.Tests.Reactive client.GetAllTeams("owner", "repo"); - github.Connection.Received(1).GetResponse>(expected); + github.Connection.Received(1).Get>(expected, + Arg.Any>(), + Arg.Any()); } } @@ -408,7 +411,7 @@ namespace Octokit.Tests.Reactive client.GetAllTags("owner", "repo"); - github.Connection.Received(1).GetResponse>(expected); + github.Connection.Received(1).Get>(expected, Arg.Any>(), null); } } diff --git a/Octokit/Clients/IRepositoriesClient.cs b/Octokit/Clients/IRepositoriesClient.cs index 0989d99f..f5436f37 100644 --- a/Octokit/Clients/IRepositoriesClient.cs +++ b/Octokit/Clients/IRepositoriesClient.cs @@ -146,6 +146,18 @@ namespace Octokit Justification = "Makes a network request")] Task> GetAllForCurrent(); + /// + /// Gets all repositories owned by the current user. + /// + /// + /// See the API documentation for more information. + /// + /// Options for changing the API response + /// Thrown if the client is not authenticated. + /// Thrown when a general API error occurs. + /// A of . + Task> GetAllForCurrent(ApiOptions options); + /// /// Gets all repositories owned by the current user. /// @@ -157,9 +169,20 @@ namespace Octokit /// Thrown if the client is not authenticated. /// Thrown when a general API error occurs. /// A of . - [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", - Justification = "Makes a network request")] Task> GetAllForCurrent(RepositoryRequest request); + + /// + /// Gets all repositories owned by the current user. + /// + /// + /// See the API documentation for more information. + /// + /// Search parameters to filter results on + /// Options for changing the API response + /// Thrown if the client is not authenticated. + /// Thrown when a general API error occurs. + /// A of . + Task> GetAllForCurrent(RepositoryRequest request, ApiOptions options); /// /// Gets all repositories owned by the specified user. @@ -168,12 +191,23 @@ namespace Octokit /// See the API documentation for more information. /// The default page size on GitHub.com is 30. /// + /// The account name to search for /// Thrown when a general API error occurs. /// A of . - [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", - Justification = "Makes a network request")] Task> GetAllForUser(string login); + /// + /// Gets all repositories owned by the specified user. + /// + /// + /// See the API documentation for more information. + /// + /// The account name to search for + /// Options for changing the API response + /// Thrown when a general API error occurs. + /// A of . + Task> GetAllForUser(string login, ApiOptions options); + /// /// Gets all repositories owned by the specified organization. /// @@ -181,12 +215,23 @@ namespace Octokit /// See the API documentation for more information. /// The default page size on GitHub.com is 30. /// + /// The organization name to search for /// Thrown when a general API error occurs. /// A of . - [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", - Justification = "Makes a network request")] Task> GetAllForOrg(string organization); + /// + /// Gets all repositories owned by the specified organization. + /// + /// + /// See the API documentation for more information. + /// + /// The organization name to search for + /// Options for changing the API response + /// Thrown when a general API error occurs. + /// A of . + Task> GetAllForOrg(string organization, ApiOptions options); + /// /// A client for GitHub's Commit Status API. /// @@ -298,6 +343,19 @@ namespace Octokit /// All es of the repository Task> GetAllBranches(string owner, string name); + /// + /// Gets all the branches for the specified repository. + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// Thrown when a general API error occurs. + /// All es of the repository + Task> GetAllBranches(string owner, string name, ApiOptions options); + /// /// Gets all contributors for the specified repository. Does not include anonymous contributors. /// @@ -309,6 +367,18 @@ namespace Octokit /// All contributors of the repository. Task> GetAllContributors(string owner, string name); + /// + /// Gets all contributors for the specified repository. Does not include anonymous contributors. + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// All contributors of the repository. + Task> GetAllContributors(string owner, string name, ApiOptions options); + /// /// Gets all contributors for the specified repository. With the option to include anonymous contributors. /// @@ -321,6 +391,19 @@ namespace Octokit /// All contributors of the repository. Task> GetAllContributors(string owner, string name, bool includeAnonymous); + /// + /// Gets all contributors for the specified repository. With the option to include anonymous contributors. + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// True if anonymous contributors should be included in result; Otherwise false + /// Options for changing the API response + /// All contributors of the repository. + Task> GetAllContributors(string owner, string name, bool includeAnonymous, ApiOptions options); + /// /// Gets all languages for the specified repository. /// @@ -343,6 +426,18 @@ namespace Octokit /// All s associated with the repository Task> GetAllTeams(string owner, string name); + /// + /// Gets all teams for the specified repository. + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// All s associated with the repository + Task> GetAllTeams(string owner, string name, ApiOptions options); + /// /// Gets all tags for the specified repository. /// @@ -354,6 +449,18 @@ namespace Octokit /// All of the repositories tags. Task> GetAllTags(string owner, string name); + /// + /// Gets all tags for the specified repository. + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// All of the repositories tags. + Task> GetAllTags(string owner, string name, ApiOptions options); + /// /// Gets the specified branch. /// diff --git a/Octokit/Clients/RepositoriesClient.cs b/Octokit/Clients/RepositoriesClient.cs index 2f901af2..3176638f 100644 --- a/Octokit/Clients/RepositoriesClient.cs +++ b/Octokit/Clients/RepositoriesClient.cs @@ -151,7 +151,7 @@ namespace Octokit { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - + return ApiConnection.Delete(ApiUrls.Repository(owner, name)); } @@ -254,7 +254,24 @@ namespace Octokit /// A of . public Task> GetAllForCurrent() { - return ApiConnection.GetAll(ApiUrls.Repositories()); + return GetAllForCurrent(ApiOptions.None); + } + + /// + /// Gets all repositories owned by the current user. + /// + /// + /// See the API documentation for more information. + /// + /// Options for changing the API response + /// Thrown if the client is not authenticated. + /// Thrown when a general API error occurs. + /// A of . + public Task> GetAllForCurrent(ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.Repositories(), options); } /// @@ -272,7 +289,15 @@ namespace Octokit { Ensure.ArgumentNotNull(request, "request"); - return ApiConnection.GetAll(ApiUrls.Repositories(), request.ToParametersDictionary()); + return GetAllForCurrent(request, ApiOptions.None); + } + + public Task> GetAllForCurrent(RepositoryRequest request, ApiOptions options) + { + Ensure.ArgumentNotNull(request, "request"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.Repositories(), request.ToParametersDictionary(), options); } /// @@ -282,13 +307,32 @@ namespace Octokit /// See the API documentation for more information. /// The default page size on GitHub.com is 30. /// + /// The account name to search for /// Thrown when a general API error occurs. /// A of . public Task> GetAllForUser(string login) { Ensure.ArgumentNotNullOrEmptyString(login, "login"); - return ApiConnection.GetAll(ApiUrls.Repositories(login)); + return GetAllForUser(login, ApiOptions.None); + } + + /// + /// Gets all repositories owned by the specified user. + /// + /// + /// See the API documentation for more information. + /// + /// The account name to search for + /// Options for changing the API response + /// Thrown when a general API error occurs. + /// A of . + public Task> GetAllForUser(string login, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(login, "login"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.Repositories(login), options); } /// @@ -304,7 +348,25 @@ namespace Octokit { Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); - return ApiConnection.GetAll(ApiUrls.OrganizationRepositories(organization)); + return GetAllForOrg(organization, ApiOptions.None); + } + + /// + /// Gets all repositories owned by the specified organization. + /// + /// + /// See the API documentation for more information. + /// + /// The organization name to search for + /// Options for changing the API response + /// Thrown when a general API error occurs. + /// A of . + public Task> GetAllForOrg(string organization, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.OrganizationRepositories(organization), options); } /// @@ -462,9 +524,28 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - return ApiConnection.GetAll(ApiUrls.RepoBranches(owner, name), null, AcceptHeaders.ProtectedBranchesApiPreview); + return GetAllBranches(owner, name, ApiOptions.None); } + /// + /// Gets all the branches for the specified repository. + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// Thrown when a general API error occurs. + /// All es of the repository + public Task> GetAllBranches(string owner, string name, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.RepoBranches(owner, name), null, AcceptHeaders.ProtectedBranchesApiPreview, options); + } /// /// Gets all contributors for the specified repository. Does not include anonymous contributors. @@ -477,9 +558,31 @@ namespace Octokit /// All contributors of the repository. public Task> GetAllContributors(string owner, string name) { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + return GetAllContributors(owner, name, false); } + /// + /// Gets all contributors for the specified repository. Does not include anonymous contributors. + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// All contributors of the repository. + public Task> GetAllContributors(string owner, string name, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(options, "options"); + + return GetAllContributors(owner, name, false, options); + } + /// /// Gets all contributors for the specified repository. With the option to include anonymous contributors. /// @@ -495,11 +598,31 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); + return GetAllContributors(owner, name, false, ApiOptions.None); + } + + /// + /// Gets all contributors for the specified repository. With the option to include anonymous contributors. + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// True if anonymous contributors should be included in result; Otherwise false + /// Options for changing the API response + /// All contributors of the repository. + public Task> GetAllContributors(string owner, string name, bool includeAnonymous, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(options, "options"); + var parameters = new Dictionary(); if (includeAnonymous) parameters.Add("anon", "1"); - return ApiConnection.GetAll(ApiUrls.RepositoryContributors(owner, name), parameters); + return ApiConnection.GetAll(ApiUrls.RepositoryContributors(owner, name), parameters, options); } /// @@ -537,7 +660,26 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - return ApiConnection.GetAll(ApiUrls.RepositoryTeams(owner, name)); + return GetAllTeams(owner, name, ApiOptions.None); + } + + /// + /// Gets all teams for the specified repository. + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// All s associated with the repository + public Task> GetAllTeams(string owner, string name, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.RepositoryTeams(owner, name), options); } /// @@ -554,7 +696,27 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - return ApiConnection.GetAll(ApiUrls.RepositoryTags(owner, name)); + return GetAllTags(owner, name, ApiOptions.None); + } + + + /// + /// Gets all tags for the specified repository. + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// All of the repositories tags. + public Task> GetAllTags(string owner, string name, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.RepositoryTags(owner, name), options); } ///