As part of my job I routinely create new Github repositories for my colleagues. One unfortunate side-effect is that I am automatically subscribed to all those repositories and get mails for any new issues, pull requests and so on.

This culminated in hundreds of mails over the weekend when we activated renovate for all repositories. But since I don’t work on these repositories, I don’t need any notifications.

Now Github offers me two ways on its website to unsubscribe:

  1. Via this webpage: There I can either unsubscribe from all (which I don’t want) or unsubscribe from each repository by hand, which is too time-consuming.
  2. Via the repositories by clicking the unwatch-button on each of these. Also too time-consuming.

Thankfully Github has a nice API where I can unsubscribe from notifications. This is the command to do it for one single repository:

gh api --method DELETE repos/T-Systems-MMS/terraform-azurerm-kubernetes-cluster/subscription

Now I only need to get all repositories I want to unsubscribe from. Thankfully they all have a topic, so I can get them with this command:

gh repo list T-Systems-MMS --topic terraform-module --json name -q .[].name

Now I only need to combine these two commands into one loop:

for NAME in $(gh repo list T-Systems-MMS --topic terraform-module --json name -q .[].name); do gh api --method DELETE repos/T-Systems-MMS/$NAME/subscription; done

Related posts: