Skip to content

Commit f6103f9

Browse files
authored
feat: add update-fork (zoo-js#90)
1 parent be479bf commit f6103f9

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

active-script/update-fork.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
require('dotenv').config();
2+
const { Octokit } = require('@octokit/rest');
3+
const axios = require('axios');
4+
5+
const {
6+
GH_TOKEN: githubToken,
7+
} = process.env;
8+
9+
const octokit = new Octokit({ auth: `token ${githubToken}` });
10+
11+
const url = 'https://raw.githubusercontent.com/zoo-js/zoo-data/main/json/organizations.json';
12+
let organizations = [];
13+
14+
const repo = 'zoo';
15+
16+
async function main() {
17+
if (organizations.length == 0) {
18+
console.log('org 0');
19+
return false;
20+
}
21+
22+
for (let i = 0; i < organizations.length; i++) {
23+
let owner = organizations[i].fullName
24+
await octokit.repos.delete({
25+
owner,
26+
repo
27+
})
28+
await octokit.repos.createFork({
29+
owner: 'zoo-js',
30+
repo,
31+
organization: owner
32+
})
33+
console.log(`${owner} done`)
34+
}
35+
};
36+
37+
async function getOrganizations() {
38+
try {
39+
const res = await axios.get(url);
40+
organizations = res.data.data;
41+
} catch(err) {
42+
console.log(err);
43+
}
44+
};
45+
46+
(async () => {
47+
await getOrganizations();
48+
await main();
49+
})();

0 commit comments

Comments
 (0)