Skip to content

Commit

Permalink
ignore commands only for processbot supported repos (#229)
Browse files Browse the repository at this point in the history
* ignore commands only for processbot supported repos
  • Loading branch information
mordamax authored Aug 14, 2023
1 parent 26101d4 commit 870cd38
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .env.example.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 1 addition & 0 deletions .env.unit-tests.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 1 addition & 0 deletions helm/values-parity-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions helm/values-parity-stg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 12 additions & 8 deletions src/commander/commander.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down
1 change: 1 addition & 0 deletions src/commander/parseCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,6 +63,7 @@ export type Config = {
gitlabJobImage: string;
cmdBotUrl: string;
botPullRequestCommentMention: string;
processBotSupportedRepos: string[];
};

export const config: Config = {
Expand Down Expand Up @@ -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,
};
2 changes: 2 additions & 0 deletions src/test/setup/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,7 @@ function getBotEnv(
MIN_LOG_LEVEL: "debug",

BOT_PR_COMMENT_MENTION: "testbot",

PROCESSBOT_SUPPORTED_REPOS: "substrate,polkadot,cumulus,command-bot-test",
};
}

0 comments on commit 870cd38

Please sign in to comment.