From 172a47526d0d4cd46ae87f8a623e0de16e987ca2 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 4 Jan 2025 14:06:01 +0100 Subject: [PATCH] misc-helper: fix commands that take an optional repository owner I overlooked that _some_ of those do not want the second parameter to refer to a PullRequest URL, and those that do no longer need to construct it from a Pull Request Number manually (because the `OptionalRepoOwnerCommand` class does it for them). This led to errors when `/submit`ing PRs, e.g. https://github.com/gitgitgadget/git/pull/1847#issuecomment-2571259843 (https://dev.azure.com/gitgitgadget/git/_build/results?buildId=232598&view=logs&j=fd490c07-0b22-5182-fac9-6d67fe1e939b&t=28e14b79-1d95-5195-ee03-3a68ac48a418&l=13 points to the exact error): node build/script/misc-helper.js handle-pr-comment 2571259843 GET /repos/gitgitgadget/git/issues/comments/NaN - 404 with id 8FC2:20D9D0:4EF0B5D:5C1E5A8:6779306A in 536ms Let's fix these inadvertent regressions. Signed-off-by: Johannes Schindelin --- script/misc-helper.ts | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/script/misc-helper.ts b/script/misc-helper.ts index a72f17ff56..5853eaeca0 100644 --- a/script/misc-helper.ts +++ b/script/misc-helper.ts @@ -270,6 +270,7 @@ const commandOptions = commander.opts(); name: string, description: string, action: (repositoryOwner: string, pullRequestURL: string) => Promise, + verbatim2ndArgument = false, ) { super(name); super.argument("[repository-owner]"); @@ -281,9 +282,10 @@ const commandOptions = commander.opts(); args[0] = config.repo.owner; } const [repositoryOwner, prNumber] = args; - const pullRequestURL = prNumber.match(/^http/) - ? prNumber - : `https://github.com/${repositoryOwner}/${config.repo.name}/pull/${prNumber}`; + const pullRequestURL = + verbatim2ndArgument || prNumber.match(/^http/) + ? prNumber + : `https://github.com/${repositoryOwner}/${config.repo.name}/pull/${prNumber}`; return await action(repositoryOwner, pullRequestURL); }); } @@ -311,9 +313,7 @@ const commandOptions = commander.opts(); new OptionalRepoOwnerCommand( "get-pr-commits", "Get the commits for a given Pull Request", - async (repositoryOwner, prNumber) => { - if (repositoryOwner === undefined) repositoryOwner = config.repo.owner; - const pullRequestURL = `https://github.com/${repositoryOwner}/${config.repo.name}/pull/${prNumber}`; + async (_repositoryOwner, pullRequestURL) => { const prMeta = await ci.getPRMetadata(pullRequestURL); if (!prMeta) { throw new Error(`No metadata found for ${pullRequestURL}`); @@ -326,10 +326,7 @@ const commandOptions = commander.opts(); new OptionalRepoOwnerCommand( "handle-pr", "Handle a given Pull Request (add it to open PRs, update commit <-> message ID mapping, etc.)", - async (repositoryOwner, prNumber) => { - if (repositoryOwner === undefined) repositoryOwner = config.repo.owner; - const pullRequestURL = `https://github.com/${repositoryOwner}/${config.repo.name}/pull/${prNumber}`; - + async (_repositoryOwner, pullRequestURL) => { const meta = await ci.getPRMetadata(pullRequestURL); if (!meta) { throw new Error(`No metadata for ${pullRequestURL}`); @@ -441,20 +438,21 @@ const commandOptions = commander.opts(); new OptionalRepoOwnerCommand( "handle-pr-comment", "Handle a comment on a Pull Request", - async (repositoryOwner: string | undefined, commentID: string) => { + async (repositoryOwner: string, commentID: string) => { if (repositoryOwner === undefined) repositoryOwner = config.repo.owner; await ci.handleComment(repositoryOwner, parseInt(commentID, 10)); }, + true, ), ); commander.addCommand( new OptionalRepoOwnerCommand( "handle-pr-push", "Handle a push to a Pull Request", - async (repositoryOwner: string | undefined, prNumber: string) => { - if (repositoryOwner === undefined) repositoryOwner = config.repo.owner; + async (repositoryOwner: string, prNumber: string) => { await ci.handlePush(repositoryOwner, parseInt(prNumber, 10)); }, + true, ), ); commander