如何在Github上轻松取消关注多个仓库?

101
我意识到我在GitHub上关注了太多仓库,唯一找到的取消关注它们的方式是进入github.com/my_user_name/following,然后进入每个仓库并点击“取消关注”按钮。
有没有更快、更简单地取消关注它们的方法?

5
现在在https://github.com/watching有一个“取消全部关注”按钮。 - Geremia
9个回答

188

对于懒人而言,可以在此网址(https://github.com/watching)上很快地完成操作,无需使用API。这是一个简洁明了的列表,只需单击即可。

此外,还有一个金色方框,取消选择即可避免自动关注您被授予推送访问权限的所有仓库。管理信噪比,真是太好了。


10
现在甚至有一个“停止关注所有仓库”的按钮! - Francesc Rosas
4
即使没有这样一个按钮,你也可以打开开发者控制台,然后输入快速命令 $('button').filter(function(){return $(this).text() === 'Unwatch'}).click()。网页 + jQuery = 最好的 API! - Patrick Oscity
5
谢谢,@p11y,好主意。这是一个改进版本,增加了账户过滤功能(如果你只想要筛选某个组织的存储库)$('button').filter(function(){return $(this).text() === 'Unwatch' && $(this).parent().parent().find("a span").html() == "organisationName" }).click(); - Matej Balantič
1
如果您有多个已观察的存储库页面,那么“取消所有观察”按钮会取消观看所有存储库还是仅当前页面上的存储库? - Dennis
谢谢您让我重新拥有我的收件箱。 - Mike Samuel
显示剩余2条评论

17

这是一个之前回答的纯JS版本。请前往 https://github.com/watching,然后运行以下代码:

一行代码版本:

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

揭秘:

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

1
未包装版本会因为定义常量org多次而抛出错误。以下代码运行正常:const orgName = 'YOUR_ORG' const query = document.querySelectorAll('.js-subscription-row') const rows = Array.prototype.slice.apply(query) rows.forEach(function (el) { let org = el.querySelector('a[href^="/' + orgName + '"]') if (org) el.querySelector('button').click() }) - Jon Dean
选择器已更改,目前有效的是Array.prototype.slice.apply(document.querySelectorAll('.Box-row')).forEach(el => { const org = el.querySelector('a[href^="/alphagov"]'); if (org) el.querySelector('button').click()}) - nacnudus
Github似乎已经更新了这个页面。上面的代码更新为:Array.from(document.querySelectorAll('.repo-list > li')).filter(el => !!el.querySelector('a[href^="/YOUR-ORG"]')).forEach(el => el.querySelector('details-menu button[value="included"]').click()) 然后刷新页面并再次运行,直到全部完成。 - J_A_X
最新版本正在此更新:https://gist.github.com/offirgolan/9b12a2a170f70d0d70e2238e8661e382 - stason

10

组织特定

如果您只想取消观看单个组织的存储库,则可以使用此选项从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(); } });

YOUR_ORG替换为您的组织名称。


2

我该如何撤销取消关注?即重新订阅。 - Hebe Hilhorst

2
https://github.com/watching页面上,现已提供了“取消关注全部”按钮。
另一种方法是使用这个脚本。
#! /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

1

0

我还发现了一个使用GitHub API取消关注多个存储库的命令行工具:https://www.npmjs.com/package/github-unwatch-org-repos

我不喜欢那些要求我在命令行中以明文形式输入密码的命令行工具(因此对于所有在正确时间运行“ps”的系统用户可见,并且除非您采取极端措施避免,否则以明文形式存储在~/.bash_history中),所以我没有尝试过它。


0

我还没有看到过,但是我们作为开发人员拥有整个宇宙的力量。使用他们的开发者API并创建一个小工具。该API非常详细。

http://developer.github.com/


0

我知道有点晚了,但这可能会很方便。提出的解决方案有些复杂,而且有些解决方案不允许您特别选择一个组织等。

# 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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接