Created
July 6, 2018 07:09
-
-
Save miyukki/808e7402f8e50800511ed3c7c47ab531 to your computer and use it in GitHub Desktop.
Get GitHub Organization Members
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
const GitHub = require('github-api'); | |
var gh = new GitHub({ | |
token: '<token>', | |
}); | |
var getOrganizationMembers = (orgnization, page = 1, members = []) => { | |
return gh.getOrganization(orgnization).listMembers({ page: page }).then(res => { | |
members = members.concat(res.data); | |
if (res.headers.link.split(",").filter(l => l.match(/rel="next"/)).length > 0) { | |
return getOrganizationMembers(orgnization, page+1, members); | |
} | |
return Promise.resolve(members); | |
}); | |
}; | |
getOrganizationMembers("<org_name>").then(members => { | |
const data = members.map((m, i) => { | |
return `${m.id}\t${m.login}\t=IMAGE("${m.avatar_url}")\t${m.type}` | |
}).join("\n"); | |
console.log(data); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment