From 7f4c6a6322112539f1637226587b30e50908472c Mon Sep 17 00:00:00 2001 From: HARALD Date: Fri, 14 Jul 2023 02:47:22 +0900 Subject: [PATCH 01/16] feat: add assign_command_enabled config --- src/configs/shared.ts | 1 + src/configs/strings.ts | 1 + src/handlers/assign/auto.ts | 3 +++ src/handlers/comment/handlers/assign.ts | 10 ++++++++-- src/handlers/comment/handlers/help.ts | 4 +++- 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/configs/shared.ts b/src/configs/shared.ts index 65d499402..b59f1e753 100644 --- a/src/configs/shared.ts +++ b/src/configs/shared.ts @@ -7,6 +7,7 @@ export const COLORS = { export const DEFAULT_BOT_DELAY = 100; // 100ms export const DEFAULT_TIME_RANGE_FOR_MAX_ISSUE = 24; export const DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED = true; +export const ASSIGN_COMMAND_ENABLED = true; /** * ms('2 days') // 172800000 * ms('1d') // 86400000 diff --git a/src/configs/strings.ts b/src/configs/strings.ts index ef96a0f2b..83ef907fb 100644 --- a/src/configs/strings.ts +++ b/src/configs/strings.ts @@ -1,4 +1,5 @@ export const GLOBAL_STRINGS = { unassignComment: "Releasing the bounty back to dev pool because the allocated duration already ended!", askUpdate: "Do you have any updates", + assignCommandDisabledComment: "`/assign` command is disabled.", }; diff --git a/src/handlers/assign/auto.ts b/src/handlers/assign/auto.ts index bc11cc48e..1643d1771 100644 --- a/src/handlers/assign/auto.ts +++ b/src/handlers/assign/auto.ts @@ -1,4 +1,5 @@ import { getBotContext, getLogger } from "../../bindings"; +import { ASSIGN_COMMAND_ENABLED } from "../../configs"; import { addAssignees, getIssueByNumber, getPullRequests } from "../../helpers"; import { gitLinkedIssueParser } from "../../helpers/parser"; import { Payload } from "../../types"; @@ -9,6 +10,8 @@ export const checkPullRequests = async () => { const logger = getLogger(); const pulls = await getPullRequests(context); + if (ASSIGN_COMMAND_ENABLED) return; + if (pulls.length === 0) { logger.debug(`No pull requests found at this time`); return; diff --git a/src/handlers/comment/handlers/assign.ts b/src/handlers/comment/handlers/assign.ts index af0759fd7..9c2930c74 100644 --- a/src/handlers/comment/handlers/assign.ts +++ b/src/handlers/comment/handlers/assign.ts @@ -1,10 +1,11 @@ -import { addAssignees, getAssignedIssues, getCommentsOfIssue, getAvailableOpenedPullRequests } from "../../../helpers"; +import { addAssignees, getAssignedIssues, getCommentsOfIssue, getAvailableOpenedPullRequests, addCommentToIssue } from "../../../helpers"; import { getBotConfig, getBotContext, getLogger } from "../../../bindings"; import { Payload, LabelItem, Comment, IssueType } from "../../../types"; import { deadLinePrefix } from "../../shared"; import { getWalletAddress, getWalletMultiplier, getMultiplierReason } from "../../../adapters/supabase"; import { tableComment } from "./table"; import { bountyInfo } from "../../wildcard"; +import { ASSIGN_COMMAND_ENABLED, GLOBAL_STRINGS } from "../../../configs"; export const assign = async (body: string) => { const { payload: _payload } = getBotContext(); @@ -19,6 +20,12 @@ export const assign = async (body: string) => { return "Skipping '/assign' because of no issue instance"; } + if (!ASSIGN_COMMAND_ENABLED) { + logger.info(`Ignore '/assign' command from user: ASSIGN_COMMAND_ENABLED config is set false`); + await addCommentToIssue(GLOBAL_STRINGS.assignCommandDisabledComment, issue.number); + return; + } + const openedPullRequests = await getAvailableOpenedPullRequests(payload.sender.login); logger.info(`Opened Pull Requests with no reviews but over 24 hours have passed: ${JSON.stringify(openedPullRequests)}`); @@ -91,7 +98,6 @@ export const assign = async (body: string) => {