From d253e4f96cab39d0f1cafc4eb4591ec99f6e0548 Mon Sep 17 00:00:00 2001 From: byteballet Date: Wed, 16 Aug 2023 23:59:07 -0700 Subject: [PATCH 1/7] feat: derive weight automatically --- .github/ubiquibot-config.yml | 10 ---------- src/handlers/assign/action.ts | 4 ++-- src/handlers/comment/handlers/assign.ts | 4 ++-- src/handlers/pricing/action.ts | 6 +++--- src/handlers/pricing/pre.ts | 4 ++-- src/handlers/shared/pricing.ts | 5 +++-- src/handlers/wildcard/analytics.ts | 6 +++--- src/helpers/label.ts | 5 +++-- src/helpers/shared.ts | 19 ++++++++++++++++++- src/types/config.ts | 1 - src/utils/private.ts | 1 - ubiquibot-config-default.json | 20 +++++--------------- 12 files changed, 41 insertions(+), 44 deletions(-) diff --git a/.github/ubiquibot-config.yml b/.github/ubiquibot-config.yml index 8aa8a4053..fa4cf462a 100644 --- a/.github/ubiquibot-config.yml +++ b/.github/ubiquibot-config.yml @@ -2,31 +2,21 @@ evm-network-id: 100 price-multiplier: 1.5 time-labels: - name: "Time: <1 Hour" - weight: 0.125 value: 3600 - name: "Time: <2 Hours" - weight: 0.25 value: 7200 - name: "Time: <4 Hours" - weight: 0.5 value: 14400 - name: "Time: <1 Day" - weight: 1 value: 86400 - name: "Time: <1 Week" - weight: 2 value: 604800 priority-labels: - name: "Priority: 0 (Normal)" - weight: 1 - name: "Priority: 1 (Medium)" - weight: 2 - name: "Priority: 2 (High)" - weight: 3 - name: "Priority: 3 (Urgent)" - weight: 4 - name: "Priority: 4 (Emergency)" - weight: 5 default-labels: - "Time: <1 Hour" - "Priority: 0 (Normal)" diff --git a/src/handlers/assign/action.ts b/src/handlers/assign/action.ts index bd71d65c3..9297ad8ef 100644 --- a/src/handlers/assign/action.ts +++ b/src/handlers/assign/action.ts @@ -1,5 +1,5 @@ import { getBotConfig, getBotContext, getLogger } from "../../bindings"; -import { addCommentToIssue, closePullRequest, getOpenedPullRequestsForAnIssue } from "../../helpers"; +import { addCommentToIssue, closePullRequest, getOpenedPullRequestsForAnIssue, calculateWeight } from "../../helpers"; import { Payload, LabelItem } from "../../types"; import { deadLinePrefix } from "../shared"; @@ -49,7 +49,7 @@ export const commentWithAssignMessage = async (): Promise => { return; } - const sorted = timeLabelsAssigned.sort((a, b) => a.weight - b.weight); + const sorted = timeLabelsAssigned.sort((a, b) => calculateWeight(a) - calculateWeight(b)); const targetTimeLabel = sorted[0]; const duration = targetTimeLabel.value; if (!duration) { diff --git a/src/handlers/comment/handlers/assign.ts b/src/handlers/comment/handlers/assign.ts index d1be127d6..f5444528b 100644 --- a/src/handlers/comment/handlers/assign.ts +++ b/src/handlers/comment/handlers/assign.ts @@ -1,4 +1,4 @@ -import { addAssignees, getAssignedIssues, getAvailableOpenedPullRequests, getAllIssueComments } from "../../../helpers"; +import { addAssignees, getAssignedIssues, getAvailableOpenedPullRequests, getAllIssueComments, calculateWeight } from "../../../helpers"; import { getBotConfig, getBotContext, getLogger } from "../../../bindings"; import { Payload, LabelItem, Comment, IssueType, Issue } from "../../../types"; import { deadLinePrefix } from "../../shared"; @@ -81,7 +81,7 @@ export const assign = async (body: string) => { return "Skipping `/start` since no time labels are set to calculate the timeline"; } - const sorted = timeLabelsAssigned.sort((a, b) => a.weight - b.weight); + const sorted = timeLabelsAssigned.sort((a, b) => calculateWeight(a) - calculateWeight(b)); const targetTimeLabel = sorted[0]; const duration = targetTimeLabel.value; if (!duration) { diff --git a/src/handlers/pricing/action.ts b/src/handlers/pricing/action.ts index 25a815bb3..38a56c858 100644 --- a/src/handlers/pricing/action.ts +++ b/src/handlers/pricing/action.ts @@ -1,6 +1,6 @@ import { getBotConfig, getBotContext, getLogger } from "../../bindings"; import { GLOBAL_STRINGS } from "../../configs"; -import { addCommentToIssue, addLabelToIssue, clearAllPriceLabelsOnIssue, createLabel, getLabel } from "../../helpers"; +import { addCommentToIssue, addLabelToIssue, clearAllPriceLabelsOnIssue, createLabel, getLabel, calculateWeight } from "../../helpers"; import { Payload } from "../../types"; import { handleLabelsAccess } from "../access"; import { getTargetPriceLabel } from "../shared"; @@ -33,8 +33,8 @@ export const pricingLabelLogic = async (): Promise => { const timeLabels = config.price.timeLabels.filter((item) => labels.map((i) => i.name).includes(item.name)); const priorityLabels = config.price.priorityLabels.filter((item) => labels.map((i) => i.name).includes(item.name)); - const minTimeLabel = timeLabels.length > 0 ? timeLabels.reduce((a, b) => (a.weight < b.weight ? a : b)).name : undefined; - const minPriorityLabel = priorityLabels.length > 0 ? priorityLabels.reduce((a, b) => (a.weight < b.weight ? a : b)).name : undefined; + const minTimeLabel = timeLabels.length > 0 ? timeLabels.reduce((a, b) => (calculateWeight(a) < calculateWeight(b) ? a : b)).name : undefined; + const minPriorityLabel = priorityLabels.length > 0 ? priorityLabels.reduce((a, b) => (calculateWeight(a) < calculateWeight(b) ? a : b)).name : undefined; const targetPriceLabel = getTargetPriceLabel(minTimeLabel, minPriorityLabel); if (targetPriceLabel) { diff --git a/src/handlers/pricing/pre.ts b/src/handlers/pricing/pre.ts index 714835386..4d048d1ca 100644 --- a/src/handlers/pricing/pre.ts +++ b/src/handlers/pricing/pre.ts @@ -1,5 +1,5 @@ import { getBotConfig, getLogger } from "../../bindings"; -import { createLabel, listLabelsForRepo } from "../../helpers"; +import { calculateWeight, createLabel, listLabelsForRepo } from "../../helpers"; import { calculateBountyPrice } from "../shared"; /** @@ -22,7 +22,7 @@ export const validatePriceLabels = async (): Promise => { const aiLabels: string[] = []; for (const timeLabel of config.price.timeLabels) { for (const priorityLabel of config.price.priorityLabels) { - const targetPrice = calculateBountyPrice(timeLabel.weight, priorityLabel.weight, config.price.baseMultiplier); + const targetPrice = calculateBountyPrice(calculateWeight(timeLabel), calculateWeight(priorityLabel), config.price.baseMultiplier); const targetPriceLabel = `Price: ${targetPrice} USD`; aiLabels.push(targetPriceLabel); } diff --git a/src/handlers/shared/pricing.ts b/src/handlers/shared/pricing.ts index 65c1079d0..0a543bc7c 100644 --- a/src/handlers/shared/pricing.ts +++ b/src/handlers/shared/pricing.ts @@ -1,4 +1,5 @@ import { getBotConfig } from "../../bindings"; +import { calculateWeight } from "../../helpers"; export const calculateBountyPrice = (timeValue: number, priorityValue: number, baseValue?: number): number => { const botConfig = getBotConfig(); @@ -12,8 +13,8 @@ export const getTargetPriceLabel = (timeLabel: string | undefined, priorityLabel const botConfig = getBotConfig(); let targetPriceLabel: string | undefined = undefined; if (timeLabel && priorityLabel) { - const timeWeight = botConfig.price.timeLabels.find((item) => item.name === timeLabel)?.weight; - const priorityWeight = botConfig.price.priorityLabels.find((item) => item.name === priorityLabel)?.weight; + const timeWeight = calculateWeight(botConfig.price.timeLabels.find((item) => item.name === timeLabel)); + const priorityWeight = calculateWeight(botConfig.price.priorityLabels.find((item) => item.name === priorityLabel)); if (timeWeight && priorityWeight) { const bountyPrice = calculateBountyPrice(timeWeight, priorityWeight); targetPriceLabel = `Price: ${bountyPrice} USD`; diff --git a/src/handlers/wildcard/analytics.ts b/src/handlers/wildcard/analytics.ts index 40e861ac7..24860a7b0 100644 --- a/src/handlers/wildcard/analytics.ts +++ b/src/handlers/wildcard/analytics.ts @@ -1,6 +1,6 @@ import { getMaxIssueNumber, upsertIssue, upsertUser } from "../../adapters/supabase"; import { getBotConfig, getLogger } from "../../bindings"; -import { listIssuesForRepo, getUser } from "../../helpers"; +import { listIssuesForRepo, getUser, calculateWeight } from "../../helpers"; import { Issue, IssueType, User, UserProfile } from "../../types"; import { getTargetPriceLabel } from "../shared"; @@ -24,8 +24,8 @@ export const bountyInfo = ( const isBounty = timeLabels.length > 0 && priorityLabels.length > 0; - const minTimeLabel = timeLabels.length > 0 ? timeLabels.reduce((a, b) => (a.weight < b.weight ? a : b)).name : undefined; - const minPriorityLabel = priorityLabels.length > 0 ? priorityLabels.reduce((a, b) => (a.weight < b.weight ? a : b)).name : undefined; + const minTimeLabel = timeLabels.length > 0 ? timeLabels.reduce((a, b) => (calculateWeight(a) < calculateWeight(b) ? a : b)).name : undefined; + const minPriorityLabel = priorityLabels.length > 0 ? priorityLabels.reduce((a, b) => (calculateWeight(a) < calculateWeight(b) ? a : b)).name : undefined; const priceLabel = getTargetPriceLabel(minTimeLabel, minPriorityLabel); diff --git a/src/helpers/label.ts b/src/helpers/label.ts index 0f30bb265..a02d6c5eb 100644 --- a/src/helpers/label.ts +++ b/src/helpers/label.ts @@ -4,6 +4,7 @@ import { COLORS } from "../configs"; import { calculateBountyPrice } from "../handlers"; import { Label, Payload } from "../types"; import { deleteLabel } from "./issue"; +import { calculateWeight } from "../helpers"; export const listLabelsForRepo = async (per_page?: number, page?: number): Promise => { const context = getBotContext(); @@ -67,11 +68,11 @@ export const updateLabelsFromBaseRate = async (owner: string, repo: string, cont for (const timeLabel of config.price.timeLabels) { for (const priorityLabel of config.price.priorityLabels) { - const targetPrice = calculateBountyPrice(timeLabel.weight, priorityLabel.weight, config.price.baseMultiplier); + const targetPrice = calculateBountyPrice(calculateWeight(timeLabel), calculateWeight(priorityLabel), config.price.baseMultiplier); const targetPriceLabel = `Price: ${targetPrice} USD`; newLabels.push(targetPriceLabel); - const previousTargetPrice = calculateBountyPrice(timeLabel.weight, priorityLabel.weight, previousBaseRate); + const previousTargetPrice = calculateBountyPrice(calculateWeight(timeLabel), calculateWeight(priorityLabel), previousBaseRate); const previousTargetPriceLabel = `Price: ${previousTargetPrice} USD`; previousLabels.push(previousTargetPriceLabel); } diff --git a/src/helpers/shared.ts b/src/helpers/shared.ts index a1a0d4c6a..25e62d012 100644 --- a/src/helpers/shared.ts +++ b/src/helpers/shared.ts @@ -1,5 +1,5 @@ import { getBotContext } from "../bindings"; -import { Payload, UserType } from "../types"; +import { LabelItem, Payload, UserType } from "../types"; const contextNamesToSkip = ["workflow_run"]; @@ -19,3 +19,20 @@ export const shouldSkip = (): { skip: boolean; reason: string } => { }; export const wait = (ms: number) => new Promise((r) => setTimeout(r, ms)); + +export const calculateWeight = (label: LabelItem | undefined): number => { + if(!label) return 0; + const matches = label.name.match(/\d+/); + const number = (matches && matches.length > 0) ? parseInt(matches[0]) : 0; + if (label.name.split(':')[0] === "Priority") + return number + 1; + if (label.name.includes('Hour')) + return number * 0.125; + if (label.name.includes('Day')) + return 1 + (number - 1) * 0.25; + if (label.name.includes('Week')) + return number + 1; + if (label.name.includes('Month')) + return 5 + (number - 1) * 8; + return 0; +} diff --git a/src/types/config.ts b/src/types/config.ts index 28f2d589b..ab4fccc50 100644 --- a/src/types/config.ts +++ b/src/types/config.ts @@ -2,7 +2,6 @@ import { Static, Type } from "@sinclair/typebox"; const LabelItemSchema = Type.Object({ name: Type.String(), - weight: Type.Number(), value: Type.Optional(Type.Number()), }); export type LabelItem = Static; diff --git a/src/utils/private.ts b/src/utils/private.ts index dba8a5464..004c987a1 100644 --- a/src/utils/private.ts +++ b/src/utils/private.ts @@ -49,7 +49,6 @@ export const getConfigSuperset = async (context: Context, type: "org" | "repo", export interface WideLabel { name: string; - weight: number; value?: number | undefined; } diff --git a/ubiquibot-config-default.json b/ubiquibot-config-default.json index 57eb6df89..fd03ca03f 100644 --- a/ubiquibot-config-default.json +++ b/ubiquibot-config-default.json @@ -5,50 +5,40 @@ "time-labels": [ { "name": "Time: <1 Hour", - "weight": 0.125, "value": 3600 }, { "name": "Time: <1 Day", - "weight": 1, "value": 86400 }, { "name": "Time: <1 Week", - "weight": 2, "value": 604800 }, { "name": "Time: <2 Weeks", - "weight": 3, "value": 1209600 }, { "name": "Time: <1 Month", - "weight": 4, "value": 2592000 } ], "priority-labels": [ { - "name": "Priority: 0 (Normal)", - "weight": 1 + "name": "Priority: 0 (Normal)" }, { - "name": "Priority: 1 (Medium)", - "weight": 2 + "name": "Priority: 1 (Medium)" }, { - "name": "Priority: 2 (High)", - "weight": 3 + "name": "Priority: 2 (High)" }, { - "name": "Priority: 3 (Urgent)", - "weight": 4 + "name": "Priority: 3 (Urgent)" }, { - "name": "Priority: 4 (Emergency)", - "weight": 5 + "name": "Priority: 4 (Emergency)" } ], "command-settings": [ From 911766b25059cc27cc2b05f8c798269ce7285bad Mon Sep 17 00:00:00 2001 From: byteballet Date: Thu, 17 Aug 2023 00:07:16 -0700 Subject: [PATCH 2/7] fix: removed weight from readme --- README.md | 2 -- src/helpers/shared.ts | 21 ++++++++------------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 0311933d0..a698b78f1 100644 --- a/README.md +++ b/README.md @@ -56,13 +56,11 @@ To test the bot, you can: `time-labels` are labels for marking the time limit of the bounty: - `name` is a human-readable name -- `weight` is a number that will be used to calculate the bounty price - `value` is number of seconds that corresponds to the time limit of the bounty `priority-labels` are labels for marking the priority of the bounty: - `name` is a human-readable name -- `weight` is a number that will be used to calculate the bounty price `default-labels` are labels that are applied when an issue is created without any time or priority labels. diff --git a/src/helpers/shared.ts b/src/helpers/shared.ts index 25e62d012..bf1a542c5 100644 --- a/src/helpers/shared.ts +++ b/src/helpers/shared.ts @@ -21,18 +21,13 @@ export const shouldSkip = (): { skip: boolean; reason: string } => { export const wait = (ms: number) => new Promise((r) => setTimeout(r, ms)); export const calculateWeight = (label: LabelItem | undefined): number => { - if(!label) return 0; + if (!label) return 0; const matches = label.name.match(/\d+/); - const number = (matches && matches.length > 0) ? parseInt(matches[0]) : 0; - if (label.name.split(':')[0] === "Priority") - return number + 1; - if (label.name.includes('Hour')) - return number * 0.125; - if (label.name.includes('Day')) - return 1 + (number - 1) * 0.25; - if (label.name.includes('Week')) - return number + 1; - if (label.name.includes('Month')) - return 5 + (number - 1) * 8; + const number = matches && matches.length > 0 ? parseInt(matches[0]) : 0; + if (label.name.split(":")[0] === "Priority") return number + 1; + if (label.name.includes("Hour")) return number * 0.125; + if (label.name.includes("Day")) return 1 + (number - 1) * 0.25; + if (label.name.includes("Week")) return number + 1; + if (label.name.includes("Month")) return 5 + (number - 1) * 8; return 0; -} +}; From 7c7ce700c1fe7c05de5ff676c9473c80b573e6f9 Mon Sep 17 00:00:00 2001 From: byteballet Date: Thu, 17 Aug 2023 00:13:26 -0700 Subject: [PATCH 3/7] fix: pulled dev branch --- src/handlers/comment/handlers/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/handlers/comment/handlers/index.ts b/src/handlers/comment/handlers/index.ts index a845426bc..bc5bd930f 100644 --- a/src/handlers/comment/handlers/index.ts +++ b/src/handlers/comment/handlers/index.ts @@ -20,6 +20,7 @@ import { getPayoutConfigByNetworkId, getTokenSymbol, getAllIssueAssignEvents, + calculateWeight, } from "../../../helpers"; import { getBotConfig, getBotContext, getLogger } from "../../../bindings"; import { handleIssueClosed } from "../../payout"; @@ -97,8 +98,8 @@ export const issueCreatedCallback = async (): Promise => { const timeLabels = config.price.timeLabels.filter((item) => labels.map((i) => i.name).includes(item.name)); const priorityLabels = config.price.priorityLabels.filter((item) => labels.map((i) => i.name).includes(item.name)); - const minTimeLabel = timeLabels.length > 0 ? timeLabels.reduce((a, b) => (a.weight < b.weight ? a : b)).name : config.price.defaultLabels[0]; - const minPriorityLabel = priorityLabels.length > 0 ? priorityLabels.reduce((a, b) => (a.weight < b.weight ? a : b)).name : config.price.defaultLabels[1]; + const minTimeLabel = timeLabels.length > 0 ? timeLabels.reduce((a, b) => (calculateWeight(a) < calculateWeight(b) ? a : b)).name : config.price.defaultLabels[0]; + const minPriorityLabel = priorityLabels.length > 0 ? priorityLabels.reduce((a, b) => (calculateWeight(a) < calculateWeight(b) ? a : b)).name : config.price.defaultLabels[1]; if (!timeLabels.length) await addLabelToIssue(minTimeLabel); if (!priorityLabels.length) await addLabelToIssue(minPriorityLabel); From ab49d26654de8db7bd46d77ecc6d07b015efcf2e Mon Sep 17 00:00:00 2001 From: byteballet Date: Thu, 17 Aug 2023 15:52:42 -0700 Subject: [PATCH 4/7] fix: weight from priority-label --- .github/ubiquibot-config.yml | 12 ++++++------ src/helpers/shared.ts | 2 +- ubiquibot-config-default.json | 10 +++++----- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/ubiquibot-config.yml b/.github/ubiquibot-config.yml index fa4cf462a..793059e57 100644 --- a/.github/ubiquibot-config.yml +++ b/.github/ubiquibot-config.yml @@ -12,14 +12,14 @@ time-labels: - name: "Time: <1 Week" value: 604800 priority-labels: - - name: "Priority: 0 (Normal)" - - name: "Priority: 1 (Medium)" - - name: "Priority: 2 (High)" - - name: "Priority: 3 (Urgent)" - - name: "Priority: 4 (Emergency)" + - name: "Priority: 1 (Normal)" + - name: "Priority: 2 (Medium)" + - name: "Priority: 3 (High)" + - name: "Priority: 4 (Urgent)" + - name: "Priority: 5 (Emergency)" default-labels: - "Time: <1 Hour" - - "Priority: 0 (Normal)" + - "Priority: 1 (Normal)" payment-permit-max-price: 1000 comment-incentives: true max-concurrent-bounties: 2 diff --git a/src/helpers/shared.ts b/src/helpers/shared.ts index bf1a542c5..6f1f62b4e 100644 --- a/src/helpers/shared.ts +++ b/src/helpers/shared.ts @@ -24,7 +24,7 @@ export const calculateWeight = (label: LabelItem | undefined): number => { if (!label) return 0; const matches = label.name.match(/\d+/); const number = matches && matches.length > 0 ? parseInt(matches[0]) : 0; - if (label.name.split(":")[0] === "Priority") return number + 1; + if (label.name.split(":")[0] === "Priority") return number; if (label.name.includes("Hour")) return number * 0.125; if (label.name.includes("Day")) return 1 + (number - 1) * 0.25; if (label.name.includes("Week")) return number + 1; diff --git a/ubiquibot-config-default.json b/ubiquibot-config-default.json index bae339a31..6874f95b8 100644 --- a/ubiquibot-config-default.json +++ b/ubiquibot-config-default.json @@ -34,19 +34,19 @@ ], "priority-labels": [ { - "name": "Priority: 0 (Normal)" + "name": "Priority: 1 (Normal)" }, { - "name": "Priority: 1 (Medium)" + "name": "Priority: 2 (Medium)" }, { - "name": "Priority: 2 (High)" + "name": "Priority: 3 (High)" }, { - "name": "Priority: 3 (Urgent)" + "name": "Priority: 4 (Urgent)" }, { - "name": "Priority: 4 (Emergency)" + "name": "Priority: 5 (Emergency)" } ], "command-settings": [ From 3389e20c8bf907ef12ce3ca5bedae6bc2097776e Mon Sep 17 00:00:00 2001 From: byteballet Date: Fri, 18 Aug 2023 14:37:10 -0700 Subject: [PATCH 5/7] fix: parse priority --- src/helpers/shared.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/shared.ts b/src/helpers/shared.ts index 6f1f62b4e..b4bc6784d 100644 --- a/src/helpers/shared.ts +++ b/src/helpers/shared.ts @@ -24,7 +24,7 @@ export const calculateWeight = (label: LabelItem | undefined): number => { if (!label) return 0; const matches = label.name.match(/\d+/); const number = matches && matches.length > 0 ? parseInt(matches[0]) : 0; - if (label.name.split(":")[0] === "Priority") return number; + if (label.name.toLowerCase().includes("priority")) return number; if (label.name.includes("Hour")) return number * 0.125; if (label.name.includes("Day")) return 1 + (number - 1) * 0.25; if (label.name.includes("Week")) return number + 1; From 00ff231b8c7bed2d45346a478c2201d2112e6642 Mon Sep 17 00:00:00 2001 From: byteballet Date: Tue, 22 Aug 2023 03:11:56 -0700 Subject: [PATCH 6/7] fix: remove value and weight --- src/handlers/assign/action.ts | 4 ++-- src/handlers/comment/handlers/assign.ts | 4 ++-- src/handlers/comment/handlers/index.ts | 6 ++++-- src/helpers/shared.ts | 22 +++++++++++++++++----- src/types/config.ts | 1 - src/utils/private.ts | 1 - ubiquibot-config-default.json | 15 +++++---------- 7 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/handlers/assign/action.ts b/src/handlers/assign/action.ts index 9297ad8ef..b42312a88 100644 --- a/src/handlers/assign/action.ts +++ b/src/handlers/assign/action.ts @@ -1,5 +1,5 @@ import { getBotConfig, getBotContext, getLogger } from "../../bindings"; -import { addCommentToIssue, closePullRequest, getOpenedPullRequestsForAnIssue, calculateWeight } from "../../helpers"; +import { addCommentToIssue, closePullRequest, getOpenedPullRequestsForAnIssue, calculateWeight, calculateDuration } from "../../helpers"; import { Payload, LabelItem } from "../../types"; import { deadLinePrefix } from "../shared"; @@ -51,7 +51,7 @@ export const commentWithAssignMessage = async (): Promise => { const sorted = timeLabelsAssigned.sort((a, b) => calculateWeight(a) - calculateWeight(b)); const targetTimeLabel = sorted[0]; - const duration = targetTimeLabel.value; + const duration = calculateDuration(targetTimeLabel); if (!duration) { logger.debug(`Missing configure for timelabel: ${targetTimeLabel.name}`); return; diff --git a/src/handlers/comment/handlers/assign.ts b/src/handlers/comment/handlers/assign.ts index c2927d90a..5394b3404 100644 --- a/src/handlers/comment/handlers/assign.ts +++ b/src/handlers/comment/handlers/assign.ts @@ -1,4 +1,4 @@ -import { addAssignees, getAssignedIssues, getAvailableOpenedPullRequests, getAllIssueComments, calculateWeight } from "../../../helpers"; +import { addAssignees, getAssignedIssues, getAvailableOpenedPullRequests, getAllIssueComments, calculateWeight, calculateDuration } from "../../../helpers"; import { getBotConfig, getBotContext, getLogger } from "../../../bindings"; import { Payload, LabelItem, Comment, IssueType, Issue } from "../../../types"; import { deadLinePrefix } from "../../shared"; @@ -83,7 +83,7 @@ export const assign = async (body: string) => { const sorted = timeLabelsAssigned.sort((a, b) => calculateWeight(a) - calculateWeight(b)); const targetTimeLabel = sorted[0]; - const duration = targetTimeLabel.value; + const duration = calculateDuration(targetTimeLabel); if (!duration) { logger.info(`Missing configure for time label: ${targetTimeLabel.name}`); return "Skipping `/start` since configuration is missing for the following labels"; diff --git a/src/handlers/comment/handlers/index.ts b/src/handlers/comment/handlers/index.ts index bc5bd930f..5470b3062 100644 --- a/src/handlers/comment/handlers/index.ts +++ b/src/handlers/comment/handlers/index.ts @@ -98,8 +98,10 @@ export const issueCreatedCallback = async (): Promise => { const timeLabels = config.price.timeLabels.filter((item) => labels.map((i) => i.name).includes(item.name)); const priorityLabels = config.price.priorityLabels.filter((item) => labels.map((i) => i.name).includes(item.name)); - const minTimeLabel = timeLabels.length > 0 ? timeLabels.reduce((a, b) => (calculateWeight(a) < calculateWeight(b) ? a : b)).name : config.price.defaultLabels[0]; - const minPriorityLabel = priorityLabels.length > 0 ? priorityLabels.reduce((a, b) => (calculateWeight(a) < calculateWeight(b) ? a : b)).name : config.price.defaultLabels[1]; + const minTimeLabel = + timeLabels.length > 0 ? timeLabels.reduce((a, b) => (calculateWeight(a) < calculateWeight(b) ? a : b)).name : config.price.defaultLabels[0]; + const minPriorityLabel = + priorityLabels.length > 0 ? priorityLabels.reduce((a, b) => (calculateWeight(a) < calculateWeight(b) ? a : b)).name : config.price.defaultLabels[1]; if (!timeLabels.length) await addLabelToIssue(minTimeLabel); if (!priorityLabels.length) await addLabelToIssue(minPriorityLabel); diff --git a/src/helpers/shared.ts b/src/helpers/shared.ts index b4bc6784d..646e0d8e9 100644 --- a/src/helpers/shared.ts +++ b/src/helpers/shared.ts @@ -23,11 +23,23 @@ export const wait = (ms: number) => new Promise((r) => setTimeout(r, ms)); export const calculateWeight = (label: LabelItem | undefined): number => { if (!label) return 0; const matches = label.name.match(/\d+/); - const number = matches && matches.length > 0 ? parseInt(matches[0]) : 0; + const number = matches && matches.length > 0 ? parseInt(matches[0]) || 0 : 0; if (label.name.toLowerCase().includes("priority")) return number; - if (label.name.includes("Hour")) return number * 0.125; - if (label.name.includes("Day")) return 1 + (number - 1) * 0.25; - if (label.name.includes("Week")) return number + 1; - if (label.name.includes("Month")) return 5 + (number - 1) * 8; + if (label.name.toLowerCase().includes("hour")) return number * 0.125; + if (label.name.toLowerCase().includes("day")) return 1 + (number - 1) * 0.25; + if (label.name.toLowerCase().includes("week")) return number + 1; + if (label.name.toLowerCase().includes("month")) return 5 + (number - 1) * 8; + return 0; +}; + +export const calculateDuration = (label: LabelItem): number => { + if (!label) return 0; + const matches = label.name.match(/\d+/); + if (label.name.toLowerCase().includes("priority")) return 0; + const number = matches && matches.length > 0 ? parseInt(matches[0]) || 0 : 0; + if (label.name.toLowerCase().includes("hour")) return number * 3600; + if (label.name.toLowerCase().includes("day")) return number * 86400; + if (label.name.toLowerCase().includes("week")) return number * 604800; + if (label.name.toLowerCase().includes("month")) return number * 2592000; return 0; }; diff --git a/src/types/config.ts b/src/types/config.ts index 6c02e782a..c654266b8 100644 --- a/src/types/config.ts +++ b/src/types/config.ts @@ -3,7 +3,6 @@ import { Level } from "../adapters/supabase"; const LabelItemSchema = Type.Object({ name: Type.String(), - value: Type.Optional(Type.Number()), }); export type LabelItem = Static; diff --git a/src/utils/private.ts b/src/utils/private.ts index e70b2f2c1..9b5e9887d 100644 --- a/src/utils/private.ts +++ b/src/utils/private.ts @@ -49,7 +49,6 @@ export const getConfigSuperset = async (context: Context, type: "org" | "repo", export interface WideLabel { name: string; - value?: number | undefined; } export interface CommandObj { diff --git a/ubiquibot-config-default.json b/ubiquibot-config-default.json index 6874f95b8..6475ffdc6 100644 --- a/ubiquibot-config-default.json +++ b/ubiquibot-config-default.json @@ -12,24 +12,19 @@ "default-labels": [], "time-labels": [ { - "name": "Time: <1 Hour", - "value": 3600 + "name": "Time: <1 Hour" }, { - "name": "Time: <1 Day", - "value": 86400 + "name": "Time: <1 Day" }, { - "name": "Time: <1 Week", - "value": 604800 + "name": "Time: <1 Week" }, { - "name": "Time: <2 Weeks", - "value": 1209600 + "name": "Time: <2 Weeks" }, { - "name": "Time: <1 Month", - "value": 2592000 + "name": "Time: <1 Month" } ], "priority-labels": [ From 3e4c7a898ccd331f510a5d9cce78afb7d5b56c2f Mon Sep 17 00:00:00 2001 From: byteballet Date: Wed, 23 Aug 2023 09:09:35 -0700 Subject: [PATCH 7/7] update: remove value from ubiquibot-config --- .github/ubiquibot-config.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/ubiquibot-config.yml b/.github/ubiquibot-config.yml index 5c92635b6..f1235dab5 100644 --- a/.github/ubiquibot-config.yml +++ b/.github/ubiquibot-config.yml @@ -2,15 +2,10 @@ evm-network-id: 100 price-multiplier: 1.5 time-labels: - name: "Time: <1 Hour" - value: 3600 - name: "Time: <2 Hours" - value: 7200 - name: "Time: <4 Hours" - value: 14400 - name: "Time: <1 Day" - value: 86400 - name: "Time: <1 Week" - value: 604800 priority-labels: - name: "Priority: 1 (Normal)" - name: "Priority: 2 (Medium)"