Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created March 31, 2017 02:01
Show Gist options
  • Save tmcw/0faf0b6b12813d50ab0324c87b47813d to your computer and use it in GitHub Desktop.
Save tmcw/0faf0b6b12813d50ab0324c87b47813d to your computer and use it in GitHub Desktop.
Managing GitHub Watching en masse

Managing GitHub Watching

I decided to unwatch many repos in multiple organizations. Here are two scripts that I wrote to make that possible. It works like:

  1. I load GitHubAccessToken in my environment, an environment variable that gives these access
  2. I run node get-all-watched.js > all-watching.txt to dump all watching into a text file
  3. Run grep "^developmentseed" all-watching > developmentseed.txt, for instance, to make a text file of only repos in the developmentseed org that I'm watching
  4. Run node unwatch-file-of-repos.js developmentseed.txt to unwatch all those repos.
var gotLinks = require('got-links');
var ghGot = require('gh-got');
var getAllWatching = accessToken => gotLinks({
got: ghGot,
url: 'user/subscriptions',
options: {
token: accessToken
},
reducer: (memo, response) => memo.concat(response.body)
});
getAllWatching(process.env.GitHubAccessToken).then(list => {
list.forEach(l => console.log(l.full_name));
});
{
"name": "manage-watching",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"gh-got": "^5.0.0",
"got-links": "^1.0.0"
}
}
var ghGot = require('gh-got');
var fs = require('fs');
fs.readFileSync(process.argv[2], 'utf8')
.split('\n')
.filter(String)
.forEach(line => ghGot(`repos/${line}/subscription`, {
method: 'DELETE',
token: accessToken
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment