using System; using System.Reactive.Threading.Tasks; using Octokit.Reactive.Internal; namespace Octokit.Reactive { /// /// A client for GitHub's Check Suites API. /// /// /// See the Check Suites API documentation for more information. /// public class ObservableCheckSuitesClient : IObservableCheckSuitesClient { readonly ICheckSuitesClient _client; readonly IConnection _connection; /// /// Initializes a new GitHub Check Suites API client. /// /// An used to make the requests public ObservableCheckSuitesClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, nameof(client)); _client = client.Check.Suite; _connection = client.Connection; } /// /// Gets a single Check Suite by Id /// /// /// See the Check Suites API documentation for more information. /// /// The owner of the repository /// The name of the repository /// The Id of the check suite public IObservable Get(string owner, string name, long checkSuiteId) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); return _client.Get(owner, name, checkSuiteId).ToObservable(); } /// /// Gets a single Check Suite by Id /// /// /// See the Check Suites API documentation for more information. /// /// The Id of the repository /// The Id of the check suite public IObservable Get(long repositoryId, long checkSuiteId) { return _client.Get(repositoryId, checkSuiteId).ToObservable(); } /// /// Lists Check Suites for a commit reference (SHA, branch name or tag name) /// /// /// See the Check Suites API documentation for more information. /// /// The owner of the repository /// The name of the repository /// The reference (SHA, branch name or tag name) to list check suites for public IObservable 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 CheckSuiteRequest(), ApiOptions.None); } /// /// Lists Check Suites for a commit reference (SHA, branch name or tag name) /// /// /// See the Check Suites API documentation for more information. /// /// The Id of the repository /// The reference (SHA, branch name or tag name) to list check suites for public IObservable GetAllForReference(long repositoryId, string reference) { Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); return GetAllForReference(repositoryId, reference, new CheckSuiteRequest(), ApiOptions.None); } /// /// Lists Check Suites for a commit reference (SHA, branch name or tag name) /// /// /// See the Check Suites API documentation for more information. /// /// The owner of the repository /// The name of the repository /// The reference (SHA, branch name or tag name) to list check suites for /// Details to filter the request, such as by App Id or Check Name public IObservable GetAllForReference(string owner, string name, string reference, CheckSuiteRequest request) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); Ensure.ArgumentNotNull(request, nameof(request)); return GetAllForReference(owner, name, reference, request, ApiOptions.None); } /// /// Lists Check Suites for a commit reference (SHA, branch name or tag name) /// /// /// See the Check Suites API documentation for more information. /// /// The Id of the repository /// The reference (SHA, branch name or tag name) to list check suites for /// Details to filter the request, such as by App Id or Check Name public IObservable GetAllForReference(long repositoryId, string reference, CheckSuiteRequest request) { Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); Ensure.ArgumentNotNull(request, nameof(request)); return GetAllForReference(repositoryId, reference, request, ApiOptions.None); } /// /// Lists Check Suites for a commit reference (SHA, branch name or tag name) /// /// /// See the Check Suites API documentation for more information. /// /// The owner of the repository /// The name of the repository /// The reference (SHA, branch name or tag name) to list check suites for /// Details to filter the request, such as by App Id or Check Name /// Options to change the API response public IObservable GetAllForReference(string owner, string name, string reference, CheckSuiteRequest request, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); Ensure.ArgumentNotNull(request, nameof(request)); Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages(ApiUrls.CheckSuitesForReference(owner, name, reference), request.ToParametersDictionary(), AcceptHeaders.ChecksApiPreview, options); } /// /// Lists Check Suites for a commit reference (SHA, branch name or tag name) /// /// /// See the Check Suites API documentation for more information. /// /// The Id of the repository /// The reference (SHA, branch name or tag name) to list check suites for /// Details to filter the request, such as by App Id or Check Name /// Options to change the API response public IObservable GetAllForReference(long repositoryId, string reference, CheckSuiteRequest request, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); Ensure.ArgumentNotNull(request, nameof(request)); Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages(ApiUrls.CheckSuitesForReference(repositoryId, reference), request.ToParametersDictionary(), AcceptHeaders.ChecksApiPreview, options); } /// /// Updates Check Suites prefrences on a repository, such as disabling automatic creation when code is pushed /// /// /// See the Check Suites API documentation for more information. /// /// The owner of the repository /// The name of the repository /// The check suite preferences public IObservable UpdatePreferences(string owner, string name, CheckSuitePreferences preferences) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(preferences, nameof(preferences)); return _client.UpdatePreferences(owner, name, preferences).ToObservable(); } /// /// Updates Check Suites prefrences on a repository, such as disabling automatic creation when code is pushed /// /// /// See the Check Suites API documentation for more information. /// /// The Id of the repository /// The check suite preferences public IObservable UpdatePreferences(long repositoryId, CheckSuitePreferences preferences) { Ensure.ArgumentNotNull(preferences, nameof(preferences)); return _client.UpdatePreferences(repositoryId, preferences).ToObservable(); } /// /// Creates a new Check Suite /// /// /// See the Check Suites API documentation for more information. /// /// The owner of the repository /// The name of the repository /// Details of the Check Suite to create public IObservable Create(string owner, string name, NewCheckSuite newCheckSuite) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(newCheckSuite, nameof(newCheckSuite)); return _client.Create(owner, name, newCheckSuite).ToObservable(); } /// /// Creates a new Check Suite /// /// /// See the Check Suites API documentation for more information. /// /// The Id of the repository /// Details of the Check Suite to create public IObservable Create(long repositoryId, NewCheckSuite newCheckSuite) { Ensure.ArgumentNotNull(newCheckSuite, nameof(newCheckSuite)); return _client.Create(repositoryId, newCheckSuite).ToObservable(); } /// /// Triggers GitHub to rerequest an existing check suite, without pushing new code to a repository /// /// /// See the Check Suites API documentation for more information. /// /// The owner of the repository /// The name of the repository /// The Id of the check suite public IObservable Rerequest(string owner, string name, long checkSuiteId) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); return _client.Rerequest(owner, name, checkSuiteId).ToObservable(); } /// /// Triggers GitHub to rerequest an existing check suite, without pushing new code to a repository /// /// /// See the Check Suites API documentation for more information. /// /// The Id of the repository /// The Id of the check suite public IObservable Rerequest(long repositoryId, long checkSuiteId) { return _client.Rerequest(repositoryId, checkSuiteId).ToObservable(); } } }