Skip to content

Commit 050b34e

Browse files
committed
Add delete-repository-webhooks.sh
Delete all webhooks from a given repository
1 parent a2ba749 commit 050b34e

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

gh-cli/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ May need to run this first in order for the gh cli to be able to have delete rep
148148
gh auth refresh -h github.com -s delete_repo
149149
```
150150

151+
## delete-repository-webhooks.sh
152+
153+
Deletes all webhooks from a repository.
154+
155+
> **Warning** This operation is not reversible.
156+
151157
## download-private-release-artifact.sh
152158

153159
Downloads a release artifact from a private/internal repository. Can either download latest version or specific version, and supports file pattern matching to download one or multiple files. See [docs](https://cli.github.com/manual/gh_release_download) for more info.

gh-cli/delete-repository-webhooks.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
if [ $# -ne 1 ]; then
4+
echo "Usage: $0 <repo>"
5+
echo "repo in the format owner/repo"
6+
exit 1
7+
fi
8+
9+
repo=$1
10+
11+
# validate if repo is in format owner/repo
12+
if [[ ! $repo =~ ^[[:alnum:]_-]+/[[:alnum:]_-]+$ ]]; then
13+
echo "ERROR: invalid repo format. Expected owner/repo"
14+
exit 1
15+
fi
16+
17+
# iterate on all repo webhooks and delete them
18+
gh api -H "X-GitHub-Api-Version: 2022-11-28" "/repos/$repo/hooks" --jq '.[].id' | while read -r id; do
19+
echo "deleting webhook $id"
20+
gh api -X DELETE "repos/$repo/hooks/$id"
21+
done
22+

0 commit comments

Comments
 (0)