Created
June 3, 2020 00:37
-
-
Save easingthemes/6d63180b29cf9a6ab9472d133632bb31 to your computer and use it in GitHub Desktop.
Get stargazers count per user of an org
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
const { Octokit } = require('@octokit/rest'); | |
const dotEnv = require('dotenv'); | |
dotEnv.config(); | |
const config = { | |
org: process.env.ORG, | |
auth: process.env.DEV_TOKEN, | |
count: 3, | |
limit: 100 | |
}; | |
const octokit = new Octokit({ | |
auth: config.auth | |
}); | |
octokit.orgs.listMembers({ | |
org: config.org, | |
}) | |
.then(({ data }) => { | |
const promises = data.map(i => { | |
const owner = i.login; | |
return octokit | |
.paginate('GET /users/:owner/repos', { | |
owner, | |
per_page: config.limit | |
}) | |
.then((userRepos) => { | |
const allStars = userRepos.map(r => r.stargazers_count); | |
const totalStars = allStars.reduce((a, b) => a + b, 0); | |
const topStars = allStars.sort((a, b) => b - a).slice(0, config.count); | |
return { | |
owner, | |
repos: userRepos.length, | |
totalStars, | |
topStars | |
} | |
}) | |
.catch(e => console.log(e)); | |
}); | |
Promise.all(promises).then((list) => { | |
list.sort((a, b) => parseFloat(b.totalStars) - parseFloat(a.totalStars)); | |
console.log(list); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment