Skip to content

Commit 1e580da

Browse files
committed
Add test for delete hook by ID
1 parent 541afca commit 1e580da

29 files changed

+601
-258
lines changed

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.google.common.collect.Iterables;
55
import org.apache.commons.io.IOUtils;
66
import org.apache.commons.lang3.SystemUtils;
7+
import org.junit.Assert;
78
import org.junit.Assume;
89
import org.junit.Ignore;
910
import org.junit.Test;
@@ -620,8 +621,8 @@ public void testCreateCommitComment() throws Exception {
620621

621622
@Test
622623
public void tryHook() throws Exception {
623-
GHOrganization o = gitHub.getOrganization(GITHUB_API_TEST_ORG);
624-
GHRepository r = o.getRepository("github-api");
624+
final GHOrganization o = gitHub.getOrganization(GITHUB_API_TEST_ORG);
625+
final GHRepository r = o.getRepository("github-api");
625626
try {
626627
GHHook hook = r.createWebHook(new URL("http://www.google.com/"));
627628
assertThat(hook.getName(), equalTo("web"));
@@ -637,6 +638,15 @@ public void tryHook() throws Exception {
637638
assertThat(hook2.getConfig().size(), equalTo(3));
638639
assertThat(hook2.isActive(), equalTo(true));
639640
hook2.ping();
641+
hook2.delete();
642+
final GHHook finalRepoHook = hook;
643+
GHFileNotFoundException e = Assert.assertThrows(GHFileNotFoundException.class,
644+
() -> r.getHook((int) finalRepoHook.getId()));
645+
assertThat(e.getMessage(),
646+
containsString("repos/hub4j-test-org/github-api/hooks/" + finalRepoHook.getId()));
647+
assertThat(e.getMessage(), containsString("rest/reference/repos#get-a-repository-webhook"));
648+
649+
hook = r.createWebHook(new URL("http://www.google.com/"));
640650
r.deleteHook((int) hook.getId());
641651

642652
hook = o.createWebHook(new URL("http://www.google.com/"));
@@ -653,13 +663,23 @@ public void tryHook() throws Exception {
653663
assertThat(hook2.getConfig().size(), equalTo(3));
654664
assertThat(hook2.isActive(), equalTo(true));
655665
hook2.ping();
666+
hook2.delete();
667+
668+
final GHHook finalOrgHook = hook;
669+
GHFileNotFoundException e2 = Assert.assertThrows(GHFileNotFoundException.class,
670+
() -> o.getHook((int) finalOrgHook.getId()));
671+
assertThat(e2.getMessage(), containsString("orgs/hub4j-test-org/hooks/" + finalOrgHook.getId()));
672+
assertThat(e2.getMessage(), containsString("rest/reference/orgs#get-an-organization-webhook"));
673+
674+
hook = o.createWebHook(new URL("http://www.google.com/"));
656675
o.deleteHook((int) hook.getId());
657676

658677
// System.out.println(hook);
659678
} finally {
660679
if (mockGitHub.isUseProxy()) {
661-
r = getNonRecordingGitHub().getOrganization(GITHUB_API_TEST_ORG).getRepository("github-api");
662-
for (GHHook h : r.getHooks()) {
680+
GHRepository cleanupRepo = getNonRecordingGitHub().getOrganization(GITHUB_API_TEST_ORG)
681+
.getRepository("github-api");
682+
for (GHHook h : cleanupRepo.getHooks()) {
663683
h.delete();
664684
}
665685
}

src/test/resources/org/kohsuke/github/AppTest/wiremock/tryHook/__files/orgs_hub4j-test-org-2.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"is_verified": false,
2121
"has_organization_projects": true,
2222
"has_repository_projects": true,
23-
"public_repos": 13,
23+
"public_repos": 19,
2424
"public_gists": 0,
2525
"followers": 0,
2626
"following": 0,
@@ -31,7 +31,7 @@
3131
"total_private_repos": 2,
3232
"owned_private_repos": 2,
3333
"private_gists": 0,
34-
"disk_usage": 152,
34+
"disk_usage": 11979,
3535
"collaborators": 0,
3636
"billing_email": "[email protected]",
3737
"default_repository_permission": "none",
@@ -44,7 +44,7 @@
4444
"name": "free",
4545
"space": 976562499,
4646
"private_repos": 10000,
47-
"filled_seats": 22,
47+
"filled_seats": 26,
4848
"seats": 3
4949
}
5050
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"type": "Organization",
3+
"id": 319833954,
4+
"name": "web",
5+
"active": true,
6+
"events": [
7+
"push"
8+
],
9+
"config": {
10+
"url": "http://www.google.com/",
11+
"insecure_ssl": "0",
12+
"content_type": "form"
13+
},
14+
"updated_at": "2021-09-24T05:58:39Z",
15+
"created_at": "2021-09-24T05:58:39Z",
16+
"url": "https://api.github.com/orgs/hub4j-test-org/hooks/319833954",
17+
"ping_url": "https://api.github.com/orgs/hub4j-test-org/hooks/319833954/pings",
18+
"deliveries_url": "https://api.github.com/orgs/hub4j-test-org/hooks/319833954/deliveries"
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"type": "Organization",
3+
"id": 319833957,
4+
"name": "web",
5+
"active": true,
6+
"events": [
7+
"push"
8+
],
9+
"config": {
10+
"url": "http://www.google.com/",
11+
"insecure_ssl": "0",
12+
"content_type": "form"
13+
},
14+
"updated_at": "2021-09-24T05:58:40Z",
15+
"created_at": "2021-09-24T05:58:40Z",
16+
"url": "https://api.github.com/orgs/hub4j-test-org/hooks/319833957",
17+
"ping_url": "https://api.github.com/orgs/hub4j-test-org/hooks/319833957/pings",
18+
"deliveries_url": "https://api.github.com/orgs/hub4j-test-org/hooks/319833957/deliveries"
19+
}

src/test/resources/org/kohsuke/github/AppTest/wiremock/tryHook/__files/orgs_hub4j-test-org_hooks-8.json

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/test/resources/org/kohsuke/github/AppTest/wiremock/tryHook/__files/orgs_hub4j-test-org_hooks_276991250-9.json

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"type": "Organization",
3+
"id": 319833954,
4+
"name": "web",
5+
"active": true,
6+
"events": [
7+
"push"
8+
],
9+
"config": {
10+
"url": "http://www.google.com/",
11+
"insecure_ssl": "0",
12+
"content_type": "form"
13+
},
14+
"updated_at": "2021-09-24T05:58:39Z",
15+
"created_at": "2021-09-24T05:58:39Z",
16+
"url": "https://api.github.com/orgs/hub4j-test-org/hooks/319833954",
17+
"ping_url": "https://api.github.com/orgs/hub4j-test-org/hooks/319833954/pings",
18+
"deliveries_url": "https://api.github.com/orgs/hub4j-test-org/hooks/319833954/deliveries"
19+
}

src/test/resources/org/kohsuke/github/AppTest/wiremock/tryHook/__files/repos_hub4j-test-org_github-api-3.json

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"site_admin": false
2626
},
2727
"html_url": "https://github.com/hub4j-test-org/github-api",
28-
"description": "Resetting",
28+
"description": "Tricky",
2929
"fork": true,
3030
"url": "https://api.github.com/repos/hub4j-test-org/github-api",
3131
"forks_url": "https://api.github.com/repos/hub4j-test-org/github-api/forks",
@@ -65,14 +65,14 @@
6565
"releases_url": "https://api.github.com/repos/hub4j-test-org/github-api/releases{/id}",
6666
"deployments_url": "https://api.github.com/repos/hub4j-test-org/github-api/deployments",
6767
"created_at": "2019-09-06T23:26:04Z",
68-
"updated_at": "2021-01-22T03:50:37Z",
69-
"pushed_at": "2020-09-03T19:05:17Z",
68+
"updated_at": "2021-04-19T20:09:00Z",
69+
"pushed_at": "2021-07-24T20:28:27Z",
7070
"git_url": "git://github.com/hub4j-test-org/github-api.git",
7171
"ssh_url": "[email protected]:hub4j-test-org/github-api.git",
7272
"clone_url": "https://github.com/hub4j-test-org/github-api.git",
7373
"svn_url": "https://github.com/hub4j-test-org/github-api",
7474
"homepage": "http://github-api.kohsuke.org/",
75-
"size": 19052,
75+
"size": 19045,
7676
"stargazers_count": 0,
7777
"watchers_count": 0,
7878
"language": "Java",
@@ -85,27 +85,31 @@
8585
"mirror_url": null,
8686
"archived": false,
8787
"disabled": false,
88-
"open_issues_count": 5,
88+
"open_issues_count": 7,
8989
"license": {
9090
"key": "mit",
9191
"name": "MIT License",
9292
"spdx_id": "MIT",
9393
"url": "https://api.github.com/licenses/mit",
9494
"node_id": "MDc6TGljZW5zZTEz"
9595
},
96+
"allow_forking": true,
9697
"forks": 0,
97-
"open_issues": 5,
98+
"open_issues": 7,
9899
"watchers": 0,
99100
"default_branch": "main",
100101
"permissions": {
101102
"admin": true,
103+
"maintain": true,
102104
"push": true,
105+
"triage": true,
103106
"pull": true
104107
},
105108
"temp_clone_token": "",
106109
"allow_squash_merge": true,
107110
"allow_merge_commit": true,
108111
"allow_rebase_merge": true,
112+
"allow_auto_merge": false,
109113
"delete_branch_on_merge": false,
110114
"organization": {
111115
"login": "hub4j-test-org",
@@ -194,37 +198,38 @@
194198
"releases_url": "https://api.github.com/repos/hub4j/github-api/releases{/id}",
195199
"deployments_url": "https://api.github.com/repos/hub4j/github-api/deployments",
196200
"created_at": "2010-04-19T04:13:03Z",
197-
"updated_at": "2021-01-22T01:29:15Z",
198-
"pushed_at": "2021-01-15T04:14:15Z",
201+
"updated_at": "2021-09-23T17:58:12Z",
202+
"pushed_at": "2021-09-24T05:33:24Z",
199203
"git_url": "git://github.com/hub4j/github-api.git",
200204
"ssh_url": "[email protected]:hub4j/github-api.git",
201205
"clone_url": "https://github.com/hub4j/github-api.git",
202206
"svn_url": "https://github.com/hub4j/github-api",
203207
"homepage": "https://github-api.kohsuke.org/",
204-
"size": 26826,
205-
"stargazers_count": 728,
206-
"watchers_count": 728,
208+
"size": 36382,
209+
"stargazers_count": 810,
210+
"watchers_count": 810,
207211
"language": "Java",
208212
"has_issues": true,
209213
"has_projects": true,
210214
"has_downloads": true,
211215
"has_wiki": true,
212216
"has_pages": true,
213-
"forks_count": 520,
217+
"forks_count": 563,
214218
"mirror_url": null,
215219
"archived": false,
216220
"disabled": false,
217-
"open_issues_count": 77,
221+
"open_issues_count": 85,
218222
"license": {
219223
"key": "mit",
220224
"name": "MIT License",
221225
"spdx_id": "MIT",
222226
"url": "https://api.github.com/licenses/mit",
223227
"node_id": "MDc6TGljZW5zZTEz"
224228
},
225-
"forks": 520,
226-
"open_issues": 77,
227-
"watchers": 728,
229+
"allow_forking": true,
230+
"forks": 563,
231+
"open_issues": 85,
232+
"watchers": 810,
228233
"default_branch": "main"
229234
},
230235
"source": {
@@ -294,39 +299,40 @@
294299
"releases_url": "https://api.github.com/repos/hub4j/github-api/releases{/id}",
295300
"deployments_url": "https://api.github.com/repos/hub4j/github-api/deployments",
296301
"created_at": "2010-04-19T04:13:03Z",
297-
"updated_at": "2021-01-22T01:29:15Z",
298-
"pushed_at": "2021-01-15T04:14:15Z",
302+
"updated_at": "2021-09-23T17:58:12Z",
303+
"pushed_at": "2021-09-24T05:33:24Z",
299304
"git_url": "git://github.com/hub4j/github-api.git",
300305
"ssh_url": "[email protected]:hub4j/github-api.git",
301306
"clone_url": "https://github.com/hub4j/github-api.git",
302307
"svn_url": "https://github.com/hub4j/github-api",
303308
"homepage": "https://github-api.kohsuke.org/",
304-
"size": 26826,
305-
"stargazers_count": 728,
306-
"watchers_count": 728,
309+
"size": 36382,
310+
"stargazers_count": 810,
311+
"watchers_count": 810,
307312
"language": "Java",
308313
"has_issues": true,
309314
"has_projects": true,
310315
"has_downloads": true,
311316
"has_wiki": true,
312317
"has_pages": true,
313-
"forks_count": 520,
318+
"forks_count": 563,
314319
"mirror_url": null,
315320
"archived": false,
316321
"disabled": false,
317-
"open_issues_count": 77,
322+
"open_issues_count": 85,
318323
"license": {
319324
"key": "mit",
320325
"name": "MIT License",
321326
"spdx_id": "MIT",
322327
"url": "https://api.github.com/licenses/mit",
323328
"node_id": "MDc6TGljZW5zZTEz"
324329
},
325-
"forks": 520,
326-
"open_issues": 77,
327-
"watchers": 728,
330+
"allow_forking": true,
331+
"forks": 563,
332+
"open_issues": 85,
333+
"watchers": 810,
328334
"default_branch": "main"
329335
},
330-
"network_count": 520,
331-
"subscribers_count": 0
336+
"network_count": 563,
337+
"subscribers_count": 1
332338
}

src/test/resources/org/kohsuke/github/AppTest/wiremock/tryHook/__files/repos_hub4j-test-org_github-api_hooks-4.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"type": "Repository",
3-
"id": 276991249,
3+
"id": 319833951,
44
"name": "web",
55
"active": true,
66
"events": [
@@ -11,11 +11,12 @@
1111
"insecure_ssl": "0",
1212
"content_type": "form"
1313
},
14-
"updated_at": "2021-01-22T21:07:49Z",
15-
"created_at": "2021-01-22T21:07:49Z",
16-
"url": "https://api.github.com/repos/hub4j-test-org/github-api/hooks/276991249",
17-
"test_url": "https://api.github.com/repos/hub4j-test-org/github-api/hooks/276991249/test",
18-
"ping_url": "https://api.github.com/repos/hub4j-test-org/github-api/hooks/276991249/pings",
14+
"updated_at": "2021-09-24T05:58:37Z",
15+
"created_at": "2021-09-24T05:58:37Z",
16+
"url": "https://api.github.com/repos/hub4j-test-org/github-api/hooks/319833951",
17+
"test_url": "https://api.github.com/repos/hub4j-test-org/github-api/hooks/319833951/test",
18+
"ping_url": "https://api.github.com/repos/hub4j-test-org/github-api/hooks/319833951/pings",
19+
"deliveries_url": "https://api.github.com/repos/hub4j-test-org/github-api/hooks/319833951/deliveries",
1920
"last_response": {
2021
"code": null,
2122
"status": "unused",

0 commit comments

Comments
 (0)