diff --git a/Octokit.AsyncPaginationExtension/Extensions.cs b/Octokit.AsyncPaginationExtension/Extensions.cs index f41c07fb..7e2f6221 100644 --- a/Octokit.AsyncPaginationExtension/Extensions.cs +++ b/Octokit.AsyncPaginationExtension/Extensions.cs @@ -235,14 +235,6 @@ namespace Octokit.AsyncPaginationExtension public static IPaginatedList GetAllAsync(this IRepoCollaboratorsClient t, long repositoryId, RepositoryCollaboratorListRequest request, int pageSize = DEFAULT_PAGE_SIZE) => pageSize > 0 ? new PaginatedList(options => t.GetAll(repositoryId, request, options), pageSize) : throw new ArgumentOutOfRangeException(nameof(pageSize), pageSize, "The page size must be positive."); - /// - public static IPaginatedList ListAllRunnerGroupOrganizationsForEnterpriseAsync(this IActionsSelfHostedRunnerGroupsClient t, string enterprise, long runnerGroupId, int pageSize = DEFAULT_PAGE_SIZE) - => pageSize > 0 ? new PaginatedList(options => t.ListAllRunnerGroupOrganizationsForEnterprise(enterprise, runnerGroupId, options), pageSize) : throw new ArgumentOutOfRangeException(nameof(pageSize), pageSize, "The page size must be positive."); - - /// - public static IPaginatedList ListAllRunnerGroupRepositoriesForOrganizationAsync(this IActionsSelfHostedRunnerGroupsClient t, string org, long runnerGroupId, int pageSize = DEFAULT_PAGE_SIZE) - => pageSize > 0 ? new PaginatedList(options => t.ListAllRunnerGroupRepositoriesForOrganization(org, runnerGroupId, options), pageSize) : throw new ArgumentOutOfRangeException(nameof(pageSize), pageSize, "The page size must be positive."); - /// public static IPaginatedList GetAllAsync(this IProjectColumnsClient t, int projectId, int pageSize = DEFAULT_PAGE_SIZE) => pageSize > 0 ? new PaginatedList(options => t.GetAll(projectId, options), pageSize) : throw new ArgumentOutOfRangeException(nameof(pageSize), pageSize, "The page size must be positive."); diff --git a/Octokit.Reactive/Clients/IObservableActionsSelfHostedRunnerGroupsClient.cs b/Octokit.Reactive/Clients/IObservableActionsSelfHostedRunnerGroupsClient.cs index 4e6aaa29..04c6e90d 100644 --- a/Octokit.Reactive/Clients/IObservableActionsSelfHostedRunnerGroupsClient.cs +++ b/Octokit.Reactive/Clients/IObservableActionsSelfHostedRunnerGroupsClient.cs @@ -117,7 +117,7 @@ namespace Octokit.Reactive /// /// The enterprise name /// The runner group id - IObservable ListAllRunnerGroupOrganizationsForEnterprise(string enterprise, long runnerGroupId); + IObservable ListAllRunnerGroupOrganizationsForEnterprise(string enterprise, long runnerGroupId); /// /// List organization access to a self-hosted runner group in an enterprise @@ -128,7 +128,7 @@ namespace Octokit.Reactive /// The enterprise name /// The runner group id /// Options for changing the API response - IObservable ListAllRunnerGroupOrganizationsForEnterprise(string enterprise, long runnerGroupId, ApiOptions options); + IObservable ListAllRunnerGroupOrganizationsForEnterprise(string enterprise, long runnerGroupId, ApiOptions options); /// /// List repository access to a self-hosted runner group in an organization @@ -138,7 +138,7 @@ namespace Octokit.Reactive /// /// The organization name /// The runner group id - IObservable ListAllRunnerGroupRepositoriesForOrganization(string org, long runnerGroupId); + IObservable ListAllRunnerGroupRepositoriesForOrganization(string org, long runnerGroupId); /// /// List repository access to a self-hosted runner group in an organization @@ -149,7 +149,7 @@ namespace Octokit.Reactive /// The organization name /// The runner group id /// Options for changing the API response - IObservable ListAllRunnerGroupRepositoriesForOrganization(string org, long runnerGroupId, ApiOptions options); + IObservable ListAllRunnerGroupRepositoriesForOrganization(string org, long runnerGroupId, ApiOptions options); } } diff --git a/Octokit.Reactive/Clients/ObservableActionsSelfHostedRunnerGroupsClient.cs b/Octokit.Reactive/Clients/ObservableActionsSelfHostedRunnerGroupsClient.cs index 7f7c0ec5..bb436912 100644 --- a/Octokit.Reactive/Clients/ObservableActionsSelfHostedRunnerGroupsClient.cs +++ b/Octokit.Reactive/Clients/ObservableActionsSelfHostedRunnerGroupsClient.cs @@ -175,7 +175,7 @@ namespace Octokit.Reactive /// /// The enterprise name /// The runner group ID - public IObservable ListAllRunnerGroupOrganizationsForEnterprise(string enterprise, long runnerGroupId) + public IObservable ListAllRunnerGroupOrganizationsForEnterprise(string enterprise, long runnerGroupId) { return ListAllRunnerGroupOrganizationsForEnterprise(enterprise, runnerGroupId, ApiOptions.None); } @@ -189,12 +189,12 @@ namespace Octokit.Reactive /// The enterprise name /// The runner group ID /// Options for changing the API response - public IObservable ListAllRunnerGroupOrganizationsForEnterprise(string enterprise, long runnerGroupId, ApiOptions options) + public IObservable ListAllRunnerGroupOrganizationsForEnterprise(string enterprise, long runnerGroupId, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(enterprise, nameof(enterprise)); Ensure.ArgumentNotNull(options, nameof(options)); - return _connection.GetAndFlattenAllPages(ApiUrls.ActionsListEnterpriseRunnerGroupOrganizations(enterprise, runnerGroupId), options); + return _client.ListAllRunnerGroupOrganizationsForEnterprise(enterprise, runnerGroupId, options).ToObservable(); } /// @@ -205,7 +205,7 @@ namespace Octokit.Reactive /// /// The organization name /// The runner group ID - public IObservable ListAllRunnerGroupRepositoriesForOrganization(string org, long runnerGroupId) + public IObservable ListAllRunnerGroupRepositoriesForOrganization(string org, long runnerGroupId) { return ListAllRunnerGroupRepositoriesForOrganization(org, runnerGroupId, ApiOptions.None); } @@ -219,12 +219,12 @@ namespace Octokit.Reactive /// The organization name /// The runner group ID /// Options for changing the API response - public IObservable ListAllRunnerGroupRepositoriesForOrganization(string org, long runnerGroupId, ApiOptions options) + public IObservable ListAllRunnerGroupRepositoriesForOrganization(string org, long runnerGroupId, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); Ensure.ArgumentNotNull(options, nameof(options)); - return _connection.GetAndFlattenAllPages(ApiUrls.ActionsListOrganizationRunnerGroupRepositories(org, runnerGroupId), options); + return _client.ListAllRunnerGroupRepositoriesForOrganization(org, runnerGroupId, options).ToObservable(); } } diff --git a/Octokit.Tests/Clients/ActionsSelfHostedRunnerGroupsClientTests.cs b/Octokit.Tests/Clients/ActionsSelfHostedRunnerGroupsClientTests.cs index a1886ad8..f9af6067 100644 --- a/Octokit.Tests/Clients/ActionsSelfHostedRunnerGroupsClientTests.cs +++ b/Octokit.Tests/Clients/ActionsSelfHostedRunnerGroupsClientTests.cs @@ -217,7 +217,7 @@ namespace Octokit.Tests.Clients await client.ListAllRunnerGroupOrganizationsForEnterprise("fake", 1); - connection.Received().GetAll( + connection.Received().GetAll( Arg.Is(u => u.ToString() == "enterprises/fake/actions/runner-groups/1/organizations"), Args.ApiOptions); } @@ -248,7 +248,7 @@ namespace Octokit.Tests.Clients await client.ListAllRunnerGroupRepositoriesForOrganization("fake", 1, ApiOptions.None); - connection.Received().GetAll( + connection.Received().GetAll( Arg.Is(u => u.ToString() == "orgs/fake/actions/runner-groups/1/repositories"), Args.ApiOptions); } diff --git a/Octokit/Clients/ActionsSelfHostedRunnerGroupsClient.cs b/Octokit/Clients/ActionsSelfHostedRunnerGroupsClient.cs index 5520af6e..a5bf26fe 100644 --- a/Octokit/Clients/ActionsSelfHostedRunnerGroupsClient.cs +++ b/Octokit/Clients/ActionsSelfHostedRunnerGroupsClient.cs @@ -203,7 +203,7 @@ namespace Octokit /// The enterprise name /// The runner group id [ManualRoute("GET", "/enterprises/{enterprise}/actions/runner-groups/{runner_group_id}/organizations")] - public Task> ListAllRunnerGroupOrganizationsForEnterprise(string enterprise, long runnerGroupId) + public Task ListAllRunnerGroupOrganizationsForEnterprise(string enterprise, long runnerGroupId) { return ListAllRunnerGroupOrganizationsForEnterprise(enterprise, runnerGroupId, ApiOptions.None); } @@ -218,11 +218,16 @@ namespace Octokit /// The runner group id /// Options for changing the API response [ManualRoute("GET", "/enterprises/{enterprise}/actions/runner-groups/{runner_group_id}/organizations")] - public Task> ListAllRunnerGroupOrganizationsForEnterprise(string enterprise, long runnerGroupId, ApiOptions options) + public async Task ListAllRunnerGroupOrganizationsForEnterprise(string enterprise, long runnerGroupId, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(enterprise, nameof(enterprise)); - return ApiConnection.GetAll(ApiUrls.ActionsListEnterpriseRunnerGroupOrganizations(enterprise, runnerGroupId), options); + var results = await ApiConnection.GetAll(ApiUrls.ActionsListEnterpriseRunnerGroupOrganizations(enterprise, runnerGroupId), options).ConfigureAwait(false); + + return new OrganizationsResponse( + results.Count > 0 ? results.Max(x => x.TotalCount) : 0, + results.SelectMany(x => x.Organizations).ToList() + ); } /// @@ -234,7 +239,7 @@ namespace Octokit /// The organization name /// The runner group id [ManualRoute("GET", "/orgs/{org}/actions/runner-groups/{runner_group_id}/repositories")] - public Task> ListAllRunnerGroupRepositoriesForOrganization(string org, long runnerGroupId) + public Task ListAllRunnerGroupRepositoriesForOrganization(string org, long runnerGroupId) { return ListAllRunnerGroupRepositoriesForOrganization(org, runnerGroupId, ApiOptions.None); } @@ -249,11 +254,16 @@ namespace Octokit /// The runner group id /// Options for changing the API response [ManualRoute("GET", "/orgs/{org}/actions/runner-groups/{runner_group_id}/repositories")] - public Task> ListAllRunnerGroupRepositoriesForOrganization(string org, long runnerGroupId, ApiOptions options) + public async Task ListAllRunnerGroupRepositoriesForOrganization(string org, long runnerGroupId, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); - return ApiConnection.GetAll(ApiUrls.ActionsListOrganizationRunnerGroupRepositories(org, runnerGroupId), options); + var results = await ApiConnection.GetAll(ApiUrls.ActionsListOrganizationRunnerGroupRepositories(org, runnerGroupId), options).ConfigureAwait(false); + + return new RepositoriesResponse( + results.Count > 0 ? results.Max(x => x.TotalCount) : 0, + results.SelectMany(x => x.Repositories).ToList() + ); } } } diff --git a/Octokit/Clients/IActionsSelfHostedRunnerGroupsClient.cs b/Octokit/Clients/IActionsSelfHostedRunnerGroupsClient.cs index 6e419407..50074677 100644 --- a/Octokit/Clients/IActionsSelfHostedRunnerGroupsClient.cs +++ b/Octokit/Clients/IActionsSelfHostedRunnerGroupsClient.cs @@ -119,7 +119,7 @@ namespace Octokit /// /// The enterprise name /// The runner group id - Task> ListAllRunnerGroupOrganizationsForEnterprise(string enterprise, long runnerGroupId); + Task ListAllRunnerGroupOrganizationsForEnterprise(string enterprise, long runnerGroupId); /// /// List organization access to a self-hosted runner group in an enterprise @@ -130,7 +130,7 @@ namespace Octokit /// The enterprise name /// The runner group id /// Options for changing the API response - Task> ListAllRunnerGroupOrganizationsForEnterprise(string enterprise, long runnerGroupId, ApiOptions options); + Task ListAllRunnerGroupOrganizationsForEnterprise(string enterprise, long runnerGroupId, ApiOptions options); /// /// List repository access to a self-hosted runner group in an organization @@ -140,7 +140,7 @@ namespace Octokit /// /// The organization name /// The runner group id - Task> ListAllRunnerGroupRepositoriesForOrganization(string org, long runnerGroupId); + Task ListAllRunnerGroupRepositoriesForOrganization(string org, long runnerGroupId); /// /// List repository access to a self-hosted runner group in an organization @@ -151,6 +151,6 @@ namespace Octokit /// The organization name /// The runner group id /// Options for changing the API response - Task> ListAllRunnerGroupRepositoriesForOrganization(string org, long runnerGroupId, ApiOptions options); + Task ListAllRunnerGroupRepositoriesForOrganization(string org, long runnerGroupId, ApiOptions options); } } diff --git a/Octokit/Models/Response/OrganizationsResponse.cs b/Octokit/Models/Response/OrganizationsResponse.cs new file mode 100644 index 00000000..3f4bbbf1 --- /dev/null +++ b/Octokit/Models/Response/OrganizationsResponse.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class OrganizationsResponse + { + public OrganizationsResponse() + { + } + + public OrganizationsResponse(int totalCount, IReadOnlyList organizations) + { + TotalCount = totalCount; + Organizations = organizations; + } + + /// + /// The total number of organizations + /// + public int TotalCount { get; private set; } + + /// + /// The retrieved organizations + /// + public IReadOnlyList Organizations { get; private set; } + + internal string DebuggerDisplay => string.Format(CultureInfo.CurrentCulture, "TotalCount: {0}, Organizations: {1}", TotalCount, Organizations.Count); + } +} diff --git a/Octokit/Models/Response/RepositoriesResponse.cs b/Octokit/Models/Response/RepositoriesResponse.cs index cf17e710..69ef9e3b 100644 --- a/Octokit/Models/Response/RepositoriesResponse.cs +++ b/Octokit/Models/Response/RepositoriesResponse.cs @@ -18,12 +18,12 @@ namespace Octokit } /// - /// The total number of check suites that match the request filter + /// The total number of repositories /// public int TotalCount { get; private set; } /// - /// The retrieved check suites + /// The retrieved repositories /// public IReadOnlyList Repositories { get; private set; }