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

Add suspended_at and suspended_by to the Installation model #2779

Merged
merged 5 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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: 2 additions & 0 deletions Octokit.Tests.Integration/Clients/GitHubAppsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public async Task GetsAllInstallations()
Assert.Equal(InstallationReadWritePermissionLevel.Read, installation.Permissions.Metadata);
Assert.False(string.IsNullOrEmpty(installation.HtmlUrl));
Assert.NotEqual(0, installation.TargetId);
Assert.Null(installation.SuspendedBy);
Assert.Null(installation.SuspendedAt);
}
}
}
Expand Down
165 changes: 165 additions & 0 deletions Octokit.Tests/Models/InstallationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
using System.Collections.Generic;
using System.Linq;
using Octokit.Internal;
using Xunit;

namespace Octokit.Tests.Models
{
public class InstallationResponseTests
{
[Fact]
public void CanBeDeserialized()
{
const string json = @"[
{
""id"": 1,
""account"": {
""login"": ""octocat"",
""id"": 1,
""node_id"": ""MDQ6VXNlcjE="",
""avatar_url"": ""https://github.com/images/error/octocat_happy.gif"",
""gravatar_id"": """",
""url"": ""https://api.github.com/users/octocat"",
""html_url"": ""https://github.com/octocat"",
""followers_url"": ""https://api.github.com/users/octocat/followers"",
""following_url"": ""https://api.github.com/users/octocat/following{/other_user}"",
""gists_url"": ""https://api.github.com/users/octocat/gists{/gist_id}"",
""starred_url"": ""https://api.github.com/users/octocat/starred{/owner}{/repo}"",
""subscriptions_url"": ""https://api.github.com/users/octocat/subscriptions"",
""organizations_url"": ""https://api.github.com/users/octocat/orgs"",
""repos_url"": ""https://api.github.com/users/octocat/repos"",
""events_url"": ""https://api.github.com/users/octocat/events{/privacy}"",
""received_events_url"": ""https://api.github.com/users/octocat/received_events"",
""type"": ""User"",
""site_admin"": false
},
""access_tokens_url"": ""https://api.github.com/app/installations/1/access_tokens"",
""repositories_url"": ""https://api.github.com/installation/repositories"",
""html_url"": ""https://github.com/organizations/github/settings/installations/1"",
""app_id"": 1,
""target_id"": 1,
""target_type"": ""Organization"",
""permissions"": {
""checks"": ""write"",
""metadata"": ""read"",
""contents"": ""read""
},
""events"": [
""push"",
""pull_request""
],
""single_file_name"": ""config.yaml"",
""has_multiple_single_files"": true,
""single_file_paths"": [
""config.yml"",
"".github/issue_TEMPLATE.md""
],
""repository_selection"": ""selected"",
""created_at"": ""2017-07-08T16:18:44-04:00"",
""updated_at"": ""2017-07-08T16:18:44-04:00"",
""app_slug"": ""github-actions"",
""suspended_at"": null,
""suspended_by"": null
}
]";

var serializer = new SimpleJsonSerializer();

var installations = serializer.Deserialize<IReadOnlyList<Installation>>(json);

Assert.NotNull(installations);
Assert.NotEmpty(installations);
Assert.Equal(1, installations.Count);
Assert.Null(installations.First().SuspendedAt);
Assert.Null(installations.First().SuspendedBy);

}

[Fact]
public void CanBeDeserializedWithSuspendedAtValues()
{
const string json = @"[
{
""id"": 1,
""account"": {
""login"": ""octocat"",
""id"": 1,
""node_id"": ""MDQ6VXNlcjE="",
""avatar_url"": ""https://github.com/images/error/octocat_happy.gif"",
""gravatar_id"": """",
""url"": ""https://api.github.com/users/octocat"",
""html_url"": ""https://github.com/octocat"",
""followers_url"": ""https://api.github.com/users/octocat/followers"",
""following_url"": ""https://api.github.com/users/octocat/following{/other_user}"",
""gists_url"": ""https://api.github.com/users/octocat/gists{/gist_id}"",
""starred_url"": ""https://api.github.com/users/octocat/starred{/owner}{/repo}"",
""subscriptions_url"": ""https://api.github.com/users/octocat/subscriptions"",
""organizations_url"": ""https://api.github.com/users/octocat/orgs"",
""repos_url"": ""https://api.github.com/users/octocat/repos"",
""events_url"": ""https://api.github.com/users/octocat/events{/privacy}"",
""received_events_url"": ""https://api.github.com/users/octocat/received_events"",
""type"": ""User"",
""site_admin"": false
},
""access_tokens_url"": ""https://api.github.com/app/installations/1/access_tokens"",
""repositories_url"": ""https://api.github.com/installation/repositories"",
""html_url"": ""https://github.com/organizations/github/settings/installations/1"",
""app_id"": 1,
""target_id"": 1,
""target_type"": ""Organization"",
""permissions"": {
""checks"": ""write"",
""metadata"": ""read"",
""contents"": ""read""
},
""events"": [
""push"",
""pull_request""
],
""single_file_name"": ""config.yaml"",
""has_multiple_single_files"": true,
""single_file_paths"": [
""config.yml"",
"".github/issue_TEMPLATE.md""
],
""repository_selection"": ""selected"",
""created_at"": ""2017-07-08T16:18:44-04:00"",
""updated_at"": ""2017-07-08T16:18:44-04:00"",
""app_slug"": ""github-actions"",
""suspended_at"": ""2017-07-08T16:18:44-04:00"",
""suspended_by"": {
""login"": ""octocat"",
""id"": 1,
""node_id"": ""MDQ6VXNlcjE="",
""avatar_url"": ""https://github.com/images/error/octocat_happy.gif"",
""gravatar_id"": """",
""url"": ""https://api.github.com/users/octocat"",
""html_url"": ""https://github.com/octocat"",
""followers_url"": ""https://api.github.com/users/octocat/followers"",
""following_url"": ""https://api.github.com/users/octocat/following{/other_user}"",
""gists_url"": ""https://api.github.com/users/octocat/gists{/gist_id}"",
""starred_url"": ""https://api.github.com/users/octocat/starred{/owner}{/repo}"",
""subscriptions_url"": ""https://api.github.com/users/octocat/subscriptions"",
""organizations_url"": ""https://api.github.com/users/octocat/orgs"",
""repos_url"": ""https://api.github.com/users/octocat/repos"",
""events_url"": ""https://api.github.com/users/octocat/events{/privacy}"",
""received_events_url"": ""https://api.github.com/users/octocat/received_events"",
""type"": ""User"",
""site_admin"": false
}
}
]";

var serializer = new SimpleJsonSerializer();

var installations = serializer.Deserialize<IReadOnlyList<Installation>>(json);

Assert.NotNull(installations);
Assert.NotEmpty(installations);
Assert.Equal(1, installations.Count);
Assert.NotNull(installations.First().SuspendedAt);
Assert.NotNull(installations.First().SuspendedBy);

}
}
}
17 changes: 15 additions & 2 deletions Octokit/Models/Response/Installation.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using Octokit.Internal;
Expand All @@ -16,7 +17,7 @@ public class Installation : InstallationId
{
public Installation() { }

public Installation(long id, User account, string accessTokensUrl, string repositoriesUrl, string htmlUrl, long appId, long targetId, AccountType targetType, InstallationPermissions permissions, IReadOnlyList<string> events, string singleFileName, string repositorySelection) : base(id)
public Installation(long id, User account, string accessTokensUrl, string repositoriesUrl, string htmlUrl, long appId, long targetId, AccountType targetType, InstallationPermissions permissions, IReadOnlyList<string> events, string singleFileName, string repositorySelection, User? suspendedBy, DateTimeOffset? suspendedAt) : base(id)
{
Account = account;
AccessTokensUrl = accessTokensUrl;
Expand All @@ -29,6 +30,8 @@ public Installation(long id, User account, string accessTokensUrl, string reposi
Events = events;
SingleFileName = singleFileName;
RepositorySelection = repositorySelection;
SuspendedBy = suspendedBy;
SuspendedAt = suspendedAt;
}

/// <summary>
Expand Down Expand Up @@ -80,6 +83,16 @@ public Installation(long id, User account, string accessTokensUrl, string reposi
/// </summary>
public StringEnum<InstallationRepositorySelection> RepositorySelection { get; private set; }

/// <summary>
/// The user who suspended the Installation. Can be null if the Installation is not suspended.
/// </summary>
public User? SuspendedBy { get; private set; }

/// <summary>
/// The date the Installation was suspended. Can be null if the Installation is not suspended.
/// </summary>
public DateTimeOffset? SuspendedAt { get; private set; }

internal new string DebuggerDisplay => string.Format(CultureInfo.InvariantCulture, "Id: {0} AppId: {1}", Id, AppId);
}

Expand Down
2 changes: 2 additions & 0 deletions Octokit/Octokit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageTags>GitHub API Octokit linqpad-samples dotnetcore</PackageTags>
<Copyright>Copyright GitHub 2017</Copyright>
<LangVersion>9</LangVersion>
lineville marked this conversation as resolved.
Show resolved Hide resolved
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup>
Expand Down
Loading