Skip to content

Commit

Permalink
fixes #6038 the -h command not always taken into account (#6181)
Browse files Browse the repository at this point in the history
  • Loading branch information
wdvr authored Jan 17, 2025
1 parent cb2e2d9 commit 1ba80a7
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
13 changes: 11 additions & 2 deletions torchci/lib/bot/pytorchBotHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,9 +532,13 @@ The explanation needs to be clear on why this is needed. Here are some good exam
is_pr_comment: boolean = true
) {
let args;
let split_args: string[] = [];

try {
const parser = getParser();
args = parser.parse_args(shlex.split(inputArgs));

split_args = shlex.split(inputArgs);
args = parser.parse_args(split_args);
} catch (err: any) {
// If the args are invalid, comment with the error + some help.
await this.addComment(
Expand All @@ -546,7 +550,12 @@ The explanation needs to be clear on why this is needed. Here are some good exam
return;
}

if (args.help) {
// if help is present as an option on the main command, or -h or --help is in any location in the args (parseargs fails to get -h at the start of the args)
if (
args.help ||
split_args.includes("-h") ||
split_args.includes("--help")
) {
return await this.addComment(getHelp());
}

Expand Down
50 changes: 50 additions & 0 deletions torchci/test/mergeCommands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1562,6 +1562,56 @@ some other text lol

handleScope(scope);
});

test("pytorchmergebot -h rebase command on pull request prints help message and does not execute rebase", async () => {
const event = requireDeepCopy("./fixtures/pull_request_comment.json");

event.payload.comment.body = "@pytorchmergebot -h rebase";
event.payload.comment.user.login = "wdvr";
event.payload.issue.user.login = "random";

const owner = event.payload.repository.owner.login;
const repo = event.payload.repository.name;
const pr_number = event.payload.issue.number;
const comment_number = event.payload.comment.id;
const scope = nock("https://api.github.com")
.post(`/repos/${owner}/${repo}/issues/${pr_number}/comments`, (body) => {
expect(JSON.stringify(body)).toContain(
"Rebase a PR. Rebasing defaults to the stable viable/strict branch of pytorch."
);
return true;
})
.reply(200, {});

await probot.receive(event);

handleScope(scope);
});

test("pytorchmergebot rebase -h command on pull request prints help message and does not execute rebase", async () => {
const event = requireDeepCopy("./fixtures/pull_request_comment.json");

event.payload.comment.body = "@pytorchmergebot rebase -h";
event.payload.comment.user.login = "wdvr";
event.payload.issue.user.login = "random";

const owner = event.payload.repository.owner.login;
const repo = event.payload.repository.name;
const pr_number = event.payload.issue.number;
const comment_number = event.payload.comment.id;
const scope = nock("https://api.github.com")
.post(`/repos/${owner}/${repo}/issues/${pr_number}/comments`, (body) => {
expect(JSON.stringify(body)).toContain(
"Rebase a PR. Rebasing defaults to the stable viable/strict branch of pytorch."
);
return true;
})
.reply(200, {});

await probot.receive(event);

handleScope(scope);
});
});

describe("merge-bot not supported repo", () => {
Expand Down

0 comments on commit 1ba80a7

Please sign in to comment.