Skip to content

Commit

Permalink
Implement Deployment Statuses Preview (#1895)
Browse files Browse the repository at this point in the history
Co-authored-by: Brendan Forster <[email protected]>
  • Loading branch information
Cyberboss and shiftkey authored Feb 25, 2020
1 parent 04c9a9a commit b904ada
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 14 deletions.
17 changes: 15 additions & 2 deletions Octokit.Tests.Integration/Clients/DeploymentStatusClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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()
{
Expand Down Expand Up @@ -243,4 +257,3 @@ public void Dispose()
_context.Dispose();
}
}

21 changes: 14 additions & 7 deletions Octokit.Tests/Clients/DeploymentStatusClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public async Task RequestsCorrectUrl()
connection.Received().GetAll<
DeploymentStatus>(Arg.Is<Uri>(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);
}

Expand All @@ -34,7 +34,10 @@ public async Task RequestsCorrectUrlWithRepositoryId()

await client.GetAll(1, 1);

connection.Received().GetAll<DeploymentStatus>(Arg.Is<Uri>(u => u.ToString() == expectedUrl), Args.ApiOptions);
connection.Received().GetAll<DeploymentStatus>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
null,
"application/vnd.github.ant-man-preview+json,application/vnd.github.flash-preview+json",
Args.ApiOptions);
}

[Fact]
Expand All @@ -56,7 +59,7 @@ public async Task RequestsCorrectUrlWithApiOptions()
connection.Received().GetAll<DeploymentStatus>(
Arg.Is<Uri>(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);
}

Expand All @@ -76,7 +79,10 @@ public async Task RequestsCorrectUrlWithRepositoryIdWithApiOptions()

await client.GetAll(1, 1, options);

connection.Received().GetAll<DeploymentStatus>(Arg.Is<Uri>(u => u.ToString() == expectedUrl), options);
connection.Received().GetAll<DeploymentStatus>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
null,
"application/vnd.github.ant-man-preview+json,application/vnd.github.flash-preview+json",
options);
}

[Fact]
Expand Down Expand Up @@ -132,7 +138,7 @@ public void PostsToCorrectUrl()

connection.Received().Post<DeploymentStatus>(Arg.Is<Uri>(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]
Expand All @@ -145,7 +151,8 @@ public void PostsToCorrectUrlWithRepositoryId()
client.Create(1, 1, newDeploymentStatus);

connection.Received().Post<DeploymentStatus>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
Arg.Any<NewDeploymentStatus>());
Arg.Any<NewDeploymentStatus>(),
"application/vnd.github.ant-man-preview+json,application/vnd.github.flash-preview+json");
}

[Fact]
Expand Down Expand Up @@ -202,7 +209,7 @@ public void SendsPreviewAcceptHeaders()

connection.Received(1).Post<DeploymentStatus>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
Arg.Any<NewDeploymentStatus>(),
Arg.Is<string>(s => s == AcceptHeaders.DeploymentApiPreview));
Arg.Is<string>(s => s == "application/vnd.github.ant-man-preview+json,application/vnd.github.flash-preview+json"));
}
}

Expand Down
12 changes: 8 additions & 4 deletions Octokit/Clients/DeploymentStatusClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public Task<IReadOnlyList<DeploymentStatus>> GetAll(string owner, string name, i

return ApiConnection.GetAll<DeploymentStatus>(ApiUrls.DeploymentStatuses(owner, name, deploymentId),
null,
AcceptHeaders.DeploymentApiPreview,
AcceptHeaders.Concat(AcceptHeaders.DeploymentApiPreview, AcceptHeaders.DeploymentStatusesPreview),
options);
}

Expand All @@ -86,7 +86,10 @@ public Task<IReadOnlyList<DeploymentStatus>> GetAll(long repositoryId, int deplo
{
Ensure.ArgumentNotNull(options, nameof(options));

return ApiConnection.GetAll<DeploymentStatus>(ApiUrls.DeploymentStatuses(repositoryId, deploymentId), options);
return ApiConnection.GetAll<DeploymentStatus>(ApiUrls.DeploymentStatuses(repositoryId, deploymentId),
null,
AcceptHeaders.Concat(AcceptHeaders.DeploymentApiPreview, AcceptHeaders.DeploymentStatusesPreview),
options);
}

/// <summary>
Expand All @@ -108,7 +111,7 @@ public Task<DeploymentStatus> Create(string owner, string name, int deploymentId

return ApiConnection.Post<DeploymentStatus>(ApiUrls.DeploymentStatuses(owner, name, deploymentId),
newDeploymentStatus,
AcceptHeaders.DeploymentApiPreview);
AcceptHeaders.Concat(AcceptHeaders.DeploymentApiPreview, AcceptHeaders.DeploymentStatusesPreview));
}

/// <summary>
Expand All @@ -126,7 +129,8 @@ public Task<DeploymentStatus> Create(long repositoryId, int deploymentId, NewDep
Ensure.ArgumentNotNull(newDeploymentStatus, nameof(newDeploymentStatus));

return ApiConnection.Post<DeploymentStatus>(ApiUrls.DeploymentStatuses(repositoryId, deploymentId),
newDeploymentStatus);
newDeploymentStatus,
AcceptHeaders.Concat(AcceptHeaders.DeploymentApiPreview, AcceptHeaders.DeploymentStatusesPreview));
}
}
}
2 changes: 2 additions & 0 deletions Octokit/Helpers/AcceptHeaders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/// <summary>
/// Combines multiple preview headers. GitHub API supports Accept header with multiple
/// values separated by comma.
Expand Down
5 changes: 5 additions & 0 deletions Octokit/Models/Request/NewDeploymentStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public NewDeploymentStatus(DeploymentState deploymentState)
/// </summary>
public string EnvironmentUrl { get; set; }

/// <summary>
/// Name for the target deployment environment.
/// </summary>
public string Environment { get; set; }

/// <summary>
/// Indicates if a new inactive status should be added to all non-transient,
/// non-production environment deployments with the same repository and environment
Expand Down
8 changes: 7 additions & 1 deletion Octokit/Models/Response/DeploymentStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ public enum DeploymentState
Failure,

[Parameter(Value = "inactive")]
Inactive
Inactive,

[Parameter(Value = "in_progress")]
InProgress,

[Parameter(Value = "queued")]
Queued
}
}

0 comments on commit b904ada

Please sign in to comment.