Skip to content

Commit

Permalink
Add delete webhook via id functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
bloslo committed Sep 22, 2021
1 parent bcb71a3 commit 541afca
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/main/java/org/kohsuke/github/GHHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ public GHHook createHook(String name, Map<String, String> config, Collection<GHE
return wrap(hook);
}

/**
* Deletes hook.
*
* @param id
* the id
* @throws IOException
* the io exception
*/
public void deleteHook(int id) throws IOException {
root().createRequest().method("DELETE").withUrlPath(collection() + "/" + id).send();
}

abstract String collection();

abstract Class<? extends GHHook[]> collectionClass();
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/kohsuke/github/GHOrganization.java
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,16 @@ public GHHook getHook(int id) throws IOException {
return GHHooks.orgContext(this).getHook(id);
}

/**
* Deletes hook.
*
* @param id
* @throws IOException
*/
public void deleteHook(int id) throws IOException {
GHHooks.orgContext(this).deleteHook(id);
}

/**
* See https://api.github.com/hooks for possible names and their configuration scheme. TODO: produce type-safe
* binding
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -1648,6 +1648,18 @@ public GHHook getHook(int id) throws IOException {
return GHHooks.repoContext(this, owner).getHook(id);
}

/**
* Deletes hook.
*
* @param id
* the id
* @throws IOException
* the io exception
*/
public void deleteHook(int id) throws IOException {
GHHooks.repoContext(this, owner).deleteHook(id);
}

/**
* Sets {@link #getCompare(String, String)} to return a {@link GHCompare} that uses a paginated commit list instead
* of limiting to 250 results.
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/kohsuke/github/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ public void tryHook() throws Exception {
assertThat(hook2.getConfig().size(), equalTo(3));
assertThat(hook2.isActive(), equalTo(true));
hook2.ping();
hook2.delete();
r.deleteHook((int) hook.getId());

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

// System.out.println(hook);
} finally {
Expand Down

0 comments on commit 541afca

Please sign in to comment.