-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathfetch-members.ts
More file actions
56 lines (47 loc) · 1.33 KB
/
fetch-members.ts
File metadata and controls
56 lines (47 loc) · 1.33 KB
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
49
50
51
52
53
54
55
56
import fetch from "isomorphic-fetch";
import { writeFileSync, existsSync, mkdirSync } from "fs";
interface Member {
name: string | null;
login: string;
websiteUrl: string | null;
avatarUrl: string;
url: string;
}
interface GitHubMember {
name?: string;
login: string;
blog?: string;
avatar_url: string;
html_url: string;
}
async function fetchMembers(organisation: string): Promise<Member[]> {
const url = `https://api.github.com/orgs/${organisation}/public_members`;
try {
const response = await fetch(url, {
headers: {
Accept: "application/vnd.github.v3+json",
"User-Agent": "nteract-member-fetcher",
},
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const members: GitHubMember[] = await response.json();
return members.map((member) => ({
name: member.name || null,
login: member.login,
websiteUrl: member.blog || null,
avatarUrl: member.avatar_url,
url: member.html_url,
}));
} catch (e) {
console.error(`Error fetching members for ${organisation}:`, e);
return [];
}
}
async function main() {
const members = await fetchMembers("nteract");
if (!existsSync("generated")) mkdirSync("generated");
writeFileSync("./generated/nteract-members.json", JSON.stringify(members));
}
main();