From 79e518c85daca2da74fea7f6a9ecd10e4068065c Mon Sep 17 00:00:00 2001 From: EtherealGlow Date: Sat, 19 Aug 2023 16:44:37 +0000 Subject: [PATCH 1/6] feat: read from env --- src/configs/shared.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/configs/shared.ts b/src/configs/shared.ts index 2d817b7a0..83328bbe7 100644 --- a/src/configs/shared.ts +++ b/src/configs/shared.ts @@ -1,10 +1,15 @@ +import dotenv from "dotenv"; + +dotenv.config(); export const COLORS = { default: "ededed", price: "1f883d", }; 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 DEFAULT_TIME_RANGE_FOR_MAX_ISSUE = parseInt(process.env.DEFAULT_TIME_RANGE_FOR_MAX_ISSUE || "24", 10); +export const DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED = process.env.DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED + ? process.env.DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED === "true" + : true; export const ASSIGN_COMMAND_ENABLED = true; /** * ms('2 days') // 172800000 From b7438bd132983ca859c3e4794bfdb068fcad53b1 Mon Sep 17 00:00:00 2001 From: EtherealGlow Date: Tue, 22 Aug 2023 16:49:34 +0000 Subject: [PATCH 2/6] feat: read from env --- src/bindings/config.ts | 17 ++++++++++++++++- src/configs/shared.ts | 7 +++---- src/helpers/issue.ts | 12 +++++++++--- src/types/config.ts | 6 ++++++ 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/bindings/config.ts b/src/bindings/config.ts index 22ec3aa6b..92f9335cc 100644 --- a/src/bindings/config.ts +++ b/src/bindings/config.ts @@ -1,7 +1,14 @@ import ms from "ms"; import { BotConfig, BotConfigSchema } from "../types"; -import { DEFAULT_BOT_DELAY, DEFAULT_DISQUALIFY_TIME, DEFAULT_FOLLOWUP_TIME, DEFAULT_PERMIT_BASE_URL } from "../configs"; +import { + DEFAULT_BOT_DELAY, + DEFAULT_DISQUALIFY_TIME, + DEFAULT_FOLLOWUP_TIME, + DEFAULT_PERMIT_BASE_URL, + DEFAULT_TIME_RANGE_FOR_MAX_ISSUE, + DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED, +} from "../configs"; import { getPayoutConfigByNetworkId } from "../helpers"; import { ajv } from "../utils"; import { Context } from "probot"; @@ -82,6 +89,14 @@ export const loadConfig = async (context: Context): Promise => { wallet: { registerWalletWithVerification: registerWalletWithVerification, }, + time: { + DEFAULT_TIME_RANGE_FOR_MAX_ISSUE: process.env.DEFAULT_TIME_RANGE_FOR_MAX_ISSUE + ? Number(process.env.DEFAULT_TIME_RANGE_FOR_MAX_ISSUE) + : DEFAULT_TIME_RANGE_FOR_MAX_ISSUE, + DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED: process.env.DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED + ? process.env.DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED == "true" + : DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED, + }, }; if (botConfig.log.ingestionKey == "") { diff --git a/src/configs/shared.ts b/src/configs/shared.ts index 83328bbe7..e14f79c0f 100644 --- a/src/configs/shared.ts +++ b/src/configs/shared.ts @@ -6,10 +6,9 @@ export const COLORS = { price: "1f883d", }; export const DEFAULT_BOT_DELAY = 100; // 100ms -export const DEFAULT_TIME_RANGE_FOR_MAX_ISSUE = parseInt(process.env.DEFAULT_TIME_RANGE_FOR_MAX_ISSUE || "24", 10); -export const DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED = process.env.DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED - ? process.env.DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED === "true" - : true; +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 diff --git a/src/helpers/issue.ts b/src/helpers/issue.ts index 4788b4919..d5880e420 100644 --- a/src/helpers/issue.ts +++ b/src/helpers/issue.ts @@ -1,5 +1,5 @@ import { Context } from "probot"; -import { getBotContext, getLogger } from "../bindings"; +import { getBotContext, getLogger, loadConfig } from "../bindings"; import { AssignEvent, Comment, IssueType, Payload } from "../types"; import { checkRateLimitGit } from "../utils"; import { DEFAULT_TIME_RANGE_FOR_MAX_ISSUE, DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED } from "../configs"; @@ -8,6 +8,7 @@ export const clearAllPriceLabelsOnIssue = async (): Promise => { const context = getBotContext(); const logger = getLogger(); const payload = context.payload as Payload; + if (!payload.issue) return; const labels = payload.issue.labels; @@ -615,8 +616,10 @@ export const getCommitsOnPullRequest = async (pullNumber: number) => { }; export const getAvailableOpenedPullRequests = async (username: string) => { - if (!DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED) return []; const context = getBotContext(); + const botConfig = await loadConfig(context); + if (!botConfig.time.DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED) return []; + const opened_prs = await getOpenedPullRequests(username); const result = []; @@ -630,7 +633,10 @@ export const getAvailableOpenedPullRequests = async (username: string) => { if (approvedReviews) result.push(pr); } - if (reviews.length === 0 && (new Date().getTime() - new Date(pr.created_at).getTime()) / (1000 * 60 * 60) >= DEFAULT_TIME_RANGE_FOR_MAX_ISSUE) { + if ( + reviews.length === 0 && + (new Date().getTime() - new Date(pr.created_at).getTime()) / (1000 * 60 * 60) >= botConfig.time.DEFAULT_TIME_RANGE_FOR_MAX_ISSUE + ) { result.push(pr); } } diff --git a/src/types/config.ts b/src/types/config.ts index 28f2d589b..7496507ee 100644 --- a/src/types/config.ts +++ b/src/types/config.ts @@ -74,6 +74,11 @@ export const CommentsSchema = Type.Object({ promotionComment: Type.String(), }); +export const TimeRangeSchema = Type.Object({ + DEFAULT_TIME_RANGE_FOR_MAX_ISSUE: Type.Number(), + DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED: Type.Boolean(), +}); + export const CommandConfigSchema = Type.Array(CommandItemSchema); export type CommandConfig = Static; @@ -94,6 +99,7 @@ export const BotConfigSchema = Type.Object({ comments: CommentsSchema, command: CommandConfigSchema, wallet: WalletSchema, + time: TimeRangeSchema, }); export type BotConfig = Static; From c40bfe0e871e13f3212e7a47644ee598b1143442 Mon Sep 17 00:00:00 2001 From: EtherealGlow Date: Tue, 22 Aug 2023 16:51:05 +0000 Subject: [PATCH 3/6] feat: read from env --- src/configs/shared.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/configs/shared.ts b/src/configs/shared.ts index e14f79c0f..8c287c4ff 100644 --- a/src/configs/shared.ts +++ b/src/configs/shared.ts @@ -1,6 +1,3 @@ -import dotenv from "dotenv"; - -dotenv.config(); export const COLORS = { default: "ededed", price: "1f883d", From 41ce93f64a124ee204f16d55e5352007d9fae28d Mon Sep 17 00:00:00 2001 From: EtherealGlow Date: Thu, 24 Aug 2023 15:49:04 +0000 Subject: [PATCH 4/6] feat: read from env --- src/bindings/config.ts | 14 ++++++-------- src/helpers/issue.ts | 4 ++-- src/types/config.ts | 8 ++------ 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/bindings/config.ts b/src/bindings/config.ts index 92f9335cc..87ff9ab1a 100644 --- a/src/bindings/config.ts +++ b/src/bindings/config.ts @@ -61,6 +61,12 @@ export const loadConfig = async (context: Context): Promise => { permitBaseUrl: process.env.PERMIT_BASE_URL || DEFAULT_PERMIT_BASE_URL, }, unassign: { + defaultTimeRangeForMaxIssue: process.env.DEFAULT_TIME_RANGE_FOR_MAX_ISSUE + ? Number(process.env.DEFAULT_TIME_RANGE_FOR_MAX_ISSUE) + : DEFAULT_TIME_RANGE_FOR_MAX_ISSUE, + defaultTimeRangeForMaxIssueEnabled: process.env.DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED + ? process.env.DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED == "true" + : DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED, followUpTime: ms(process.env.FOLLOW_UP_TIME || DEFAULT_FOLLOWUP_TIME), disqualifyTime: ms(process.env.DISQUALIFY_TIME || DEFAULT_DISQUALIFY_TIME), }, @@ -89,14 +95,6 @@ export const loadConfig = async (context: Context): Promise => { wallet: { registerWalletWithVerification: registerWalletWithVerification, }, - time: { - DEFAULT_TIME_RANGE_FOR_MAX_ISSUE: process.env.DEFAULT_TIME_RANGE_FOR_MAX_ISSUE - ? Number(process.env.DEFAULT_TIME_RANGE_FOR_MAX_ISSUE) - : DEFAULT_TIME_RANGE_FOR_MAX_ISSUE, - DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED: process.env.DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED - ? process.env.DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED == "true" - : DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED, - }, }; if (botConfig.log.ingestionKey == "") { diff --git a/src/helpers/issue.ts b/src/helpers/issue.ts index d5880e420..e3e2594fc 100644 --- a/src/helpers/issue.ts +++ b/src/helpers/issue.ts @@ -618,7 +618,7 @@ export const getCommitsOnPullRequest = async (pullNumber: number) => { export const getAvailableOpenedPullRequests = async (username: string) => { const context = getBotContext(); const botConfig = await loadConfig(context); - if (!botConfig.time.DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED) return []; + if (!botConfig.unassign.defaultTimeRangeForMaxIssueEnabled) return []; const opened_prs = await getOpenedPullRequests(username); @@ -635,7 +635,7 @@ export const getAvailableOpenedPullRequests = async (username: string) => { if ( reviews.length === 0 && - (new Date().getTime() - new Date(pr.created_at).getTime()) / (1000 * 60 * 60) >= botConfig.time.DEFAULT_TIME_RANGE_FOR_MAX_ISSUE + (new Date().getTime() - new Date(pr.created_at).getTime()) / (1000 * 60 * 60) >= botConfig.unassign.defaultTimeRangeForMaxIssue ) { result.push(pr); } diff --git a/src/types/config.ts b/src/types/config.ts index 7496507ee..b8feea943 100644 --- a/src/types/config.ts +++ b/src/types/config.ts @@ -47,6 +47,8 @@ export const PayoutConfigSchema = Type.Object({ export const UnassignConfigSchema = Type.Object({ followUpTime: Type.Number(), disqualifyTime: Type.Number(), + defaultTimeRangeForMaxIssue: Type.Number(), + defaultTimeRangeForMaxIssueEnabled: Type.Boolean(), }); export const ModeSchema = Type.Object({ @@ -74,11 +76,6 @@ export const CommentsSchema = Type.Object({ promotionComment: Type.String(), }); -export const TimeRangeSchema = Type.Object({ - DEFAULT_TIME_RANGE_FOR_MAX_ISSUE: Type.Number(), - DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED: Type.Boolean(), -}); - export const CommandConfigSchema = Type.Array(CommandItemSchema); export type CommandConfig = Static; @@ -99,7 +96,6 @@ export const BotConfigSchema = Type.Object({ comments: CommentsSchema, command: CommandConfigSchema, wallet: WalletSchema, - time: TimeRangeSchema, }); export type BotConfig = Static; From d8cfe7ec9a14e5f17432fead54e59981b82880d8 Mon Sep 17 00:00:00 2001 From: EtherealGlow Date: Thu, 24 Aug 2023 15:53:03 +0000 Subject: [PATCH 5/6] feat: read from env --- src/helpers/issue.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/helpers/issue.ts b/src/helpers/issue.ts index e3e2594fc..65d0e821f 100644 --- a/src/helpers/issue.ts +++ b/src/helpers/issue.ts @@ -2,7 +2,6 @@ import { Context } from "probot"; import { getBotContext, getLogger, loadConfig } from "../bindings"; import { AssignEvent, Comment, IssueType, Payload } from "../types"; import { checkRateLimitGit } from "../utils"; -import { DEFAULT_TIME_RANGE_FOR_MAX_ISSUE, DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED } from "../configs"; export const clearAllPriceLabelsOnIssue = async (): Promise => { const context = getBotContext(); From d2e48aaa9dbd019de6804c91baf4088b753d85c0 Mon Sep 17 00:00:00 2001 From: EtherealGlow Date: Sat, 26 Aug 2023 07:34:38 +0000 Subject: [PATCH 6/6] feat: read from env --- src/bindings/config.ts | 4 ++-- src/helpers/issue.ts | 7 ++----- src/types/config.ts | 4 ++-- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/bindings/config.ts b/src/bindings/config.ts index 87ff9ab1a..dc69ee77a 100644 --- a/src/bindings/config.ts +++ b/src/bindings/config.ts @@ -61,10 +61,10 @@ export const loadConfig = async (context: Context): Promise => { permitBaseUrl: process.env.PERMIT_BASE_URL || DEFAULT_PERMIT_BASE_URL, }, unassign: { - defaultTimeRangeForMaxIssue: process.env.DEFAULT_TIME_RANGE_FOR_MAX_ISSUE + timeRangeForMaxIssue: process.env.DEFAULT_TIME_RANGE_FOR_MAX_ISSUE ? Number(process.env.DEFAULT_TIME_RANGE_FOR_MAX_ISSUE) : DEFAULT_TIME_RANGE_FOR_MAX_ISSUE, - defaultTimeRangeForMaxIssueEnabled: process.env.DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED + timeRangeForMaxIssueEnabled: process.env.DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED ? process.env.DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED == "true" : DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED, followUpTime: ms(process.env.FOLLOW_UP_TIME || DEFAULT_FOLLOWUP_TIME), diff --git a/src/helpers/issue.ts b/src/helpers/issue.ts index 65d0e821f..9253271d8 100644 --- a/src/helpers/issue.ts +++ b/src/helpers/issue.ts @@ -617,7 +617,7 @@ export const getCommitsOnPullRequest = async (pullNumber: number) => { export const getAvailableOpenedPullRequests = async (username: string) => { const context = getBotContext(); const botConfig = await loadConfig(context); - if (!botConfig.unassign.defaultTimeRangeForMaxIssueEnabled) return []; + if (!botConfig.unassign.timeRangeForMaxIssueEnabled) return []; const opened_prs = await getOpenedPullRequests(username); @@ -632,10 +632,7 @@ export const getAvailableOpenedPullRequests = async (username: string) => { if (approvedReviews) result.push(pr); } - if ( - reviews.length === 0 && - (new Date().getTime() - new Date(pr.created_at).getTime()) / (1000 * 60 * 60) >= botConfig.unassign.defaultTimeRangeForMaxIssue - ) { + if (reviews.length === 0 && (new Date().getTime() - new Date(pr.created_at).getTime()) / (1000 * 60 * 60) >= botConfig.unassign.timeRangeForMaxIssue) { result.push(pr); } } diff --git a/src/types/config.ts b/src/types/config.ts index b8feea943..963820646 100644 --- a/src/types/config.ts +++ b/src/types/config.ts @@ -47,8 +47,8 @@ export const PayoutConfigSchema = Type.Object({ export const UnassignConfigSchema = Type.Object({ followUpTime: Type.Number(), disqualifyTime: Type.Number(), - defaultTimeRangeForMaxIssue: Type.Number(), - defaultTimeRangeForMaxIssueEnabled: Type.Boolean(), + timeRangeForMaxIssue: Type.Number(), + timeRangeForMaxIssueEnabled: Type.Boolean(), }); export const ModeSchema = Type.Object({