Skip to content

Commit 59e951e

Browse files
committed
misc-helper get-pr-meta/get-pr-commits/handle-pr: prepare for git/git
To allow GitGitGadget to be used with PRs other than at https://github.com/gitgitgadget/git, i.e. to support https://github.com/git/git, let's teach these `misc-helper` commands about (optionally) using a different repository. This is a companion patch to the previous two, but unlike them, these commands are not wired up in any active Azure Pipeline. Therefore, we technically do not have to be careful to make the repository owner optional. We still do because why not. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent a7706c6 commit 59e951e

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

script/misc-helper.ts

+21-12
Original file line numberDiff line numberDiff line change
@@ -241,38 +241,47 @@ async function getCIHelper(): Promise<CIHelper> {
241241

242242
console.log(toPrettyJSON(await ci.getMailMetadata(messageID)));
243243
} else if (command === "get-pr-meta") {
244-
if (commander.args.length !== 2) {
245-
process.stderr.write(`${command}: need a Pull Request number\n`);
244+
if (commander.args.length !== 2 && commander.args.length !== 3) {
245+
process.stderr.write(`${command}: need a repository owner and ${
246+
""}a Pull Request number\n`);
246247
process.exit(1);
247248
}
248-
const prNumber = commander.args[1];
249+
const repositoryOwner = commander.args.length === 3 ?
250+
commander.args[1] : "gitgitgadget";
251+
const prNumber = commander.args[commander.args.length === 3 ? 2 : 1];
249252

250253
const pullRequestURL = prNumber.match(/^http/) ? prNumber :
251-
`https://github.com/gitgitgadget/git/pull/${prNumber}`;
254+
`https://github.com/${repositoryOwner}/git/pull/${prNumber}`;
252255
console.log(toPrettyJSON(await ci.getPRMetadata(pullRequestURL)));
253256
} else if (command === "get-pr-commits") {
254-
if (commander.args.length !== 2) {
255-
process.stderr.write(`${command}: need a Pull Request number\n`);
257+
if (commander.args.length !== 2 && commander.args.length !== 3) {
258+
process.stderr.write(`${command}: need a repository owner and ${
259+
""}a Pull Request number\n`);
256260
process.exit(1);
257261
}
258-
const prNumber = commander.args[1];
262+
const repositoryOwner = commander.args.length === 3 ?
263+
commander.args[1] : "gitgitgadget";
264+
const prNumber = commander.args[commander.args.length === 3 ? 2 : 1];
259265

260266
const pullRequestURL =
261-
`https://github.com/gitgitgadget/git/pull/${prNumber}`;
267+
`https://github.com/${repositoryOwner}/git/pull/${prNumber}`;
262268
const prMeta = await ci.getPRMetadata(pullRequestURL);
263269
if (!prMeta) {
264270
throw new Error(`No metadata found for ${pullRequestURL}`);
265271
}
266272
console.log(toPrettyJSON(await ci.getOriginalCommitsForPR(prMeta)));
267273
} else if (command === "handle-pr") {
268-
if (commander.args.length !== 2) {
269-
process.stderr.write(`${command}: need a Pull Request number\n`);
274+
if (commander.args.length !== 2 && commander.args.length !== 3) {
275+
process.stderr.write(`${command}: need a repository owner and ${
276+
""}a Pull Request number\n`);
270277
process.exit(1);
271278
}
272-
const prNumber = commander.args[1];
279+
const repositoryOwner = commander.args.length === 3 ?
280+
commander.args[1] : "gitgitgadget";
281+
const prNumber = commander.args[commander.args.length === 3 ? 2 : 1];
273282

274283
const pullRequestURL =
275-
`https://github.com/gitgitgadget/git/pull/${prNumber}`;
284+
`https://github.com/${repositoryOwner}/git/pull/${prNumber}`;
276285

277286
const meta = await ci.getPRMetadata(pullRequestURL);
278287
if (!meta) {

0 commit comments

Comments
 (0)