Created
November 3, 2017 12:53
-
-
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
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 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No error handling, care for rate limit!