using System.Threading.Tasks; using System.Linq; using System.Collections.Generic; namespace Octokit { /// /// A client for GitHub's Actions Self-hosted runners API. /// /// /// See the Actions Self-hosted runners API documentation for more information. /// public class ActionsSelfHostedRunnersClient : ApiClient, IActionsSelfHostedRunnersClient { /// /// Initializes a new GitHub Actions Self-hosted runners API client /// /// An API connection public ActionsSelfHostedRunnersClient(IApiConnection apiConnection) : base(apiConnection) { } /// /// Lists all self-hosted runners for an enterprise /// /// /// https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runners?apiVersion=2022-11-28#list-self-hosted-runners-for-an-enterprise /// /// The enterprise. [ManualRoute("GET", "/enterprises/{enterprise}/actions/runners")] public Task ListAllRunnersForEnterprise(string enterprise) { return ListAllRunnersForEnterprise(enterprise, ApiOptions.None); } /// /// Lists all self-hosted runners for an enterprise /// /// /// https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runners?apiVersion=2022-11-28#list-self-hosted-runners-for-an-enterprise /// /// The enterprise. /// Options for changing the API response [ManualRoute("GET", "/enterprises/{enterprise}/actions/runners")] public async Task ListAllRunnersForEnterprise(string enterprise, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(enterprise, nameof(enterprise)); Ensure.ArgumentNotNull(options, nameof(options)); var results = await ApiConnection.GetAll(ApiUrls.ActionsListSelfHostedRunnersForEnterprise(enterprise), options).ConfigureAwait(false); return new RunnerResponse( results.Count > 0 ? results[0].TotalCount : 0, results.SelectMany(x => x.Runners).ToList() ); } /// /// Lists all self-hosted runners for an organization /// /// /// https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#list-self-hosted-runners-for-an-organization /// /// The organization. [ManualRoute("GET", "/orgs/{org}/actions/runners")] public Task ListAllRunnersForOrganization(string organization) { return ListAllRunnersForOrganization(organization, ApiOptions.None); } /// /// Lists all self-hosted runners for an organization /// /// /// https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#list-self-hosted-runners-for-an-organization /// /// The organization. /// Options for changing the API response [ManualRoute("GET", "/orgs/{org}/actions/runners")] public async Task ListAllRunnersForOrganization(string organization, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(organization, nameof(organization)); var results = await ApiConnection.GetAll(ApiUrls.ActionsListSelfHostedRunnersForOrganization(organization), options).ConfigureAwait(false); return new RunnerResponse( results.Count > 0 ? results.Max(x => x.TotalCount) : 0, results.SelectMany(x => x.Runners).ToList() ); } /// /// Lists all self-hosted runners for a repository /// /// /// https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#list-self-hosted-runners-for-a-repository /// /// The owner of the repository. /// The name of the repository. [ManualRoute("GET", "/repos/{owner}/{repo}/actions/runners")] public Task ListAllRunnersForRepository(string owner, string name) { return ListAllRunnersForRepository(owner, name, ApiOptions.None); } /// /// Lists all self-hosted runners for a repository /// /// /// https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#list-self-hosted-runners-for-a-repository /// /// The owner of the repository. /// The name of the repository. /// Options for changing the API response [ManualRoute("GET", "/repos/{owner}/{repo}/actions/runners")] public async Task ListAllRunnersForRepository(string owner, string name, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); var results = await ApiConnection.GetAll(ApiUrls.ActionsListSelfHostedRunnersForRepository(owner, name), options).ConfigureAwait(false); return new RunnerResponse( results.Count > 0 ? results.Max(x => x.TotalCount) : 0, results.SelectMany(x => x.Runners).ToList() ); } /// /// List runner applications for an enterprise /// /// /// https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runners?apiVersion=2022-11-28#list-runner-applications-for-an-enterprise /// /// The enterprise. [ManualRoute("GET", "/enterprises/{enterprise}/actions/runners/downloads")] public Task> ListAllRunnerApplicationsForEnterprise(string enterprise) { return ListAllRunnerApplicationsForEnterprise(enterprise, ApiOptions.None); } /// /// List runner applications for an enterprise /// /// /// https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runners?apiVersion=2022-11-28#list-runner-applications-for-an-enterprise /// /// The enterprise. /// Options for changing the API response [ManualRoute("GET", "/enterprises/{enterprise}/actions/runners/downloads")] public async Task> ListAllRunnerApplicationsForEnterprise(string enterprise, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(enterprise, nameof(enterprise)); var results = await ApiConnection.GetAll>(ApiUrls.ActionsListRunnerApplicationsForEnterprise(enterprise), options).ConfigureAwait(false); return results.SelectMany(x => x).ToList(); } /// /// List runner applications for an organization /// /// /// https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runners?apiVersion=2022-11-28#list-runner-applications-for-an-organization /// /// The organization. [ManualRoute("GET", "/orgs/{org}/actions/runners/downloads")] public Task> ListAllRunnerApplicationsForOrganization(string organization) { return ListAllRunnerApplicationsForOrganization(organization, ApiOptions.None); } /// /// List runner applications for an organization /// /// /// https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runners?apiVersion=2022-11-28#list-runner-applications-for-an-organization /// /// The organization. /// Options for changing the API response [ManualRoute("GET", "/orgs/{org}/actions/runners/downloads")] public async Task> ListAllRunnerApplicationsForOrganization(string organization, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(organization, nameof(organization)); var results = await ApiConnection.GetAll>(ApiUrls.ActionsListRunnerApplicationsForOrganization(organization), options).ConfigureAwait(false); return results.SelectMany(x => x).ToList(); } /// /// List runner applications for a repository /// /// /// https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runners?apiVersion=2022-11-28#list-runner-applications-for-a-repository /// /// The owner. /// The repo. [ManualRoute("GET", "/repos/{owner}/{repo}/actions/runners/downloads")] public Task> ListAllRunnerApplicationsForRepository(string owner, string repo) { return ListAllRunnerApplicationsForRepository(owner, repo, ApiOptions.None); } /// /// List runner applications for a repository /// /// /// https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runners?apiVersion=2022-11-28#list-runner-applications-for-a-repository /// /// The owner. /// The repo. /// Options for changing the API response [ManualRoute("GET", "/repos/{owner}/{repo}/actions/runners/downloads")] public async Task> ListAllRunnerApplicationsForRepository(string owner, string repo, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(repo, nameof(repo)); var results = await ApiConnection.GetAll>(ApiUrls.ActionsListRunnerApplicationsForRepository(owner, repo), options).ConfigureAwait(false); return results.SelectMany(x => x).ToList(); } /// /// Delete a self-hosted runner from an enterprise /// /// /// https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runners?apiVersion=2022-11-28#delete-a-self-hosted-runner-from-an-enterprise /// /// The enterprise. /// The runner id. [ManualRoute("DELETE", "/enterprises/{enterprise}/actions/runners/{runner_id}")] public Task DeleteEnterpriseRunner(string enterprise, long runnerId) { return DeleteEnterpriseRunner(enterprise, runnerId, ApiOptions.None); } /// /// Delete a self-hosted runner from an enterprise /// /// /// https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runners?apiVersion=2022-11-28#delete-a-self-hosted-runner-from-an-enterprise /// /// The enterprise. /// The runner id. /// Options for changing the API response [ManualRoute("DELETE", "/enterprises/{enterprise}/actions/runners/{runner_id}")] public Task DeleteEnterpriseRunner(string enterprise, long runnerId, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(enterprise, nameof(enterprise)); return ApiConnection.Delete(ApiUrls.ActionsDeleteEnterpriseRunner(enterprise, runnerId), options); } /// /// Delete a self-hosted runner from an organization /// /// /// https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runners?apiVersion=2022-11-28#delete-a-self-hosted-runner-from-an-organization /// /// The organization. /// The runner id. [ManualRoute("DELETE", "/orgs/{org}/actions/runners/{runner_id}")] public Task DeleteOrganizationRunner(string organization, long runnerId) { return DeleteOrganizationRunner(organization, runnerId, ApiOptions.None); } /// /// Delete a self-hosted runner from an organization /// /// /// https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runners?apiVersion=2022-11-28#delete-a-self-hosted-runner-from-an-organization /// /// The organization. /// The runner id. /// Options for changing the API response [ManualRoute("DELETE", "/orgs/{org}/actions/runners/{runner_id}")] public Task DeleteOrganizationRunner(string organization, long runnerId, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(organization, nameof(organization)); return ApiConnection.Delete(ApiUrls.ActionsDeleteOrganizationRunner(organization, runnerId), options); } /// /// Delete a self-hosted runner from a repository /// /// /// https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runners?apiVersion=2022-11-28#delete-a-self-hosted-runner-from-a-repository /// /// The owner. /// The repo. /// The runner id. [ManualRoute("DELETE", "/repos/{owner}/{repo}/actions/runners/{runner_id}")] public Task DeleteRepositoryRunner(string owner, string repo, long runnerId) { return DeleteRepositoryRunner(owner, repo, runnerId, ApiOptions.None); } /// /// Delete a self-hosted runner from a repository /// /// /// https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runners?apiVersion=2022-11-28#delete-a-self-hosted-runner-from-a-repository /// /// The owner. /// The repo. /// The runner id. /// Options for changing the API response [ManualRoute("DELETE", "/repos/{owner}/{repo}/actions/runners/{runner_id}")] public Task DeleteRepositoryRunner(string owner, string repo, long runnerId, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(repo, nameof(repo)); return ApiConnection.Delete(ApiUrls.ActionsDeleteRepositoryRunner(owner, repo, runnerId), options); } /// /// Create a self-hosted runner registration token for an enterprise /// /// /// https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runners?apiVersion=2022-11-28#create-a-self-hosted-runner-registration-token-for-an-enterprise /// /// The enterprise. [ManualRoute("POST", "/enterprises/{enterprise}/actions/runners/registration-token")] public Task CreateEnterpriseRegistrationToken(string enterprise) { return CreateEnterpriseRegistrationToken(enterprise, ApiOptions.None); } /// /// Create a self-hosted runner registration token for an enterprise /// /// /// https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runners?apiVersion=2022-11-28#create-a-self-hosted-runner-registration-token-for-an-enterprise /// /// The enterprise. /// Options for changing the API response [ManualRoute("POST", "/enterprises/{enterprise}/actions/runners/registration-token")] public Task CreateEnterpriseRegistrationToken(string enterprise, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(enterprise, nameof(enterprise)); return ApiConnection.Post(ApiUrls.ActionsCreateEnterpriseRegistrationToken(enterprise), options); } /// /// Create a self-hosted runner registration token for an organization /// /// /// https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runners?apiVersion=2022-11-28#create-a-self-hosted-runner-registration-token-for-an-organization /// /// The organization. [ManualRoute("POST", "/orgs/{org}/actions/runners/registration-token")] public Task CreateOrganizationRegistrationToken(string organization) { return CreateOrganizationRegistrationToken(organization, ApiOptions.None); } /// /// Create a self-hosted runner registration token for an organization /// /// /// https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runners?apiVersion=2022-11-28#create-a-self-hosted-runner-registration-token-for-an-organization /// /// The organization. /// Options for changing the API response [ManualRoute("POST", "/orgs/{org}/actions/runners/registration-token")] public Task CreateOrganizationRegistrationToken(string organization, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(organization, nameof(organization)); return ApiConnection.Post(ApiUrls.ActionsCreateOrganizationRegistrationToken(organization), options); } /// /// Create a self-hosted runner registration token for a repository /// /// /// https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runners?apiVersion=2022-11-28#create-a-self-hosted-runner-registration-token-for-a-repository /// /// The owner. /// The repo. [ManualRoute("POST", "/repos/{owner}/{repo}/actions/runners/registration-token")] public Task CreateRepositoryRegistrationToken(string owner, string repo) { return CreateRepositoryRegistrationToken(owner, repo, ApiOptions.None); } /// /// Create a self-hosted runner registration token for a repository /// /// /// https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runners?apiVersion=2022-11-28#create-a-self-hosted-runner-registration-token-for-a-repository /// /// The owner. /// The repo. /// Options for changing the API response [ManualRoute("POST", "/repos/{owner}/{repo}/actions/runners/registration-token")] public Task CreateRepositoryRegistrationToken(string owner, string repo, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(repo, nameof(repo)); return ApiConnection.Post(ApiUrls.ActionsCreateRepositoryRegistrationToken(owner, repo), options); } } }