Skip to content

Commit 1ba80a7

Browse files
authored
fixes #6038 the -h command not always taken into account (#6181)
1 parent cb2e2d9 commit 1ba80a7

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

torchci/lib/bot/pytorchBotHandler.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,9 +532,13 @@ The explanation needs to be clear on why this is needed. Here are some good exam
532532
is_pr_comment: boolean = true
533533
) {
534534
let args;
535+
let split_args: string[] = [];
536+
535537
try {
536538
const parser = getParser();
537-
args = parser.parse_args(shlex.split(inputArgs));
539+
540+
split_args = shlex.split(inputArgs);
541+
args = parser.parse_args(split_args);
538542
} catch (err: any) {
539543
// If the args are invalid, comment with the error + some help.
540544
await this.addComment(
@@ -546,7 +550,12 @@ The explanation needs to be clear on why this is needed. Here are some good exam
546550
return;
547551
}
548552

549-
if (args.help) {
553+
// 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)
554+
if (
555+
args.help ||
556+
split_args.includes("-h") ||
557+
split_args.includes("--help")
558+
) {
550559
return await this.addComment(getHelp());
551560
}
552561

torchci/test/mergeCommands.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,6 +1562,56 @@ some other text lol
15621562

15631563
handleScope(scope);
15641564
});
1565+
1566+
test("pytorchmergebot -h rebase command on pull request prints help message and does not execute rebase", async () => {
1567+
const event = requireDeepCopy("./fixtures/pull_request_comment.json");
1568+
1569+
event.payload.comment.body = "@pytorchmergebot -h rebase";
1570+
event.payload.comment.user.login = "wdvr";
1571+
event.payload.issue.user.login = "random";
1572+
1573+
const owner = event.payload.repository.owner.login;
1574+
const repo = event.payload.repository.name;
1575+
const pr_number = event.payload.issue.number;
1576+
const comment_number = event.payload.comment.id;
1577+
const scope = nock("https://api.github.com")
1578+
.post(`/repos/${owner}/${repo}/issues/${pr_number}/comments`, (body) => {
1579+
expect(JSON.stringify(body)).toContain(
1580+
"Rebase a PR. Rebasing defaults to the stable viable/strict branch of pytorch."
1581+
);
1582+
return true;
1583+
})
1584+
.reply(200, {});
1585+
1586+
await probot.receive(event);
1587+
1588+
handleScope(scope);
1589+
});
1590+
1591+
test("pytorchmergebot rebase -h command on pull request prints help message and does not execute rebase", async () => {
1592+
const event = requireDeepCopy("./fixtures/pull_request_comment.json");
1593+
1594+
event.payload.comment.body = "@pytorchmergebot rebase -h";
1595+
event.payload.comment.user.login = "wdvr";
1596+
event.payload.issue.user.login = "random";
1597+
1598+
const owner = event.payload.repository.owner.login;
1599+
const repo = event.payload.repository.name;
1600+
const pr_number = event.payload.issue.number;
1601+
const comment_number = event.payload.comment.id;
1602+
const scope = nock("https://api.github.com")
1603+
.post(`/repos/${owner}/${repo}/issues/${pr_number}/comments`, (body) => {
1604+
expect(JSON.stringify(body)).toContain(
1605+
"Rebase a PR. Rebasing defaults to the stable viable/strict branch of pytorch."
1606+
);
1607+
return true;
1608+
})
1609+
.reply(200, {});
1610+
1611+
await probot.receive(event);
1612+
1613+
handleScope(scope);
1614+
});
15651615
});
15661616

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

0 commit comments

Comments
 (0)