From 870cd38bf16ef029c0759870fddb5b30785a7e1d Mon Sep 17 00:00:00 2001 From: Maksym H <1177472+mordamax@users.noreply.github.com> Date: Mon, 14 Aug 2023 12:09:36 +0100 Subject: [PATCH] ignore commands only for processbot supported repos (#229) * ignore commands only for processbot supported repos --- .env.example.cjs | 2 ++ .env.unit-tests.cjs | 1 + helm/values-parity-prod.yaml | 1 + helm/values-parity-stg.yaml | 1 + src/commander/commander.ts | 20 ++++++++++++-------- src/commander/parseCommand.ts | 1 + src/config.ts | 7 +++++++ src/test/setup/bot.ts | 2 ++ 8 files changed, 27 insertions(+), 8 deletions(-) diff --git a/.env.example.cjs b/.env.example.cjs index 5ee27afa..cb08d840 100644 --- a/.env.example.cjs +++ b/.env.example.cjs @@ -124,3 +124,5 @@ process.env.CMD_BOT_URL ??= "http://localhost:3000/" process.env.MIN_LOG_LEVEL ??= "debug" process.env.BOT_PR_COMMENT_MENTION ??= "localbot" + +process.env.PROCESSBOT_SUPPORTED_REPOS ??= "substrate,polkadot,cumulus" diff --git a/.env.unit-tests.cjs b/.env.unit-tests.cjs index 649b1e11..d003304e 100644 --- a/.env.unit-tests.cjs +++ b/.env.unit-tests.cjs @@ -17,3 +17,4 @@ process.env.ALLOWED_ORGANIZATIONS ??= "123,456" process.env.MASTER_TOKEN ??= "placeholder" process.env.TASK_DB_VERSION ??= "123" process.env.CMD_BOT_URL ??= "http://localhost:3000/" +process.env.PROCESSBOT_SUPPORTED_REPOS ??= "substrate,polkadot,cumulus" diff --git a/helm/values-parity-prod.yaml b/helm/values-parity-prod.yaml index 76a80256..77b16592 100644 --- a/helm/values-parity-prod.yaml +++ b/helm/values-parity-prod.yaml @@ -26,6 +26,7 @@ common: CMD_BOT_URL: https://command-bot.parity-prod.parity.io/ BOT_PR_COMMENT_MENTION: bot PIPELINE_SCRIPTS_REF: main + PROCESSBOT_SUPPORTED_REPOS: "substrate,polkadot,cumulus" secrets: ALLOWED_ORGANIZATIONS: ref+vault://kv/gitlab/parity/mirrors/command-bot/devops-parity-prod#ALLOWED_ORGANIZATIONS APP_ID: ref+vault://kv/gitlab/parity/mirrors/command-bot/devops-parity-prod#APP_ID diff --git a/helm/values-parity-stg.yaml b/helm/values-parity-stg.yaml index ade46560..c83290bb 100644 --- a/helm/values-parity-stg.yaml +++ b/helm/values-parity-stg.yaml @@ -26,6 +26,7 @@ common: CMD_BOT_URL: https://command-bot.parity-stg.parity.io/ PIPELINE_SCRIPTS_REF: main BOT_PR_COMMENT_MENTION: bot + PROCESSBOT_SUPPORTED_REPOS: "substrate,polkadot,cumulus" secrets: ALLOWED_ORGANIZATIONS: ref+vault://kv/gitlab/parity/mirrors/command-bot/devops-parity-stg#ALLOWED_ORGANIZATIONS APP_ID: ref+vault://kv/gitlab/parity/mirrors/command-bot/devops-parity-stg#APP_ID diff --git a/src/commander/commander.ts b/src/commander/commander.ts index 2161cfc4..2ab8f1c1 100644 --- a/src/commander/commander.ts +++ b/src/commander/commander.ts @@ -30,8 +30,9 @@ export function getCommanderFromConfiguration( ctx: LoggerContext, docsPath: string, commandConfigs: CommandConfigs, + repo: string, ): ExtendedCommander { - const { botPullRequestCommentMention } = config; + const { botPullRequestCommentMention, processBotSupportedRepos } = config; const root = new Command(botPullRequestCommentMention) as ExtendedCommander; let unknownCommand: string | undefined; let parsedCommand: ParseResults["parsedCommand"] = undefined; @@ -62,13 +63,16 @@ export function getCommanderFromConfiguration( parsedCommand = new CancelCommand(taskId || ""); }); - for (const ignoredCommand of botPullRequestIgnoreCommands) { - root - .command(ignoredCommand) - .exitOverride() - .action(() => { - parsedCommand = new SkipEvent(`Ignored command: ${ignoredCommand}`); - }); + // ignore `bot merge` / `bot rebase` for repos which support processbot + if (processBotSupportedRepos.includes(repo)) { + for (const ignoredCommand of botPullRequestIgnoreCommands) { + root + .command(ignoredCommand) + .exitOverride() + .action(() => { + parsedCommand = new SkipEvent(`Ignored command: ${ignoredCommand}`); + }); + } } for (const [commandKey, commandConfig] of Object.entries(commandConfigs)) { diff --git a/src/commander/parseCommand.ts b/src/commander/parseCommand.ts index 1cc4accc..78e538fc 100644 --- a/src/commander/parseCommand.ts +++ b/src/commander/parseCommand.ts @@ -27,6 +27,7 @@ export async function parseCommand( ctx, parsedConfigs.result.docsPath, parsedConfigs.result.commandConfigs, + repo, ); // parse the command again, this time with the argument validators based on branch from above diff --git a/src/config.ts b/src/config.ts index e00b77d0..fcf47527 100644 --- a/src/config.ts +++ b/src/config.ts @@ -31,6 +31,11 @@ const allowedOrganizations = envVar("ALLOWED_ORGANIZATIONS") return parsedValue; }); +const processBotSupportedRepos = envVar("PROCESSBOT_SUPPORTED_REPOS") + .split(",") + .map((repo) => repo.trim()) + .filter((value) => value.length !== 0); + export type Config = { dataPath: string; pipelineScripts: PipelineScripts; @@ -58,6 +63,7 @@ export type Config = { gitlabJobImage: string; cmdBotUrl: string; botPullRequestCommentMention: string; + processBotSupportedRepos: string[]; }; export const config: Config = { @@ -87,4 +93,5 @@ export const config: Config = { gitlabJobImage: envVar("GITLAB_JOB_IMAGE"), cmdBotUrl: envVar("CMD_BOT_URL"), botPullRequestCommentMention: process.env.BOT_PR_COMMENT_MENTION || "bot", + processBotSupportedRepos, }; diff --git a/src/test/setup/bot.ts b/src/test/setup/bot.ts index a8d03538..70dd9957 100644 --- a/src/test/setup/bot.ts +++ b/src/test/setup/bot.ts @@ -120,5 +120,7 @@ function getBotEnv( MIN_LOG_LEVEL: "debug", BOT_PR_COMMENT_MENTION: "testbot", + + PROCESSBOT_SUPPORTED_REPOS: "substrate,polkadot,cumulus,command-bot-test", }; }