Skip to content

Instantly share code, notes, and snippets.

@mikesprague
Forked from yyx990803/count.js
Created May 16, 2017 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikesprague/6e1fef992c14b38f5d93d069c7d29b1c to your computer and use it in GitHub Desktop.
Save mikesprague/6e1fef992c14b38f5d93d069c7d29b1c to your computer and use it in GitHub Desktop.
// $ yarn add request request-promise
// $ node count userA userB
const request = require('request-promise')
const get = resource => request({
url: /^https/.test(resource) ? resource : `https://api.github.com/${resource}`,
headers: {
'User-Agent': 'GitHub Contrib Counter',
'Authorization': 'token YOUR_PERSONAL_ACCESS_TOKEN'
},
json: true
}).catch(e => {
console.error(e.message)
})
const flatten = arr => [].concat.apply([], arr)
const count = async () => {
const orgs = process.argv.slice(2)
const repos = await Promise.all(orgs.map(o => get(`users/${o}/repos`)))
const contribs = await Promise.all(flatten(repos).map(r => get(r.contributors_url)))
console.log(new Set(flatten(contribs).map(u => u.login)).size)
}
count()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment