How to unwatch multiple repos easily on github?
GithubGithub Problem Overview
I realize I watch too many repos in GitHub and the only way I've found to unwatch many of them is going to github.com/my_user_name/following, getting inside each of them and pressing Unwatch button.
Isn't there any way to unwatch them faster and easily?
Github Solutions
Solution 1 - Github
For the lazy, one can do this without the API reasonably quickly at this url: https://github.com/watching
A clean simple list, click click click click.
Additionally, there's a box that is golden. Uncheck it to not automatically be set to watch all repos you're given push access to. Hooray for managing the signal to noise ratio.
Solution 2 - Github
Native JS version of a previous answer. Navigate to https://github.com/watching and then run:
Oneliner:
Array.prototype.slice.apply(document.querySelectorAll('.js-subscription-row')).forEach(el => { const org = el.querySelector('a[href^="/YOUR_ORG"]'); if (org) el.querySelector('button').click()})
Unwrapped:
const org = 'YOUR_ORG'
const query = document.querySelectorAll('.js-subscription-row')
const rows = Array.prototype.slice.apply(query)
rows.forEach(function (el) {
const org = el.querySelector('a[href^="/' + org + '"]')
if (org) el.querySelector('button').click()
})
Solution 3 - Github
##Organisation specific
If you just want to unwatch repos from a single organisation, you can use this from https://github.com/watching
$('.js-subscription-row').each(function(){
var isYourOrganisation = $(this).find("a[href^='/YOUR_ORG']");
if(isYourOrganisation.length){
$(this).find('button:contains("Unwatch")').click();
}
});```
Substitute `YOUR_ORG` with whatever your organisation is called.
Solution 4 - Github
Github has an API. You could write a script to do this using Github's API, particularly the part that deals with watching repos.
Solution 5 - Github
I haven't seen any but, As we have power of the entire universe(in short we are developers). Use their developer API and create a small tool. The API is very descriptive,
Solution 6 - Github
A few comments have mentioned the Unwatch all button at https://github.com/watching
Here's a picture:
Solution 7 - Github
I've also found a command-line tool that use the GitHub API to unwatch multiple repositories: https://www.npmjs.com/package/github-unwatch-org-repos
I'm not a fan of command-line tools that want my password in plain text on the command line (thus visible to all system users who run 'ps' at the right time, and also stored in plain text in ~/.bash_history unless you take extreme care to avoid that), so I haven't tried it.
Solution 8 - Github
Unwatch all button on https://github.com/watching is available.
An alternative method is to use this script.
#! /bin/bash
# dry run:
# ./github-unwatch.bash [unwatch repository pattern] [github account] [github token]
#
# execute actually:
# ./github-unwatch.bash [unwatch repository pattern] [github account] [github token] run
set -eu
readonly REPOSITORY_PATTERN="$1"
readonly CREDENTIALS="$2:$3"
readonly RUN="${4:-dry-run}"
page=1
targets=()
while :
do
result=($( curl \
-u $CREDENTIALS \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/user/subscriptions?per_page=100&page=$page" \
| jq -r '.[].full_name' ))
if [[ ${#result[@]} -eq 0 ]]; then
break
fi
for e in "${result[@]}"
do
if [[ $e =~ $REPOSITORY_PATTERN ]]; then
targets+=($e)
fi
done
page=$((++page))
done
if [[ ${#targets[@]} -eq 0 ]]; then
exit 0
fi
for target in "${targets[@]}"
do
echo "Unwatch: $target"
if [[ "$RUN" == "run" ]]; then
curl \
-u $CREDENTIALS \
-X DELETE \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/$target/subscription"
fi
done