-
Notifications
You must be signed in to change notification settings - Fork 30
/
fetch-members.js
48 lines (41 loc) · 1.08 KB
/
fetch-members.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const { GraphQLClient } = require("graphql-request");
const { writeFileSync, existsSync, mkdirSync } = require("fs");
async function fetchMembers(organisation) {
const token = process.env.GH_TOKEN;
if (!token) {
console.error("'GH_TOKEN' not set. Could not fetch nteract members.");
return [];
}
const client = new GraphQLClient("https://api.github.com/graphql", {
headers: {
Authorization: `Bearer ${token}`
}
});
const query = `{
organization(login: "${organisation}") {
membersWithRole(first: 100) {
totalCount
nodes {
name
login
websiteUrl
avatarUrl
url
}
}
}
}`;
try {
const data = await client.request(query);
return data.organization.membersWithRole.nodes;
} catch (e) {
console.error(e);
return [];
}
}
async function main() {
const members = await fetchMembers("nteract");
if (!existsSync("generated")) mkdirSync("generated");
writeFileSync("./generated/nteract-members.json", JSON.stringify(members));
}
main();