diff --git a/Octokit.Tests.Integration/Clients/DeploymentStatusClientTests.cs b/Octokit.Tests.Integration/Clients/DeploymentStatusClientTests.cs index 953969f2..49ee43ef 100644 --- a/Octokit.Tests.Integration/Clients/DeploymentStatusClientTests.cs +++ b/Octokit.Tests.Integration/Clients/DeploymentStatusClientTests.cs @@ -58,13 +58,15 @@ public class DeploymentStatusClientTests : IDisposable [IntegrationTest] public async Task CanReadDeploymentStatuses() { - var newStatus = new NewDeploymentStatus(DeploymentState.Success); + var newStatus = new NewDeploymentStatus(DeploymentState.Success) { LogUrl = "http://test.com/log", EnvironmentUrl = "http:test.com/staging" }; await _deploymentsClient.Status.Create(_context.RepositoryOwner, _context.RepositoryName, _deployment.Id, newStatus); var statuses = await _deploymentsClient.Status.GetAll(_context.RepositoryOwner, _context.RepositoryName, _deployment.Id); Assert.NotEmpty(statuses); Assert.Equal(DeploymentState.Success, statuses[0].State); + Assert.Equal(newStatus.LogUrl, statuses[0].LogUrl); + Assert.Equal(newStatus.EnvironmentUrl, statuses[0].EnvironmentUrl); } [IntegrationTest] diff --git a/Octokit.Tests.Integration/Clients/DeploymentsClientTests.cs b/Octokit.Tests.Integration/Clients/DeploymentsClientTests.cs index 8cc015ff..42e1b6a7 100644 --- a/Octokit.Tests.Integration/Clients/DeploymentsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/DeploymentsClientTests.cs @@ -78,11 +78,13 @@ public class DeploymentsClientTests : IDisposable [IntegrationTest] public async Task CanCreateDeployment() { - var newDeployment = new NewDeployment(_commit.Sha) { AutoMerge = false }; + var newDeployment = new NewDeployment(_commit.Sha) { AutoMerge = false, TransientEnvironment = true, ProductionEnvironment = true }; var deployment = await _deploymentsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newDeployment); Assert.NotNull(deployment); + Assert.Equal(newDeployment.TransientEnvironment, deployment.TransientEnvironment); + Assert.Equal(newDeployment.ProductionEnvironment, deployment.ProductionEnvironment); } [IntegrationTest] diff --git a/Octokit.Tests/Clients/DeploymentStatusClientTests.cs b/Octokit.Tests/Clients/DeploymentStatusClientTests.cs index 849457ab..87c97bfb 100644 --- a/Octokit.Tests/Clients/DeploymentStatusClientTests.cs +++ b/Octokit.Tests/Clients/DeploymentStatusClientTests.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using NSubstitute; using Octokit; @@ -59,7 +60,10 @@ public class DeploymentStatusClientTests var expectedUrl = "repos/owner/name/deployments/1/statuses"; client.GetAll("owner", "name", 1); - connection.Received().GetAll(Arg.Is(u => u.ToString() == expectedUrl), Args.ApiOptions); + connection.Received().GetAll(Arg.Is(u => u.ToString() == expectedUrl), + Arg.Any>(), + Arg.Any(), + Args.ApiOptions); } [Fact] @@ -69,7 +73,7 @@ public class DeploymentStatusClientTests var client = new DeploymentStatusClient(connection); var expectedUrl = "repos/owner/name/deployments/1/statuses"; - var options =new ApiOptions + var options = new ApiOptions { StartPage = 1, PageCount = 1, @@ -77,7 +81,24 @@ public class DeploymentStatusClientTests }; client.GetAll("owner", "name", 1, options); - connection.Received().GetAll(Arg.Is(u => u.ToString() == expectedUrl), 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); } } @@ -127,7 +148,36 @@ public class DeploymentStatusClientTests client.Create("owner", "repo", 1, newDeploymentStatus); connection.Received().Post(Arg.Is(u => u.ToString() == expectedUrl), - Arg.Any()); + Arg.Any(), + Arg.Any()); + } + + [Fact] + public void PassesNewDeploymentRequest() + { + 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, + Arg.Any()); + } + + [Fact] + public void SendsPreviewAcceptHeaders() + { + 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(1).Post(Arg.Is(u => u.ToString() == expectedUrl), + Arg.Any(), + Arg.Is(s => s == AcceptHeaders.DeploymentApiPreview)); } } diff --git a/Octokit.Tests/Clients/DeploymentsClientTests.cs b/Octokit.Tests/Clients/DeploymentsClientTests.cs index a29e555a..26f6b15b 100644 --- a/Octokit.Tests/Clients/DeploymentsClientTests.cs +++ b/Octokit.Tests/Clients/DeploymentsClientTests.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using NSubstitute; using Octokit; @@ -54,7 +55,10 @@ public class DeploymentsClientTests client.GetAll(owner, name); connection.Received(1) - .GetAll(Arg.Is(u => u.ToString() == expectedUrl), Args.ApiOptions); + .GetAll(Arg.Is(u => u.ToString() == expectedUrl), + Arg.Any>(), + Arg.Any(), + Args.ApiOptions); } [Fact] @@ -73,7 +77,25 @@ public class DeploymentsClientTests client.GetAll(owner, name, options); connection.Received(1) - .GetAll(Arg.Is(u => u.ToString() == expectedUrl), options); + .GetAll(Arg.Is(u => u.ToString() == expectedUrl), + Arg.Any>(), + Arg.Any(), + options); + } + + [Fact] + public void RequestsCorrectUrlWithPreviewAcceptHeaders() + { + var connection = Substitute.For(); + var client = new DeploymentsClient(connection); + var expectedUrl = string.Format("repos/{0}/{1}/deployments", owner, name); + + client.GetAll(owner, name); + connection.Received(1) + .GetAll(Arg.Is(u => u.ToString() == expectedUrl), + Arg.Any>(), + Arg.Is(s => s == AcceptHeaders.DeploymentApiPreview), + Args.ApiOptions); } } @@ -124,7 +146,8 @@ public class DeploymentsClientTests client.Create("owner", "name", newDeployment); connection.Received(1).Post(Arg.Is(u => u.ToString() == expectedUrl), - Arg.Any()); + Arg.Any(), + Arg.Any()); } [Fact] @@ -136,7 +159,21 @@ public class DeploymentsClientTests client.Create("owner", "name", newDeployment); connection.Received(1).Post(Arg.Any(), - newDeployment); + newDeployment, + Arg.Any()); + } + + [Fact] + public void SendsPreviewAcceptHeaders() + { + var connection = Substitute.For(); + var client = new DeploymentsClient(connection); + + client.Create("owner", "name", newDeployment); + + connection.Received(1).Post(Arg.Any(), + Arg.Any(), + Arg.Is(s => s == AcceptHeaders.DeploymentApiPreview)); } } diff --git a/Octokit/Clients/DeploymentStatusClient.cs b/Octokit/Clients/DeploymentStatusClient.cs index 62722ec4..7495c462 100644 --- a/Octokit/Clients/DeploymentStatusClient.cs +++ b/Octokit/Clients/DeploymentStatusClient.cs @@ -54,7 +54,10 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(options, "options"); - return ApiConnection.GetAll(ApiUrls.DeploymentStatuses(owner, name, deploymentId), options); + return ApiConnection.GetAll(ApiUrls.DeploymentStatuses(owner, name, deploymentId), + null, + AcceptHeaders.DeploymentApiPreview, + options); } /// @@ -76,7 +79,8 @@ namespace Octokit Ensure.ArgumentNotNull(newDeploymentStatus, "newDeploymentStatus"); return ApiConnection.Post(ApiUrls.DeploymentStatuses(owner, name, deploymentId), - newDeploymentStatus); + newDeploymentStatus, + AcceptHeaders.DeploymentApiPreview); } } } diff --git a/Octokit/Clients/DeploymentsClient.cs b/Octokit/Clients/DeploymentsClient.cs index b543e73e..e341c641 100644 --- a/Octokit/Clients/DeploymentsClient.cs +++ b/Octokit/Clients/DeploymentsClient.cs @@ -57,7 +57,10 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(options, "options"); - return ApiConnection.GetAll(ApiUrls.Deployments(owner, name), options); + return ApiConnection.GetAll(ApiUrls.Deployments(owner, name), + null, + AcceptHeaders.DeploymentApiPreview, + options); } /// @@ -78,7 +81,8 @@ namespace Octokit Ensure.ArgumentNotNull(newDeployment, "newDeployment"); return ApiConnection.Post(ApiUrls.Deployments(owner, name), - newDeployment); + newDeployment, + AcceptHeaders.DeploymentApiPreview); } /// diff --git a/Octokit/Helpers/AcceptHeaders.cs b/Octokit/Helpers/AcceptHeaders.cs index 0002896a..53625763 100644 --- a/Octokit/Helpers/AcceptHeaders.cs +++ b/Octokit/Helpers/AcceptHeaders.cs @@ -30,5 +30,7 @@ namespace Octokit [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gpg")] public const string GpgKeysPreview = "application/vnd.github.cryptographer-preview"; + + public const string DeploymentApiPreview = "application/vnd.github.ant-man-preview+json"; } } diff --git a/Octokit/Models/Request/NewDeployment.cs b/Octokit/Models/Request/NewDeployment.cs index f12f3c9f..1df2e2e4 100644 --- a/Octokit/Models/Request/NewDeployment.cs +++ b/Octokit/Models/Request/NewDeployment.cs @@ -74,6 +74,18 @@ namespace Octokit /// public string Description { get; set; } + /// + /// Indicates if the environment is specific to a deployment and will no longer exist at some point in the future. + /// (DEFAULT if not specified: False) + /// + public bool? TransientEnvironment { get; set; } + + /// + /// Indicates if the environment is one with which end users directly interact. + /// (DEFAULT if not specified: True when environment is "production" and False otherwise) + /// + public bool? ProductionEnvironment { get; set; } + internal string DebuggerDisplay { get diff --git a/Octokit/Models/Request/NewDeploymentStatus.cs b/Octokit/Models/Request/NewDeploymentStatus.cs index 426148cf..9054c939 100644 --- a/Octokit/Models/Request/NewDeploymentStatus.cs +++ b/Octokit/Models/Request/NewDeploymentStatus.cs @@ -1,3 +1,4 @@ +using System; using System.Diagnostics; using System.Globalization; @@ -28,13 +29,34 @@ namespace Octokit /// output to keep the user updated while the task is running or serve as /// historical information for what happened in the deployment /// + [Obsolete("This property is obsolete. Use LogUrl instead.", false)] public string TargetUrl { get; set; } + /// + /// The target URL to associate with this status. This URL should contain + /// output to keep the user updated while the task is running or serve as + /// historical information for what happened in the deployment + /// + public string LogUrl { get; set; } + /// /// A short description of the status. /// public string Description { get; set; } + /// + /// The URL for accessing your environment. + /// + public string EnvironmentUrl { get; set; } + + /// + /// Indicates if a new inactive status should be added to all non-transient, + /// non-production environment deployments with the same repository and environment + /// name as the created status's deployment. + /// (DEFAULT if not specified: True) + /// + public bool? AutoInactive { get; set; } + internal string DebuggerDisplay { get diff --git a/Octokit/Models/Response/Deployment.cs b/Octokit/Models/Response/Deployment.cs index 43976458..b1254dce 100644 --- a/Octokit/Models/Response/Deployment.cs +++ b/Octokit/Models/Response/Deployment.cs @@ -71,6 +71,16 @@ namespace Octokit /// public string StatusesUrl { get; protected set; } + /// + /// Indicates if the environment is specific to a deployment and will no longer exist at some point in the future. + /// + public bool TransientEnvironment { get; protected set; } + + /// + /// Indicates if the environment is one with which end users directly interact. + /// + public bool ProductionEnvironment { get; protected set; } + internal string DebuggerDisplay { get diff --git a/Octokit/Models/Response/DeploymentStatus.cs b/Octokit/Models/Response/DeploymentStatus.cs index db42f80b..70e75a8b 100644 --- a/Octokit/Models/Response/DeploymentStatus.cs +++ b/Octokit/Models/Response/DeploymentStatus.cs @@ -55,6 +55,18 @@ namespace Octokit /// public string TargetUrl { get; protected set; } + /// + /// The target URL of this deployment status. This URL should contain + /// output to keep the user updated while the task is running or serve as + /// historical information for what happened in the deployment + /// + public string LogUrl { get; protected set; } + + /// + /// The URL for accessing your environment. + /// + public string EnvironmentUrl { get; protected set; } + /// /// The date and time that the status was created. /// @@ -84,6 +96,7 @@ namespace Octokit Pending, Success, Error, - Failure + Failure, + Inactive } } \ No newline at end of file