Last active
July 31, 2017 04:07
-
-
Save yyx990803/a64cd4349915d5b3c19fdfb44f55cfbf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// $ 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