Skip to content

Instantly share code, notes, and snippets.

@njam
Last active February 21, 2020 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save njam/03545521a019b19472690fb33463e09f to your computer and use it in GitHub Desktop.
Save njam/03545521a019b19472690fb33463e09f to your computer and use it in GitHub Desktop.
List license of all repos in a Github organisation
var GitHubApi = require('github');
var assert = require('assert');
var org = 'cargomedia';
var token = '<github-token>';
var api = new GitHubApi({
version: '3.0.0',
protocol: 'https',
headers: {'user-agent': 'repo-lister'}
});
api.authenticate({
type: 'oauth',
token: token
});
api.repos.getFromOrg({org: org, per_page: 9999, headers: {'Accept': 'application/vnd.github.drax-preview+json'}}, function(error, result) {
assert.equal(null, error);
result.forEach(function(result) {
var name = result['name'];
var fork = result['fork'];
if (!fork) {
var license = result['license'];
if (result['license']) {
license = result['license']['name'];
} else {
license = 'Closed source';
}
console.log('- ' + name + ': ' + license);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment