Created
February 28, 2020 05:56
-
-
Save ryanjyost/3e04237e11156c0784a7f101b4efc144 to your computer and use it in GitHub Desktop.
Get starred repos from list of top JS devs
This file contains 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 axios = require("axios"); | |
const moment = require("moment"); | |
module.exports = async function() { | |
const devs = [ | |
"gaearon", | |
"addyosmani", | |
"paulirish", | |
"thefoxis", | |
"umaar", | |
"elijahmanor", | |
"jeresig", | |
"dshaw", | |
"kentcdodds", | |
"johnpapa", | |
"darkwing", | |
"sachag", | |
"wesbos", | |
"getify", | |
"markdalgleish", | |
"chriscoyier", | |
"mdo", | |
"ry", | |
"yyx990803", | |
"Rich-Harris", | |
"sdras", | |
"emmabostian", | |
"markerikson", | |
"btholt", | |
"benlesh" | |
]; | |
const MAP = {}; | |
for (let dev of devs) { | |
const githubUrl = `https://api.github.com/users/${dev}/starred?per_page=50`; | |
const { data } = await axios.get(githubUrl, { | |
headers: { | |
Accept: "application/vnd.github.v3.star+json" | |
}, | |
auth: { | |
username: process.env.GITHUB_CLIENT_ID, | |
password: process.env.GITHUB_CLIENT_SECRET | |
} | |
}); | |
const final = data | |
.filter(item => { | |
const { repo } = item; | |
return ( | |
!repo.fork && | |
["JavaScript", "TypeScript"].includes(repo.language) && | |
moment(item.starred_at).isAfter(moment().subtract(6, "months")) | |
); | |
}) | |
.sort((a, b) => { | |
a = moment(a); | |
b = moment(b); | |
if (a.isAfter(b)) return 1; | |
if (b.isAfter(a)) return -1; | |
return 0; | |
}) | |
.map(item => { | |
if (!MAP[item.repo.name]) { | |
MAP[item.repo.name] = item; | |
MAP[item.repo.name].count = 1; | |
} else { | |
MAP[item.repo.name].count++; | |
} | |
return item.repo; | |
}); | |
} | |
const moreThan1 = Object.keys(MAP).filter(key => MAP[key].count > 1); | |
return moreThan1; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment