Skip to content

Commit

Permalink
Fix runner group access return type (#2965)
Browse files Browse the repository at this point in the history
* Fix runner group access return type

* Fix tests

* Fix observables
  • Loading branch information
MatisseHack authored Aug 30, 2024
1 parent 21559ef commit 160a723
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 32 deletions.
8 changes: 0 additions & 8 deletions Octokit.AsyncPaginationExtension/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,6 @@ public static IPaginatedList<Collaborator> GetAllAsync(this IRepoCollaboratorsCl
public static IPaginatedList<Collaborator> GetAllAsync(this IRepoCollaboratorsClient t, long repositoryId, RepositoryCollaboratorListRequest request, int pageSize = DEFAULT_PAGE_SIZE)
=> pageSize > 0 ? new PaginatedList<Collaborator>(options => t.GetAll(repositoryId, request, options), pageSize) : throw new ArgumentOutOfRangeException(nameof(pageSize), pageSize, "The page size must be positive.");

/// <inheritdoc cref="IActionsSelfHostedRunnerGroupsClient.ListAllRunnerGroupOrganizationsForEnterprise(string, long, ApiOptions)"/>
public static IPaginatedList<Organization> ListAllRunnerGroupOrganizationsForEnterpriseAsync(this IActionsSelfHostedRunnerGroupsClient t, string enterprise, long runnerGroupId, int pageSize = DEFAULT_PAGE_SIZE)
=> pageSize > 0 ? new PaginatedList<Organization>(options => t.ListAllRunnerGroupOrganizationsForEnterprise(enterprise, runnerGroupId, options), pageSize) : throw new ArgumentOutOfRangeException(nameof(pageSize), pageSize, "The page size must be positive.");

/// <inheritdoc cref="IActionsSelfHostedRunnerGroupsClient.ListAllRunnerGroupRepositoriesForOrganization(string, long, ApiOptions)"/>
public static IPaginatedList<Repository> ListAllRunnerGroupRepositoriesForOrganizationAsync(this IActionsSelfHostedRunnerGroupsClient t, string org, long runnerGroupId, int pageSize = DEFAULT_PAGE_SIZE)
=> pageSize > 0 ? new PaginatedList<Repository>(options => t.ListAllRunnerGroupRepositoriesForOrganization(org, runnerGroupId, options), pageSize) : throw new ArgumentOutOfRangeException(nameof(pageSize), pageSize, "The page size must be positive.");

/// <inheritdoc cref="IProjectColumnsClient.GetAll(int, ApiOptions)"/>
public static IPaginatedList<ProjectColumn> GetAllAsync(this IProjectColumnsClient t, int projectId, int pageSize = DEFAULT_PAGE_SIZE)
=> pageSize > 0 ? new PaginatedList<ProjectColumn>(options => t.GetAll(projectId, options), pageSize) : throw new ArgumentOutOfRangeException(nameof(pageSize), pageSize, "The page size must be positive.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public interface IObservableActionsSelfHostedRunnerGroupsClient
/// </remarks>
/// <param name="enterprise">The enterprise name</param>
/// <param name="runnerGroupId">The runner group id</param>
IObservable<Organization> ListAllRunnerGroupOrganizationsForEnterprise(string enterprise, long runnerGroupId);
IObservable<OrganizationsResponse> ListAllRunnerGroupOrganizationsForEnterprise(string enterprise, long runnerGroupId);

/// <summary>
/// List organization access to a self-hosted runner group in an enterprise
Expand All @@ -128,7 +128,7 @@ public interface IObservableActionsSelfHostedRunnerGroupsClient
/// <param name="enterprise">The enterprise name</param>
/// <param name="runnerGroupId">The runner group id</param>
/// <param name="options">Options for changing the API response</param>
IObservable<Organization> ListAllRunnerGroupOrganizationsForEnterprise(string enterprise, long runnerGroupId, ApiOptions options);
IObservable<OrganizationsResponse> ListAllRunnerGroupOrganizationsForEnterprise(string enterprise, long runnerGroupId, ApiOptions options);

/// <summary>
/// List repository access to a self-hosted runner group in an organization
Expand All @@ -138,7 +138,7 @@ public interface IObservableActionsSelfHostedRunnerGroupsClient
/// </remarks>
/// <param name="org">The organization name</param>
/// <param name="runnerGroupId">The runner group id</param>
IObservable<Repository> ListAllRunnerGroupRepositoriesForOrganization(string org, long runnerGroupId);
IObservable<RepositoriesResponse> ListAllRunnerGroupRepositoriesForOrganization(string org, long runnerGroupId);

/// <summary>
/// List repository access to a self-hosted runner group in an organization
Expand All @@ -149,7 +149,7 @@ public interface IObservableActionsSelfHostedRunnerGroupsClient
/// <param name="org">The organization name</param>
/// <param name="runnerGroupId">The runner group id</param>
/// <param name="options">Options for changing the API response</param>
IObservable<Repository> ListAllRunnerGroupRepositoriesForOrganization(string org, long runnerGroupId, ApiOptions options);
IObservable<RepositoriesResponse> ListAllRunnerGroupRepositoriesForOrganization(string org, long runnerGroupId, ApiOptions options);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public IObservable<RunnerResponse> ListAllRunnersForOrganizationRunnerGroup(stri
/// </remarks>
/// <param name="enterprise">The enterprise name</param>
/// <param name="runnerGroupId">The runner group ID</param>
public IObservable<Organization> ListAllRunnerGroupOrganizationsForEnterprise(string enterprise, long runnerGroupId)
public IObservable<OrganizationsResponse> ListAllRunnerGroupOrganizationsForEnterprise(string enterprise, long runnerGroupId)
{
return ListAllRunnerGroupOrganizationsForEnterprise(enterprise, runnerGroupId, ApiOptions.None);
}
Expand All @@ -189,12 +189,12 @@ public IObservable<Organization> ListAllRunnerGroupOrganizationsForEnterprise(st
/// <param name="enterprise">The enterprise name</param>
/// <param name="runnerGroupId">The runner group ID</param>
/// <param name="options">Options for changing the API response</param>
public IObservable<Organization> ListAllRunnerGroupOrganizationsForEnterprise(string enterprise, long runnerGroupId, ApiOptions options)
public IObservable<OrganizationsResponse> ListAllRunnerGroupOrganizationsForEnterprise(string enterprise, long runnerGroupId, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(enterprise, nameof(enterprise));
Ensure.ArgumentNotNull(options, nameof(options));

return _connection.GetAndFlattenAllPages<Organization>(ApiUrls.ActionsListEnterpriseRunnerGroupOrganizations(enterprise, runnerGroupId), options);
return _client.ListAllRunnerGroupOrganizationsForEnterprise(enterprise, runnerGroupId, options).ToObservable();
}

/// <summary>
Expand All @@ -205,7 +205,7 @@ public IObservable<Organization> ListAllRunnerGroupOrganizationsForEnterprise(st
/// </remarks>
/// <param name="org">The organization name</param>
/// <param name="runnerGroupId">The runner group ID</param>
public IObservable<Repository> ListAllRunnerGroupRepositoriesForOrganization(string org, long runnerGroupId)
public IObservable<RepositoriesResponse> ListAllRunnerGroupRepositoriesForOrganization(string org, long runnerGroupId)
{
return ListAllRunnerGroupRepositoriesForOrganization(org, runnerGroupId, ApiOptions.None);
}
Expand All @@ -219,12 +219,12 @@ public IObservable<Repository> ListAllRunnerGroupRepositoriesForOrganization(str
/// <param name="org">The organization name</param>
/// <param name="runnerGroupId">The runner group ID</param>
/// <param name="options">Options for changing the API response</param>
public IObservable<Repository> ListAllRunnerGroupRepositoriesForOrganization(string org, long runnerGroupId, ApiOptions options)
public IObservable<RepositoriesResponse> ListAllRunnerGroupRepositoriesForOrganization(string org, long runnerGroupId, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNull(options, nameof(options));

return _connection.GetAndFlattenAllPages<Repository>(ApiUrls.ActionsListOrganizationRunnerGroupRepositories(org, runnerGroupId), options);
return _client.ListAllRunnerGroupRepositoriesForOrganization(org, runnerGroupId, options).ToObservable();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public async Task RequestsCorrectUrl()

await client.ListAllRunnerGroupOrganizationsForEnterprise("fake", 1);

connection.Received().GetAll<Organization>(
connection.Received().GetAll<OrganizationsResponse>(
Arg.Is<Uri>(u => u.ToString() == "enterprises/fake/actions/runner-groups/1/organizations"), Args.ApiOptions);
}

Expand Down Expand Up @@ -248,7 +248,7 @@ public async Task RequestsCorrectUrl()

await client.ListAllRunnerGroupRepositoriesForOrganization("fake", 1, ApiOptions.None);

connection.Received().GetAll<Repository>(
connection.Received().GetAll<RepositoriesResponse>(
Arg.Is<Uri>(u => u.ToString() == "orgs/fake/actions/runner-groups/1/repositories"), Args.ApiOptions);
}

Expand Down
22 changes: 16 additions & 6 deletions Octokit/Clients/ActionsSelfHostedRunnerGroupsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public async Task<RunnerResponse> ListAllRunnersForOrganizationRunnerGroup(strin
/// <param name="enterprise">The enterprise name</param>
/// <param name="runnerGroupId">The runner group id</param>
[ManualRoute("GET", "/enterprises/{enterprise}/actions/runner-groups/{runner_group_id}/organizations")]
public Task<IReadOnlyList<Organization>> ListAllRunnerGroupOrganizationsForEnterprise(string enterprise, long runnerGroupId)
public Task<OrganizationsResponse> ListAllRunnerGroupOrganizationsForEnterprise(string enterprise, long runnerGroupId)
{
return ListAllRunnerGroupOrganizationsForEnterprise(enterprise, runnerGroupId, ApiOptions.None);
}
Expand All @@ -218,11 +218,16 @@ public Task<IReadOnlyList<Organization>> ListAllRunnerGroupOrganizationsForEnter
/// <param name="runnerGroupId">The runner group id</param>
/// <param name="options">Options for changing the API response</param>
[ManualRoute("GET", "/enterprises/{enterprise}/actions/runner-groups/{runner_group_id}/organizations")]
public Task<IReadOnlyList<Organization>> ListAllRunnerGroupOrganizationsForEnterprise(string enterprise, long runnerGroupId, ApiOptions options)
public async Task<OrganizationsResponse> ListAllRunnerGroupOrganizationsForEnterprise(string enterprise, long runnerGroupId, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(enterprise, nameof(enterprise));

return ApiConnection.GetAll<Organization>(ApiUrls.ActionsListEnterpriseRunnerGroupOrganizations(enterprise, runnerGroupId), options);
var results = await ApiConnection.GetAll<OrganizationsResponse>(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()
);
}

/// <summary>
Expand All @@ -234,7 +239,7 @@ public Task<IReadOnlyList<Organization>> ListAllRunnerGroupOrganizationsForEnter
/// <param name="org">The organization name</param>
/// <param name="runnerGroupId">The runner group id</param>
[ManualRoute("GET", "/orgs/{org}/actions/runner-groups/{runner_group_id}/repositories")]
public Task<IReadOnlyList<Repository>> ListAllRunnerGroupRepositoriesForOrganization(string org, long runnerGroupId)
public Task<RepositoriesResponse> ListAllRunnerGroupRepositoriesForOrganization(string org, long runnerGroupId)
{
return ListAllRunnerGroupRepositoriesForOrganization(org, runnerGroupId, ApiOptions.None);
}
Expand All @@ -249,11 +254,16 @@ public Task<IReadOnlyList<Repository>> ListAllRunnerGroupRepositoriesForOrganiza
/// <param name="runnerGroupId">The runner group id</param>
/// <param name="options">Options for changing the API response</param>
[ManualRoute("GET", "/orgs/{org}/actions/runner-groups/{runner_group_id}/repositories")]
public Task<IReadOnlyList<Repository>> ListAllRunnerGroupRepositoriesForOrganization(string org, long runnerGroupId, ApiOptions options)
public async Task<RepositoriesResponse> ListAllRunnerGroupRepositoriesForOrganization(string org, long runnerGroupId, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));

return ApiConnection.GetAll<Repository>(ApiUrls.ActionsListOrganizationRunnerGroupRepositories(org, runnerGroupId), options);
var results = await ApiConnection.GetAll<RepositoriesResponse>(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()
);
}
}
}
8 changes: 4 additions & 4 deletions Octokit/Clients/IActionsSelfHostedRunnerGroupsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public interface IActionsSelfHostedRunnerGroupsClient
/// </remarks>
/// <param name="enterprise">The enterprise name</param>
/// <param name="runnerGroupId">The runner group id</param>
Task<IReadOnlyList<Organization>> ListAllRunnerGroupOrganizationsForEnterprise(string enterprise, long runnerGroupId);
Task<OrganizationsResponse> ListAllRunnerGroupOrganizationsForEnterprise(string enterprise, long runnerGroupId);

/// <summary>
/// List organization access to a self-hosted runner group in an enterprise
Expand All @@ -130,7 +130,7 @@ public interface IActionsSelfHostedRunnerGroupsClient
/// <param name="enterprise">The enterprise name</param>
/// <param name="runnerGroupId">The runner group id</param>
/// <param name="options">Options for changing the API response</param>
Task<IReadOnlyList<Organization>> ListAllRunnerGroupOrganizationsForEnterprise(string enterprise, long runnerGroupId, ApiOptions options);
Task<OrganizationsResponse> ListAllRunnerGroupOrganizationsForEnterprise(string enterprise, long runnerGroupId, ApiOptions options);

/// <summary>
/// List repository access to a self-hosted runner group in an organization
Expand All @@ -140,7 +140,7 @@ public interface IActionsSelfHostedRunnerGroupsClient
/// </remarks>
/// <param name="org">The organization name</param>
/// <param name="runnerGroupId">The runner group id</param>
Task<IReadOnlyList<Repository>> ListAllRunnerGroupRepositoriesForOrganization(string org, long runnerGroupId);
Task<RepositoriesResponse> ListAllRunnerGroupRepositoriesForOrganization(string org, long runnerGroupId);

/// <summary>
/// List repository access to a self-hosted runner group in an organization
Expand All @@ -151,6 +151,6 @@ public interface IActionsSelfHostedRunnerGroupsClient
/// <param name="org">The organization name</param>
/// <param name="runnerGroupId">The runner group id</param>
/// <param name="options">Options for changing the API response</param>
Task<IReadOnlyList<Repository>> ListAllRunnerGroupRepositoriesForOrganization(string org, long runnerGroupId, ApiOptions options);
Task<RepositoriesResponse> ListAllRunnerGroupRepositoriesForOrganization(string org, long runnerGroupId, ApiOptions options);
}
}
32 changes: 32 additions & 0 deletions Octokit/Models/Response/OrganizationsResponse.cs
Original file line number Diff line number Diff line change
@@ -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<Repository> organizations)
{
TotalCount = totalCount;
Organizations = organizations;
}

/// <summary>
/// The total number of organizations
/// </summary>
public int TotalCount { get; private set; }

/// <summary>
/// The retrieved organizations
/// </summary>
public IReadOnlyList<Repository> Organizations { get; private set; }

internal string DebuggerDisplay => string.Format(CultureInfo.CurrentCulture, "TotalCount: {0}, Organizations: {1}", TotalCount, Organizations.Count);
}
}
4 changes: 2 additions & 2 deletions Octokit/Models/Response/RepositoriesResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public RepositoriesResponse(int totalCount, IReadOnlyList<Repository> repositori
}

/// <summary>
/// The total number of check suites that match the request filter
/// The total number of repositories
/// </summary>
public int TotalCount { get; private set; }

/// <summary>
/// The retrieved check suites
/// The retrieved repositories
/// </summary>
public IReadOnlyList<Repository> Repositories { get; private set; }

Expand Down

0 comments on commit 160a723

Please sign in to comment.