From 44d7976435e9c7267fcb4c5958bfef7958285448 Mon Sep 17 00:00:00 2001 From: 0xCodercrane <108444211+0xcodercrane@users.noreply.github.com> Date: Wed, 2 Aug 2023 11:05:29 +0800 Subject: [PATCH 1/5] refactor: hotfix --- src/utils/private.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/utils/private.ts b/src/utils/private.ts index 0a6e98064..4314de1e0 100644 --- a/src/utils/private.ts +++ b/src/utils/private.ts @@ -20,11 +20,12 @@ import { } from "./helpers"; const CONFIG_REPO = "ubiquibot-config"; -const KEY_PATH = ".github/ubiquibot-config.yml"; +const CONFIG_PATH = ".github/ubiquibot-config.yml"; +const DEFAULT_CONFIG_PATH = "./ubiquibot-config-default.yml"; const KEY_NAME = "private-key-encrypted"; const KEY_PREFIX = "HSK_"; -export const getConfigSuperset = async (context: Context, type: "org" | "repo"): Promise => { +export const getConfigSuperset = async (context: Context, type: "org" | "repo", filePath: string): Promise => { try { const payload = context.payload as Payload; const repo = type === "org" ? CONFIG_REPO : payload.repository.name; @@ -33,7 +34,7 @@ export const getConfigSuperset = async (context: Context, type: "org" | "repo"): const { data } = await context.octokit.rest.repos.getContent({ owner, repo, - path: KEY_PATH, + path: filePath, mediaType: { format: "raw", }, @@ -130,12 +131,16 @@ export const getScalarKey = async (X25519_PRIVATE_KEY: string | undefined): Prom }; export const getWideConfig = async (context: Context) => { - const orgConfig = await getConfigSuperset(context, "org"); - const repoConfig = await getConfigSuperset(context, "repo"); + const orgConfig = await getConfigSuperset(context, "org", CONFIG_PATH); + const repoConfig = await getConfigSuperset(context, "repo", CONFIG_PATH); const parsedOrg: WideOrgConfig | undefined = parseYAML(orgConfig); const parsedRepo: WideRepoConfig | undefined = parseYAML(repoConfig); - const parsedDefault: WideRepoConfig = getDefaultConfig(); + const defaultConfig = await getConfigSuperset(context, "repo", DEFAULT_CONFIG_PATH); + const parsedDefault: WideRepoConfig | undefined = parseYAML(defaultConfig); + if (!parsedDefault) { + throw new Error("Default configuration missing!"); + } const privateKeyDecrypted = parsedOrg && parsedOrg[KEY_NAME] ? await getPrivateKey(parsedOrg[KEY_NAME]) : undefined; const configs = { parsedRepo, parsedOrg, parsedDefault }; From 144b715720c5e975437c983d205111102fc67514 Mon Sep 17 00:00:00 2001 From: 0xCodercrane <108444211+0xcodercrane@users.noreply.github.com> Date: Wed, 2 Aug 2023 11:09:29 +0800 Subject: [PATCH 2/5] chore: update config --- ubiquibot-config-default.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ubiquibot-config-default.yml b/ubiquibot-config-default.yml index 5b0c70ac9..6828dfe3e 100644 --- a/ubiquibot-config-default.yml +++ b/ubiquibot-config-default.yml @@ -1,6 +1,6 @@ --- -evm-network-id: 1 -price-multiplier: 1000 +evm-network-id: 100 +price-multiplier: 1.5 issue-creator-multiplier: 2000 time-labels: - name: "Time: <1 Hour" @@ -29,6 +29,10 @@ priority-labels: weight: 4 - name: "Priority: 4 (Emergency)" weight: 5 +default-labels: + - "Time: <1 Hour" + - "Priority: 0 (Normal)" + - "Test" auto-pay-mode: true disable-analytics: true comment-incentives: false From e5d364309ac7a67429d0dc64458df665af44f70a Mon Sep 17 00:00:00 2001 From: 0xCodercrane <108444211+0xcodercrane@users.noreply.github.com> Date: Wed, 2 Aug 2023 11:12:40 +0800 Subject: [PATCH 3/5] fix: can read in .github --- .../ubiquibot-config-default.yml | 0 src/utils/private.ts | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename ubiquibot-config-default.yml => .github/ubiquibot-config-default.yml (100%) diff --git a/ubiquibot-config-default.yml b/.github/ubiquibot-config-default.yml similarity index 100% rename from ubiquibot-config-default.yml rename to .github/ubiquibot-config-default.yml diff --git a/src/utils/private.ts b/src/utils/private.ts index 4314de1e0..c387823a2 100644 --- a/src/utils/private.ts +++ b/src/utils/private.ts @@ -21,7 +21,7 @@ import { const CONFIG_REPO = "ubiquibot-config"; const CONFIG_PATH = ".github/ubiquibot-config.yml"; -const DEFAULT_CONFIG_PATH = "./ubiquibot-config-default.yml"; +const DEFAULT_CONFIG_PATH = ".github/ubiquibot-config-default.yml"; const KEY_NAME = "private-key-encrypted"; const KEY_PREFIX = "HSK_"; From 09044eb139c88a3133c79d46ada4c40e3ca67b4c Mon Sep 17 00:00:00 2001 From: 0xCodercrane <108444211+0xcodercrane@users.noreply.github.com> Date: Wed, 2 Aug 2023 11:52:19 +0800 Subject: [PATCH 4/5] fix: readfilesync not working with function --- .github/ubiquibot-config-default.yml | 48 -------------------- src/utils/private.ts | 15 ++---- ubiquibot-config-default.json | 68 ++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 59 deletions(-) delete mode 100644 .github/ubiquibot-config-default.yml create mode 100644 ubiquibot-config-default.json diff --git a/.github/ubiquibot-config-default.yml b/.github/ubiquibot-config-default.yml deleted file mode 100644 index 6828dfe3e..000000000 --- a/.github/ubiquibot-config-default.yml +++ /dev/null @@ -1,48 +0,0 @@ ---- -evm-network-id: 100 -price-multiplier: 1.5 -issue-creator-multiplier: 2000 -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: 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)" - - "Test" -auto-pay-mode: true -disable-analytics: true -comment-incentives: false -max-concurrent-assigns: 2 -comment-element-pricing: - text: 0.1 - link: 0.5 - list: 0.5 - code: 5 - image: 5 -default-labels: [] -promotion-comment: "\n
If you enjoy the DevPool experience, please follow Ubiquity on GitHub and star this repo to show your support. It helps a lot!
" -register-wallet-with-verification: false diff --git a/src/utils/private.ts b/src/utils/private.ts index c387823a2..550914b1a 100644 --- a/src/utils/private.ts +++ b/src/utils/private.ts @@ -19,9 +19,11 @@ import { getRegisterWalletWithVerification, } from "./helpers"; +import DEFAULT_CONFIG_JSON from "../../ubiquibot-config-default.json"; + const CONFIG_REPO = "ubiquibot-config"; const CONFIG_PATH = ".github/ubiquibot-config.yml"; -const DEFAULT_CONFIG_PATH = ".github/ubiquibot-config-default.yml"; +const DEFAULT_CONFIG_PATH = "/ubiquibot-config-default.yml"; const KEY_NAME = "private-key-encrypted"; const KEY_PREFIX = "HSK_"; @@ -85,11 +87,6 @@ export const parseYAML = (data?: string): WideConfig | undefined => { } }; -export const getDefaultConfig = (): WideRepoConfig => { - const defaultConfig = readFileSync(`${__dirname}/../../ubiquibot-config-default.yml`, "utf8"); - return parseYAML(defaultConfig) as WideRepoConfig; -}; - export const getPrivateKey = async (cipherText: string): Promise => { try { await _sodium.ready; @@ -136,11 +133,7 @@ export const getWideConfig = async (context: Context) => { const parsedOrg: WideOrgConfig | undefined = parseYAML(orgConfig); const parsedRepo: WideRepoConfig | undefined = parseYAML(repoConfig); - const defaultConfig = await getConfigSuperset(context, "repo", DEFAULT_CONFIG_PATH); - const parsedDefault: WideRepoConfig | undefined = parseYAML(defaultConfig); - if (!parsedDefault) { - throw new Error("Default configuration missing!"); - } + const parsedDefault: WideRepoConfig = DEFAULT_CONFIG_JSON; const privateKeyDecrypted = parsedOrg && parsedOrg[KEY_NAME] ? await getPrivateKey(parsedOrg[KEY_NAME]) : undefined; const configs = { parsedRepo, parsedOrg, parsedDefault }; diff --git a/ubiquibot-config-default.json b/ubiquibot-config-default.json new file mode 100644 index 000000000..0fd16c052 --- /dev/null +++ b/ubiquibot-config-default.json @@ -0,0 +1,68 @@ +{ + "evm-network-id": 100, + "price-multiplier": 1.5, + "issue-creator-multiplier": 2000, + "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: 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)", "Test"], + "auto-pay-mode": true, + "disable-analytics": true, + "comment-incentives": false, + "max-concurrent-assigns": 2, + "comment-element-pricing": { + "text": 0.1, + "link": 0.5, + "list": 0.5, + "code": 5, + "image": 5 + }, + "promotion-comment": "\n
If you enjoy the DevPool experience, please follow Ubiquity on GitHub and star this repo to show your support. It helps a lot!
", + "register-wallet-with-verification": false +} From 7e8baf088b9d837b04878dba1699a110e1b3930c Mon Sep 17 00:00:00 2001 From: 0xCodercrane <108444211+0xcodercrane@users.noreply.github.com> Date: Wed, 2 Aug 2023 11:53:55 +0800 Subject: [PATCH 5/5] fix: don't use readfilesync --- src/utils/private.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/utils/private.ts b/src/utils/private.ts index 550914b1a..ca23be510 100644 --- a/src/utils/private.ts +++ b/src/utils/private.ts @@ -2,7 +2,6 @@ import _sodium from "libsodium-wrappers"; import YAML from "yaml"; import { Payload } from "../types"; import { Context } from "probot"; -import { readFileSync } from "fs"; import { getAnalyticsMode, getAutoPayMode, @@ -23,7 +22,6 @@ import DEFAULT_CONFIG_JSON from "../../ubiquibot-config-default.json"; const CONFIG_REPO = "ubiquibot-config"; const CONFIG_PATH = ".github/ubiquibot-config.yml"; -const DEFAULT_CONFIG_PATH = "/ubiquibot-config-default.yml"; const KEY_NAME = "private-key-encrypted"; const KEY_PREFIX = "HSK_";