|
2 | 2 | (async function () {
|
3 | 3 | const { argv } = require("yargs");
|
4 | 4 |
|
| 5 | + const isDryRun = !!argv.dryRun; |
| 6 | + |
| 7 | + // Force verbose output in dry run mode |
| 8 | + if (isDryRun) { |
| 9 | + argv.verbose = true; |
| 10 | + } |
| 11 | + |
5 | 12 | // Up front validation
|
6 | 13 | const providedRepoSelectors = [argv.org, argv.user, argv.repo].filter(
|
7 | 14 | (v) => v
|
|
41 | 48 | rate: { remaining },
|
42 | 49 | },
|
43 | 50 | } = await octokit.rateLimit.get();
|
44 |
| - console.log(`You have ${remaining} API requests remaining`); |
| 51 | + console.log(`You have ${remaining} API requests remaining\n`); |
45 | 52 | }
|
46 | 53 |
|
47 | 54 | const repos = await getRepos(argv, octokit);
|
|
56 | 63 |
|
57 | 64 | const [owner, repo] = r.split("/", 2);
|
58 | 65 | const currentMasterSha = await getBranchSha(owner, repo, old, octokit);
|
59 |
| - const mainBranch = await createBranch( |
60 |
| - owner, |
61 |
| - repo, |
62 |
| - target, |
63 |
| - currentMasterSha, |
64 |
| - octokit |
65 |
| - ); |
| 66 | + |
| 67 | + if (argv.verbose) { |
| 68 | + console.log(`✏️ Creating branch [${target}] at [${currentMasterSha}]`); |
| 69 | + } |
| 70 | + |
| 71 | + if (!isDryRun) { |
| 72 | + const mainBranch = await createBranch( |
| 73 | + owner, |
| 74 | + repo, |
| 75 | + target, |
| 76 | + currentMasterSha, |
| 77 | + octokit |
| 78 | + ); |
| 79 | + } |
66 | 80 |
|
67 | 81 | // List all PRs
|
68 | 82 | let pulls = await octokit.paginate(
|
|
82 | 96 | continue;
|
83 | 97 | }
|
84 | 98 |
|
85 |
| - await octokit.pulls.update({ |
| 99 | + if (argv.verbose) { |
| 100 | + console.log( |
| 101 | + `✏️ Updating pull request [#${pr.number}] in [${repo}] from [${pr.base.ref}] to [${target}]` |
| 102 | + ); |
| 103 | + } |
| 104 | + |
| 105 | + if (!isDryRun) { |
| 106 | + await octokit.pulls.update({ |
| 107 | + owner, |
| 108 | + repo, |
| 109 | + pull_number: pr.number, |
| 110 | + base: target, |
| 111 | + }); |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + if (argv.verbose) { |
| 116 | + console.log(`✏️ Updating default branch to [${target}] in [${repo}]`); |
| 117 | + } |
| 118 | + |
| 119 | + if (!isDryRun) { |
| 120 | + // Update the default branch in the repo |
| 121 | + await octokit.repos.update({ |
86 | 122 | owner,
|
87 | 123 | repo,
|
88 |
| - pull_number: pr.number, |
89 |
| - base: target, |
| 124 | + default_branch: target, |
90 | 125 | });
|
91 | 126 | }
|
92 | 127 |
|
93 |
| - // Update the default branch in the repo |
94 |
| - await octokit.repos.update({ |
95 |
| - owner, |
96 |
| - repo, |
97 |
| - default_branch: target, |
98 |
| - }); |
| 128 | + if (argv.verbose) { |
| 129 | + console.log(`✏️ Deleting old branch [${old}] in ${repo}`); |
| 130 | + } |
| 131 | + |
| 132 | + if (!isDryRun) { |
| 133 | + // Remove old branch if required |
| 134 | + if (!argv.keepOld) { |
| 135 | + await removeBranch(owner, repo, old, octokit); |
| 136 | + } |
| 137 | + } |
99 | 138 |
|
100 |
| - // Remove old branch if required |
101 |
| - if (!argv.keepOld) { |
102 |
| - await removeBranch(owner, repo, old, octokit); |
| 139 | + // Add an empty new line to break up the output for each repo |
| 140 | + if (argv.verbose) { |
| 141 | + console.log(""); |
103 | 142 | }
|
104 | 143 | }
|
105 | 144 |
|
|
0 commit comments