using System.Linq;
using System.Threading.Tasks;
namespace Octokit
{
///
/// A client for GitHub's Actions Workflows jobs API.
///
///
/// See the Actions Workflows jobs API documentation for more information.
///
public class ActionsWorkflowJobsClient : ApiClient, IActionsWorkflowJobsClient
{
///
/// Initializes a new GitHub Actions Workflows jobs API client
///
/// An API connection
public ActionsWorkflowJobsClient(IApiConnection apiConnection) : base(apiConnection)
{
}
///
/// Re-runs a specific workflow job in a repository.
///
///
/// https://developer.github.com/v3/actions/workflow-runs/#re-run-a-job-from-a-workflow-run
///
/// The owner of the repository.
/// The name of the repository.
/// The Id of the workflow job.
[ManualRoute("POST", "/repos/{owner}/{repo}/actions/jobs/{job_id}/rerun")]
public Task Rerun(string owner, string name, long jobId)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
return ApiConnection.Post(ApiUrls.ActionsRerunWorkflowJob(owner, name, jobId));
}
///
/// Gets a specific job in a workflow run.
///
///
/// https://developer.github.com/v3/actions/workflow-jobs/#get-a-job-for-a-workflow-run
///
/// The owner of the repository.
/// The name of the repository.
/// The unique identifier of the job.
[ManualRoute("GET", "\n/repos/{owner}/{repo}/actions/jobs/{job_id}")]
public Task Get(string owner, string name, long jobId)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
return ApiConnection.Get(ApiUrls.ActionsGetWorkflowJob(owner, name, jobId));
}
///
/// Gets the plain text log file for a workflow job.
///
///
/// https://developer.github.com/v3/actions/workflow-jobs/#download-job-logs-for-a-workflow-run
///
/// The owner of the repository.
/// The name of the repository.
/// The Id of the workflow job.
[ManualRoute("GET", "/repos/{owner}/{repo}/actions/jobs/{job_id}/logs")]
public async Task GetLogs(string owner, string name, long jobId)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
var response = await Connection.Get(ApiUrls.ActionsGetWorkflowJobLogs(owner, name, jobId), null).ConfigureAwait(false);
return response.Body;
}
///
/// Lists jobs for a specific workflow run.
///
///
/// https://developer.github.com/v3/actions/workflow-runs/#list-jobs-for-a-workflow-run
///
/// The owner of the repository.
/// The name of the repository.
/// The Id of the workflow run.
[ManualRoute("GET", "/repos/{owner}/{repo}/actions/runs/{run_id}/jobs")]
public Task List(string owner, string name, long runId)
{
return List(owner, name, runId, new WorkflowRunJobsRequest(), ApiOptions.None);
}
///
/// Lists jobs for a specific workflow run.
///
///
/// https://developer.github.com/v3/actions/workflow-runs/#list-jobs-for-a-workflow-run
///
/// The owner of the repository.
/// The name of the repository.
/// The Id of the workflow run.
/// Details to filter the request, such as by when completed.
[ManualRoute("GET", "/repos/{owner}/{repo}/actions/runs/{run_id}/jobs")]
public Task List(string owner, string name, long runId, WorkflowRunJobsRequest workflowRunJobsRequest)
{
return List(owner, name, runId, workflowRunJobsRequest, ApiOptions.None);
}
///
/// Lists jobs for a specific workflow run.
///
///
/// https://developer.github.com/v3/actions/workflow-runs/#list-jobs-for-a-workflow-run
///
/// The owner of the repository.
/// The name of the repository.
/// The Id of the workflow run.
/// Details to filter the request, such as by when completed.
/// Options to change the API response.
[ManualRoute("GET", "/repos/{owner}/{repo}/actions/runs/{run_id}/jobs")]
public async Task List(string owner, string name, long runId, WorkflowRunJobsRequest workflowRunJobsRequest, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(workflowRunJobsRequest, nameof(workflowRunJobsRequest));
var results = await ApiConnection.GetAll(ApiUrls.ActionsListWorkflowJobs(owner, name, runId), workflowRunJobsRequest.ToParametersDictionary(), options).ConfigureAwait(false);
return new WorkflowJobsResponse(
results.Count > 0 ? results.Max(x => x.TotalCount) : 0,
results.SelectMany(x => x.Jobs).ToList());
}
///
/// Lists jobs for a specific workflow run attempt.
///
///
/// https://developer.github.com/v3/actions/workflow-runs/#list-jobs-for-a-workflow-run-attempt
///
/// The owner of the repository.
/// The name of the repository.
/// The Id of the workflow run.
/// The attempt number of the workflow run.
[ManualRoute("GET", "/repos/{owner}/{repo}/actions/runs/{run_id}/attempts/{attempt_number}/jobs")]
public Task List(string owner, string name, long runId, int attemptNumber)
{
return List(owner, name, runId, attemptNumber, ApiOptions.None);
}
///
/// Lists jobs for a specific workflow run attempt.
///
///
/// https://developer.github.com/v3/actions/workflow-runs/#list-jobs-for-a-workflow-run-attempt
///
/// The owner of the repository.
/// The name of the repository.
/// The Id of the workflow run.
/// The attempt number of the workflow run.
/// Options to change the API response.
[ManualRoute("GET", "/repos/{owner}/{repo}/actions/runs/{run_id}/attempts/{attempt_number}/jobs")]
public async Task List(string owner, string name, long runId, int attemptNumber, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
var results = await ApiConnection.GetAll(ApiUrls.ActionsListWorkflowJobs(owner, name, runId, attemptNumber), null, options).ConfigureAwait(false);
return new WorkflowJobsResponse(
results.Count > 0 ? results.Max(x => x.TotalCount) : 0,
results.SelectMany(x => x.Jobs).ToList());
}
}
}