-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgenerateConfig.js
61 lines (48 loc) · 1.34 KB
/
generateConfig.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
49
50
51
52
53
54
55
56
57
58
59
60
61
const { join } = require('path');
const fs = require('fs/promises');
const prettier = require('prettier');
const _orderBy = require('lodash/orderBy');
const { Octokit } = require('@octokit/core');
require('dotenv').config();
const CONFIG_FILE = 'examples.config.js';
const OUT_DIR = 'examples';
const octokit = new Octokit({
auth: process.env.GITHUB_API_TOKEN,
});
(async () => {
const exampleRepos = await getExampleRepos();
const repoUrls = exampleRepos.map(
({ ssh_url: repo, default_branch: branch }) => ({ repo, branch })
);
const content = `module.exports = ${JSON.stringify({
outDir: OUT_DIR,
repos: _orderBy(repoUrls, 'repo'),
})}`;
await fs.writeFile(
join(process.cwd(), CONFIG_FILE),
prettier.format(content)
);
})();
async function getRepositories() {
let page = 0;
let allRepos = [];
while (true) {
const { data } = (resp = await octokit.request('GET /orgs/{org}/repos', {
org: 'edgio-docs',
page: ++page,
}));
allRepos.push(...data);
if (data.length === 0) {
break;
}
}
console.log('Total repo count:', allRepos.length);
return allRepos;
}
async function getExampleRepos() {
const exampleRepoRE = /^(edgio)(.+example)$/i;
const repos = await getRepositories();
return repos.filter(
({ name, archived }) => !archived && name.match(exampleRepoRE)
);
}