From 4b25e827b398aff02a53bd21b81a09f903da1fde Mon Sep 17 00:00:00 2001 From: Liam Neville Date: Wed, 20 Sep 2023 14:57:31 -0400 Subject: [PATCH 1/4] add suspended_at and suspended_by --- Octokit/Models/Response/Installation.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Octokit/Models/Response/Installation.cs b/Octokit/Models/Response/Installation.cs index 99d4e372f9..66bddce703 100644 --- a/Octokit/Models/Response/Installation.cs +++ b/Octokit/Models/Response/Installation.cs @@ -16,7 +16,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 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 events, string singleFileName, string repositorySelection, User suspendedBy, DateTimeOffset? suspendedAt) : base(id) { Account = account; AccessTokensUrl = accessTokensUrl; @@ -29,6 +29,8 @@ public Installation(long id, User account, string accessTokensUrl, string reposi Events = events; SingleFileName = singleFileName; RepositorySelection = repositorySelection; + SuspendedBy = suspendedBy; + SuspendedAt = suspendedAt; } /// @@ -80,6 +82,16 @@ public Installation(long id, User account, string accessTokensUrl, string reposi /// public StringEnum RepositorySelection { get; private set; } + /// + /// The user who suspended the Installation. Can be null if the Installation is not suspended. + /// + public User SuspendedBy { get; private set; } + + /// + /// The date the Installation was suspended. Can be null if the Installation is not suspended. + /// + public DateTimeOffset? SuspendedAt { get; private set; } + internal new string DebuggerDisplay => string.Format(CultureInfo.InvariantCulture, "Id: {0} AppId: {1}", Id, AppId); } From f42cc8898983fb7d2c42030ef6b7fb5700462643 Mon Sep 17 00:00:00 2001 From: Liam Neville Date: Wed, 20 Sep 2023 14:47:13 -0500 Subject: [PATCH 2/4] nullable ref types, installation model updates --- Octokit.Tests/Models/InstallationTests.cs | 165 ++++++++++++++++++++++ Octokit/Models/Response/Installation.cs | 7 +- Octokit/Octokit.csproj | 2 + 3 files changed, 171 insertions(+), 3 deletions(-) create mode 100644 Octokit.Tests/Models/InstallationTests.cs diff --git a/Octokit.Tests/Models/InstallationTests.cs b/Octokit.Tests/Models/InstallationTests.cs new file mode 100644 index 0000000000..5a5e71ba34 --- /dev/null +++ b/Octokit.Tests/Models/InstallationTests.cs @@ -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>(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>(json); + + Assert.NotNull(installations); + Assert.NotEmpty(installations); + Assert.Equal(1, installations.Count); + Assert.NotNull(installations.First().SuspendedAt); + Assert.NotNull(installations.First().SuspendedBy); + + } + } +} diff --git a/Octokit/Models/Response/Installation.cs b/Octokit/Models/Response/Installation.cs index 66bddce703..2b83882932 100644 --- a/Octokit/Models/Response/Installation.cs +++ b/Octokit/Models/Response/Installation.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using Octokit.Internal; @@ -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 events, string singleFileName, string repositorySelection, User suspendedBy, DateTimeOffset? suspendedAt) : base(id) + public Installation(long id, User account, string accessTokensUrl, string repositoriesUrl, string htmlUrl, long appId, long targetId, AccountType targetType, InstallationPermissions permissions, IReadOnlyList events, string singleFileName, string repositorySelection, User? suspendedBy, DateTimeOffset? suspendedAt) : base(id) { Account = account; AccessTokensUrl = accessTokensUrl; @@ -85,7 +86,7 @@ public Installation(long id, User account, string accessTokensUrl, string reposi /// /// The user who suspended the Installation. Can be null if the Installation is not suspended. /// - public User SuspendedBy { get; private set; } + public User? SuspendedBy { get; private set; } /// /// The date the Installation was suspended. Can be null if the Installation is not suspended. diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index ebee405f40..cc5a5e9697 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -17,6 +17,8 @@ MIT GitHub API Octokit linqpad-samples dotnetcore Copyright GitHub 2017 + 9 + enable From c8021215a1f4add756a3a1f3c52d985950e9e0fe Mon Sep 17 00:00:00 2001 From: Liam Neville Date: Wed, 20 Sep 2023 15:56:06 -0400 Subject: [PATCH 3/4] update int tests --- Octokit.Tests.Integration/Clients/GitHubAppsClientTests.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Octokit.Tests.Integration/Clients/GitHubAppsClientTests.cs b/Octokit.Tests.Integration/Clients/GitHubAppsClientTests.cs index e5f97e77ef..a445e3c783 100644 --- a/Octokit.Tests.Integration/Clients/GitHubAppsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/GitHubAppsClientTests.cs @@ -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); } } } From 12e7542b9b8097cb6366c222396cf5bee385cfb9 Mon Sep 17 00:00:00 2001 From: Liam Neville Date: Thu, 21 Sep 2023 12:49:54 -0500 Subject: [PATCH 4/4] revert nullable change --- Octokit/Models/Response/Installation.cs | 4 ++-- Octokit/Octokit.csproj | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Octokit/Models/Response/Installation.cs b/Octokit/Models/Response/Installation.cs index 2b83882932..60f4c126e0 100644 --- a/Octokit/Models/Response/Installation.cs +++ b/Octokit/Models/Response/Installation.cs @@ -17,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 events, string singleFileName, string repositorySelection, User? suspendedBy, DateTimeOffset? suspendedAt) : base(id) + public Installation(long id, User account, string accessTokensUrl, string repositoriesUrl, string htmlUrl, long appId, long targetId, AccountType targetType, InstallationPermissions permissions, IReadOnlyList events, string singleFileName, string repositorySelection, User suspendedBy, DateTimeOffset? suspendedAt) : base(id) { Account = account; AccessTokensUrl = accessTokensUrl; @@ -86,7 +86,7 @@ public Installation(long id, User account, string accessTokensUrl, string reposi /// /// The user who suspended the Installation. Can be null if the Installation is not suspended. /// - public User? SuspendedBy { get; private set; } + public User SuspendedBy { get; private set; } /// /// The date the Installation was suspended. Can be null if the Installation is not suspended. diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index cc5a5e9697..ebee405f40 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -17,8 +17,6 @@ MIT GitHub API Octokit linqpad-samples dotnetcore Copyright GitHub 2017 - 9 - enable