-
Notifications
You must be signed in to change notification settings - Fork 0
/
license-adder.js
executable file
·61 lines (45 loc) · 1.51 KB
/
license-adder.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
#!/usr/bin/env node
import { Octokit } from "octokit";
import { simpleGit } from 'simple-git';
import * as fs from 'node:fs/promises';
const octokit = new Octokit({
auth: process.env.ENV_GITHUB_PAT
});
export const getRepos = async allRepos => {
console.log("Checking for repos...");
const repos = await octokit.request("GET /search/repositories?q=org%3Adocknetwork");
//console.log(repos);
console.log(`Found ${repos.data.total_count} repos.`);
if (repos.data.total_count == 0) {
return;
}
const git = simpleGit();
repos.data.items.map(async r => {
if (r.license || r.private || r.archived) {
return;
}
if (r.fork) {
console.log(`Skipping fork ${r.name} ...`);
return;
}
console.log(`Checking out ${r.name} ...`);
try {
const localPath = `repos/${r.name}`;
await git.clone(r.ssh_url, localPath);
await git.cwd(localPath);
console.log(`Adding license file in ${r.name} ...`);
await fs.copyFile("LICENSE", `${localPath}/LICENSE`);
console.log(`Generating commit in ${r.name} ...`)
await git.add(`LICENSE`);
await git.commit("Adding license file.");
console.log(`Pushing commit to ${r.name} ...`);
await git.push("origin");
console.log(`Cleaning up ${r.name} ...`);
await fs.rm(localPath, { recursive: true, force: true });
console.log(`Finished updating ${r.name}.`);
} catch (error) {
console.error(`Failed to update repo ${r.name}`, error);
}
});
}
await getRepos();