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