From 06c9fcd932ff2cf7a4f1d00eab94cbef72ce1742 Mon Sep 17 00:00:00 2001 From: Roman Zabaluev Date: Thu, 3 Aug 2023 01:49:19 +0800 Subject: [PATCH 01/11] Do not populate repo list in case of installation:deleted event --- src/main/java/org/kohsuke/github/GHEventPayload.java | 5 +++++ src/test/java/org/kohsuke/github/GHEventPayloadTest.java | 8 ++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHEventPayload.java b/src/main/java/org/kohsuke/github/GHEventPayload.java index b6549faadd..3f19496dc9 100644 --- a/src/main/java/org/kohsuke/github/GHEventPayload.java +++ b/src/main/java/org/kohsuke/github/GHEventPayload.java @@ -286,6 +286,11 @@ void lateBind() { "Expected installation payload, but got something else. Maybe we've got another type of event?"); } super.lateBind(); + + if ("deleted".equalsIgnoreCase(getAction())) { + repositories.clear(); // can't populate repo list on a deleted installation + } + if (repositories != null && !repositories.isEmpty()) { try { for (GHRepository singleRepo : repositories) { diff --git a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java index 1b3be27bd4..e077ce55c6 100644 --- a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java +++ b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java @@ -26,6 +26,7 @@ import static org.hamcrest.Matchers.sameInstance; import static org.hamcrest.Matchers.startsWith; import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; // TODO: Auto-generated Javadoc /** @@ -1000,12 +1001,7 @@ public void InstallationEvent() throws Exception { assertThat(event.getInstallation().getId(), is(2L)); assertThat(event.getInstallation().getAccount().getLogin(), is("octocat")); - assertThat(event.getRepositories().get(0).getId(), is(1296269L)); - assertThat(event.getRepositories().get(0).getNodeId(), is("MDEwOlJlcG9zaXRvcnkxMjk2MjY5")); - assertThat(event.getRepositories().get(0).getName(), is("Hello-World")); - assertThat(event.getRepositories().get(0).getFullName(), is("octocat/Hello-World")); - assertThat(event.getRepositories().get(0).isPrivate(), is(false)); - assertThat(event.getRepositories().get(0).getOwner().getLogin(), is("octocat")); + assertTrue(event.getRepositories().isEmpty()); assertThat(event.getSender().getLogin(), is("octocat")); } From 89c51f6b459fcd9e333290ca95794e078822b481 Mon Sep 17 00:00:00 2001 From: Roman Zabaluev Date: Sat, 11 Nov 2023 11:55:03 +0800 Subject: [PATCH 02/11] Implement discussed way to handle the situation --- .../org/kohsuke/github/GHEventPayload.java | 107 ++++++++++++++--- .../kohsuke/github/GHEventPayloadTest.java | 30 ++++- .../installation_created.json | 98 ++++++++++++++++ ...llation.json => installation_deleted.json} | 0 .../__files/repos_octocat_hello-world-1.json | 0 .../mappings/repos_octocat_hello-world-1.json | 0 .../__files/repos_octocat_hello-world-1.json | 108 ++++++++++++++++++ .../__files/users_octocat-2.json | 0 .../mappings/repos_octocat_hello-world-1.json | 47 ++++++++ .../mappings/users_octocat-2.json | 0 10 files changed, 371 insertions(+), 19 deletions(-) create mode 100644 src/test/resources/org/kohsuke/github/GHEventPayloadTest/installation_created.json rename src/test/resources/org/kohsuke/github/GHEventPayloadTest/{installation.json => installation_deleted.json} (100%) rename src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/{InstallationEvent => InstallationCreatedEvent}/__files/repos_octocat_hello-world-1.json (100%) rename src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/{InstallationEvent => InstallationCreatedEvent}/mappings/repos_octocat_hello-world-1.json (100%) create mode 100644 src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationDeletedEvent/__files/repos_octocat_hello-world-1.json rename src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/{InstallationEvent => InstallationDeletedEvent}/__files/users_octocat-2.json (100%) create mode 100644 src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationDeletedEvent/mappings/repos_octocat_hello-world-1.json rename src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/{InstallationEvent => InstallationDeletedEvent}/mappings/users_octocat-2.json (100%) diff --git a/src/main/java/org/kohsuke/github/GHEventPayload.java b/src/main/java/org/kohsuke/github/GHEventPayload.java index 3f19496dc9..8c0615005c 100644 --- a/src/main/java/org/kohsuke/github/GHEventPayload.java +++ b/src/main/java/org/kohsuke/github/GHEventPayload.java @@ -1,5 +1,6 @@ package org.kohsuke.github; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonSetter; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; @@ -9,6 +10,7 @@ import java.util.Date; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; // TODO: Auto-generated Javadoc /** @@ -265,16 +267,68 @@ void lateBind() { * @see GitHub App Installation */ public static class Installation extends GHEventPayload { + + private boolean reposLoaded = false; private List repositories; + private List rawRepositories; /** * Gets repositories. + * For the "deleted" action please rather call {@link #getRawRepositories()} * * @return the repositories */ public List getRepositories() { + if ("deleted".equalsIgnoreCase(getAction())) { + throw new IllegalStateException("Can't call #getRepositories() on Installation event " + + "with 'deleted' action. Please rather call #getRawRepositories()"); + } + + if (reposLoaded) { + return Collections.unmodifiableList(repositories); + } + + if (repositories == null || repositories.isEmpty()) { + return Collections.emptyList(); + } + + try { + for (GHRepository singleRepo : repositories) { + // populate each repository + // the repository information provided here is so limited + // as to be unusable without populating, so we do it eagerly + singleRepo.populate(); + } + } catch (IOException e) { + throw new GHException("Failed to refresh repositories", e); + } finally { + reposLoaded = true; + } + return Collections.unmodifiableList(repositories); - }; + } + + ; + + /** + * Returns a list of raw, unpopulated repositories. + * Useful when calling from within Installation event with action "deleted". + * You can't fetch the info for repositories of an already deleted installation. + * + * @return List + */ + public List getRawRepositories() { + return Collections.unmodifiableList(rawRepositories); + } + + @JsonSetter + public void setRepositories(List repositories) { + this.repositories = repositories; + this.rawRepositories = repositories + .stream() + .map(r -> new Repository(r.getId(), r.getFullName(), r.getName(), r.getNodeId(), r.isPrivate())) + .collect(Collectors.toList()); + } /** * Late bind. @@ -286,22 +340,47 @@ void lateBind() { "Expected installation payload, but got something else. Maybe we've got another type of event?"); } super.lateBind(); + } - if ("deleted".equalsIgnoreCase(getAction())) { - repositories.clear(); // can't populate repo list on a deleted installation + /** + * A special minimal implementation of a {@link GHRepository} which contains + * only fields from "Properties of repositories" from + * here + */ + public static class Repository { + private final long id; + private final String fullName; + private final String name; + private final String nodeId; + @JsonProperty(value = "private") + private boolean isPrivate; + + public Repository(long id, String fullName, String name, String nodeId, boolean isPrivate) { + this.id = id; + this.fullName = fullName; + this.name = name; + this.nodeId = nodeId; + this.isPrivate = isPrivate; } - if (repositories != null && !repositories.isEmpty()) { - try { - for (GHRepository singleRepo : repositories) { - // populate each repository - // the repository information provided here is so limited - // as to be unusable without populating, so we do it eagerly - singleRepo.populate(); - } - } catch (IOException e) { - throw new GHException("Failed to refresh repositories", e); - } + public long getId() { + return id; + } + + public String getFullName() { + return fullName; + } + + public String getName() { + return name; + } + + public String getNodeId() { + return nodeId; + } + + public boolean isPrivate() { + return isPrivate; } } } diff --git a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java index 0b905426c8..bfbabe239b 100644 --- a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java +++ b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java @@ -25,8 +25,7 @@ import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.sameInstance; import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; // TODO: Auto-generated Javadoc /** @@ -984,6 +983,25 @@ public void InstallationRepositoriesEvent() throws Exception { assertThat(event.getSender().getLogin(), is("Codertocat")); } + @Test + @Payload("installation_created") + public void InstallationCreatedEvent() throws Exception { + final GHEventPayload.Installation event = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl()) + .build() + .parseEventPayload(payload.asReader(), GHEventPayload.Installation.class); + + assertThat(event.getAction(), is("created")); + assertThat(event.getInstallation().getId(), is(43898337L)); + assertThat(event.getInstallation().getAccount().getLogin(), is("CronFire")); + + assertFalse(event.getRepositories().isEmpty()); + assertEquals(event.getRepositories().get(0).getId(), 1296269); + assertFalse(event.getRawRepositories().isEmpty()); + assertEquals(event.getRawRepositories().get(0).getId(), 1296269); + + assertThat(event.getSender().getLogin(), is("Haarolean")); + } + /** * Installation event. * @@ -991,8 +1009,8 @@ public void InstallationRepositoriesEvent() throws Exception { * the exception */ @Test - @Payload("installation") - public void InstallationEvent() throws Exception { + @Payload("installation_deleted") + public void InstallationDeletedEvent() throws Exception { final GHEventPayload.Installation event = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl()) .build() .parseEventPayload(payload.asReader(), GHEventPayload.Installation.class); @@ -1001,7 +1019,9 @@ public void InstallationEvent() throws Exception { assertThat(event.getInstallation().getId(), is(2L)); assertThat(event.getInstallation().getAccount().getLogin(), is("octocat")); - assertTrue(event.getRepositories().isEmpty()); + assertThrows(IllegalStateException.class, () -> event.getRepositories().isEmpty()); + assertFalse(event.getRawRepositories().isEmpty()); + assertEquals(event.getRawRepositories().get(0).getId(), 1296269); assertThat(event.getSender().getLogin(), is("octocat")); } diff --git a/src/test/resources/org/kohsuke/github/GHEventPayloadTest/installation_created.json b/src/test/resources/org/kohsuke/github/GHEventPayloadTest/installation_created.json new file mode 100644 index 0000000000..d9923841e1 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHEventPayloadTest/installation_created.json @@ -0,0 +1,98 @@ +{ + "action": "created", + "installation": { + "id": 43898337, + "account": { + "login": "CronFire", + "id": 68755481, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjY4NzU1NDgx", + "avatar_url": "https://avatars.githubusercontent.com/u/68755481?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/CronFire", + "html_url": "https://github.com/CronFire", + "followers_url": "https://api.github.com/users/CronFire/followers", + "following_url": "https://api.github.com/users/CronFire/following{/other_user}", + "gists_url": "https://api.github.com/users/CronFire/gists{/gist_id}", + "starred_url": "https://api.github.com/users/CronFire/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/CronFire/subscriptions", + "organizations_url": "https://api.github.com/users/CronFire/orgs", + "repos_url": "https://api.github.com/users/CronFire/repos", + "events_url": "https://api.github.com/users/CronFire/events{/privacy}", + "received_events_url": "https://api.github.com/users/CronFire/received_events", + "type": "Organization", + "site_admin": false + }, + "repository_selection": "selected", + "access_tokens_url": "https://api.github.com/app/installations/43898337/access_tokens", + "repositories_url": "https://api.github.com/installation/repositories", + "html_url": "https://github.com/organizations/CronFire/settings/installations/43898337", + "app_id": 421464, + "app_slug": "kapybro-dev", + "target_id": 68755481, + "target_type": "Organization", + "permissions": { + "checks": "write", + "issues": "write", + "actions": "read", + "members": "read", + "contents": "write", + "metadata": "read", + "statuses": "write", + "single_file": "read", + "pull_requests": "write", + "administration": "read" + }, + "events": [ + "issues", + "issue_comment", + "organization", + "public", + "pull_request", + "pull_request_review", + "pull_request_review_comment", + "push", + "repository", + "status" + ], + "created_at": "2023-11-11T10:55:06.000+08:00", + "updated_at": "2023-11-11T10:55:06.000+08:00", + "single_file_name": ".github/kapybro/config.yml", + "has_multiple_single_files": true, + "single_file_paths": [ + ".github/kapybro/config.yml", + ".github/kapybro/rules.yml" + ], + "suspended_by": null, + "suspended_at": null + }, + "repositories": [ + { + "id": 1296269, + "node_id": "MDEwOlJlcG9zaXRvcnkxMjk2MjY5", + "name": "Hello-World", + "full_name": "octocat/Hello-World", + "private": false + } + ], + "requester": null, + "sender": { + "login": "Haarolean", + "id": 1494347, + "node_id": "MDQ6VXNlcjE0OTQzNDc=", + "avatar_url": "https://avatars.githubusercontent.com/u/1494347?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/Haarolean", + "html_url": "https://github.com/Haarolean", + "followers_url": "https://api.github.com/users/Haarolean/followers", + "following_url": "https://api.github.com/users/Haarolean/following{/other_user}", + "gists_url": "https://api.github.com/users/Haarolean/gists{/gist_id}", + "starred_url": "https://api.github.com/users/Haarolean/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/Haarolean/subscriptions", + "organizations_url": "https://api.github.com/users/Haarolean/orgs", + "repos_url": "https://api.github.com/users/Haarolean/repos", + "events_url": "https://api.github.com/users/Haarolean/events{/privacy}", + "received_events_url": "https://api.github.com/users/Haarolean/received_events", + "type": "User", + "site_admin": false + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHEventPayloadTest/installation.json b/src/test/resources/org/kohsuke/github/GHEventPayloadTest/installation_deleted.json similarity index 100% rename from src/test/resources/org/kohsuke/github/GHEventPayloadTest/installation.json rename to src/test/resources/org/kohsuke/github/GHEventPayloadTest/installation_deleted.json diff --git a/src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationEvent/__files/repos_octocat_hello-world-1.json b/src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationCreatedEvent/__files/repos_octocat_hello-world-1.json similarity index 100% rename from src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationEvent/__files/repos_octocat_hello-world-1.json rename to src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationCreatedEvent/__files/repos_octocat_hello-world-1.json diff --git a/src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationEvent/mappings/repos_octocat_hello-world-1.json b/src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationCreatedEvent/mappings/repos_octocat_hello-world-1.json similarity index 100% rename from src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationEvent/mappings/repos_octocat_hello-world-1.json rename to src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationCreatedEvent/mappings/repos_octocat_hello-world-1.json diff --git a/src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationDeletedEvent/__files/repos_octocat_hello-world-1.json b/src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationDeletedEvent/__files/repos_octocat_hello-world-1.json new file mode 100644 index 0000000000..fd3c1ce7ca --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationDeletedEvent/__files/repos_octocat_hello-world-1.json @@ -0,0 +1,108 @@ +{ + "id": 1296269, + "node_id": "MDEwOlJlcG9zaXRvcnkxMjk2MjY5", + "name": "Hello-World", + "full_name": "octocat/Hello-World", + "private": false, + "owner": { + "login": "octocat", + "id": 583231, + "node_id": "MDQ6VXNlcjU4MzIzMQ==", + "avatar_url": "https://avatars.githubusercontent.com/u/583231?v=4", + "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 + }, + "html_url": "https://github.com/octocat/Hello-World", + "description": "My first repository on GitHub!", + "fork": false, + "url": "https://api.github.com/repos/octocat/Hello-World", + "forks_url": "https://api.github.com/repos/octocat/Hello-World/forks", + "keys_url": "https://api.github.com/repos/octocat/Hello-World/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/octocat/Hello-World/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/octocat/Hello-World/teams", + "hooks_url": "https://api.github.com/repos/octocat/Hello-World/hooks", + "issue_events_url": "https://api.github.com/repos/octocat/Hello-World/issues/events{/number}", + "events_url": "https://api.github.com/repos/octocat/Hello-World/events", + "assignees_url": "https://api.github.com/repos/octocat/Hello-World/assignees{/user}", + "branches_url": "https://api.github.com/repos/octocat/Hello-World/branches{/branch}", + "tags_url": "https://api.github.com/repos/octocat/Hello-World/tags", + "blobs_url": "https://api.github.com/repos/octocat/Hello-World/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/octocat/Hello-World/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/octocat/Hello-World/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/octocat/Hello-World/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/octocat/Hello-World/statuses/{sha}", + "languages_url": "https://api.github.com/repos/octocat/Hello-World/languages", + "stargazers_url": "https://api.github.com/repos/octocat/Hello-World/stargazers", + "contributors_url": "https://api.github.com/repos/octocat/Hello-World/contributors", + "subscribers_url": "https://api.github.com/repos/octocat/Hello-World/subscribers", + "subscription_url": "https://api.github.com/repos/octocat/Hello-World/subscription", + "commits_url": "https://api.github.com/repos/octocat/Hello-World/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/octocat/Hello-World/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/octocat/Hello-World/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/octocat/Hello-World/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/octocat/Hello-World/contents/{+path}", + "compare_url": "https://api.github.com/repos/octocat/Hello-World/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/octocat/Hello-World/merges", + "archive_url": "https://api.github.com/repos/octocat/Hello-World/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/octocat/Hello-World/downloads", + "issues_url": "https://api.github.com/repos/octocat/Hello-World/issues{/number}", + "pulls_url": "https://api.github.com/repos/octocat/Hello-World/pulls{/number}", + "milestones_url": "https://api.github.com/repos/octocat/Hello-World/milestones{/number}", + "notifications_url": "https://api.github.com/repos/octocat/Hello-World/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/octocat/Hello-World/labels{/name}", + "releases_url": "https://api.github.com/repos/octocat/Hello-World/releases{/id}", + "deployments_url": "https://api.github.com/repos/octocat/Hello-World/deployments", + "created_at": "2011-01-26T19:01:12Z", + "updated_at": "2022-02-03T00:06:57Z", + "pushed_at": "2022-01-30T18:13:40Z", + "git_url": "git://github.com/octocat/Hello-World.git", + "ssh_url": "git@github.com:octocat/Hello-World.git", + "clone_url": "https://github.com/octocat/Hello-World.git", + "svn_url": "https://github.com/octocat/Hello-World", + "homepage": "", + "size": 1, + "stargazers_count": 1764, + "watchers_count": 1764, + "language": null, + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "forks_count": 1682, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 802, + "license": null, + "allow_forking": true, + "is_template": false, + "topics": [], + "visibility": "public", + "forks": 1682, + "open_issues": 802, + "watchers": 1764, + "default_branch": "master", + "permissions": { + "admin": false, + "maintain": false, + "push": false, + "triage": false, + "pull": true + }, + "temp_clone_token": "", + "network_count": 1682, + "subscribers_count": 1731 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationEvent/__files/users_octocat-2.json b/src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationDeletedEvent/__files/users_octocat-2.json similarity index 100% rename from src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationEvent/__files/users_octocat-2.json rename to src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationDeletedEvent/__files/users_octocat-2.json diff --git a/src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationDeletedEvent/mappings/repos_octocat_hello-world-1.json b/src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationDeletedEvent/mappings/repos_octocat_hello-world-1.json new file mode 100644 index 0000000000..942435fa56 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationDeletedEvent/mappings/repos_octocat_hello-world-1.json @@ -0,0 +1,47 @@ +{ + "id": "825b1b2a-1bcf-4273-9204-54f989479669", + "name": "repos_octocat_hello-world", + "request": { + "url": "/repos/octocat/Hello-World", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.baptiste-preview+json, application/vnd.github.nebula-preview+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "repos_octocat_hello-world-1.json", + "headers": { + "Server": "GitHub.com", + "Date": "Thu, 03 Feb 2022 14:07:49 GMT", + "Content-Type": "application/json; charset=utf-8", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"54ebfbf708e274f11202ea42a54ccb98955c89b119059c79c8f1bf7e76126198\"", + "Last-Modified": "Thu, 03 Feb 2022 00:06:57 GMT", + "X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, gist, notifications, repo, user, workflow, write:discussion", + "X-Accepted-OAuth-Scopes": "repo", + "X-GitHub-Media-Type": "github.v3; param=baptiste-preview.nebula-preview; format=json", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4999", + "X-RateLimit-Reset": "1643900869", + "X-RateLimit-Used": "1", + "X-RateLimit-Resource": "core", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "0", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "AD00:CEBF:18E9BF0:19A3623:61FBE1B5" + } + }, + "uuid": "825b1b2a-1bcf-4273-9204-54f989479669", + "persistent": true, + "insertionIndex": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationEvent/mappings/users_octocat-2.json b/src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationDeletedEvent/mappings/users_octocat-2.json similarity index 100% rename from src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationEvent/mappings/users_octocat-2.json rename to src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationDeletedEvent/mappings/users_octocat-2.json From b704a77c047ed1bacf7380e3116a1f31e760848f Mon Sep 17 00:00:00 2001 From: Roman Zabaluev Date: Mon, 13 Nov 2023 19:33:50 +0800 Subject: [PATCH 03/11] Fix codestyle --- .../org/kohsuke/github/GHEventPayload.java | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHEventPayload.java b/src/main/java/org/kohsuke/github/GHEventPayload.java index 8c0615005c..b235295701 100644 --- a/src/main/java/org/kohsuke/github/GHEventPayload.java +++ b/src/main/java/org/kohsuke/github/GHEventPayload.java @@ -273,15 +273,14 @@ public static class Installation extends GHEventPayload { private List rawRepositories; /** - * Gets repositories. - * For the "deleted" action please rather call {@link #getRawRepositories()} + * Gets repositories. For the "deleted" action please rather call {@link #getRawRepositories()} * * @return the repositories */ public List getRepositories() { if ("deleted".equalsIgnoreCase(getAction())) { - throw new IllegalStateException("Can't call #getRepositories() on Installation event " + - "with 'deleted' action. Please rather call #getRawRepositories()"); + throw new IllegalStateException("Can't call #getRepositories() on Installation event " + + "with 'deleted' action. Please rather call #getRawRepositories()"); } if (reposLoaded) { @@ -311,9 +310,8 @@ public List getRepositories() { ; /** - * Returns a list of raw, unpopulated repositories. - * Useful when calling from within Installation event with action "deleted". - * You can't fetch the info for repositories of an already deleted installation. + * Returns a list of raw, unpopulated repositories. Useful when calling from within Installation event with + * action "deleted". You can't fetch the info for repositories of an already deleted installation. * * @return List */ @@ -324,8 +322,7 @@ public List getRawRepositories() { @JsonSetter public void setRepositories(List repositories) { this.repositories = repositories; - this.rawRepositories = repositories - .stream() + this.rawRepositories = repositories.stream() .map(r -> new Repository(r.getId(), r.getFullName(), r.getName(), r.getNodeId(), r.isPrivate())) .collect(Collectors.toList()); } @@ -343,9 +340,9 @@ void lateBind() { } /** - * A special minimal implementation of a {@link GHRepository} which contains - * only fields from "Properties of repositories" from - * here + * A special minimal implementation of a {@link GHRepository} which contains only fields from "Properties of + * repositories" from here */ public static class Repository { private final long id; From 71fbe49e73459b2cc0df0e92615b291f68a3151e Mon Sep 17 00:00:00 2001 From: Roman Zabaluev Date: Thu, 16 Nov 2023 21:45:36 +0800 Subject: [PATCH 04/11] Fix build (I hope?) --- src/main/java/org/kohsuke/github/GHEventPayload.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/kohsuke/github/GHEventPayload.java b/src/main/java/org/kohsuke/github/GHEventPayload.java index b235295701..db454e3036 100644 --- a/src/main/java/org/kohsuke/github/GHEventPayload.java +++ b/src/main/java/org/kohsuke/github/GHEventPayload.java @@ -320,7 +320,7 @@ public List getRawRepositories() { } @JsonSetter - public void setRepositories(List repositories) { + private void setRepositories(List repositories) { this.repositories = repositories; this.rawRepositories = repositories.stream() .map(r -> new Repository(r.getId(), r.getFullName(), r.getName(), r.getNodeId(), r.isPrivate())) From 2711dcf2b5b7b4a2212e3beadf6156355b382e8b Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Tue, 12 Mar 2024 15:55:24 -0700 Subject: [PATCH 05/11] Update GHEventPayload.java --- .../org/kohsuke/github/GHEventPayload.java | 92 ++++++++++--------- 1 file changed, 47 insertions(+), 45 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHEventPayload.java b/src/main/java/org/kohsuke/github/GHEventPayload.java index d3aad9c6f6..af203c2b62 100644 --- a/src/main/java/org/kohsuke/github/GHEventPayload.java +++ b/src/main/java/org/kohsuke/github/GHEventPayload.java @@ -268,9 +268,9 @@ void lateBind() { */ public static class Installation extends GHEventPayload { - private boolean reposLoaded = false; - private List repositories; - private List rawRepositories; + private List ghRepositories = null; + + private List repositories; /** * Gets repositories. For the "deleted" action please rather call {@link #getRawRepositories()} @@ -280,31 +280,24 @@ public static class Installation extends GHEventPayload { public List getRepositories() { if ("deleted".equalsIgnoreCase(getAction())) { throw new IllegalStateException("Can't call #getRepositories() on Installation event " - + "with 'deleted' action. Please rather call #getRawRepositories()"); - } - - if (reposLoaded) { - return Collections.unmodifiableList(repositories); - } - - if (repositories == null || repositories.isEmpty()) { - return Collections.emptyList(); + + "with 'deleted' action. Call #getRawRepositories() instead."); } - try { - for (GHRepository singleRepo : repositories) { - // populate each repository - // the repository information provided here is so limited - // as to be unusable without populating, so we do it eagerly - singleRepo.populate(); + if (ghRepositories == null) { + ghRepositories = new ArrayList<>(repositories.size()); + try { + for (Repository singleRepo : repositories) { + // populate each repository + // the repository information provided here is so limited + // as to be unusable without populating, so we do it eagerly + ghRepositories.add(this.root().getRepositoryById(singleRepo.getId())); + } + } catch (IOException e) { + throw new GHException("Failed to refresh repositories", e); } - } catch (IOException e) { - throw new GHException("Failed to refresh repositories", e); - } finally { - reposLoaded = true; } - return Collections.unmodifiableList(repositories); + return Collections.unmodifiableList(ghRepositories); } ; @@ -313,18 +306,10 @@ public List getRepositories() { * Returns a list of raw, unpopulated repositories. Useful when calling from within Installation event with * action "deleted". You can't fetch the info for repositories of an already deleted installation. * - * @return List + * @return the list of raw Repository records */ public List getRawRepositories() { - return Collections.unmodifiableList(rawRepositories); - } - - @JsonSetter - private void setRepositories(List repositories) { - this.repositories = repositories; - this.rawRepositories = repositories.stream() - .map(r -> new Repository(r.getId(), r.getFullName(), r.getName(), r.getNodeId(), r.isPrivate())) - .collect(Collectors.toList()); + return Collections.unmodifiableList(repositories); } /** @@ -345,37 +330,54 @@ void lateBind() { * "https://docs.github.com/en/webhooks-and-events/webhooks/webhook-events-and-payloads#installation">here */ public static class Repository { - private final long id; - private final String fullName; - private final String name; - private final String nodeId; + private long id; + private String fullName; + private String name; + private String nodeId; @JsonProperty(value = "private") private boolean isPrivate; - public Repository(long id, String fullName, String name, String nodeId, boolean isPrivate) { - this.id = id; - this.fullName = fullName; - this.name = name; - this.nodeId = nodeId; - this.isPrivate = isPrivate; - } - + /** + * Get the id. + * + * @return the id + */ public long getId() { return id; } + /** + * Gets the full name. + * + * @return the full name + */ public String getFullName() { return fullName; } + /** + * Gets the name. + * + * @return the name + */ public String getName() { return name; } + /** + * Gets the node id. + * + * @return the node id + */ public String getNodeId() { return nodeId; } + /** + * Gets the repository private flag. + * + * @return whether the repository is private + */ public boolean isPrivate() { return isPrivate; } From 2720ffdf8634ee131b6f54fb5e8634bdfe4c8851 Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Tue, 12 Mar 2024 16:02:07 -0700 Subject: [PATCH 06/11] Update GHEventPayload.java --- src/main/java/org/kohsuke/github/GHEventPayload.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHEventPayload.java b/src/main/java/org/kohsuke/github/GHEventPayload.java index af203c2b62..df29473305 100644 --- a/src/main/java/org/kohsuke/github/GHEventPayload.java +++ b/src/main/java/org/kohsuke/github/GHEventPayload.java @@ -10,7 +10,6 @@ import java.util.Date; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; // TODO: Auto-generated Javadoc /** @@ -268,9 +267,8 @@ void lateBind() { */ public static class Installation extends GHEventPayload { - private List ghRepositories = null; - private List repositories; + private List ghRepositories = null; /** * Gets repositories. For the "deleted" action please rather call {@link #getRawRepositories()} @@ -300,8 +298,6 @@ public List getRepositories() { return Collections.unmodifiableList(ghRepositories); } - ; - /** * Returns a list of raw, unpopulated repositories. Useful when calling from within Installation event with * action "deleted". You can't fetch the info for repositories of an already deleted installation. @@ -339,7 +335,7 @@ public static class Repository { /** * Get the id. - * + * * @return the id */ public long getId() { @@ -348,7 +344,7 @@ public long getId() { /** * Gets the full name. - * + * * @return the full name */ public String getFullName() { From b7cf3e200cafc97bf5826fa75f45801eb18f102f Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Tue, 12 Mar 2024 16:18:15 -0700 Subject: [PATCH 07/11] Fix missing import --- src/main/java/org/kohsuke/github/GHEventPayload.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/kohsuke/github/GHEventPayload.java b/src/main/java/org/kohsuke/github/GHEventPayload.java index df29473305..0f65498678 100644 --- a/src/main/java/org/kohsuke/github/GHEventPayload.java +++ b/src/main/java/org/kohsuke/github/GHEventPayload.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.io.Reader; +import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.List; From 5e417259e013afea48ff61a6b34e0ad78f748940 Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Tue, 12 Mar 2024 16:40:44 -0700 Subject: [PATCH 08/11] Update src/test/java/org/kohsuke/github/GHEventPayloadTest.java --- src/test/java/org/kohsuke/github/GHEventPayloadTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java index dd60f37cc3..e97dcc094f 100644 --- a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java +++ b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java @@ -983,6 +983,12 @@ public void InstallationRepositoriesEvent() throws Exception { assertThat(event.getSender().getLogin(), is("Codertocat")); } + /** + * Installation event. + * + * @throws Exception + * the exception + */ @Test @Payload("installation_created") public void InstallationCreatedEvent() throws Exception { From 0ae2f36fbb71222b2fd0146833309cc0195a0548 Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Tue, 12 Mar 2024 16:41:33 -0700 Subject: [PATCH 09/11] Update src/test/java/org/kohsuke/github/GHEventPayloadTest.java --- src/test/java/org/kohsuke/github/GHEventPayloadTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java index e97dcc094f..e412b0704e 100644 --- a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java +++ b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java @@ -25,7 +25,7 @@ import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.sameInstance; import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.*; +import static org.junit.Assert.assertThrows; // TODO: Auto-generated Javadoc /** From d1867d6d3cfb9e16e0c27de5390a57630a8683ac Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Tue, 12 Mar 2024 16:45:27 -0700 Subject: [PATCH 10/11] Apply suggestions from code review --- .../java/org/kohsuke/github/GHEventPayloadTest.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java index e412b0704e..db88196b17 100644 --- a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java +++ b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java @@ -1000,10 +1000,10 @@ public void InstallationCreatedEvent() throws Exception { assertThat(event.getInstallation().getId(), is(43898337L)); assertThat(event.getInstallation().getAccount().getLogin(), is("CronFire")); - assertFalse(event.getRepositories().isEmpty()); - assertEquals(event.getRepositories().get(0).getId(), 1296269); - assertFalse(event.getRawRepositories().isEmpty()); - assertEquals(event.getRawRepositories().get(0).getId(), 1296269); + assertThat(event.getRepositories().isEmpty(), is(false)); + assertThat(event.getRepositories().get(0).getId(), is(1296269)); + assertThat(event.getRawRepositories().isEmpty(), is(false)); + assertThat(event.getRawRepositories().get(0).getId(), is(1296269)); assertThat(event.getSender().getLogin(), is("Haarolean")); } @@ -1026,8 +1026,8 @@ public void InstallationDeletedEvent() throws Exception { assertThat(event.getInstallation().getAccount().getLogin(), is("octocat")); assertThrows(IllegalStateException.class, () -> event.getRepositories().isEmpty()); - assertFalse(event.getRawRepositories().isEmpty()); - assertEquals(event.getRawRepositories().get(0).getId(), 1296269); + assertThat(event.getRepositories().isEmpty(), is(false)); + assertThat(event.getRepositories().get(0).getId(), is(1296269)); assertThat(event.getSender().getLogin(), is("octocat")); } From acc027f5cc9345bea291d0391885d3be2ff37e38 Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Wed, 13 Mar 2024 17:06:54 -0700 Subject: [PATCH 11/11] Update test data --- .../kohsuke/github/GHEventPayloadTest.java | 12 +- ...lo-world-1.json => 1-r_o_hello-world.json} | 0 .../__files/2-repositories_1296269.json | 103 ++++++++++++++++++ ...lo-world-1.json => 1-r_o_hello-world.json} | 2 +- .../mappings/2-repositories_1296269.json | 46 ++++++++ 5 files changed, 158 insertions(+), 5 deletions(-) rename src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationCreatedEvent/__files/{repos_octocat_hello-world-1.json => 1-r_o_hello-world.json} (100%) create mode 100644 src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationCreatedEvent/__files/2-repositories_1296269.json rename src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationCreatedEvent/mappings/{repos_octocat_hello-world-1.json => 1-r_o_hello-world.json} (97%) create mode 100644 src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationCreatedEvent/mappings/2-repositories_1296269.json diff --git a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java index db88196b17..91560170c7 100644 --- a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java +++ b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java @@ -1001,9 +1001,9 @@ public void InstallationCreatedEvent() throws Exception { assertThat(event.getInstallation().getAccount().getLogin(), is("CronFire")); assertThat(event.getRepositories().isEmpty(), is(false)); - assertThat(event.getRepositories().get(0).getId(), is(1296269)); + assertThat(event.getRepositories().get(0).getId(), is(1296269L)); assertThat(event.getRawRepositories().isEmpty(), is(false)); - assertThat(event.getRawRepositories().get(0).getId(), is(1296269)); + assertThat(event.getRawRepositories().get(0).getId(), is(1296269L)); assertThat(event.getSender().getLogin(), is("Haarolean")); } @@ -1026,8 +1026,12 @@ public void InstallationDeletedEvent() throws Exception { assertThat(event.getInstallation().getAccount().getLogin(), is("octocat")); assertThrows(IllegalStateException.class, () -> event.getRepositories().isEmpty()); - assertThat(event.getRepositories().isEmpty(), is(false)); - assertThat(event.getRepositories().get(0).getId(), is(1296269)); + assertThat(event.getRawRepositories().isEmpty(), is(false)); + assertThat(event.getRawRepositories().get(0).getId(), is(1296269L)); + assertThat(event.getRawRepositories().get(0).getNodeId(), is("MDEwOlJlcG9zaXRvcnkxMjk2MjY5")); + assertThat(event.getRawRepositories().get(0).getName(), is("Hello-World")); + assertThat(event.getRawRepositories().get(0).getFullName(), is("octocat/Hello-World")); + assertThat(event.getRawRepositories().get(0).isPrivate(), is(false)); assertThat(event.getSender().getLogin(), is("octocat")); } diff --git a/src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationCreatedEvent/__files/repos_octocat_hello-world-1.json b/src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationCreatedEvent/__files/1-r_o_hello-world.json similarity index 100% rename from src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationCreatedEvent/__files/repos_octocat_hello-world-1.json rename to src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationCreatedEvent/__files/1-r_o_hello-world.json diff --git a/src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationCreatedEvent/__files/2-repositories_1296269.json b/src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationCreatedEvent/__files/2-repositories_1296269.json new file mode 100644 index 0000000000..8b2db1e11c --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationCreatedEvent/__files/2-repositories_1296269.json @@ -0,0 +1,103 @@ +{ + "id": 1296269, + "node_id": "MDEwOlJlcG9zaXRvcnkxMjk2MjY5", + "name": "Hello-World", + "full_name": "octocat/Hello-World", + "private": false, + "owner": { + "login": "octocat", + "id": 583231, + "node_id": "MDQ6VXNlcjU4MzIzMQ==", + "avatar_url": "https://avatars.githubusercontent.com/u/583231?v=4", + "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 + }, + "html_url": "https://github.com/octocat/Hello-World", + "description": "My first repository on GitHub!", + "fork": false, + "url": "https://api.github.com/repos/octocat/Hello-World", + "forks_url": "https://api.github.com/repos/octocat/Hello-World/forks", + "keys_url": "https://api.github.com/repos/octocat/Hello-World/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/octocat/Hello-World/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/octocat/Hello-World/teams", + "hooks_url": "https://api.github.com/repos/octocat/Hello-World/hooks", + "issue_events_url": "https://api.github.com/repos/octocat/Hello-World/issues/events{/number}", + "events_url": "https://api.github.com/repos/octocat/Hello-World/events", + "assignees_url": "https://api.github.com/repos/octocat/Hello-World/assignees{/user}", + "branches_url": "https://api.github.com/repos/octocat/Hello-World/branches{/branch}", + "tags_url": "https://api.github.com/repos/octocat/Hello-World/tags", + "blobs_url": "https://api.github.com/repos/octocat/Hello-World/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/octocat/Hello-World/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/octocat/Hello-World/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/octocat/Hello-World/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/octocat/Hello-World/statuses/{sha}", + "languages_url": "https://api.github.com/repos/octocat/Hello-World/languages", + "stargazers_url": "https://api.github.com/repos/octocat/Hello-World/stargazers", + "contributors_url": "https://api.github.com/repos/octocat/Hello-World/contributors", + "subscribers_url": "https://api.github.com/repos/octocat/Hello-World/subscribers", + "subscription_url": "https://api.github.com/repos/octocat/Hello-World/subscription", + "commits_url": "https://api.github.com/repos/octocat/Hello-World/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/octocat/Hello-World/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/octocat/Hello-World/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/octocat/Hello-World/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/octocat/Hello-World/contents/{+path}", + "compare_url": "https://api.github.com/repos/octocat/Hello-World/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/octocat/Hello-World/merges", + "archive_url": "https://api.github.com/repos/octocat/Hello-World/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/octocat/Hello-World/downloads", + "issues_url": "https://api.github.com/repos/octocat/Hello-World/issues{/number}", + "pulls_url": "https://api.github.com/repos/octocat/Hello-World/pulls{/number}", + "milestones_url": "https://api.github.com/repos/octocat/Hello-World/milestones{/number}", + "notifications_url": "https://api.github.com/repos/octocat/Hello-World/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/octocat/Hello-World/labels{/name}", + "releases_url": "https://api.github.com/repos/octocat/Hello-World/releases{/id}", + "deployments_url": "https://api.github.com/repos/octocat/Hello-World/deployments", + "created_at": "2011-01-26T19:01:12Z", + "updated_at": "2024-03-13T21:25:44Z", + "pushed_at": "2024-03-09T06:28:31Z", + "git_url": "git://github.com/octocat/Hello-World.git", + "ssh_url": "git@github.com:octocat/Hello-World.git", + "clone_url": "https://github.com/octocat/Hello-World.git", + "svn_url": "https://github.com/octocat/Hello-World", + "homepage": "", + "size": 1, + "stargazers_count": 2486, + "watchers_count": 2486, + "language": null, + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "has_discussions": false, + "forks_count": 2168, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 1291, + "license": null, + "allow_forking": true, + "is_template": false, + "web_commit_signoff_required": false, + "topics": [], + "visibility": "public", + "forks": 2168, + "open_issues": 1291, + "watchers": 2486, + "default_branch": "master", + "temp_clone_token": null, + "network_count": 2168, + "subscribers_count": 1731 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationCreatedEvent/mappings/repos_octocat_hello-world-1.json b/src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationCreatedEvent/mappings/1-r_o_hello-world.json similarity index 97% rename from src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationCreatedEvent/mappings/repos_octocat_hello-world-1.json rename to src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationCreatedEvent/mappings/1-r_o_hello-world.json index 942435fa56..885e76133f 100644 --- a/src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationCreatedEvent/mappings/repos_octocat_hello-world-1.json +++ b/src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationCreatedEvent/mappings/1-r_o_hello-world.json @@ -12,7 +12,7 @@ }, "response": { "status": 200, - "bodyFileName": "repos_octocat_hello-world-1.json", + "bodyFileName": "1-r_o_hello-world.json", "headers": { "Server": "GitHub.com", "Date": "Thu, 03 Feb 2022 14:07:49 GMT", diff --git a/src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationCreatedEvent/mappings/2-repositories_1296269.json b/src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationCreatedEvent/mappings/2-repositories_1296269.json new file mode 100644 index 0000000000..bc21ed64a4 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/InstallationCreatedEvent/mappings/2-repositories_1296269.json @@ -0,0 +1,46 @@ +{ + "id": "71720657-76be-4371-932d-edc25c1e1972", + "name": "repositories_1296269", + "request": { + "url": "/repositories/1296269", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "2-repositories_1296269.json", + "headers": { + "Server": "GitHub.com", + "Date": "Thu, 14 Mar 2024 00:05:07 GMT", + "Content-Type": "application/json; charset=utf-8", + "Cache-Control": "public, max-age=60, s-maxage=60", + "Vary": "Accept, Accept-Encoding, Accept, X-Requested-With", + "ETag": "W/\"463b3a1acb093fa3ed0bb1f11b4182aa6b7f54a6f613cb6293b24c6150c757f9\"", + "Last-Modified": "Wed, 13 Mar 2024 21:25:44 GMT", + "X-GitHub-Media-Type": "github.v3; format=json", + "x-github-api-version-selected": "2022-11-28", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "0", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-RateLimit-Limit": "60", + "X-RateLimit-Remaining": "59", + "X-RateLimit-Reset": "1710378307", + "X-RateLimit-Resource": "core", + "X-RateLimit-Used": "1", + "Accept-Ranges": "bytes", + "X-GitHub-Request-Id": "D434:1950C9:DD1F3:134998:65F23F32" + } + }, + "uuid": "71720657-76be-4371-932d-edc25c1e1972", + "persistent": true, + "insertionIndex": 2 +} \ No newline at end of file