using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace Octokit { /// /// A client for GitHub's Actions Self-hosted runner groups API. /// /// /// See the Actions Self-hosted runner groups API documentation for more information. /// public class ActionsSelfHostedRunnerGroupsClient : ApiClient, IActionsSelfHostedRunnerGroupsClient { /// /// Initializes a new GitHub Actions Self-hosted runner groups API client /// /// An API connection public ActionsSelfHostedRunnerGroupsClient(IApiConnection apiConnection) : base(apiConnection) { } /// /// Get a self-hosted runner group for an enterprise /// /// /// https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runner-groups?apiVersion=2022-11-28#get-a-self-hosted-runner-group-for-an-enterprise /// /// The enterprise name. /// Unique identifier of the self-hosted runner group. [ManualRoute("GET", "/enterprises/{enterprise}/actions/runner-groups/{runner_group_id}")] public async Task GetRunnerGroupForEnterprise(string enterprise, long runnerGroupId) { Ensure.ArgumentNotNullOrEmptyString(enterprise, nameof(enterprise)); return await ApiConnection.Get(ApiUrls.ActionsGetEnterpriseRunnerGroup(enterprise, runnerGroupId)).ConfigureAwait(false); } /// /// Get a self-hosted runner group for an organization /// /// /// https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runner-groups?apiVersion=2022-11-28#get-a-self-hosted-runner-group-for-an-organization /// /// The organization name. /// Unique identifier of the self-hosted runner group. [ManualRoute("GET", "/orgs/{org}/actions/runner-groups/{runner_group_id}")] public async Task GetRunnerGroupForOrganization(string org, long runnerGroupId) { Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); return await ApiConnection.Get(ApiUrls.ActionsGetOrganizationRunnerGroup(org, runnerGroupId)).ConfigureAwait(false); } /// /// List self-hosted runner groups for an enterprise /// /// /// https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runner-groups?apiVersion=2022-11-28#list-self-hosted-runner-groups-for-an-enterprise /// /// The enterprise name [ManualRoute("GET", "/enterprises/{enterprise}/actions/runner-groups")] public Task ListAllRunnerGroupsForEnterprise(string enterprise) { return ListAllRunnerGroupsForEnterprise(enterprise, ApiOptions.None); } /// /// List self-hosted runner groups for an enterprise /// /// /// https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runner-groups?apiVersion=2022-11-28#list-self-hosted-runner-groups-for-an-enterprise /// /// The enterprise name /// Options for changing the API response [ManualRoute("GET", "/enterprises/{enterprise}/actions/runner-groups")] public async Task ListAllRunnerGroupsForEnterprise(string enterprise, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(enterprise, nameof(enterprise)); var results = await ApiConnection.GetAll(ApiUrls.ActionsListEnterpriseRunnerGroups(enterprise), options).ConfigureAwait(false); return new RunnerGroupResponse( results.Count > 0 ? results[0].TotalCount : 0, results.SelectMany(x => x.RunnerGroups).ToList() ); } /// /// List self-hosted runners groups for an organization /// /// /// https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runner-groups?apiVersion=2022-11-28#list-self-hosted-runner-groups-for-an-organization /// /// The organization name [ManualRoute("GET", "/orgs/{org}/actions/runner-groups")] public Task ListAllRunnerGroupsForOrganization(string org) { return ListAllRunnerGroupsForOrganization(org, ApiOptions.None); } /// /// List self-hosted runners groups for an organization /// /// /// https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runner-groups?apiVersion=2022-11-28#list-self-hosted-runner-groups-for-an-organization /// /// The organization name /// Options for changing the API response [ManualRoute("GET", "/orgs/{org}/actions/runner-groups")] public async Task ListAllRunnerGroupsForOrganization(string org, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); var results = await ApiConnection.GetAll(ApiUrls.ActionsListOrganizationRunnerGroups(org), options).ConfigureAwait(false); return new RunnerGroupResponse( results.Count > 0 ? results[0].TotalCount : 0, results.SelectMany(x => x.RunnerGroups).ToList() ); } /// /// List self-hosted runners in a group for an enterprise /// /// /// https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runner-groups?apiVersion=2022-11-28#list-self-hosted-runners-in-a-group-for-an-enterprise /// /// The enterprise. /// The runner group ID. [ManualRoute("GET", "/enterprises/{enterprise}/actions/runner-groups/{runner_group_id}/runners")] public Task ListAllRunnersForEnterpriseRunnerGroup(string enterprise, long runnerGroupId) { return ListAllRunnersForEnterpriseRunnerGroup(enterprise, runnerGroupId, ApiOptions.None); } /// /// List self-hosted runners in a group for an enterprise /// /// /// https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runner-groups?apiVersion=2022-11-28#list-self-hosted-runners-in-a-group-for-an-enterprise /// /// The enterprise. /// The runner group ID. /// Options for changing the API response [ManualRoute("GET", "/enterprises/{enterprise}/actions/runner-groups/{runner_group_id}/runners")] public async Task ListAllRunnersForEnterpriseRunnerGroup(string enterprise, long runnerGroupId, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(enterprise, nameof(enterprise)); var results = await ApiConnection.GetAll(ApiUrls.ActionsListSelfHostedRunnersForEnterpriseRunnerGroup(enterprise, runnerGroupId), options).ConfigureAwait(false); return new RunnerResponse( results.Count > 0 ? results.Max(x => x.TotalCount) : 0, results.SelectMany(x => x.Runners).ToList() ); } /// /// List self-hosted runners in a group for an organization /// /// /// https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runner-groups?apiVersion=2022-11-28#list-self-hosted-runners-in-a-group-for-an-organization /// /// The organization. /// The runner group ID. [ManualRoute("GET", "/orgs/{org}/actions/runner-groups/{runner_group_id}/runners")] public Task ListAllRunnersForOrganizationRunnerGroup(string organization, long runnerGroupId) { return ListAllRunnersForOrganizationRunnerGroup(organization, runnerGroupId, ApiOptions.None); } /// /// List self-hosted runners in a group for an organization /// /// /// https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runner-groups?apiVersion=2022-11-28#list-self-hosted-runners-in-a-group-for-an-organization /// /// The organization. /// The runner group ID. /// Options for changing the API response [ManualRoute("GET", "/orgs/{org}/actions/runner-groups/{runner_group_id}/runners")] public async Task ListAllRunnersForOrganizationRunnerGroup(string organization, long runnerGroupId, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(organization, nameof(organization)); var results = await ApiConnection.GetAll(ApiUrls.ActionsListSelfHostedRunnersForOrganizationRunnerGroup(organization, runnerGroupId), options).ConfigureAwait(false); return new RunnerResponse( results.Count > 0 ? results.Max(x => x.TotalCount) : 0, results.SelectMany(x => x.Runners).ToList() ); } /// /// List organization access to a self-hosted runner group in an enterprise /// /// /// https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runner-groups?apiVersion=2022-11-28#list-organization-access-to-a-self-hosted-runner-group-in-an-enterprise /// /// 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) { return ListAllRunnerGroupOrganizationsForEnterprise(enterprise, runnerGroupId, ApiOptions.None); } /// /// List organization access to a self-hosted runner group in an enterprise /// /// /// https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runner-groups?apiVersion=2022-11-28#list-organization-access-to-a-self-hosted-runner-group-in-an-enterprise /// /// The enterprise name /// The runner group id /// Options for changing the API response [ManualRoute("GET", "/enterprises/{enterprise}/actions/runner-groups/{runner_group_id}/organizations")] public async Task ListAllRunnerGroupOrganizationsForEnterprise(string enterprise, long runnerGroupId, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(enterprise, nameof(enterprise)); 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() ); } /// /// List repository access to a self-hosted runner group in an organization /// /// /// https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runner-groups?apiVersion=2022-11-28#list-repository-access-to-a-self-hosted-runner-group-in-an-organization /// /// 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) { return ListAllRunnerGroupRepositoriesForOrganization(org, runnerGroupId, ApiOptions.None); } /// /// List repository access to a self-hosted runner group in an organization /// /// /// https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runner-groups?apiVersion=2022-11-28#list-repository-access-to-a-self-hosted-runner-group-in-an-organization /// /// The organization name /// The runner group id /// Options for changing the API response [ManualRoute("GET", "/orgs/{org}/actions/runner-groups/{runner_group_id}/repositories")] public async Task ListAllRunnerGroupRepositoriesForOrganization(string org, long runnerGroupId, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); 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() ); } } }