This repository was archived by the owner on Jan 23, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 466
/
Copy pathget-former-members.ts
77 lines (62 loc) · 1.71 KB
/
get-former-members.ts
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
import { config } from 'dotenv'
import fs from 'fs'
import { Octokit } from 'octokit'
config()
export interface IFormerMember {
name: string | null
githubName: string | null
components: string[] | null
}
async function main() {
fs.writeFileSync(
CONFIG_PATH,
JSON.stringify(await generateFormerMemberData(), null, 2),
)
}
const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN,
})
const CONFIG_PATH = './.all-former-membersrc'
const REPO_CONFIG = {
mediaType: {
format: 'raw',
},
owner: 'chakra-ui',
repo: 'chakra-ui',
path: '.notes/previous-maintainers.md',
}
async function generateFormerMemberData() {
const { data } = await octokit.rest.repos.getContent(REPO_CONFIG)
const tableLines = (data as any)
.split('\n')
.filter((line) => line.startsWith('|'))
// remove 'table header' lines
tableLines.splice(0, 2)
return parseRepoData(tableLines)
}
// removes whitespaces at the beginning and the end
const normalizeString = (s: string) => s.replace(/^\s+|\s+$/g, '')
const parseRepoData = (lines: string[]) => {
const parsedData: IFormerMember[] = []
for (const line of lines) {
const segments = line.split('|').filter((segment) => segment !== '')
const components = segments[1]
.split(',')
.map((component) => normalizeString(component) || null)
parsedData.push({
name:
normalizeString(segments[0].slice(0, segments[0].indexOf('@'))) || null,
githubName:
normalizeString(segments[0].slice(segments[0].indexOf('@') + 1)) ||
null,
// avoid empty strings in the array
components: components[0] ? components : null,
})
}
return parsedData
}
try {
main()
} catch (err) {
console.log(err)
}