-
-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathgenerate-contributors.ts
43 lines (34 loc) · 1.15 KB
/
generate-contributors.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
import 'dotenv/config';
import fs from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { Octokit } from 'octokit';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
async function getOcto() {
if (!process.env.GITHUB_TOKEN) {
console.error('No GitHub token provided. Please set GITHUB_TOKEN env var.');
process.exit(1);
}
const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });
// get paginated contributors
const res = await octokit.paginate(octokit.rest.repos.listContributors, {
owner: 'danstepanov',
repo: 'create-expo-stack',
per_page: 100
});
const contributors = res.map((contributor) => contributor).filter((contributor) => contributor.type !== 'Bot');
return contributors;
}
async function start() {
const contributors = await getOcto();
const text = [
`// prettier-ignore`,
`// eslint-disable`,
`export const contributors = ${JSON.stringify(contributors, null, 4)}`,
``
].join('\n');
const dir = path.join(__dirname, '../www/src');
await fs.writeFile(`${dir}/contributors.ts`, text);
}
start();