Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add merge/rebase response; fix crashing app on wrong argument in root #240

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading