Adds missing fields for deployments API (#2560)

This commit is contained in:
Hans Bakker
2022-09-12 20:37:54 +02:00
committed by GitHub
parent 9ceb1885dc
commit 098557b767
5 changed files with 51 additions and 15 deletions
@@ -4,7 +4,7 @@
<Description>Convention-based tests for Octokit</Description>
<AssemblyTitle>Octokit.Tests.Conventions</AssemblyTitle>
<Authors>GitHub</Authors>
<TargetFrameworks>netcoreapp3.1;net462</TargetFrameworks>
<TargetFrameworks>net6.0;netcoreapp3.1;net462</TargetFrameworks>
<NoWarn>$(NoWarn);CS4014;CS1998</NoWarn>
<AssemblyName>Octokit.Tests.Conventions</AssemblyName>
<PackageId>Octokit.Tests.Conventions</PackageId>
@@ -4,7 +4,7 @@
<Description>Integration tests for Octokit</Description>
<AssemblyTitle>Octokit.Tests.Integration</AssemblyTitle>
<Authors>GitHub</Authors>
<TargetFrameworks>netcoreapp3.1;net462</TargetFrameworks>
<TargetFrameworks>net6.0;netcoreapp3.1;net462</TargetFrameworks>
<NoWarn>$(NoWarn);CS4014;CS1998</NoWarn>
<AssemblyName>Octokit.Tests.Integration</AssemblyName>
<PackageId>Octokit.Tests.Integration</PackageId>
+22 -10
View File
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Security.Policy;
using Octokit.Internal;
using Xunit;
@@ -13,10 +14,10 @@ namespace Octokit.Tests.Models
{
var deployment = new NewDeployment("ref")
{
Payload = new Dictionary<string, string> {{"environment", "production"}}
Payload = new Dictionary<string, string> { { "environment", "production" } }
};
var deserialized = new SimpleJsonSerializer().Serialize(deployment);
Assert.Equal(@"{""ref"":""ref"",""payload"":{""environment"":""production""}}", deserialized);
}
@@ -24,14 +25,22 @@ namespace Octokit.Tests.Models
public void CanDeserialize()
{
const string json = @"{
""id"": 1,
""sha"": ""topic-branch"",
""url"": ""https://api.github.com/repos/octocat/example/deployments/1"",
""id"": 1,
""node_id"": ""MDEwOkRlcGxveW1lbnQx"",
""sha"": ""a84d88e7554fc1fa21bcbc4efae3c782a70d2b9d"",
""ref"": ""topic-branch"",
""task"": ""deploy"",
""payload"": {},
""original_environment"": ""staging"",
""environment"": ""production"",
""description"": ""Deploy request from hubot"",
""creator"": {
""login"": ""octocat"",
""id"": 1,
""node_id"": ""MDQ6VXNlcjE="",
""avatar_url"": ""https://github.com/images/error/octocat_happy.gif"",
""gravatar_id"": ""somehexcode"",
""gravatar_id"": """",
""url"": ""https://api.github.com/users/octocat"",
""html_url"": ""https://github.com/octocat"",
""followers_url"": ""https://api.github.com/users/octocat/followers"",
@@ -46,24 +55,27 @@ namespace Octokit.Tests.Models
""type"": ""User"",
""site_admin"": false
},
""payload"": { ""environment"":""production""},
""created_at"": ""2012-07-20T01:19:13Z"",
""updated_at"": ""2012-07-20T01:19:13Z"",
""description"": ""Deploy request from hubot"",
""statuses_url"": ""https://api.github.com/repos/octocat/example/deployments/1/statuses"",
""task"": ""deploy""
""repository_url"": ""https://api.github.com/repos/octocat/example"",
""transient_environment"": false,
""production_environment"": true
}";
var actual = new SimpleJsonSerializer().Deserialize<Deployment>(json);
Assert.Equal(1, actual.Id);
Assert.Equal("topic-branch", actual.Sha);
Assert.Equal("a84d88e7554fc1fa21bcbc4efae3c782a70d2b9d", actual.Sha);
Assert.Equal("topic-branch", actual.Ref);
Assert.Equal("https://api.github.com/repos/octocat/example/deployments/1", actual.Url);
Assert.Equal(new ReadOnlyDictionary<string, string>(new Dictionary<string, string> { { "environment", "production" } }), actual.Payload);
Assert.Equal("production", actual.Environment);
Assert.Equal("staging", actual.OriginalEnvironment);
Assert.Equal(DateTimeOffset.Parse("2012-07-20T01:19:13Z"), actual.CreatedAt);
Assert.Equal(DateTimeOffset.Parse("2012-07-20T01:19:13Z"), actual.UpdatedAt);
Assert.Equal("Deploy request from hubot", actual.Description);
Assert.Equal("https://api.github.com/repos/octocat/example/deployments/1/statuses", actual.StatusesUrl);
Assert.Equal("https://api.github.com/repos/octocat/example", actual.RepositoryUrl);
Assert.Equal("deploy", actual.Task);
}
}
+1 -1
View File
@@ -4,7 +4,7 @@
<Description>Tests for Octokit</Description>
<AssemblyTitle>Octokit.Tests</AssemblyTitle>
<Authors>GitHub</Authors>
<TargetFrameworks>netcoreapp3.1;net462</TargetFrameworks>
<TargetFrameworks>net6.0;netcoreapp3.1;net462</TargetFrameworks>
<NoWarn>$(NoWarn);CS4014;CS1998</NoWarn>
<AssemblyName>Octokit.Tests</AssemblyName>
<PackageId>Octokit.Tests</PackageId>
+26 -2
View File
@@ -13,11 +13,12 @@ namespace Octokit
{
public Deployment() { }
public Deployment(int id, string nodeId, string sha, string url, User creator, IReadOnlyDictionary<string, string> payload, DateTimeOffset createdAt, DateTimeOffset updatedAt, string description, string statusesUrl, bool transientEnvironment, bool productionEnvironment, string task)
public Deployment(int id, string nodeId, string sha, string @ref, string url, User creator, IReadOnlyDictionary<string, string> payload, DateTimeOffset createdAt, DateTimeOffset updatedAt, string description, string statusesUrl, string repositoryUrl, string environment, string originalEnvironment, bool transientEnvironment, bool productionEnvironment, string task)
{
Id = id;
NodeId = nodeId;
Sha = sha;
Ref = @ref;
Url = url;
Creator = creator;
Payload = payload;
@@ -25,6 +26,9 @@ namespace Octokit
UpdatedAt = updatedAt;
Description = description;
StatusesUrl = statusesUrl;
RepositoryUrl = repositoryUrl;
Environment = environment;
OriginalEnvironment = originalEnvironment;
TransientEnvironment = transientEnvironment;
ProductionEnvironment = productionEnvironment;
Task = task;
@@ -41,10 +45,15 @@ namespace Octokit
public string NodeId { get; private set; }
/// <summary>
///
/// The SHA recorded at creation time.
/// </summary>
public string Sha { get; private set; }
/// <summary>
/// The name of the ref. This can be a branch, tag, or SHA.
/// </summary>
public string Ref { get; private set; }
/// <summary>
/// The API URL for this deployment.
/// </summary>
@@ -80,6 +89,21 @@ namespace Octokit
/// </summary>
public string StatusesUrl { get; private set; }
/// <summary>
/// The API URL for the <seealso cref="Repository"/> of this deployment.
/// </summary>
public string RepositoryUrl { get; private set; }
/// <summary>
/// The name of the <seealso cref="Environment"/> that was deployed to (e.g., staging or production).
/// </summary>
public string Environment { get; private set; }
/// <summary>
/// The name of the that was originally deployed to (e.g., staging or production).
/// </summary>
public string OriginalEnvironment { get; private set; }
/// <summary>
/// Indicates if the environment is specific to a deployment and will no longer exist at some point in the future.
/// </summary>