Last active
March 22, 2024 12:04
-
-
Save sparky-raccoon/80031d03157758a38d2df871f4deb265 to your computer and use it in GitHub Desktop.
Unsubscribe and ignore automatically every repository of your organisation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# GH_TOKEN= | |
# GITHUB_TOKEN=$GH_TOKEN | |
# ORGANIZATION= | |
# LOG_FILE= | |
exec 3>&1 1>>${LOG_FILE} 2>&1 | |
now=$(date) | |
echo ">>>> Script started at: $now" | |
echo "" | |
gh auth login --with-token <<< $GH_TOKEN | |
subscribed=($(gh api -H "Accept: application/vnd.github.json" -H "X-GitHub-Api-Version: 2022-11-28" /user/subscriptions --jq '.[].full_name') ) | |
echo ">> Unsubscribe automatically subscribed repositories from $ORGANIZATION" | |
echo "$subscribed" | |
for it in "${subscribed[@]}" | |
do | |
if [[ $it == *"$ORGANIZATION"* ]]; then | |
gh api \ | |
--method PUT \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
"/repos/${it}/subscription" \ | |
-F subscribed=false \ | |
-F ignored=true | jq . | |
fi | |
done | |
echo "" | |
echo ">> Cleaning notifications" | |
gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /notifications --jq '.[].repository.full_name' | |
notified=($(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /notifications --jq '.[].repository.full_name')) | |
echo "$notified" | |
for it in "${notified[@]}" | |
do | |
# Mark them as read. Missing steps : | |
# unsubscribe (/notifications/beta/unsubscribe) + done (/notifications/beta/archive) | |
if [[ $it == *"$ORGANIZATION"* ]]; then | |
gh api \ | |
--method PUT \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
"/repos/${it}/notifications" | |
fi | |
done | |
echo "" | |
now=$(date) | |
echo ">>>> Script ended at: $now" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Another option that might help to avoid automatic subscription at all is the "Automatically watch repositories > When you're given push access to a repository, automatically receive notifications for it." notifications setting from your profile. However, as a global setting it would prevent you to automatically watch repositories that do not belong to a specific organisation.