Skip to content

Instantly share code, notes, and snippets.

@secustor
Created October 18, 2025 19:39
Show Gist options
  • Select an option

  • Save secustor/0b1b881d1db5cf7c83e17b86ee58010b to your computer and use it in GitHub Desktop.

Select an option

Save secustor/0b1b881d1db5cf7c83e17b86ee58010b to your computer and use it in GitHub Desktop.
Delete notifications for specific repositories
1 #!/usr/bin/env bash
2 set -euo pipefail
3
4 # Repositories whose notification threads should be deleted.
5 TARGET_REPOS=("ventures-gitcoin/gitcoin.com" "ycoombinator/-co")
6 DRY_RUN="${DRY_RUN:-0}" # Set DRY_RUN=1 to skip deletions.
7
8 page=1
9 printed=0
10 deleted=0
11
12 while true; do
13 resp="$(gh api "notifications?all=true&page=${page}")"
14 count="$(echo "$resp" | jq 'length')"
15 if [[ "$count" -eq 0 ]]; then
16 break
17 fi
18
19 echo "$resp" | jq -c '.[] | { id, title: .subject.title, repo: .repository.full_name }' | while read -r obj; do
20 # Pretty print the JSON object.
21 # echo "$obj" | jq .
22 printed=$((printed+1))
23
24 id="$(echo "$obj" | jq -r '.id')"
25 repo="$(echo "$obj" | jq -r '.repo')"
26
27 for target in "${TARGET_REPOS[@]}"; do
28 if [[ "$repo" == "$target" ]]; then
29 if [[ "$DRY_RUN" == "1" ]]; then
30 echo "DRY_RUN: would delete thread ${id} for repo ${repo}" >&2
31 else
32 echo "Deleting thread ${id} for repo ${repo}" >&2
33 gh api --method DELETE "notifications/threads/${id}" >/dev/null
34 fi
35 deleted=$((deleted+1))
36 break
37 fi
38 done
39 done
40
41 page=$((page+1))
42 done
43
44 echo "Finished. printed=${printed} deleted=${deleted} dry_run=${DRY_RUN}" >&2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment