Skip to content

Instantly share code, notes, and snippets.

@derhuerst
Created May 10, 2016 10:22
Show Gist options
  • Select an option

  • Save derhuerst/19e0844796fa3b62e1e9567a1dc0b5a3 to your computer and use it in GitHub Desktop.

Select an option

Save derhuerst/19e0844796fa3b62e1e9567a1dc0b5a3 to your computer and use it in GitHub Desktop.
how fetch a GitHub user's stars
[
{
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
}
// …
]
'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)
@SuperZombi
Copy link

For vanila JS:

const stars = (user) =>
	fetch(`https://api.github.com/users/${user}/starred`)
	.then((res) => res.json())
	.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
	})))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment