-
./watching.sh > repositories.json-stream
. -
Review the repositories.json-stream and remove all the repositories you want to be subscribed on.
-
./unwatch.sh
.
Created
January 8, 2025 11:16
-
-
Save madhead/dbdb6640d400d77a1e87c0a76062525f to your computer and use it in GitHub Desktop.
Bulk Unwatch GitHub Repositories
This file contains hidden or 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
#!/bin/bash | |
TOKEN="" | |
GRAPHQL_API="https://api.github.com/graphql" | |
unwatch_repository() { | |
local repo_id=$1 | |
local mutation=$(cat <<EOF | |
{ | |
"query": "mutation (\$repoId: ID!) { \ | |
updateSubscription(input: {subscribableId: \$repoId, state: UNSUBSCRIBED}) { \ | |
subscribable { \ | |
id \ | |
} \ | |
} \ | |
}", \ | |
"variables": { \ | |
"repoId": "$repo_id" \ | |
} \ | |
} | |
EOF | |
) | |
curl -s -H "Authorization: Bearer $TOKEN" -d "$mutation" $GRAPHQL_API | |
} | |
jq -c '.' repositories.json-stream | while read -r object; do | |
repo_id=$(echo "$object" | jq -r '.id') | |
repo=$(echo "$object" | jq -r '.nameWithOwner') | |
unwatch_repository "$repo_id" | |
echo "Unwatched $repo ($repo_id)" | |
done |
This file contains hidden or 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
#!/bin/bash | |
TOKEN="" | |
GRAPHQL_API="https://api.github.com/graphql" | |
fetch_repositories() { | |
local cursor=$1 | |
local query=$(cat <<EOF | |
{ | |
"query": "query(\$cursor: String) { \ | |
viewer { \ | |
watching(first: 100, after: \$cursor) { \ | |
nodes { \ | |
id \ | |
nameWithOwner \ | |
} \ | |
pageInfo { \ | |
hasNextPage \ | |
endCursor \ | |
} \ | |
} \ | |
} \ | |
}", \ | |
"variables": { \ | |
"cursor": $cursor \ | |
} | |
} | |
EOF | |
) | |
curl -s -H "Authorization: Bearer $TOKEN" -d "$query" $GRAPHQL_API | |
} | |
cursor="null" | |
while true; do | |
response=$(fetch_repositories $cursor) | |
has_next_page=$(echo $response | jq -r '.data.viewer.watching.pageInfo.hasNextPage') | |
cursor=$(echo $response | jq -r '.data.viewer.watching.pageInfo.endCursor') | |
[ "$cursor" != "null" ] && cursor="\"$cursor\"" | |
echo $response | jq '.data.viewer.watching.nodes[]' | |
if [ "$has_next_page" != "true" ]; then | |
break | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment