using System; using System.Reactive; using System.Reactive.Threading.Tasks; namespace Octokit.Reactive { public class ObservableActionsWorkflowsClient : IObservableActionsWorkflowsClient { readonly IActionsWorkflowsClient _client; /// /// Instantiate a new GitHub Actions Workflows API client. /// /// A GitHub client. public ObservableActionsWorkflowsClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, nameof(client)); _client = client.Actions.Workflows; Jobs = new ObservableActionsWorkflowJobsClient(client); Runs = new ObservableActionsWorkflowRunsClient(client); } /// /// Manually triggers a GitHub Actions workflow run in a repository by slug. /// /// /// https://developer.github.com/v3/actions/workflows/#create-a-workflow-dispatch-event /// /// The owner of the repository. /// The name of the repository. /// The workflow file name. /// The parameters to use to trigger the workflow run. public IObservable CreateDispatch(string owner, string name, string workflowFileName, CreateWorkflowDispatch createDispatch) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNullOrEmptyString(workflowFileName, nameof(workflowFileName)); Ensure.ArgumentNotNull(createDispatch, nameof(createDispatch)); return _client.CreateDispatch(owner, name, workflowFileName, createDispatch).ToObservable(); } /// /// Manually triggers a GitHub Actions workflow run in a repository by slug. /// /// /// https://developer.github.com/v3/actions/workflows/#create-a-workflow-dispatch-event /// /// The owner of the repository. /// The name of the repository. /// The Id of the workflow. /// The parameters to use to trigger the workflow run. public IObservable CreateDispatch(string owner, string name, long workflowId, CreateWorkflowDispatch createDispatch) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(createDispatch, nameof(createDispatch)); return _client.CreateDispatch(owner, name, workflowId, createDispatch).ToObservable(); } /// /// Manually triggers a GitHub Actions workflow run in a repository by slug. /// /// /// https://developer.github.com/v3/actions/workflows/#create-a-workflow-dispatch-event /// /// The Id of the repository. /// The workflow file name. /// The parameters to use to trigger the workflow run. public IObservable CreateDispatch(long repositoryId, string workflowFileName, CreateWorkflowDispatch createDispatch) { Ensure.ArgumentNotNullOrEmptyString(workflowFileName, nameof(workflowFileName)); Ensure.ArgumentNotNull(createDispatch, nameof(createDispatch)); return _client.CreateDispatch(repositoryId, workflowFileName, createDispatch).ToObservable(); } /// /// Manually triggers a GitHub Actions workflow run in a repository by Id. /// /// /// https://developer.github.com/v3/actions/workflows/#create-a-workflow-dispatch-event /// /// The Id of the repository. /// The Id of the workflow. /// The parameters to use to trigger the workflow run. public IObservable CreateDispatch(long repositoryId, long workflowId, CreateWorkflowDispatch createDispatch) { Ensure.ArgumentNotNull(createDispatch, nameof(createDispatch)); return _client.CreateDispatch(repositoryId, workflowId, createDispatch).ToObservable(); } /// /// Disables a specific workflow in a repository by Id. /// /// /// https://developer.github.com/v3/actions/workflows/#disable-a-workflow /// /// The owner of the repository. /// The name of the repository. /// The workflow file name. public IObservable Disable(string owner, string name, string workflowFileName) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNullOrEmptyString(workflowFileName, nameof(workflowFileName)); return _client.Disable(owner, name, workflowFileName).ToObservable(); } /// /// Disables a specific workflow in a repository by Id. /// /// /// https://developer.github.com/v3/actions/workflows/#disable-a-workflow /// /// The owner of the repository. /// The name of the repository. /// The Id of the workflow. public IObservable Disable(string owner, string name, long workflowId) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); return _client.Disable(owner, name, workflowId).ToObservable(); } /// /// Enables a specific workflow in a repository by Id. /// /// /// https://developer.github.com/v3/actions/workflows/#enable-a-workflow /// /// The owner of the repository. /// The name of the repository. /// The workflow file name. public IObservable Enable(string owner, string name, string workflowFileName) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNullOrEmptyString(workflowFileName, nameof(workflowFileName)); return _client.Enable(owner, name, workflowFileName).ToObservable(); } /// /// Enables a specific workflow in a repository by Id. /// /// /// https://developer.github.com/v3/actions/workflows/#enable-a-workflow /// /// The owner of the repository. /// The name of the repository. /// The Id of the workflow. public IObservable Enable(string owner, string name, long workflowId) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); return _client.Enable(owner, name, workflowId).ToObservable(); } /// /// Gets a specific workflow in a repository by Id. Anyone with read access to the repository can use this endpoint. /// /// /// https://developer.github.com/v3/actions/workflows/#get-a-workflow /// /// The owner of the repository. /// The name of the repository. /// The workflow file name. public IObservable Get(string owner, string name, string workflowFileName) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNullOrEmptyString(workflowFileName, nameof(workflowFileName)); return _client.Get(owner, name, workflowFileName).ToObservable(); } /// /// Gets a specific workflow in a repository by Id. Anyone with read access to the repository can use this endpoint. /// /// /// https://developer.github.com/v3/actions/workflows/#get-a-workflow /// /// The owner of the repository. /// The name of the repository. /// The Id of the workflow. public IObservable Get(string owner, string name, long workflowId) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); return _client.Get(owner, name, workflowId).ToObservable(); } /// /// Gets useage of a specific workflow in a repository by Id. Anyone with read access to the repository can use this endpoint. /// /// /// https://developer.github.com/v3/actions/workflows/#get-workflow-usage /// /// The owner of the repository. /// The name of the repository. /// The workflow file name. public IObservable GetUsage(string owner, string name, string workflowFileName) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNullOrEmptyString(workflowFileName, nameof(workflowFileName)); return _client.GetUsage(owner, name, workflowFileName).ToObservable(); } /// /// Gets useage of a specific workflow in a repository by Id. Anyone with read access to the repository can use this endpoint. /// /// /// https://developer.github.com/v3/actions/workflows/#get-workflow-usage /// /// The owner of the repository. /// The name of the repository. /// The Id of the workflow. public IObservable GetUsage(string owner, string name, long workflowId) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); return _client.GetUsage(owner, name, workflowId).ToObservable(); } /// /// Lists the workflows in a repository. Anyone with read access to the repository can use this endpoint. /// /// /// https://developer.github.com/v3/actions/workflows/#list-repository-workflows /// /// The owner of the repository. /// The name of the repository. public IObservable List(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); return _client.List(owner, name).ToObservable(); } /// /// Lists the workflows in a repository. Anyone with read access to the repository can use this endpoint. /// /// /// https://developer.github.com/v3/actions/workflows/#list-repository-workflows /// /// The owner of the repository. /// The name of the repository. /// Options to change the API response. public IObservable List(string owner, string name, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(options, nameof(options)); return _client.List(owner, name, options).ToObservable(); } /// /// Client for the Workflow jobs API. /// public IObservableActionsWorkflowJobsClient Jobs { get; private set; } /// /// Client for the Workflow runs API. /// public IObservableActionsWorkflowRunsClient Runs { get; private set; } } }