Created
May 10, 2016 10:22
-
-
Save derhuerst/19e0844796fa3b62e1e9567a1dc0b5a3 to your computer and use it in GitHub Desktop.
how fetch a GitHub user's stars
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
[ | |
{ | |
owner: 'bcoe', | |
repo: 'top-npm-users', | |
description: ':star: Generate a list of top npm users by based on monthly downloads.', | |
language: 'JavaScript', | |
isFork: false, | |
stargazers: 27, | |
watchers: 27 | |
} | |
// … | |
] |
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
'use strict' | |
const got = require('got') | |
const stars = (user) => | |
got(`https://api.github.com/users/${user}/starred`) | |
.then((res) => JSON.parse(res.body)) | |
.then((starred) => starred.map((s) => ({ | |
owner: s.owner.login | |
, repo: s.name | |
, description: s.description | |
, language: s.language | |
, isFork: false | |
, stargazers: s.stargazers_count | |
, watchers: s.watchers_count | |
}))) | |
stars('jonschlinkert').then(console.log) |
https://api.github.com/users/${user}/starred
gives me the list, how do I get the total number of starred repo so I can run request using that api for the list in parallel?
you can use this trick:
https://github.community/t/how-can-i-know-the-number-of-repository-by-user-name/13767/3
Bonus tips, since no one mentioned it here: the query only shows the most recent 30 stars. If the user has more than that, you may want to use the page=${num}
URL attribute, to navigate the least recent stars. Page 1 is implicit and is from the 1st to 30th most recent stars, page 2 is from the 31th to 60th most recent stars, and so on. For example, https://api.github.com/users/${user}/starred?&page=2
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://api.github.com/users/${user}/starred
gives me the list, how do I get the total number of starred repo so I can run request using that api for the list in parallel?