如何在 github 上轻松取消观看多次回购?

我意识到自己在 gitHub 上看了太多的回购 GitHub.com/my_user_name/following ,我发现唯一能够取消看这些回购的方法就是进入每一个回购页面,然后按下取消看这些回购页面的按钮。

有没有什么办法可以更快更容易地忘记他们?

18519 次浏览

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,

http://developer.github.com/

Github has an API. You could write a script to do this using Github's API, particularly the part that deals with watching repos.

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.

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.

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.

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()
})

A few comments have mentioned the Unwatch all button at https://github.com/watching

Here's a picture:

enter image description here

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

I know it's a bit late but this might be handy. The proposed solutions are little complex & few solutions doesn't allow you to specifically select an organization, etc.

# Make sure the personal access token has access to notifications & repo
GH_TOKEN=<TOKEN-HERE>
ORGANIZATION=<ORG-NAME>
MAX_REPO_COUNT=5000
repolist=$(GH_TOKEN=$GH_TOKEN gh repo list $ORGANIZATION -L $MAX_REPO_COUNT --json name --jq '.[].name')
echo $repolist | while read repo; do
echo "Unsubscribing from $ORGANIZATION/$repo\n"
GH_TOKEN=$GH_TOKEN gh api -H "Accept: application/vnd.github+json" /repos/$ORGANIZATION/$repo/subscription --method PUT -F ignored=true | jq '.'
done