Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add delete webhook via id functionality. #1237

Merged
merged 2 commits into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need to test both pathways of hook2.delete().

o.deleteHook((int) hook.getId());

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