Skip to content

Commit

Permalink
misc-helper: fix commands that take an optional repository owner
Browse files Browse the repository at this point in the history
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.
gitgitgadget/git#1847 (comment)
(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 <[email protected]>
  • Loading branch information
dscho committed Jan 4, 2025
1 parent e968309 commit 172a475
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions script/misc-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ const commandOptions = commander.opts<ICommanderOptions>();
name: string,
description: string,
action: (repositoryOwner: string, pullRequestURL: string) => Promise<void>,
verbatim2ndArgument = false,
) {
super(name);
super.argument("[repository-owner]");
Expand All @@ -281,9 +282,10 @@ const commandOptions = commander.opts<ICommanderOptions>();
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);
});
}
Expand Down Expand Up @@ -311,9 +313,7 @@ const commandOptions = commander.opts<ICommanderOptions>();
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}`);
Expand All @@ -326,10 +326,7 @@ const commandOptions = commander.opts<ICommanderOptions>();
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}`);
Expand Down Expand Up @@ -441,20 +438,21 @@ const commandOptions = commander.opts<ICommanderOptions>();
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
Expand Down

0 comments on commit 172a475

Please sign in to comment.