Skip to content

Commit 8de03e2

Browse files
authored
Merge branch 'main' into patch-1
2 parents bc43b80 + 9b164ca commit 8de03e2

10 files changed

Lines changed: 257 additions & 33 deletions

File tree

src/main/java/org/kohsuke/github/GHEventPayload.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,15 @@ public List<GHRepository> getRepositories() {
267267
void lateBind() {
268268
if (getInstallation() == null) {
269269
throw new IllegalStateException(
270-
"Expected check_suite payload, but got something else. Maybe we've got another type of event?");
270+
"Expected installation payload, but got something else. Maybe we've got another type of event?");
271271
}
272272
super.lateBind();
273273
if (repositories != null && !repositories.isEmpty()) {
274274
try {
275-
for (GHRepository singleRepo : repositories) { // warp each of the repository
275+
for (GHRepository singleRepo : repositories) {
276+
// populate each repository
277+
// the repository information provided here is so limited
278+
// as to be unusable without populating, so we do it eagerly
276279
singleRepo.populate();
277280
}
278281
} catch (IOException e) {
@@ -326,7 +329,7 @@ public List<GHRepository> getRepositoriesRemoved() {
326329
void lateBind() {
327330
if (getInstallation() == null) {
328331
throw new IllegalStateException(
329-
"Expected check_suite payload, but got something else. Maybe we've got another type of event?");
332+
"Expected installation_repositories payload, but got something else. Maybe we've got another type of event?");
330333
}
331334
super.lateBind();
332335
List<GHRepository> repositories;

src/main/java/org/kohsuke/github/GHRepository.java

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
package org.kohsuke.github;
2525

2626
import com.fasterxml.jackson.annotation.JsonProperty;
27-
import com.fasterxml.jackson.core.JsonParseException;
2827
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
2928
import edu.umd.cs.findbugs.annotations.CheckForNull;
3029
import edu.umd.cs.findbugs.annotations.NonNull;
@@ -2978,7 +2977,7 @@ String getApiTailUrl(String tail) {
29782977
if (tail.length() > 0 && !tail.startsWith("/")) {
29792978
tail = '/' + tail;
29802979
}
2981-
return "/repos/" + getOwnerName() + "/" + name + tail;
2980+
return "/repos/" + full_name + tail;
29822981
}
29832982

29842983
/**
@@ -3257,29 +3256,13 @@ void populate() throws IOException {
32573256
return; // can't populate if the root is offline
32583257
}
32593258

3260-
final URL url = requireNonNull(getUrl(), "Missing instance URL!");
3259+
// We don't use the URL provided in the JSON because it is not reliable:
3260+
// 1. There is bug in Push event payloads that returns the wrong url.
3261+
// For Push event repository records, they take the form "https://github.com/{fullName}".
3262+
// All other occurrences of "url" take the form "https://api.github.com/...".
3263+
// 2. For Installation event payloads, the URL is not provided at all.
32613264

3262-
try {
3263-
// IMPORTANT: the url for repository records does not reliably point to the API url.
3264-
// There is bug in Push event payloads that returns the wrong url.
3265-
// All other occurrences of "url" take the form "https://api.github.com/...".
3266-
// For Push event repository records, they take the form "https://github.com/{fullName}".
3267-
root().createRequest()
3268-
.withPreview(BAPTISTE)
3269-
.withPreview(NEBULA)
3270-
.setRawUrlPath(url.toString())
3271-
.fetchInto(this);
3272-
} catch (HttpException e) {
3273-
if (e.getCause() instanceof JsonParseException) {
3274-
root().createRequest()
3275-
.withPreview(BAPTISTE)
3276-
.withPreview(NEBULA)
3277-
.withUrlPath("/repos/" + full_name)
3278-
.fetchInto(this);
3279-
} else {
3280-
throw e;
3281-
}
3282-
}
3265+
root().createRequest().withPreview(BAPTISTE).withPreview(NEBULA).withUrlPath(getApiTailUrl("")).fetchInto(this);
32833266
}
32843267

32853268
/**

src/test/java/org/kohsuke/github/GHEventPayloadTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ public void checkRunEvent() throws Exception {
630630
GHEventPayload.CheckRun.class);
631631
final GHCheckRun checkRun2 = verifyBasicCheckRunEvent(event2);
632632

633-
int expectedRequestCount = mockGitHub.isUseProxy() ? 3 : 2;
633+
int expectedRequestCount = 2;
634634
assertThat("pull body should be populated",
635635
checkRun2.getPullRequests().get(0).getBody(),
636636
equalTo("This is a pretty simple change that we need to pull into main."));
@@ -767,18 +767,20 @@ public void InstallationRepositoriesEvent() throws Exception {
767767
@Test
768768
@Payload("installation")
769769
public void InstallationEvent() throws Exception {
770-
final GHEventPayload.Installation event = GitHub.offline()
770+
final GHEventPayload.Installation event = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl())
771+
.build()
771772
.parseEventPayload(payload.asReader(), GHEventPayload.Installation.class);
772773

773774
assertThat(event.getAction(), is("deleted"));
774775
assertThat(event.getInstallation().getId(), is(2L));
775776
assertThat(event.getInstallation().getAccount().getLogin(), is("octocat"));
776777

777778
assertThat(event.getRepositories().get(0).getId(), is(1296269L));
778-
assertThat(event.getRepositories().get(0).getNodeId(), is("MDEwOlJlcG9zaXRvcnkxODY4NTMwMDc="));
779+
assertThat(event.getRepositories().get(0).getNodeId(), is("MDEwOlJlcG9zaXRvcnkxMjk2MjY5"));
779780
assertThat(event.getRepositories().get(0).getName(), is("Hello-World"));
780781
assertThat(event.getRepositories().get(0).getFullName(), is("octocat/Hello-World"));
781782
assertThat(event.getRepositories().get(0).isPrivate(), is(false));
783+
assertThat(event.getRepositories().get(0).getOwner().getLogin(), is("octocat"));
782784

783785
assertThat(event.getSender().getLogin(), is("octocat"));
784786
}

src/test/resources/org/kohsuke/github/GHEventPayloadTest/installation.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"repositories": [
4646
{
4747
"id": 1296269,
48-
"node_id": "MDEwOlJlcG9zaXRvcnkxODY4NTMwMDc=",
48+
"node_id": "MDEwOlJlcG9zaXRvcnkxMjk2MjY5",
4949
"name": "Hello-World",
5050
"full_name": "octocat/Hello-World",
5151
"private": false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
{
2+
"id": 1296269,
3+
"node_id": "MDEwOlJlcG9zaXRvcnkxMjk2MjY5",
4+
"name": "Hello-World",
5+
"full_name": "octocat/Hello-World",
6+
"private": false,
7+
"owner": {
8+
"login": "octocat",
9+
"id": 583231,
10+
"node_id": "MDQ6VXNlcjU4MzIzMQ==",
11+
"avatar_url": "https://avatars.githubusercontent.com/u/583231?v=4",
12+
"gravatar_id": "",
13+
"url": "https://api.github.com/users/octocat",
14+
"html_url": "https://github.com/octocat",
15+
"followers_url": "https://api.github.com/users/octocat/followers",
16+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
17+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
18+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
19+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
20+
"organizations_url": "https://api.github.com/users/octocat/orgs",
21+
"repos_url": "https://api.github.com/users/octocat/repos",
22+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
23+
"received_events_url": "https://api.github.com/users/octocat/received_events",
24+
"type": "User",
25+
"site_admin": false
26+
},
27+
"html_url": "https://github.com/octocat/Hello-World",
28+
"description": "My first repository on GitHub!",
29+
"fork": false,
30+
"url": "https://api.github.com/repos/octocat/Hello-World",
31+
"forks_url": "https://api.github.com/repos/octocat/Hello-World/forks",
32+
"keys_url": "https://api.github.com/repos/octocat/Hello-World/keys{/key_id}",
33+
"collaborators_url": "https://api.github.com/repos/octocat/Hello-World/collaborators{/collaborator}",
34+
"teams_url": "https://api.github.com/repos/octocat/Hello-World/teams",
35+
"hooks_url": "https://api.github.com/repos/octocat/Hello-World/hooks",
36+
"issue_events_url": "https://api.github.com/repos/octocat/Hello-World/issues/events{/number}",
37+
"events_url": "https://api.github.com/repos/octocat/Hello-World/events",
38+
"assignees_url": "https://api.github.com/repos/octocat/Hello-World/assignees{/user}",
39+
"branches_url": "https://api.github.com/repos/octocat/Hello-World/branches{/branch}",
40+
"tags_url": "https://api.github.com/repos/octocat/Hello-World/tags",
41+
"blobs_url": "https://api.github.com/repos/octocat/Hello-World/git/blobs{/sha}",
42+
"git_tags_url": "https://api.github.com/repos/octocat/Hello-World/git/tags{/sha}",
43+
"git_refs_url": "https://api.github.com/repos/octocat/Hello-World/git/refs{/sha}",
44+
"trees_url": "https://api.github.com/repos/octocat/Hello-World/git/trees{/sha}",
45+
"statuses_url": "https://api.github.com/repos/octocat/Hello-World/statuses/{sha}",
46+
"languages_url": "https://api.github.com/repos/octocat/Hello-World/languages",
47+
"stargazers_url": "https://api.github.com/repos/octocat/Hello-World/stargazers",
48+
"contributors_url": "https://api.github.com/repos/octocat/Hello-World/contributors",
49+
"subscribers_url": "https://api.github.com/repos/octocat/Hello-World/subscribers",
50+
"subscription_url": "https://api.github.com/repos/octocat/Hello-World/subscription",
51+
"commits_url": "https://api.github.com/repos/octocat/Hello-World/commits{/sha}",
52+
"git_commits_url": "https://api.github.com/repos/octocat/Hello-World/git/commits{/sha}",
53+
"comments_url": "https://api.github.com/repos/octocat/Hello-World/comments{/number}",
54+
"issue_comment_url": "https://api.github.com/repos/octocat/Hello-World/issues/comments{/number}",
55+
"contents_url": "https://api.github.com/repos/octocat/Hello-World/contents/{+path}",
56+
"compare_url": "https://api.github.com/repos/octocat/Hello-World/compare/{base}...{head}",
57+
"merges_url": "https://api.github.com/repos/octocat/Hello-World/merges",
58+
"archive_url": "https://api.github.com/repos/octocat/Hello-World/{archive_format}{/ref}",
59+
"downloads_url": "https://api.github.com/repos/octocat/Hello-World/downloads",
60+
"issues_url": "https://api.github.com/repos/octocat/Hello-World/issues{/number}",
61+
"pulls_url": "https://api.github.com/repos/octocat/Hello-World/pulls{/number}",
62+
"milestones_url": "https://api.github.com/repos/octocat/Hello-World/milestones{/number}",
63+
"notifications_url": "https://api.github.com/repos/octocat/Hello-World/notifications{?since,all,participating}",
64+
"labels_url": "https://api.github.com/repos/octocat/Hello-World/labels{/name}",
65+
"releases_url": "https://api.github.com/repos/octocat/Hello-World/releases{/id}",
66+
"deployments_url": "https://api.github.com/repos/octocat/Hello-World/deployments",
67+
"created_at": "2011-01-26T19:01:12Z",
68+
"updated_at": "2022-02-03T00:06:57Z",
69+
"pushed_at": "2022-01-30T18:13:40Z",
70+
"git_url": "git://github.com/octocat/Hello-World.git",
71+
"ssh_url": "git@github.com:octocat/Hello-World.git",
72+
"clone_url": "https://github.com/octocat/Hello-World.git",
73+
"svn_url": "https://github.com/octocat/Hello-World",
74+
"homepage": "",
75+
"size": 1,
76+
"stargazers_count": 1764,
77+
"watchers_count": 1764,
78+
"language": null,
79+
"has_issues": true,
80+
"has_projects": true,
81+
"has_downloads": true,
82+
"has_wiki": true,
83+
"has_pages": false,
84+
"forks_count": 1682,
85+
"mirror_url": null,
86+
"archived": false,
87+
"disabled": false,
88+
"open_issues_count": 802,
89+
"license": null,
90+
"allow_forking": true,
91+
"is_template": false,
92+
"topics": [],
93+
"visibility": "public",
94+
"forks": 1682,
95+
"open_issues": 802,
96+
"watchers": 1764,
97+
"default_branch": "master",
98+
"permissions": {
99+
"admin": false,
100+
"maintain": false,
101+
"push": false,
102+
"triage": false,
103+
"pull": true
104+
},
105+
"temp_clone_token": "",
106+
"network_count": 1682,
107+
"subscribers_count": 1731
108+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"login": "octocat",
3+
"id": 583231,
4+
"node_id": "MDQ6VXNlcjU4MzIzMQ==",
5+
"avatar_url": "https://avatars.githubusercontent.com/u/583231?v=4",
6+
"gravatar_id": "",
7+
"url": "https://api.github.com/users/octocat",
8+
"html_url": "https://github.com/octocat",
9+
"followers_url": "https://api.github.com/users/octocat/followers",
10+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
11+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
12+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
13+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
14+
"organizations_url": "https://api.github.com/users/octocat/orgs",
15+
"repos_url": "https://api.github.com/users/octocat/repos",
16+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
17+
"received_events_url": "https://api.github.com/users/octocat/received_events",
18+
"type": "User",
19+
"site_admin": false,
20+
"name": "The Octocat",
21+
"company": "@github",
22+
"blog": "https://github.blog",
23+
"location": "San Francisco",
24+
"email": "octocat@github.com",
25+
"hireable": null,
26+
"bio": null,
27+
"twitter_username": null,
28+
"public_repos": 8,
29+
"public_gists": 8,
30+
"followers": 4752,
31+
"following": 9,
32+
"created_at": "2011-01-25T18:44:36Z",
33+
"updated_at": "2022-01-24T15:08:43Z"
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"id": "825b1b2a-1bcf-4273-9204-54f989479669",
3+
"name": "repos_octocat_hello-world",
4+
"request": {
5+
"url": "/repos/octocat/Hello-World",
6+
"method": "GET",
7+
"headers": {
8+
"Accept": {
9+
"equalTo": "application/vnd.github.baptiste-preview+json, application/vnd.github.nebula-preview+json"
10+
}
11+
}
12+
},
13+
"response": {
14+
"status": 200,
15+
"bodyFileName": "repos_octocat_hello-world-1.json",
16+
"headers": {
17+
"Server": "GitHub.com",
18+
"Date": "Thu, 03 Feb 2022 14:07:49 GMT",
19+
"Content-Type": "application/json; charset=utf-8",
20+
"Cache-Control": "private, max-age=60, s-maxage=60",
21+
"Vary": [
22+
"Accept, Authorization, Cookie, X-GitHub-OTP",
23+
"Accept-Encoding, Accept, X-Requested-With"
24+
],
25+
"ETag": "W/\"54ebfbf708e274f11202ea42a54ccb98955c89b119059c79c8f1bf7e76126198\"",
26+
"Last-Modified": "Thu, 03 Feb 2022 00:06:57 GMT",
27+
"X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, gist, notifications, repo, user, workflow, write:discussion",
28+
"X-Accepted-OAuth-Scopes": "repo",
29+
"X-GitHub-Media-Type": "github.v3; param=baptiste-preview.nebula-preview; format=json",
30+
"X-RateLimit-Limit": "5000",
31+
"X-RateLimit-Remaining": "4999",
32+
"X-RateLimit-Reset": "1643900869",
33+
"X-RateLimit-Used": "1",
34+
"X-RateLimit-Resource": "core",
35+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
36+
"X-Frame-Options": "deny",
37+
"X-Content-Type-Options": "nosniff",
38+
"X-XSS-Protection": "0",
39+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
40+
"Content-Security-Policy": "default-src 'none'",
41+
"X-GitHub-Request-Id": "AD00:CEBF:18E9BF0:19A3623:61FBE1B5"
42+
}
43+
},
44+
"uuid": "825b1b2a-1bcf-4273-9204-54f989479669",
45+
"persistent": true,
46+
"insertionIndex": 1
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"id": "a801936f-7ec1-4f5a-8e1a-999cff08aec8",
3+
"name": "users_octocat",
4+
"request": {
5+
"url": "/users/octocat",
6+
"method": "GET",
7+
"headers": {
8+
"Accept": {
9+
"equalTo": "application/vnd.github.v3+json"
10+
}
11+
}
12+
},
13+
"response": {
14+
"status": 200,
15+
"bodyFileName": "users_octocat-2.json",
16+
"headers": {
17+
"Server": "GitHub.com",
18+
"Date": "Thu, 03 Feb 2022 14:09:13 GMT",
19+
"Content-Type": "application/json; charset=utf-8",
20+
"Cache-Control": "private, max-age=60, s-maxage=60",
21+
"Vary": [
22+
"Accept, Authorization, Cookie, X-GitHub-OTP",
23+
"Accept-Encoding, Accept, X-Requested-With"
24+
],
25+
"ETag": "W/\"6b9192ff77357b29af6623ef400f86c862e7b184905220e1f1d09cfd0a545d37\"",
26+
"Last-Modified": "Mon, 24 Jan 2022 15:08:43 GMT",
27+
"X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, gist, notifications, repo, user, workflow, write:discussion",
28+
"X-Accepted-OAuth-Scopes": "",
29+
"X-GitHub-Media-Type": "github.v3; format=json",
30+
"X-RateLimit-Limit": "5000",
31+
"X-RateLimit-Remaining": "4998",
32+
"X-RateLimit-Reset": "1643900869",
33+
"X-RateLimit-Used": "2",
34+
"X-RateLimit-Resource": "core",
35+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
36+
"X-Frame-Options": "deny",
37+
"X-Content-Type-Options": "nosniff",
38+
"X-XSS-Protection": "0",
39+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
40+
"Content-Security-Policy": "default-src 'none'",
41+
"X-GitHub-Request-Id": "AD02:CC9B:2A1ACBB:2AF0199:61FBE209"
42+
}
43+
},
44+
"uuid": "a801936f-7ec1-4f5a-8e1a-999cff08aec8",
45+
"persistent": true,
46+
"insertionIndex": 2
47+
}

src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/pushToFork/__files/repos_hub4j-test-org_github-api-2.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,4 +331,4 @@
331331
},
332332
"network_count": 478,
333333
"subscribers_count": 0
334-
}
334+
}

src/test/resources/org/kohsuke/github/GHEventPayloadTest/wiremock/pushToFork/mappings/repos_hub4j-test-org_github-api-2.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@
4444
"uuid": "90aa0017-3f50-4829-bda4-6531fbcfba60",
4545
"persistent": true,
4646
"insertionIndex": 2
47-
}
47+
}

0 commit comments

Comments
 (0)