Skip to content

Commit

Permalink
Add test for delete hook by ID
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwiseman committed Sep 24, 2021
1 parent 541afca commit f3b193e
Show file tree
Hide file tree
Showing 29 changed files with 597 additions and 258 deletions.
24 changes: 20 additions & 4 deletions src/test/java/org/kohsuke/github/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.google.common.collect.Iterables;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.SystemUtils;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Ignore;
import org.junit.Test;
Expand Down Expand Up @@ -620,8 +621,8 @@ public void testCreateCommitComment() throws Exception {

@Test
public void tryHook() throws Exception {
GHOrganization o = gitHub.getOrganization(GITHUB_API_TEST_ORG);
GHRepository r = o.getRepository("github-api");
final GHOrganization o = gitHub.getOrganization(GITHUB_API_TEST_ORG);
final GHRepository r = o.getRepository("github-api");
try {
GHHook hook = r.createWebHook(new URL("http://www.google.com/"));
assertThat(hook.getName(), equalTo("web"));
Expand All @@ -637,6 +638,13 @@ public void tryHook() throws Exception {
assertThat(hook2.getConfig().size(), equalTo(3));
assertThat(hook2.isActive(), equalTo(true));
hook2.ping();
hook2.delete();
final GHHook finalRepoHook = hook;
GHFileNotFoundException e = Assert.assertThrows(GHFileNotFoundException.class, () -> r.getHook((int) finalRepoHook.getId()));
assertThat(e.getMessage(), containsString("repos/hub4j-test-org/github-api/hooks/" + finalRepoHook.getId()));
assertThat(e.getMessage(), containsString("rest/reference/repos#get-a-repository-webhook"));

hook = r.createWebHook(new URL("http://www.google.com/"));
r.deleteHook((int) hook.getId());

hook = o.createWebHook(new URL("http://www.google.com/"));
Expand All @@ -653,13 +661,21 @@ public void tryHook() throws Exception {
assertThat(hook2.getConfig().size(), equalTo(3));
assertThat(hook2.isActive(), equalTo(true));
hook2.ping();
hook2.delete();

final GHHook finalOrgHook = hook;
GHFileNotFoundException e2 = Assert.assertThrows(GHFileNotFoundException.class, () -> o.getHook((int) finalOrgHook.getId()));
assertThat(e2.getMessage(), containsString("orgs/hub4j-test-org/hooks/" + finalOrgHook.getId()));
assertThat(e2.getMessage(), containsString("rest/reference/orgs#get-an-organization-webhook"));

hook = o.createWebHook(new URL("http://www.google.com/"));
o.deleteHook((int) hook.getId());

// System.out.println(hook);
} finally {
if (mockGitHub.isUseProxy()) {
r = getNonRecordingGitHub().getOrganization(GITHUB_API_TEST_ORG).getRepository("github-api");
for (GHHook h : r.getHooks()) {
GHRepository cleanupRepo = getNonRecordingGitHub().getOrganization(GITHUB_API_TEST_ORG).getRepository("github-api");
for (GHHook h : cleanupRepo.getHooks()) {
h.delete();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"is_verified": false,
"has_organization_projects": true,
"has_repository_projects": true,
"public_repos": 13,
"public_repos": 19,
"public_gists": 0,
"followers": 0,
"following": 0,
Expand All @@ -31,7 +31,7 @@
"total_private_repos": 2,
"owned_private_repos": 2,
"private_gists": 0,
"disk_usage": 152,
"disk_usage": 11979,
"collaborators": 0,
"billing_email": "[email protected]",
"default_repository_permission": "none",
Expand All @@ -44,7 +44,7 @@
"name": "free",
"space": 976562499,
"private_repos": 10000,
"filled_seats": 22,
"filled_seats": 26,
"seats": 3
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"type": "Organization",
"id": 319833954,
"name": "web",
"active": true,
"events": [
"push"
],
"config": {
"url": "http://www.google.com/",
"insecure_ssl": "0",
"content_type": "form"
},
"updated_at": "2021-09-24T05:58:39Z",
"created_at": "2021-09-24T05:58:39Z",
"url": "https://api.github.com/orgs/hub4j-test-org/hooks/319833954",
"ping_url": "https://api.github.com/orgs/hub4j-test-org/hooks/319833954/pings",
"deliveries_url": "https://api.github.com/orgs/hub4j-test-org/hooks/319833954/deliveries"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"type": "Organization",
"id": 319833957,
"name": "web",
"active": true,
"events": [
"push"
],
"config": {
"url": "http://www.google.com/",
"insecure_ssl": "0",
"content_type": "form"
},
"updated_at": "2021-09-24T05:58:40Z",
"created_at": "2021-09-24T05:58:40Z",
"url": "https://api.github.com/orgs/hub4j-test-org/hooks/319833957",
"ping_url": "https://api.github.com/orgs/hub4j-test-org/hooks/319833957/pings",
"deliveries_url": "https://api.github.com/orgs/hub4j-test-org/hooks/319833957/deliveries"
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"type": "Organization",
"id": 319833954,
"name": "web",
"active": true,
"events": [
"push"
],
"config": {
"url": "http://www.google.com/",
"insecure_ssl": "0",
"content_type": "form"
},
"updated_at": "2021-09-24T05:58:39Z",
"created_at": "2021-09-24T05:58:39Z",
"url": "https://api.github.com/orgs/hub4j-test-org/hooks/319833954",
"ping_url": "https://api.github.com/orgs/hub4j-test-org/hooks/319833954/pings",
"deliveries_url": "https://api.github.com/orgs/hub4j-test-org/hooks/319833954/deliveries"
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"site_admin": false
},
"html_url": "https://github.com/hub4j-test-org/github-api",
"description": "Resetting",
"description": "Tricky",
"fork": true,
"url": "https://api.github.com/repos/hub4j-test-org/github-api",
"forks_url": "https://api.github.com/repos/hub4j-test-org/github-api/forks",
Expand Down Expand Up @@ -65,14 +65,14 @@
"releases_url": "https://api.github.com/repos/hub4j-test-org/github-api/releases{/id}",
"deployments_url": "https://api.github.com/repos/hub4j-test-org/github-api/deployments",
"created_at": "2019-09-06T23:26:04Z",
"updated_at": "2021-01-22T03:50:37Z",
"pushed_at": "2020-09-03T19:05:17Z",
"updated_at": "2021-04-19T20:09:00Z",
"pushed_at": "2021-07-24T20:28:27Z",
"git_url": "git://github.com/hub4j-test-org/github-api.git",
"ssh_url": "[email protected]:hub4j-test-org/github-api.git",
"clone_url": "https://github.com/hub4j-test-org/github-api.git",
"svn_url": "https://github.com/hub4j-test-org/github-api",
"homepage": "http://github-api.kohsuke.org/",
"size": 19052,
"size": 19045,
"stargazers_count": 0,
"watchers_count": 0,
"language": "Java",
Expand All @@ -85,27 +85,31 @@
"mirror_url": null,
"archived": false,
"disabled": false,
"open_issues_count": 5,
"open_issues_count": 7,
"license": {
"key": "mit",
"name": "MIT License",
"spdx_id": "MIT",
"url": "https://api.github.com/licenses/mit",
"node_id": "MDc6TGljZW5zZTEz"
},
"allow_forking": true,
"forks": 0,
"open_issues": 5,
"open_issues": 7,
"watchers": 0,
"default_branch": "main",
"permissions": {
"admin": true,
"maintain": true,
"push": true,
"triage": true,
"pull": true
},
"temp_clone_token": "",
"allow_squash_merge": true,
"allow_merge_commit": true,
"allow_rebase_merge": true,
"allow_auto_merge": false,
"delete_branch_on_merge": false,
"organization": {
"login": "hub4j-test-org",
Expand Down Expand Up @@ -194,37 +198,38 @@
"releases_url": "https://api.github.com/repos/hub4j/github-api/releases{/id}",
"deployments_url": "https://api.github.com/repos/hub4j/github-api/deployments",
"created_at": "2010-04-19T04:13:03Z",
"updated_at": "2021-01-22T01:29:15Z",
"pushed_at": "2021-01-15T04:14:15Z",
"updated_at": "2021-09-23T17:58:12Z",
"pushed_at": "2021-09-24T05:33:24Z",
"git_url": "git://github.com/hub4j/github-api.git",
"ssh_url": "[email protected]:hub4j/github-api.git",
"clone_url": "https://github.com/hub4j/github-api.git",
"svn_url": "https://github.com/hub4j/github-api",
"homepage": "https://github-api.kohsuke.org/",
"size": 26826,
"stargazers_count": 728,
"watchers_count": 728,
"size": 36382,
"stargazers_count": 810,
"watchers_count": 810,
"language": "Java",
"has_issues": true,
"has_projects": true,
"has_downloads": true,
"has_wiki": true,
"has_pages": true,
"forks_count": 520,
"forks_count": 563,
"mirror_url": null,
"archived": false,
"disabled": false,
"open_issues_count": 77,
"open_issues_count": 85,
"license": {
"key": "mit",
"name": "MIT License",
"spdx_id": "MIT",
"url": "https://api.github.com/licenses/mit",
"node_id": "MDc6TGljZW5zZTEz"
},
"forks": 520,
"open_issues": 77,
"watchers": 728,
"allow_forking": true,
"forks": 563,
"open_issues": 85,
"watchers": 810,
"default_branch": "main"
},
"source": {
Expand Down Expand Up @@ -294,39 +299,40 @@
"releases_url": "https://api.github.com/repos/hub4j/github-api/releases{/id}",
"deployments_url": "https://api.github.com/repos/hub4j/github-api/deployments",
"created_at": "2010-04-19T04:13:03Z",
"updated_at": "2021-01-22T01:29:15Z",
"pushed_at": "2021-01-15T04:14:15Z",
"updated_at": "2021-09-23T17:58:12Z",
"pushed_at": "2021-09-24T05:33:24Z",
"git_url": "git://github.com/hub4j/github-api.git",
"ssh_url": "[email protected]:hub4j/github-api.git",
"clone_url": "https://github.com/hub4j/github-api.git",
"svn_url": "https://github.com/hub4j/github-api",
"homepage": "https://github-api.kohsuke.org/",
"size": 26826,
"stargazers_count": 728,
"watchers_count": 728,
"size": 36382,
"stargazers_count": 810,
"watchers_count": 810,
"language": "Java",
"has_issues": true,
"has_projects": true,
"has_downloads": true,
"has_wiki": true,
"has_pages": true,
"forks_count": 520,
"forks_count": 563,
"mirror_url": null,
"archived": false,
"disabled": false,
"open_issues_count": 77,
"open_issues_count": 85,
"license": {
"key": "mit",
"name": "MIT License",
"spdx_id": "MIT",
"url": "https://api.github.com/licenses/mit",
"node_id": "MDc6TGljZW5zZTEz"
},
"forks": 520,
"open_issues": 77,
"watchers": 728,
"allow_forking": true,
"forks": 563,
"open_issues": 85,
"watchers": 810,
"default_branch": "main"
},
"network_count": 520,
"subscribers_count": 0
"network_count": 563,
"subscribers_count": 1
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"type": "Repository",
"id": 276991249,
"id": 319833951,
"name": "web",
"active": true,
"events": [
Expand All @@ -11,11 +11,12 @@
"insecure_ssl": "0",
"content_type": "form"
},
"updated_at": "2021-01-22T21:07:49Z",
"created_at": "2021-01-22T21:07:49Z",
"url": "https://api.github.com/repos/hub4j-test-org/github-api/hooks/276991249",
"test_url": "https://api.github.com/repos/hub4j-test-org/github-api/hooks/276991249/test",
"ping_url": "https://api.github.com/repos/hub4j-test-org/github-api/hooks/276991249/pings",
"updated_at": "2021-09-24T05:58:37Z",
"created_at": "2021-09-24T05:58:37Z",
"url": "https://api.github.com/repos/hub4j-test-org/github-api/hooks/319833951",
"test_url": "https://api.github.com/repos/hub4j-test-org/github-api/hooks/319833951/test",
"ping_url": "https://api.github.com/repos/hub4j-test-org/github-api/hooks/319833951/pings",
"deliveries_url": "https://api.github.com/repos/hub4j-test-org/github-api/hooks/319833951/deliveries",
"last_response": {
"code": null,
"status": "unused",
Expand Down
Loading

0 comments on commit f3b193e

Please sign in to comment.