Merge pull request #1365 from ErikSchierboom/deployment-status-enhancements

Deployment and DeploymentStatus API enhancements preview period. (#1249)
This commit is contained in:
Ryan Gribble
2016-06-17 21:18:13 +10:00
committed by GitHub
11 changed files with 173 additions and 15 deletions
@@ -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]
@@ -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]
@@ -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<DeploymentStatus>(Arg.Is<Uri>(u => u.ToString() == expectedUrl), Args.ApiOptions);
connection.Received().GetAll<DeploymentStatus>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
Arg.Any<IDictionary<string, string>>(),
Arg.Any<string>(),
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<DeploymentStatus>(Arg.Is<Uri>(u => u.ToString() == expectedUrl), options);
connection.Received().GetAll<DeploymentStatus>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
Arg.Any<IDictionary<string, string>>(),
Arg.Any<string>(),
options);
}
[Fact]
public void RequestsCorrectUrlWithPreviewAcceptHeaders()
{
var connection = Substitute.For<IApiConnection>();
var client = new DeploymentStatusClient(connection);
var expectedUrl = "repos/owner/name/deployments/1/statuses";
client.GetAll("owner", "name", 1);
connection.Received().GetAll<DeploymentStatus>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
Arg.Any<IDictionary<string, string>>(),
Arg.Is<string>(a => a == AcceptHeaders.DeploymentApiPreview),
Args.ApiOptions);
}
}
@@ -127,7 +148,36 @@ public class DeploymentStatusClientTests
client.Create("owner", "repo", 1, newDeploymentStatus);
connection.Received().Post<DeploymentStatus>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
Arg.Any<NewDeploymentStatus>());
Arg.Any<NewDeploymentStatus>(),
Arg.Any<string>());
}
[Fact]
public void PassesNewDeploymentRequest()
{
var connection = Substitute.For<IApiConnection>();
var client = new DeploymentStatusClient(connection);
var expectedUrl = "repos/owner/repo/deployments/1/statuses";
client.Create("owner", "repo", 1, newDeploymentStatus);
connection.Received().Post<DeploymentStatus>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
newDeploymentStatus,
Arg.Any<string>());
}
[Fact]
public void SendsPreviewAcceptHeaders()
{
var connection = Substitute.For<IApiConnection>();
var client = new DeploymentStatusClient(connection);
var expectedUrl = "repos/owner/repo/deployments/1/statuses";
client.Create("owner", "repo", 1, newDeploymentStatus);
connection.Received(1).Post<DeploymentStatus>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
Arg.Any<NewDeploymentStatus>(),
Arg.Is<string>(s => s == AcceptHeaders.DeploymentApiPreview));
}
}
@@ -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<Deployment>(Arg.Is<Uri>(u => u.ToString() == expectedUrl), Args.ApiOptions);
.GetAll<Deployment>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
Arg.Any<IDictionary<string, string>>(),
Arg.Any<string>(),
Args.ApiOptions);
}
[Fact]
@@ -73,7 +77,25 @@ public class DeploymentsClientTests
client.GetAll(owner, name, options);
connection.Received(1)
.GetAll<Deployment>(Arg.Is<Uri>(u => u.ToString() == expectedUrl), options);
.GetAll<Deployment>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
Arg.Any<IDictionary<string, string>>(),
Arg.Any<string>(),
options);
}
[Fact]
public void RequestsCorrectUrlWithPreviewAcceptHeaders()
{
var connection = Substitute.For<IApiConnection>();
var client = new DeploymentsClient(connection);
var expectedUrl = string.Format("repos/{0}/{1}/deployments", owner, name);
client.GetAll(owner, name);
connection.Received(1)
.GetAll<Deployment>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
Arg.Any<IDictionary<string, string>>(),
Arg.Is<string>(s => s == AcceptHeaders.DeploymentApiPreview),
Args.ApiOptions);
}
}
@@ -124,7 +146,8 @@ public class DeploymentsClientTests
client.Create("owner", "name", newDeployment);
connection.Received(1).Post<Deployment>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
Arg.Any<NewDeployment>());
Arg.Any<NewDeployment>(),
Arg.Any<string>());
}
[Fact]
@@ -136,7 +159,21 @@ public class DeploymentsClientTests
client.Create("owner", "name", newDeployment);
connection.Received(1).Post<Deployment>(Arg.Any<Uri>(),
newDeployment);
newDeployment,
Arg.Any<string>());
}
[Fact]
public void SendsPreviewAcceptHeaders()
{
var connection = Substitute.For<IApiConnection>();
var client = new DeploymentsClient(connection);
client.Create("owner", "name", newDeployment);
connection.Received(1).Post<Deployment>(Arg.Any<Uri>(),
Arg.Any<NewDeployment>(),
Arg.Is<string>(s => s == AcceptHeaders.DeploymentApiPreview));
}
}
+6 -2
View File
@@ -54,7 +54,10 @@ namespace Octokit
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(options, "options");
return ApiConnection.GetAll<DeploymentStatus>(ApiUrls.DeploymentStatuses(owner, name, deploymentId), options);
return ApiConnection.GetAll<DeploymentStatus>(ApiUrls.DeploymentStatuses(owner, name, deploymentId),
null,
AcceptHeaders.DeploymentApiPreview,
options);
}
/// <summary>
@@ -76,7 +79,8 @@ namespace Octokit
Ensure.ArgumentNotNull(newDeploymentStatus, "newDeploymentStatus");
return ApiConnection.Post<DeploymentStatus>(ApiUrls.DeploymentStatuses(owner, name, deploymentId),
newDeploymentStatus);
newDeploymentStatus,
AcceptHeaders.DeploymentApiPreview);
}
}
}
+6 -2
View File
@@ -57,7 +57,10 @@ namespace Octokit
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(options, "options");
return ApiConnection.GetAll<Deployment>(ApiUrls.Deployments(owner, name), options);
return ApiConnection.GetAll<Deployment>(ApiUrls.Deployments(owner, name),
null,
AcceptHeaders.DeploymentApiPreview,
options);
}
/// <summary>
@@ -78,7 +81,8 @@ namespace Octokit
Ensure.ArgumentNotNull(newDeployment, "newDeployment");
return ApiConnection.Post<Deployment>(ApiUrls.Deployments(owner, name),
newDeployment);
newDeployment,
AcceptHeaders.DeploymentApiPreview);
}
/// <summary>
+2
View File
@@ -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";
}
}
+12
View File
@@ -74,6 +74,18 @@ namespace Octokit
/// </summary>
public string Description { get; set; }
/// <summary>
/// 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)
/// </summary>
public bool? TransientEnvironment { get; set; }
/// <summary>
/// Indicates if the environment is one with which end users directly interact.
/// (DEFAULT if not specified: True when environment is "production" and False otherwise)
/// </summary>
public bool? ProductionEnvironment { get; set; }
internal string DebuggerDisplay
{
get
@@ -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
/// </summary>
[Obsolete("This property is obsolete. Use LogUrl instead.", false)]
public string TargetUrl { get; set; }
/// <summary>
/// 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
/// </summary>
public string LogUrl { get; set; }
/// <summary>
/// A short description of the status.
/// </summary>
public string Description { get; set; }
/// <summary>
/// The URL for accessing your environment.
/// </summary>
public string EnvironmentUrl { 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
/// name as the created status's deployment.
/// (DEFAULT if not specified: True)
/// </summary>
public bool? AutoInactive { get; set; }
internal string DebuggerDisplay
{
get
+10
View File
@@ -71,6 +71,16 @@ namespace Octokit
/// </summary>
public string StatusesUrl { get; protected set; }
/// <summary>
/// Indicates if the environment is specific to a deployment and will no longer exist at some point in the future.
/// </summary>
public bool TransientEnvironment { get; protected set; }
/// <summary>
/// Indicates if the environment is one with which end users directly interact.
/// </summary>
public bool ProductionEnvironment { get; protected set; }
internal string DebuggerDisplay
{
get
+14 -1
View File
@@ -55,6 +55,18 @@ namespace Octokit
/// </summary>
public string TargetUrl { get; protected set; }
/// <summary>
/// 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
/// </summary>
public string LogUrl { get; protected set; }
/// <summary>
/// The URL for accessing your environment.
/// </summary>
public string EnvironmentUrl { get; protected set; }
/// <summary>
/// The date and time that the status was created.
/// </summary>
@@ -84,6 +96,7 @@ namespace Octokit
Pending,
Success,
Error,
Failure
Failure,
Inactive
}
}