-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.js
76 lines (62 loc) · 1.78 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
68
69
70
71
72
73
74
75
76
const Octokit = require("./src/octokit");
const log = require("debug")("ghdb");
module.exports = async (argv) => {
let options = {
log,
...argv,
};
options = {
...options,
octokit: Octokit(options),
};
const target = options.new;
options.target = target;
// Check current rate limit
await require("./data-sources/check-rate-limit")(options);
// Load the list of repos to interact with
const { repos } = await require("./data-sources/list-repos")(options);
const getBranchSha = require("./data-sources/get-branch-sha");
// For each repo
for (let r of repos) {
log(`Processing ${r}`);
const [owner, repo] = r.split("/", 2);
const repoOptions = {
...options,
owner,
repo,
};
// Fetch the old branch sha
try {
repoOptions.sha = await getBranchSha(repoOptions);
} catch (e) {
// Typically, this will fail when the old branch, i.e. master, doesn't exist.
log(`Skipping ${r}: ${e.message}`);
continue;
}
// Apply all transforms
let transforms = [
"create-branch",
"update-default-branch",
"github-pages",
"retarget-pull-requests",
"retarget-draft-releases",
"branch-protection",
"delete-old-branch",
];
// Remove any disallowed transforms
transforms = transforms.filter((transform) => {
const skip = Object.keys(repoOptions).includes(`skip-${transform}`);
if (skip) {
log(`Skipping transform [${transform}]`);
}
return !skip;
});
for (let transform of transforms) {
await require(`./transforms/${transform}`)(repoOptions);
}
// Update all content files
log("Updating content");
const updateContent = require("./src/update-content");
await updateContent(repoOptions);
}
};