using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Octokit
{
///
/// A client for GitHub's Check Runs API
///
///
/// See the Check Runs API documentation for more information.
///
public class CheckRunsClient : ApiClient, ICheckRunsClient
{
///
/// Initializes a new GitHub Check Runs API client
///
/// An API connection
public CheckRunsClient(IApiConnection apiConnection) : base(apiConnection)
{
}
///
/// Creates a new check run for a specific commit in a repository
///
///
/// See the Check Runs API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// Details of the Check Run to create
[Preview("antiope")]
[ManualRoute("POST", "/repos/{owner}/{repo}/check-runs")]
public Task Create(string owner, string name, NewCheckRun newCheckRun)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(newCheckRun, nameof(newCheckRun));
return ApiConnection.Post(ApiUrls.CheckRuns(owner, name), newCheckRun, AcceptHeaders.ChecksApiPreview);
}
///
/// Creates a new check run for a specific commit in a repository
///
///
/// See the Check Runs API documentation for more information.
///
/// The Id of the repository
/// Details of the Check Run to create
[Preview("antiope")]
[ManualRoute("POST", "/repositories/{id}/check-runs")]
public Task Create(long repositoryId, NewCheckRun newCheckRun)
{
Ensure.ArgumentNotNull(newCheckRun, nameof(newCheckRun));
return ApiConnection.Post(ApiUrls.CheckRuns(repositoryId), newCheckRun, AcceptHeaders.ChecksApiPreview);
}
///
/// Updates a check run for a specific commit in a repository
///
///
/// See the Check Runs API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The Id of the check run
/// The updates to the check run
[Preview("antiope")]
[ManualRoute("PATCH", "/repos/{owner}/{repo}/check-runs/{check_run_id}")]
public Task Update(string owner, string name, long checkRunId, CheckRunUpdate checkRunUpdate)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(checkRunUpdate, nameof(checkRunUpdate));
return ApiConnection.Patch(ApiUrls.CheckRun(owner, name, checkRunId), checkRunUpdate, AcceptHeaders.ChecksApiPreview);
}
///
/// Updates a check run for a specific commit in a repository
///
///
/// See the Check Runs API documentation for more information.
///
/// The Id of the repository
/// The Id of the check run
/// The updates to the check run
[Preview("antiope")]
[ManualRoute("PATCH", "/repositories/{id}/check-runs/{check_run_id}")]
public Task Update(long repositoryId, long checkRunId, CheckRunUpdate checkRunUpdate)
{
Ensure.ArgumentNotNull(checkRunUpdate, nameof(checkRunUpdate));
return ApiConnection.Patch(ApiUrls.CheckRun(repositoryId, checkRunId), checkRunUpdate, AcceptHeaders.ChecksApiPreview);
}
///
/// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name
///
///
/// See the Check Runs API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The commit reference (can be a SHA, branch name, or a tag name)
[ManualRoute("GET", "/repos/{owner}/{repo}/commits/{commit_sha}/check-runs")]
public Task GetAllForReference(string owner, string name, string reference)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference));
return GetAllForReference(owner, name, reference, new CheckRunRequest(), ApiOptions.None);
}
///
/// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name
///
///
/// See the Check Runs API documentation for more information.
///
/// The Id of the repository
/// The commit reference (can be a SHA, branch name, or a tag name)
[ManualRoute("GET", "/repositories/{id}/commits/{commit_sha}/check-runs")]
public Task GetAllForReference(long repositoryId, string reference)
{
Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference));
return GetAllForReference(repositoryId, reference, new CheckRunRequest(), ApiOptions.None);
}
///
/// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name
///
///
/// See the Check Runs API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The commit reference (can be a SHA, branch name, or a tag name)
/// Details to filter the request, such as by check name
[ManualRoute("GET", "/repos/{owner}/{repo}/commits/{commit_sha}/check-runs")]
public Task GetAllForReference(string owner, string name, string reference, CheckRunRequest checkRunRequest)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference));
Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest));
return GetAllForReference(owner, name, reference, checkRunRequest, ApiOptions.None);
}
///
/// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name
///
///
/// See the Check Runs API documentation for more information.
///
/// The Id of the repository
/// The commit reference (can be a SHA, branch name, or a tag name)
/// Details to filter the request, such as by check name
[ManualRoute("GET", "/repositories/{id}/commits/{commit_sha}/check-runs")]
public Task GetAllForReference(long repositoryId, string reference, CheckRunRequest checkRunRequest)
{
Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference));
Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest));
return GetAllForReference(repositoryId, reference, checkRunRequest, ApiOptions.None);
}
///
/// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name
///
///
/// See the Check Runs API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The commit reference (can be a SHA, branch name, or a tag name)
/// Details to filter the request, such as by check name
/// Options to change the API response
[Preview("antiope")]
[ManualRoute("GET", "/repos/{owner}/{repo}/commits/{commit_sha}/check-runs")]
public async Task GetAllForReference(string owner, string name, string reference, CheckRunRequest checkRunRequest, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference));
Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest));
Ensure.ArgumentNotNull(options, nameof(options));
var results = await ApiConnection.GetAll(ApiUrls.CheckRunsForReference(owner, name, reference), checkRunRequest.ToParametersDictionary(), AcceptHeaders.ChecksApiPreview, options).ConfigureAwait(false);
return new CheckRunsResponse(
results.Count > 0 ? results.Max(x => x.TotalCount) : 0,
results.SelectMany(x => x.CheckRuns).ToList());
}
///
/// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name
///
///
/// See the Check Runs API documentation for more information.
///
/// The Id of the repository
/// The commit reference (can be a SHA, branch name, or a tag name)
/// Details to filter the request, such as by check name
/// Options to change the API response
[Preview("antiope")]
[ManualRoute("GET", "/repositories/{id}/commits/{commit_sha}/check-runs")]
public async Task GetAllForReference(long repositoryId, string reference, CheckRunRequest checkRunRequest, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference));
Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest));
Ensure.ArgumentNotNull(options, nameof(options));
var results = await ApiConnection.GetAll(ApiUrls.CheckRunsForReference(repositoryId, reference), checkRunRequest.ToParametersDictionary(), AcceptHeaders.ChecksApiPreview, options).ConfigureAwait(false);
return new CheckRunsResponse(
results.Count > 0 ? results.Max(x => x.TotalCount) : 0,
results.SelectMany(x => x.CheckRuns).ToList());
}
///
/// Lists check runs for a check suite using its Id
///
///
/// See the Check Runs API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The Id of the check suite
[ManualRoute("GET", "/repos/{owner}/{repo}/check-suite/{check_suite_id}/check-runs")]
public Task GetAllForCheckSuite(string owner, string name, long checkSuiteId)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
return GetAllForCheckSuite(owner, name, checkSuiteId, new CheckRunRequest(), ApiOptions.None);
}
///
/// Lists check runs for a check suite using its Id
///
///
/// See the Check Runs API documentation for more information.
///
/// The Id of the repository
/// The Id of the check suite
[ManualRoute("GET", "/repositories/{id}/check-suites/{check_suite_id}/check-runs")]
public Task GetAllForCheckSuite(long repositoryId, long checkSuiteId)
{
return GetAllForCheckSuite(repositoryId, checkSuiteId, new CheckRunRequest(), ApiOptions.None);
}
///
/// Lists check runs for a check suite using its Id
///
///
/// See the Check Runs API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The Id of the check suite
/// Details to filter the request, such as by check name
[ManualRoute("GET", "/repos/{owner}/{repo}/check-suite/{check_suite_id}/check-runs")]
public Task GetAllForCheckSuite(string owner, string name, long checkSuiteId, CheckRunRequest checkRunRequest)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest));
return GetAllForCheckSuite(owner, name, checkSuiteId, checkRunRequest, ApiOptions.None);
}
///
/// Lists check runs for a check suite using its Id
///
///
/// See the Check Runs API documentation for more information.
///
/// The Id of the repository
/// The Id of the check suite
/// Details to filter the request, such as by check name
[ManualRoute("GET", "/repositories/{id}/check-suites/{check_suite_id}/check-runs")]
public Task GetAllForCheckSuite(long repositoryId, long checkSuiteId, CheckRunRequest checkRunRequest)
{
Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest));
return GetAllForCheckSuite(repositoryId, checkSuiteId, checkRunRequest, ApiOptions.None);
}
///
/// Lists check runs for a check suite using its Id
///
///
/// See the Check Runs API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The Id of the check suite
/// Details to filter the request, such as by check name
/// Options to change the API response
[Preview("antiope")]
[ManualRoute("GET", "/repos/{owner}/{repo}/check-suite/{check_suite_id}/check-runs")]
public async Task GetAllForCheckSuite(string owner, string name, long checkSuiteId, CheckRunRequest checkRunRequest, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest));
Ensure.ArgumentNotNull(options, nameof(options));
var results = await ApiConnection.GetAll(ApiUrls.CheckRunsForCheckSuite(owner, name, checkSuiteId), checkRunRequest.ToParametersDictionary(), AcceptHeaders.ChecksApiPreview, options).ConfigureAwait(false);
return new CheckRunsResponse(
results.Count > 0 ? results.Max(x => x.TotalCount) : 0,
results.SelectMany(x => x.CheckRuns).ToList());
}
///
/// Lists check runs for a check suite using its Id
///
///
/// See the Check Runs API documentation for more information.
///
/// The Id of the repository
/// The Id of the check suite
/// Details to filter the request, such as by check name
/// Options to change the API response
[Preview("antiope")]
[ManualRoute("GET", "/repositories/{id}/check-suites/{check_suite_id}/check-runs")]
public async Task GetAllForCheckSuite(long repositoryId, long checkSuiteId, CheckRunRequest checkRunRequest, ApiOptions options)
{
Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest));
Ensure.ArgumentNotNull(options, nameof(options));
var results = await ApiConnection.GetAll(ApiUrls.CheckRunsForCheckSuite(repositoryId, checkSuiteId), checkRunRequest.ToParametersDictionary(), AcceptHeaders.ChecksApiPreview, options).ConfigureAwait(false);
return new CheckRunsResponse(
results.Count > 0 ? results.Max(x => x.TotalCount) : 0,
results.SelectMany(x => x.CheckRuns).ToList());
}
///
/// Gets a single check run using its Id
///
///
/// See the Check Runs API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The Id of the check run
[Preview("antiope")]
[ManualRoute("GET", "/repos/{owner}/{repo}/check-runs/{check_run_id}")]
public Task Get(string owner, string name, long checkRunId)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
return ApiConnection.Get(ApiUrls.CheckRun(owner, name, checkRunId), null, AcceptHeaders.ChecksApiPreview);
}
///
/// Gets a single check run using its Id
///
///
/// See the Check Runs API documentation for more information.
///
/// The Id of the repository
/// The Id of the check run
[Preview("antiope")]
[ManualRoute("GET", "/repositories/{id}/check-runs/{check_run_id}")]
public Task Get(long repositoryId, long checkRunId)
{
return ApiConnection.Get(ApiUrls.CheckRun(repositoryId, checkRunId), null, AcceptHeaders.ChecksApiPreview);
}
///
/// Lists annotations for a check run using the check run Id
///
///
/// See the Check Runs API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The Id of the check run
[ManualRoute("GET", "/repos/{owner}/{repo}/check-runs/{check_run_id}/annotations")]
public Task> GetAllAnnotations(string owner, string name, long checkRunId)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
return GetAllAnnotations(owner, name, checkRunId, ApiOptions.None);
}
///
/// Lists annotations for a check run using the check run Id
///
///
/// See the Check Runs API documentation for more information.
///
/// The Id of the repository
/// The Id of the check run
///
[ManualRoute("GET", "/repositories/{id}/check-runs/{check_run_id}/annotations")]
public Task> GetAllAnnotations(long repositoryId, long checkRunId)
{
return GetAllAnnotations(repositoryId, checkRunId, ApiOptions.None);
}
///
/// Lists annotations for a check run using the check run Id
///
///
/// See the Check Runs API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The Id of the check run
/// Options to change the API response
[Preview("antiope")]
[ManualRoute("GET", "/repos/{owner}/{repo}/check-runs/{check_run_id}/annotations")]
public Task> GetAllAnnotations(string owner, string name, long checkRunId, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(options, nameof(options));
return ApiConnection.GetAll(ApiUrls.CheckRunAnnotations(owner, name, checkRunId), null, AcceptHeaders.ChecksApiPreview, options);
}
///
/// Lists annotations for a check run using the check run Id
///
///
/// See the Check Runs API documentation for more information.
///
/// The Id of the repository
/// The Id of the check run
/// Options to change the API response
[Preview("antiope")]
[ManualRoute("GET", "/repositories/{id}/check-runs/{check_run_id}/annotations")]
public Task> GetAllAnnotations(long repositoryId, long checkRunId, ApiOptions options)
{
Ensure.ArgumentNotNull(options, nameof(options));
return ApiConnection.GetAll(ApiUrls.CheckRunAnnotations(repositoryId, checkRunId), null, AcceptHeaders.ChecksApiPreview, options);
}
}
}