Skip to content

Instantly share code, notes, and snippets.

@akullpp
Created November 3, 2017 12:53
Show Gist options
  • Save akullpp/a2788525c7126428277c5dafaad3767c to your computer and use it in GitHub Desktop.
Save akullpp/a2788525c7126428277c5dafaad3767c to your computer and use it in GitHub Desktop.
Get license for all repos of a user via nodejs and GitHub v3 API
const https = require('https')
const USER = 'akullpp'
const OPTIONS = {
method: 'GET',
host: 'api.github.com',
headers: {
'Accept': 'application/json',
'User-Agent': USER,
}
}
const findLicense = repo => https.request(Object.assign(OPTIONS, {
path: `/repos/${USER}/${repo.name}/license`
}), res => res.statusCode !== 200 && console.log(`Missing license in ${repo.name}`)).end()
const handleReposRequest = res => {
const data = [];
res.on('data', chunk => data.push(chunk))
res.on('end', () => JSON.parse(data.join('')).map(findLicense))
}
https.request(Object.assign(OPTIONS, {
path: `/users/${USER}/repos`
}), handleReposRequest).end()
@akullpp
Copy link
Author

akullpp commented Nov 3, 2017

No error handling, care for rate limit!

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