diff --git a/Octokit.Reactive/Clients/IObservableDeploymentStatusClient.cs b/Octokit.Reactive/Clients/IObservableDeploymentStatusClient.cs index 2b67fae7..2e799858 100644 --- a/Octokit.Reactive/Clients/IObservableDeploymentStatusClient.cs +++ b/Octokit.Reactive/Clients/IObservableDeploymentStatusClient.cs @@ -2,6 +2,13 @@ using System; namespace Octokit.Reactive { + /// + /// 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 interface IObservableDeploymentStatusClient { /// @@ -14,9 +21,19 @@ namespace Octokit.Reactive /// The owner of the repository. /// The name of the repository. /// The id of the deployment. - /// All deployment statuses for the given deployment. IObservable GetAll(string owner, string name, int deploymentId); + /// + /// 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. + IObservable GetAll(int repositoryId, int deploymentId); + /// /// Gets all the statuses for the given deployment. Any user with pull access to a repository can /// view deployments. @@ -28,9 +45,20 @@ namespace Octokit.Reactive /// The name of the repository. /// The id of the deployment. /// Options for changing the API response - /// All deployment statuses for the given deployment. IObservable GetAll(string owner, string name, int deploymentId, ApiOptions 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 + IObservable GetAll(int repositoryId, int deploymentId, ApiOptions options); + /// /// Creates a new status for the given deployment. Users with push access can create deployment /// statuses for a given deployment. @@ -42,7 +70,18 @@ namespace Octokit.Reactive /// The name of the repository. /// The id of the deployment. /// The new deployment status to create. - /// IObservable Create(string owner, string name, int deploymentId, NewDeploymentStatus newDeploymentStatus); + + /// + /// 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. + IObservable Create(int repositoryId, int deploymentId, NewDeploymentStatus newDeploymentStatus); } -} \ No newline at end of file +} diff --git a/Octokit.Reactive/Clients/ObservableDeploymentStatusClient.cs b/Octokit.Reactive/Clients/ObservableDeploymentStatusClient.cs index 8295f6b0..eb8b4af0 100644 --- a/Octokit.Reactive/Clients/ObservableDeploymentStatusClient.cs +++ b/Octokit.Reactive/Clients/ObservableDeploymentStatusClient.cs @@ -4,6 +4,13 @@ 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; @@ -27,7 +34,6 @@ namespace Octokit.Reactive.Clients /// The owner of the repository. /// The name of the repository. /// The id of the deployment. - /// All deployment statuses for the given deployment. public IObservable GetAll(string owner, string name, int deploymentId) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -36,6 +42,20 @@ namespace Octokit.Reactive.Clients 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(int 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. @@ -47,7 +67,6 @@ namespace Octokit.Reactive.Clients /// The name of the repository. /// The id of the deployment. /// Options for changing the API response - /// All deployment statuses for the given deployment. public IObservable GetAll(string owner, string name, int deploymentId, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -58,6 +77,24 @@ namespace Octokit.Reactive.Clients 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(int repositoryId, int deploymentId, ApiOptions options) + { + Ensure.ArgumentNotNull(options, "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. @@ -69,10 +106,30 @@ namespace Octokit.Reactive.Clients /// 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, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(newDeploymentStatus, "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(int repositoryId, int deploymentId, NewDeploymentStatus newDeploymentStatus) + { + Ensure.ArgumentNotNull(newDeploymentStatus, "newDeploymentStatus"); + + return _client.Create(repositoryId, deploymentId, newDeploymentStatus).ToObservable(); + } } } diff --git a/Octokit.Tests.Integration/Clients/DeploymentStatusClientTests.cs b/Octokit.Tests.Integration/Clients/DeploymentStatusClientTests.cs index 49ee43ef..4c6ae338 100644 --- a/Octokit.Tests.Integration/Clients/DeploymentStatusClientTests.cs +++ b/Octokit.Tests.Integration/Clients/DeploymentStatusClientTests.cs @@ -55,6 +55,17 @@ public class DeploymentStatusClientTests : IDisposable Assert.Equal(DeploymentState.Success, status.State); } + [IntegrationTest] + public async Task CanCreateDeploymentStatusWithRepositoryId() + { + var newStatus = new NewDeploymentStatus(DeploymentState.Success); + + var status = await _deploymentsClient.Status.Create(_context.Repository.Id, _deployment.Id, newStatus); + + Assert.NotNull(status); + Assert.Equal(DeploymentState.Success, status.State); + } + [IntegrationTest] public async Task CanReadDeploymentStatuses() { @@ -69,6 +80,18 @@ public class DeploymentStatusClientTests : IDisposable Assert.Equal(newStatus.EnvironmentUrl, statuses[0].EnvironmentUrl); } + [IntegrationTest] + public async Task CanReadDeploymentStatusesWithRepositoryId() + { + var newStatus = new NewDeploymentStatus(DeploymentState.Success); + await _deploymentsClient.Status.Create(_context.Repository.Id, _deployment.Id, newStatus); + + var statuses = await _deploymentsClient.Status.GetAll(_context.Repository.Id, _deployment.Id); + + Assert.NotEmpty(statuses); + Assert.Equal(DeploymentState.Success, statuses[0].State); + } + [IntegrationTest] public async Task ReturnsCorrectCountOfDeploymentStatusesWithoutStart() { @@ -90,6 +113,27 @@ public class DeploymentStatusClientTests : IDisposable Assert.Equal(3, deploymentStatuses.Count); } + [IntegrationTest] + public async Task ReturnsCorrectCountOfDeploymentStatusesWithoutStartWithRepositoryId() + { + var newStatus1 = new NewDeploymentStatus(DeploymentState.Success); + var newStatus2 = new NewDeploymentStatus(DeploymentState.Success); + var newStatus3 = new NewDeploymentStatus(DeploymentState.Success); + await _deploymentsClient.Status.Create(_context.Repository.Id, _deployment.Id, newStatus1); + await _deploymentsClient.Status.Create(_context.Repository.Id, _deployment.Id, newStatus2); + await _deploymentsClient.Status.Create(_context.Repository.Id, _deployment.Id, newStatus3); + + var options = new ApiOptions + { + PageSize = 3, + PageCount = 1 + }; + + var deploymentStatuses = await _deploymentsClient.Status.GetAll(_context.Repository.Id, _deployment.Id, options); + + Assert.Equal(3, deploymentStatuses.Count); + } + [IntegrationTest] public async Task ReturnsCorrectCountOfDeploymentStatusesWithStart() { @@ -112,6 +156,28 @@ public class DeploymentStatusClientTests : IDisposable Assert.Equal(1, deploymentStatuses.Count); } + [IntegrationTest] + public async Task ReturnsCorrectCountOfDeploymentStatusesWithStartWithRepositoryId() + { + var newStatus1 = new NewDeploymentStatus(DeploymentState.Success); + var newStatus2 = new NewDeploymentStatus(DeploymentState.Success); + var newStatus3 = new NewDeploymentStatus(DeploymentState.Success); + await _deploymentsClient.Status.Create(_context.Repository.Id,_deployment.Id, newStatus1); + await _deploymentsClient.Status.Create(_context.Repository.Id, _deployment.Id, newStatus2); + await _deploymentsClient.Status.Create(_context.Repository.Id, _deployment.Id, newStatus3); + + var options = new ApiOptions + { + PageSize = 2, + PageCount = 1, + StartPage = 2 + }; + + var deploymentStatuses = await _deploymentsClient.Status.GetAll(_context.Repository.Id, _deployment.Id, options); + + Assert.Equal(1, deploymentStatuses.Count); + } + [IntegrationTest] public async Task ReturnsDistinctDeploymentStatusesBasedOnStartPage() { @@ -142,6 +208,36 @@ public class DeploymentStatusClientTests : IDisposable Assert.NotEqual(firstPage[0].Id, secondPage[0].Id); } + [IntegrationTest] + public async Task ReturnsDistinctDeploymentStatusesBasedOnStartPageWithRepositoryId() + { + var newStatus1 = new NewDeploymentStatus(DeploymentState.Success); + var newStatus2 = new NewDeploymentStatus(DeploymentState.Success); + var newStatus3 = new NewDeploymentStatus(DeploymentState.Success); + await _deploymentsClient.Status.Create(_context.Repository.Id, _deployment.Id, newStatus1); + await _deploymentsClient.Status.Create(_context.Repository.Id, _deployment.Id, newStatus2); + await _deploymentsClient.Status.Create(_context.Repository.Id, _deployment.Id, newStatus3); + + var startOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1 + }; + + var firstPage = await _deploymentsClient.Status.GetAll(_context.Repository.Id, _deployment.Id, startOptions); + + var skipStartOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + + var secondPage = await _deploymentsClient.Status.GetAll(_context.Repository.Id, _deployment.Id, skipStartOptions); + + Assert.NotEqual(firstPage[0].Id, secondPage[0].Id); + } + public void Dispose() { _context.Dispose(); diff --git a/Octokit.Tests/Clients/DeploymentStatusClientTests.cs b/Octokit.Tests/Clients/DeploymentStatusClientTests.cs index 87c97bfb..fc1e7e65 100644 --- a/Octokit.Tests/Clients/DeploymentStatusClientTests.cs +++ b/Octokit.Tests/Clients/DeploymentStatusClientTests.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Threading.Tasks; using NSubstitute; using Octokit; @@ -10,6 +9,76 @@ public class DeploymentStatusClientTests { public class TheGetAllMethod { + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new DeploymentStatusClient(connection); + var expectedUrl = "repos/owner/name/deployments/1/statuses"; + + await client.GetAll("owner", "name", 1); + + connection.Received().GetAll< + DeploymentStatus>(Arg.Is(u => u.ToString() == expectedUrl), + null, + "application/vnd.github.ant-man-preview+json", + Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new DeploymentStatusClient(connection); + var expectedUrl = "repositories/1/deployments/1/statuses"; + + await client.GetAll(1, 1); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == expectedUrl), Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new DeploymentStatusClient(connection); + var expectedUrl = "repos/owner/name/deployments/1/statuses"; + + var options = new ApiOptions + { + StartPage = 1, + PageCount = 1, + PageSize = 1 + }; + + await client.GetAll("owner", "name", 1, options); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == expectedUrl), + null, + "application/vnd.github.ant-man-preview+json", + options); + } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryIdWithApiOptions() + { + var connection = Substitute.For(); + var client = new DeploymentStatusClient(connection); + var expectedUrl = "repositories/1/deployments/1/statuses"; + + var options = new ApiOptions + { + StartPage = 1, + PageCount = 1, + PageSize = 1 + }; + + await client.GetAll(1, 1, options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == expectedUrl), options); + } + [Fact] public async Task EnsuresNonNullArguments() { @@ -21,16 +90,11 @@ public class DeploymentStatusClientTests await Assert.ThrowsAsync(() => client.GetAll(null, "name", 1, ApiOptions.None)); await Assert.ThrowsAsync(() => client.GetAll("owner", null, 1, ApiOptions.None)); await Assert.ThrowsAsync(() => client.GetAll("owner", "name", 1, null)); - } - [Fact] - public async Task EnsuresNonEmptyArguments() - { - var client = new DeploymentStatusClient(Substitute.For()); + await Assert.ThrowsAsync(() => client.GetAll(1, 1, null)); await Assert.ThrowsAsync(() => client.GetAll("", "name", 1)); await Assert.ThrowsAsync(() => client.GetAll("owner", "", 1)); - await Assert.ThrowsAsync(() => client.GetAll("", "name", 1, ApiOptions.None)); await Assert.ThrowsAsync(() => client.GetAll("owner", "", 1, ApiOptions.None)); } @@ -51,61 +115,39 @@ public class DeploymentStatusClientTests await Assert.ThrowsAsync(() => client.GetAll(whitespace, "name", 1, ApiOptions.None)); await Assert.ThrowsAsync(() => client.GetAll("owner", whitespace, 1, ApiOptions.None)); } - - [Fact] - public void RequestsCorrectUrl() - { - var connection = Substitute.For(); - var client = new DeploymentStatusClient(connection); - var expectedUrl = "repos/owner/name/deployments/1/statuses"; - - client.GetAll("owner", "name", 1); - connection.Received().GetAll(Arg.Is(u => u.ToString() == expectedUrl), - Arg.Any>(), - Arg.Any(), - Args.ApiOptions); - } - - [Fact] - public void RequestsCorrectUrlWithApiOptions() - { - var connection = Substitute.For(); - var client = new DeploymentStatusClient(connection); - var expectedUrl = "repos/owner/name/deployments/1/statuses"; - - var options = new ApiOptions - { - StartPage = 1, - PageCount = 1, - PageSize = 1 - }; - - client.GetAll("owner", "name", 1, options); - connection.Received().GetAll(Arg.Is(u => u.ToString() == expectedUrl), - Arg.Any>(), - Arg.Any(), - options); - } - - [Fact] - public void RequestsCorrectUrlWithPreviewAcceptHeaders() - { - var connection = Substitute.For(); - var client = new DeploymentStatusClient(connection); - var expectedUrl = "repos/owner/name/deployments/1/statuses"; - - client.GetAll("owner", "name", 1); - connection.Received().GetAll(Arg.Is(u => u.ToString() == expectedUrl), - Arg.Any>(), - Arg.Is(a => a == AcceptHeaders.DeploymentApiPreview), - Args.ApiOptions); - } } public class TheCreateMethod { readonly NewDeploymentStatus newDeploymentStatus = new NewDeploymentStatus(DeploymentState.Success); + [Fact] + public void PostsToCorrectUrl() + { + var connection = Substitute.For(); + var client = new DeploymentStatusClient(connection); + var expectedUrl = "repos/owner/repo/deployments/1/statuses"; + + client.Create("owner", "repo", 1, newDeploymentStatus); + + connection.Received().Post(Arg.Is(u => u.ToString() == expectedUrl), + newDeploymentStatus, + "application/vnd.github.ant-man-preview+json"); + } + + [Fact] + public void PostsToCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new DeploymentStatusClient(connection); + var expectedUrl = "repositories/1/deployments/1/statuses"; + + client.Create(1, 1, newDeploymentStatus); + + connection.Received().Post(Arg.Is(u => u.ToString() == expectedUrl), + Arg.Any()); + } + [Fact] public async Task EnsuresNonNullArguments() { @@ -113,15 +155,12 @@ public class DeploymentStatusClientTests await Assert.ThrowsAsync(() => client.Create(null, "name", 1, newDeploymentStatus)); await Assert.ThrowsAsync(() => client.Create("owner", null, 1, newDeploymentStatus)); - } + await Assert.ThrowsAsync(() => client.Create("owner", "name", 1, null)); - [Fact] - public async Task EnsuresNonEmptyArguments() - { - var client = new DeploymentStatusClient(Substitute.For()); + await Assert.ThrowsAsync(() => client.Create(1, 1, null)); - await Assert.ThrowsAsync(() => client.GetAll("", "name", 1)); - await Assert.ThrowsAsync(() => client.GetAll("owner", "", 1)); + await Assert.ThrowsAsync(() => client.Create("", "name", 1, newDeploymentStatus)); + await Assert.ThrowsAsync(() => client.Create("owner", "", 1, newDeploymentStatus)); } [Theory] @@ -138,20 +177,6 @@ public class DeploymentStatusClientTests await Assert.ThrowsAsync(() => client.Create("owner", whitespace, 1, newDeploymentStatus)); } - [Fact] - public void PostsToCorrectUrl() - { - var connection = Substitute.For(); - var client = new DeploymentStatusClient(connection); - var expectedUrl = "repos/owner/repo/deployments/1/statuses"; - - client.Create("owner", "repo", 1, newDeploymentStatus); - - connection.Received().Post(Arg.Is(u => u.ToString() == expectedUrl), - Arg.Any(), - Arg.Any()); - } - [Fact] public void PassesNewDeploymentRequest() { @@ -189,4 +214,4 @@ public class DeploymentStatusClientTests Assert.Throws(() => new DeploymentStatusClient(null)); } } -} \ No newline at end of file +} diff --git a/Octokit.Tests/Reactive/ObservableDeploymentStatusClientTests.cs b/Octokit.Tests/Reactive/ObservableDeploymentStatusClientTests.cs index 21567fba..6fd20001 100644 --- a/Octokit.Tests/Reactive/ObservableDeploymentStatusClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableDeploymentStatusClientTests.cs @@ -22,23 +22,85 @@ namespace Octokit.Tests.Reactive _client = new ObservableDeploymentStatusClient(_githubClient); } + [Fact] + public void RequestsCorrectUrl() + { + var expectedUri = string.Format("repos/{0}/{1}/deployments/{2}/statuses", "owner", "repo", 1); + + _client.GetAll("owner", "repo", 1); + + _githubClient.Connection.Received(1) + .Get>(Arg.Is(uri => uri.ToString() == expectedUri), + Args.EmptyDictionary, + null); + } + + [Fact] + public void RequestsCorrectUrlWithRepositoryId() + { + var expectedUri = string.Format("repositories/{0}/deployments/{1}/statuses", 1, 1); + + _client.GetAll(1, 1); + + _githubClient.Connection.Received(1) + .Get>(Arg.Is(uri => uri.ToString() == expectedUri), + Args.EmptyDictionary, + null); + } + + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var expectedUri = string.Format("repos/{0}/{1}/deployments/{2}/statuses", "owner", "repo", 1); + + var options = new ApiOptions + { + StartPage = 1, + PageCount = 1, + PageSize = 1 + }; + + _client.GetAll("owner", "repo", 1, options); + + _githubClient.Connection.Received(1) + .Get>(Arg.Is(uri => uri.ToString() == expectedUri), + Arg.Is>(dictionary => dictionary.Count == 2), + null); + } + + [Fact] + public void RequestsCorrectUrlWithRepositoryIdWithApiOptions() + { + var expectedUri = string.Format("repositories/{0}/deployments/{1}/statuses", 1, 1); + + var options = new ApiOptions + { + StartPage = 1, + PageCount = 1, + PageSize = 1 + }; + + _client.GetAll(1, 1, options); + + _githubClient.Connection.Received(1) + .Get>(Arg.Is(uri => uri.ToString() == expectedUri), + Arg.Is>(dictionary => dictionary.Count == 2), + null); + } + [Fact] public void EnsuresNonNullArguments() { Assert.Throws(() => _client.GetAll(null, "repo", 1)); Assert.Throws(() => _client.GetAll("owner", null, 1)); - Assert.Throws(() => _client.GetAll(null, "repo", 1, ApiOptions.None)); Assert.Throws(() => _client.GetAll("owner", null, 1, ApiOptions.None)); Assert.Throws(() => _client.GetAll("owner", "repo", 1, null)); - } - [Fact] - public void EnsuresNonEmptyArguments() - { + Assert.Throws(() => _client.GetAll(1, 1, null)); + Assert.Throws(() => _client.GetAll("", "repo", 1)); Assert.Throws(() => _client.GetAll("owner", "", 1)); - Assert.Throws(() => _client.GetAll("", "repo", 1, ApiOptions.None)); Assert.Throws(() => _client.GetAll("owner", "", 1, ApiOptions.None)); } @@ -56,39 +118,6 @@ namespace Octokit.Tests.Reactive await AssertEx.ThrowsWhenGivenWhitespaceArgument( async whitespace => await _client.GetAll("owner", whitespace, 1, ApiOptions.None)); } - - [Fact] - public void RequestsCorrectUrl() - { - var expectedUri = ApiUrls.DeploymentStatuses("owner", "repo", 1); - - _client.GetAll("owner", "repo", 1); - - _githubClient.Connection.Received(1) - .Get>(Arg.Is(expectedUri), - Args.EmptyDictionary, - null); - } - - [Fact] - public void RequestsCorrectUrlWitApiOptions() - { - var expectedUri = ApiUrls.DeploymentStatuses("owner", "repo", 1); - - var options = new ApiOptions - { - StartPage = 1, - PageCount = 1, - PageSize = 1 - }; - - _client.GetAll("owner", "repo", 1, options); - - _githubClient.Connection.Received(1) - .Get>(Arg.Is(expectedUri), - Arg.Is>(dictionary => dictionary.Count == 2), - null); - } } public class TheCreateMethod @@ -109,18 +138,42 @@ namespace Octokit.Tests.Reactive } [Fact] - public async Task EnsuresNonNullArguments() + public void CallsIntoDeploymentStatusClient() { - SetupWithNonReactiveClient(); - Assert.Throws(() => _client.Create(null, "repo", 1, new NewDeploymentStatus(DeploymentState.Success))); - Assert.Throws(() => _client.Create("owner", null, 1, new NewDeploymentStatus(DeploymentState.Success))); - Assert.Throws(() => _client.Create("owner", "repo", 1, null)); + SetupWithoutNonReactiveClient(); + + var newStatus = new NewDeploymentStatus(DeploymentState.Success); + + _client.Create("owner", "repo", 1, newStatus); + + _githubClient.Repository.Deployment.Status.Received(1) + .Create("owner", "repo", 1, newStatus); } [Fact] - public async Task EnsuresNonEmptyArguments() + public void CallsIntoDeploymentStatusClientWithRepositoryId() + { + SetupWithoutNonReactiveClient(); + + var newStatus = new NewDeploymentStatus(DeploymentState.Success); + + _client.Create(1, 1, newStatus); + + _githubClient.Repository.Deployment.Status.Received(1) + .Create(1, 1, newStatus); + } + + [Fact] + public async Task EnsuresNonNullArguments() { SetupWithNonReactiveClient(); + + Assert.Throws(() => _client.Create(null, "repo", 1, new NewDeploymentStatus(DeploymentState.Success))); + Assert.Throws(() => _client.Create("owner", null, 1, new NewDeploymentStatus(DeploymentState.Success))); + Assert.Throws(() => _client.Create("owner", "repo", 1, null)); + + Assert.Throws(() => _client.Create(1, 1, null)); + Assert.Throws(() => _client.Create("", "repo", 1, new NewDeploymentStatus(DeploymentState.Success))); Assert.Throws(() => _client.Create("owner", "", 1, new NewDeploymentStatus(DeploymentState.Success))); } @@ -129,25 +182,12 @@ namespace Octokit.Tests.Reactive public async Task EnsureNonWhitespaceArguments() { SetupWithNonReactiveClient(); + await AssertEx.ThrowsWhenGivenWhitespaceArgument( async whitespace => await _client.Create(whitespace, "repo", 1, new NewDeploymentStatus(DeploymentState.Success))); await AssertEx.ThrowsWhenGivenWhitespaceArgument( async whitespace => await _client.Create("owner", whitespace, 1, new NewDeploymentStatus(DeploymentState.Success))); } - - [Fact] - public void CallsIntoDeploymentStatusClient() - { - SetupWithoutNonReactiveClient(); - - var newStatus = new NewDeploymentStatus(DeploymentState.Success); - _client.Create("owner", "repo", 1, newStatus); - _githubClient.Repository.Deployment.Status.Received(1) - .Create(Arg.Is("owner"), - Arg.Is("repo"), - Arg.Is(1), - Arg.Is(newStatus)); - } } public class TheCtor diff --git a/Octokit/Clients/DeploymentStatusClient.cs b/Octokit/Clients/DeploymentStatusClient.cs index 7495c462..858515b8 100644 --- a/Octokit/Clients/DeploymentStatusClient.cs +++ b/Octokit/Clients/DeploymentStatusClient.cs @@ -27,7 +27,6 @@ namespace Octokit /// The owner of the repository. /// The name of the repository. /// The id of the deployment. - /// All deployment statuses for the given deployment. public Task> GetAll(string owner, string name, int deploymentId) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -36,6 +35,20 @@ namespace Octokit 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 Task> GetAll(int 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. @@ -47,7 +60,6 @@ namespace Octokit /// The name of the repository. /// The id of the deployment. /// Options for changing the API response - /// All deployment statuses for the given deployment. public Task> GetAll(string owner, string name, int deploymentId, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -60,6 +72,23 @@ namespace Octokit 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 Task> GetAll(int repositoryId, int deploymentId, ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(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. @@ -70,8 +99,7 @@ namespace Octokit /// The owner of the repository. /// The name of the repository. /// The id of the deployment. - /// - /// + /// The new deployment status to create. public Task Create(string owner, string name, int deploymentId, NewDeploymentStatus newDeploymentStatus) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -82,5 +110,23 @@ namespace Octokit newDeploymentStatus, AcceptHeaders.DeploymentApiPreview); } + + /// + /// 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 Task Create(int repositoryId, int deploymentId, NewDeploymentStatus newDeploymentStatus) + { + Ensure.ArgumentNotNull(newDeploymentStatus, "newDeploymentStatus"); + + return ApiConnection.Post(ApiUrls.DeploymentStatuses(repositoryId, deploymentId), + newDeploymentStatus); + } } } diff --git a/Octokit/Clients/IDeploymentStatusClient.cs b/Octokit/Clients/IDeploymentStatusClient.cs index 077c17c1..57a879ab 100644 --- a/Octokit/Clients/IDeploymentStatusClient.cs +++ b/Octokit/Clients/IDeploymentStatusClient.cs @@ -22,9 +22,19 @@ namespace Octokit /// The owner of the repository. /// The name of the repository. /// The id of the deployment. - /// All deployment statuses for the given deployment. Task> GetAll(string owner, string name, int deploymentId); + /// + /// 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. + Task> GetAll(int repositoryId, int deploymentId); + /// /// Gets all the statuses for the given deployment. Any user with pull access to a repository can /// view deployments. @@ -36,9 +46,20 @@ namespace Octokit /// The name of the repository. /// The id of the deployment. /// Options for changing the API response - /// All deployment statuses for the given deployment. Task> GetAll(string owner, string name, int deploymentId, ApiOptions 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 + Task> GetAll(int repositoryId, int deploymentId, ApiOptions options); + /// /// Creates a new status for the given deployment. Users with push access can create deployment /// statuses for a given deployment. @@ -49,8 +70,19 @@ namespace Octokit /// The owner of the repository. /// The name of the repository. /// The id of the deployment. - /// - /// + /// The new deployment status to create. Task Create(string owner, string name, int deploymentId, NewDeploymentStatus newDeploymentStatus); + + /// + /// 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. + Task Create(int repositoryId, int deploymentId, NewDeploymentStatus newDeploymentStatus); } } \ No newline at end of file