-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
67 lines (53 loc) · 1.58 KB
/
index.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
62
63
64
65
66
67
import { execaCommandSync } from "execa";
import config from "./config.js";
function getConfig() {
const listingConfig = config.listConfig;
const configToArguments = Object.keys(listingConfig).map((item) => {
if (typeof listingConfig[item] === "boolean") return `--${item}`;
return `--${item} ${listingConfig[item]}`;
});
const sanitizedArguments = configToArguments
.filter((item) => item)
.toString()
.replaceAll(",", " ");
return sanitizedArguments;
}
function getRepositoriesList() {
const args = getConfig();
const githubRepos = execaCommandSync(`gh repo list ${args}`);
const repositoriesList = JSON.parse(githubRepos.stdout);
return repositoriesList
.map(({ name }) => {
if (!config.ignoreRepositories.includes(name)) {
return name;
}
})
.filter((item) => item);
}
function setRepositoryVisibility(repositoriesList) {
repositoriesList.map((repository) => {
console.log(`⏺️ setting ${repository} to ${config.visibility}`);
try {
execaCommandSync(
`
gh repo edit "${config.owner}/${repository}" --visibility "${config.visibility}"
`,
{ shell: true }
);
console.log(`✅ ${repository} is now ${config.visibility}`);
} catch (error) {
console.warn(
`⛔ cannot set ${repository} to ${config.visibility}: ${error}`
);
}
});
}
function execute() {
const repositoriesList = getRepositoriesList();
setRepositoryVisibility(repositoriesList);
}
if (process.argv.includes("--list")) {
console.log(getRepositoriesList());
} else {
execute();
}