Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added missing fields for deployments API #2560

Merged
merged 7 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion Octokit.Tests.Integration/Octokit.Tests.Integration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
32 changes: 22 additions & 10 deletions Octokit.Tests/Models/DeploymentTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Security.Policy;
using Octokit.Internal;
using Xunit;

Expand All @@ -13,25 +14,33 @@ public void CanSerialize()
{
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);
}

[Fact]
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"",
Expand All @@ -46,24 +55,27 @@ public void CanDeserialize()
""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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Octokit.Tests/Octokit.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
28 changes: 26 additions & 2 deletions Octokit/Models/Response/Deployment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,22 @@ public class Deployment
{
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;
CreatedAt = createdAt;
UpdatedAt = updatedAt;
Description = description;
StatusesUrl = statusesUrl;
RepositoryUrl = repositoryUrl;
Environment = environment;
OriginalEnvironment = originalEnvironment;
TransientEnvironment = transientEnvironment;
ProductionEnvironment = productionEnvironment;
Task = task;
Expand All @@ -41,10 +45,15 @@ public Deployment(int id, string nodeId, string sha, string url, User creator, I
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>
Expand Down Expand Up @@ -80,6 +89,21 @@ public Deployment(int id, string nodeId, string sha, string url, User creator, I
/// </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>
Expand Down