From b904ada89f62b4d9fa2516821dcd824244580a99 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Tue, 25 Feb 2020 18:59:03 -0500 Subject: [PATCH] Implement Deployment Statuses Preview (#1895) Co-authored-by: Brendan Forster --- .../Clients/DeploymentStatusClientTests.cs | 17 +++++++++++++-- .../Clients/DeploymentStatusClientTests.cs | 21 ++++++++++++------- Octokit/Clients/DeploymentStatusClient.cs | 12 +++++++---- Octokit/Helpers/AcceptHeaders.cs | 2 ++ Octokit/Models/Request/NewDeploymentStatus.cs | 5 +++++ Octokit/Models/Response/DeploymentStatus.cs | 8 ++++++- 6 files changed, 51 insertions(+), 14 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/DeploymentStatusClientTests.cs b/Octokit.Tests.Integration/Clients/DeploymentStatusClientTests.cs index bb6ce3aaee..5d8ad0ccf5 100644 --- a/Octokit.Tests.Integration/Clients/DeploymentStatusClientTests.cs +++ b/Octokit.Tests.Integration/Clients/DeploymentStatusClientTests.cs @@ -40,7 +40,10 @@ public DeploymentStatusClientTests() var commit = github.Git.Commit.Create(_context.RepositoryOwner, _context.RepositoryName, newCommit).Result; - var newDeployment = new NewDeployment(commit.Sha) { AutoMerge = false }; + var newDeployment = new NewDeployment(commit.Sha) { + Environment = "production", + AutoMerge = false + }; _deployment = _deploymentsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newDeployment).Result; } @@ -55,6 +58,17 @@ public async Task CanCreateDeploymentStatus() Assert.Equal(DeploymentState.Success, status.State); } + [IntegrationTest] + public async Task CanCreateDeploymentStatusWithNewState() + { + var newStatus = new NewDeploymentStatus(DeploymentState.InProgress); + + var status = await _deploymentsClient.Status.Create(_context.RepositoryOwner, _context.RepositoryName, _deployment.Id, newStatus); + + Assert.NotNull(status); + Assert.Equal(DeploymentState.InProgress, status.State); + } + [IntegrationTest] public async Task CanCreateDeploymentStatusWithRepositoryId() { @@ -243,4 +257,3 @@ public void Dispose() _context.Dispose(); } } - diff --git a/Octokit.Tests/Clients/DeploymentStatusClientTests.cs b/Octokit.Tests/Clients/DeploymentStatusClientTests.cs index fc1e7e65f4..9cf4c083ef 100644 --- a/Octokit.Tests/Clients/DeploymentStatusClientTests.cs +++ b/Octokit.Tests/Clients/DeploymentStatusClientTests.cs @@ -21,7 +21,7 @@ public async Task RequestsCorrectUrl() connection.Received().GetAll< DeploymentStatus>(Arg.Is(u => u.ToString() == expectedUrl), null, - "application/vnd.github.ant-man-preview+json", + "application/vnd.github.ant-man-preview+json,application/vnd.github.flash-preview+json", Args.ApiOptions); } @@ -34,7 +34,10 @@ public async Task RequestsCorrectUrlWithRepositoryId() await client.GetAll(1, 1); - connection.Received().GetAll(Arg.Is(u => u.ToString() == expectedUrl), Args.ApiOptions); + connection.Received().GetAll(Arg.Is(u => u.ToString() == expectedUrl), + null, + "application/vnd.github.ant-man-preview+json,application/vnd.github.flash-preview+json", + Args.ApiOptions); } [Fact] @@ -56,7 +59,7 @@ public async Task RequestsCorrectUrlWithApiOptions() connection.Received().GetAll( Arg.Is(u => u.ToString() == expectedUrl), null, - "application/vnd.github.ant-man-preview+json", + "application/vnd.github.ant-man-preview+json,application/vnd.github.flash-preview+json", options); } @@ -76,7 +79,10 @@ public async Task RequestsCorrectUrlWithRepositoryIdWithApiOptions() await client.GetAll(1, 1, options); - connection.Received().GetAll(Arg.Is(u => u.ToString() == expectedUrl), options); + connection.Received().GetAll(Arg.Is(u => u.ToString() == expectedUrl), + null, + "application/vnd.github.ant-man-preview+json,application/vnd.github.flash-preview+json", + options); } [Fact] @@ -132,7 +138,7 @@ public void PostsToCorrectUrl() connection.Received().Post(Arg.Is(u => u.ToString() == expectedUrl), newDeploymentStatus, - "application/vnd.github.ant-man-preview+json"); + "application/vnd.github.ant-man-preview+json,application/vnd.github.flash-preview+json"); } [Fact] @@ -145,7 +151,8 @@ public void PostsToCorrectUrlWithRepositoryId() client.Create(1, 1, newDeploymentStatus); connection.Received().Post(Arg.Is(u => u.ToString() == expectedUrl), - Arg.Any()); + Arg.Any(), + "application/vnd.github.ant-man-preview+json,application/vnd.github.flash-preview+json"); } [Fact] @@ -202,7 +209,7 @@ public void SendsPreviewAcceptHeaders() connection.Received(1).Post(Arg.Is(u => u.ToString() == expectedUrl), Arg.Any(), - Arg.Is(s => s == AcceptHeaders.DeploymentApiPreview)); + Arg.Is(s => s == "application/vnd.github.ant-man-preview+json,application/vnd.github.flash-preview+json")); } } diff --git a/Octokit/Clients/DeploymentStatusClient.cs b/Octokit/Clients/DeploymentStatusClient.cs index c1f874eacc..61735e8d2a 100644 --- a/Octokit/Clients/DeploymentStatusClient.cs +++ b/Octokit/Clients/DeploymentStatusClient.cs @@ -68,7 +68,7 @@ public Task> GetAll(string owner, string name, i return ApiConnection.GetAll(ApiUrls.DeploymentStatuses(owner, name, deploymentId), null, - AcceptHeaders.DeploymentApiPreview, + AcceptHeaders.Concat(AcceptHeaders.DeploymentApiPreview, AcceptHeaders.DeploymentStatusesPreview), options); } @@ -86,7 +86,10 @@ public Task> GetAll(long repositoryId, int deplo { Ensure.ArgumentNotNull(options, nameof(options)); - return ApiConnection.GetAll(ApiUrls.DeploymentStatuses(repositoryId, deploymentId), options); + return ApiConnection.GetAll(ApiUrls.DeploymentStatuses(repositoryId, deploymentId), + null, + AcceptHeaders.Concat(AcceptHeaders.DeploymentApiPreview, AcceptHeaders.DeploymentStatusesPreview), + options); } /// @@ -108,7 +111,7 @@ public Task Create(string owner, string name, int deploymentId return ApiConnection.Post(ApiUrls.DeploymentStatuses(owner, name, deploymentId), newDeploymentStatus, - AcceptHeaders.DeploymentApiPreview); + AcceptHeaders.Concat(AcceptHeaders.DeploymentApiPreview, AcceptHeaders.DeploymentStatusesPreview)); } /// @@ -126,7 +129,8 @@ public Task Create(long repositoryId, int deploymentId, NewDep Ensure.ArgumentNotNull(newDeploymentStatus, nameof(newDeploymentStatus)); return ApiConnection.Post(ApiUrls.DeploymentStatuses(repositoryId, deploymentId), - newDeploymentStatus); + newDeploymentStatus, + AcceptHeaders.Concat(AcceptHeaders.DeploymentApiPreview, AcceptHeaders.DeploymentStatusesPreview)); } } } diff --git a/Octokit/Helpers/AcceptHeaders.cs b/Octokit/Helpers/AcceptHeaders.cs index 3a857cca3f..45cbbd63a9 100644 --- a/Octokit/Helpers/AcceptHeaders.cs +++ b/Octokit/Helpers/AcceptHeaders.cs @@ -71,6 +71,8 @@ public static class AcceptHeaders public const string IssueEventsApiPreview = "application/vnd.github.starfox-preview"; + public const string DeploymentStatusesPreview = "application/vnd.github.flash-preview+json"; + /// /// Combines multiple preview headers. GitHub API supports Accept header with multiple /// values separated by comma. diff --git a/Octokit/Models/Request/NewDeploymentStatus.cs b/Octokit/Models/Request/NewDeploymentStatus.cs index 5a4da78973..7bbec67dbc 100644 --- a/Octokit/Models/Request/NewDeploymentStatus.cs +++ b/Octokit/Models/Request/NewDeploymentStatus.cs @@ -41,6 +41,11 @@ public NewDeploymentStatus(DeploymentState deploymentState) /// public string EnvironmentUrl { get; set; } + /// + /// Name for the target deployment environment. + /// + public string Environment { 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 diff --git a/Octokit/Models/Response/DeploymentStatus.cs b/Octokit/Models/Response/DeploymentStatus.cs index a7bef3ca05..cd46e7339e 100644 --- a/Octokit/Models/Response/DeploymentStatus.cs +++ b/Octokit/Models/Response/DeploymentStatus.cs @@ -115,6 +115,12 @@ public enum DeploymentState Failure, [Parameter(Value = "inactive")] - Inactive + Inactive, + + [Parameter(Value = "in_progress")] + InProgress, + + [Parameter(Value = "queued")] + Queued } } \ No newline at end of file