-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_members.js
More file actions
88 lines (68 loc) · 2.55 KB
/
update_members.js
File metadata and controls
88 lines (68 loc) · 2.55 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import fetch from 'node-fetch';
import fs from 'fs';
async function fetchTeams() {
const response = await fetch(`https://api.github.com/orgs/CompPsyUnion/teams`, {
headers: {
'Authorization': `token ${process.env.PAT_TOKEN}`,
'Accept': 'application/vnd.github.v3+json',
},
});
if (!response.ok) {
console.error(`Error fetching teams: ${response.statusText}`);
return [];
}
return await response.json();
}
async function fetchTeamMembers(membersUrl) {
const response = await fetch(membersUrl, {
headers: {
'Authorization': `token ${process.env.PAT_TOKEN}`,
'Accept': 'application/vnd.github.v3+json',
},
});
if (!response.ok) {
console.error(`Error fetching team members: ${response.statusText}`);
return [];
}
return await response.json();
}
async function main() {
const teams = await fetchTeams();
let content = ""; // Initialize content for the Markdown file
for (const team of teams) {
const membersUrl = team.members_url.replace("{/member}", ""); // Remove the placeholder
const members = await fetchTeamMembers(membersUrl);
content += `### ${team.name}\n\n`; // Markdown for headings
const maxMembersPerRow = 10; // Show a maximum of 10 members per row
// Loop through the members and create the table rows
for (let i = 0; i < members.length; i += maxMembersPerRow) {
const rowMembers = members.slice(i, i + maxMembersPerRow); // Get the next set of members
// Create a row for avatars
content += '|'; // Start of a new row
for (const member of rowMembers) {
const avatar_url = member.avatar_url;
// Use HTML <img> tag to control image size
content += ` <img src="${avatar_url}" width="36" height="36" /> |`;
}
content += '\n'; // End of the row for avatars
// Create a row for usernames
content += '|'; // Start of a new row for usernames
for (const member of rowMembers) {
const login = member.login;
const link = `https://github.com/${login}`;
// Add the username below the avatar
content += ` [@${login}](${link}) |`;
}
content += '\n\n'; // End of the row for usernames, separate sections with newlines
}
content += '\n'; // Separate sections with newlines
}
// Add P.S. section at the end of the file
content += '### P.S.\n该社员墙通过工作流进行定时更新。\n';
// Write members section to members.md
fs.writeFileSync('members.md', content);
}
main().catch(err => {
console.error(err);
process.exit(1);
});