using System; using System.Reactive.Threading.Tasks; using Octokit.Reactive.Internal; namespace Octokit.Reactive.Clients { /// /// A client for GitHub's Repository Deployment Statuses API. /// Gets and creates Deployment Statuses. /// /// /// See the Repository Deployment Statuses API documentation for more information. /// public class ObservableDeploymentStatusClient : IObservableDeploymentStatusClient { private readonly IDeploymentStatusClient _client; private readonly IConnection _connection; public ObservableDeploymentStatusClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, nameof(client)); _client = client.Repository.Deployment.Status; _connection = client.Connection; } /// /// Gets all the statuses for the given deployment. Any user with pull access to a repository can /// view deployments. /// /// /// http://developer.github.com/v3/repos/deployments/#list-deployment-statuses /// /// The owner of the repository. /// The name of the repository. /// The id of the deployment. public IObservable GetAll(string owner, string name, int deploymentId) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); return GetAll(owner, name, deploymentId, ApiOptions.None); } /// /// Gets all the statuses for the given deployment. Any user with pull access to a repository can /// view deployments. /// /// /// http://developer.github.com/v3/repos/deployments/#list-deployment-statuses /// /// The Id of the repository. /// The id of the deployment. public IObservable GetAll(long repositoryId, int deploymentId) { return GetAll(repositoryId, deploymentId, ApiOptions.None); } /// /// Gets all the statuses for the given deployment. Any user with pull access to a repository can /// view deployments. /// /// /// http://developer.github.com/v3/repos/deployments/#list-deployment-statuses /// /// The owner of the repository. /// The name of the repository. /// The id of the deployment. /// Options for changing the API response public IObservable GetAll(string owner, string name, int deploymentId, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages( ApiUrls.DeploymentStatuses(owner, name, deploymentId), options); } /// /// Gets all the statuses for the given deployment. Any user with pull access to a repository can /// view deployments. /// /// /// http://developer.github.com/v3/repos/deployments/#list-deployment-statuses /// /// The Id of the repository. /// The id of the deployment. /// Options for changing the API response public IObservable GetAll(long repositoryId, int deploymentId, ApiOptions options) { Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages( ApiUrls.DeploymentStatuses(repositoryId, deploymentId), options); } /// /// Creates a new status for the given deployment. Users with push access can create deployment /// statuses for a given deployment. /// /// /// http://developer.github.com/v3/repos/deployments/#create-a-deployment-status /// /// The owner of the repository. /// The name of the repository. /// The id of the deployment. /// The new deployment status to create. public IObservable Create(string owner, string name, int deploymentId, NewDeploymentStatus newDeploymentStatus) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(newDeploymentStatus, nameof(newDeploymentStatus)); return _client.Create(owner, name, deploymentId, newDeploymentStatus).ToObservable(); } /// /// Creates a new status for the given deployment. Users with push access can create deployment /// statuses for a given deployment. /// /// /// http://developer.github.com/v3/repos/deployments/#create-a-deployment-status /// /// The Id of the repository. /// The id of the deployment. /// The new deployment status to create. public IObservable Create(long repositoryId, int deploymentId, NewDeploymentStatus newDeploymentStatus) { Ensure.ArgumentNotNull(newDeploymentStatus, nameof(newDeploymentStatus)); return _client.Create(repositoryId, deploymentId, newDeploymentStatus).ToObservable(); } } }