Skip to content

Instantly share code, notes, and snippets.

@miyukki
Created July 6, 2018 07:09
Show Gist options
  • Save miyukki/808e7402f8e50800511ed3c7c47ab531 to your computer and use it in GitHub Desktop.
Save miyukki/808e7402f8e50800511ed3c7c47ab531 to your computer and use it in GitHub Desktop.
Get GitHub Organization Members
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