Skip to content

Commit

Permalink
add merge/rebase response; fix crashing app on wrong argument in root (
Browse files Browse the repository at this point in the history
  • Loading branch information
mordamax authored Sep 11, 2023
1 parent 51b8a83 commit 57b8b08
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@types/node-fetch": "^2.6.2",
"@types/pug": "^2.0.6",
"async-mutex": "0.3.2",
"commander": "^10.0.1",
"commander": "^11.0.0",
"date-fns": "2.28.0",
"express-prom-bundle": "^6.6.0",
"glob": "^8.0.3",
Expand Down
17 changes: 9 additions & 8 deletions src/bot/parse/parsePullRequestBotCommandLine.namedArgs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,22 +227,23 @@ const dataProvider: DataProvider[] = [
{
suitName: "ignored command merge",
commandLine: "bot merge",
expectedResponse: new SkipEvent("Ignored command: merge"),
expectedResponse: new Error(
`\`bot merge\` and \`bot rebase\` are not supported anymore. Please use native Github "Auto-Merge" and "Update Branch" buttons instead. \n![image](https://github.com/paritytech/polkadot-sdk/assets/1177472/e0883113-9440-4517-9d42-d4255573a2be)`,
),
},
{
suitName: "ignored command merge force",
commandLine: "bot merge force",
expectedResponse: new SkipEvent("Ignored command: merge"),
expectedResponse: new Error(
`\`bot merge\` and \`bot rebase\` are not supported anymore. Please use native Github "Auto-Merge" and "Update Branch" buttons instead. \n![image](https://github.com/paritytech/polkadot-sdk/assets/1177472/e0883113-9440-4517-9d42-d4255573a2be)`,
),
},
{
suitName: "ignored command rebase",
commandLine: "bot rebase",
expectedResponse: new SkipEvent("Ignored command: rebase"),
},
{
suitName: "ignored command 2",
commandLine: "bot rebase",
expectedResponse: new SkipEvent("Ignored command: rebase"),
expectedResponse: new Error(
`\`bot merge\` and \`bot rebase\` are not supported anymore. Please use native Github "Auto-Merge" and "Update Branch" buttons instead. \n![image](https://github.com/paritytech/polkadot-sdk/assets/1177472/e0883113-9440-4517-9d42-d4255573a2be)`,
),
},

/*
Expand Down
13 changes: 13 additions & 0 deletions src/commander/commander.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export function getCommanderFromConfiguration(
}
throw new Error((e as CommanderError).message.replace("error: ", ""));
};

const addPresetOptions = (cfg: {
presetCommand: Command;
presetConfig: NonNullable<CmdJson["command"]["presets"]>[keyof NonNullable<CmdJson["command"]["presets"]>];
Expand Down Expand Up @@ -88,6 +89,16 @@ export function getCommanderFromConfiguration(
parsedCommand = new CleanCommand();
});

root
.command("merge")
.alias("rebase")
.exitOverride()
.action(() => {
parsedCommand = new Error(
`\`bot merge\` and \`bot rebase\` are not supported anymore. Please use native Github "Auto-Merge" and "Update Branch" buttons instead. \n![image](https://github.com/paritytech/polkadot-sdk/assets/1177472/e0883113-9440-4517-9d42-d4255573a2be)`,
);
});

root
.command("cancel [taskid]")
.description("cancel previous command")
Expand All @@ -108,6 +119,8 @@ export function getCommanderFromConfiguration(
}
}

// allows unknown options, so we can parse them later if command is unknown
root.allowUnknownOption(true);
root.addOption(getVariablesOption()).exitOverride(variablesExitOverride);

for (const [commandKey, commandConfig] of Object.entries(commandConfigs)) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/github-ignore-comands.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ beforeAll(async () => {
await initRepo(gitDaemons.gitLab, "paritytech-stg", "command-bot-test.git", []);
});

describe.each(commandsDataProvider)(
describe.skip.each(commandsDataProvider)(
"$suitName: Non pipeline scenario (GitHub webhook)",
// eslint-disable-next-line unused-imports/no-unused-vars-ts
({ suitName, commandLine }) => {
Expand Down
27 changes: 27 additions & 0 deletions src/test/github-non-pipeline-cases.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,33 @@ const commandsDataProvider: CommandDataProviderItem[] = [
'@somedev123 Unknown subcommand of "fmt". Refer to [help docs](http://localhost:3000/static/docs/latest.html?repo=command-bot-test) and/or [source code](https://github.com/paritytech/command-bot-scripts).',
},
},

{
suitName: "[merge/rebase] merge",
commandLine: "testbot merge",
expected: {
startMessage: `@somedev123 \`bot merge\` and \`bot rebase\` are not supported anymore. Please use native Github "Auto-Merge" and "Update Branch" buttons instead.
![image](https://github.com/paritytech/polkadot-sdk/assets/1177472/e0883113-9440-4517-9d42-d4255573a2be)`,
},
},

{
suitName: "[merge/rebase] merge force",
commandLine: "testbot merge force",
expected: {
startMessage: `@somedev123 \`bot merge\` and \`bot rebase\` are not supported anymore. Please use native Github "Auto-Merge" and "Update Branch" buttons instead.
![image](https://github.com/paritytech/polkadot-sdk/assets/1177472/e0883113-9440-4517-9d42-d4255573a2be)`,
},
},

{
suitName: "[merge/rebase] rebase",
commandLine: "testbot rebase",
expected: {
startMessage: `@somedev123 \`bot merge\` and \`bot rebase\` are not supported anymore. Please use native Github "Auto-Merge" and "Update Branch" buttons instead.
![image](https://github.com/paritytech/polkadot-sdk/assets/1177472/e0883113-9440-4517-9d42-d4255573a2be)`,
},
},
// TODO: add test for clean after moving to opstooling-testing
// {
// suitName: "[clean] command",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2484,10 +2484,10 @@ combined-stream@^1.0.8:
dependencies:
delayed-stream "~1.0.0"

commander@^10.0.1:
version "10.0.1"
resolved "https://registry.yarnpkg.com/commander/-/commander-10.0.1.tgz#881ee46b4f77d1c1dccc5823433aa39b022cbe06"
integrity sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug==
commander@^11.0.0:
version "11.0.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-11.0.0.tgz#43e19c25dbedc8256203538e8d7e9346877a6f67"
integrity sha512-9HMlXtt/BNoYr8ooyjjNRdIilOTkVJXB+GhxMTtOKwk0R4j4lS4NpjuqmRxroBfnfTSHQIHQB7wryHhXarNjmQ==

commander@^2.19.0:
version "2.20.3"
Expand Down

0 comments on commit 57b8b08

Please sign in to comment.