diff --git a/src/utils/private.ts b/src/utils/private.ts index 0a6e98064..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, @@ -19,12 +18,14 @@ import { getRegisterWalletWithVerification, } from "./helpers"; +import DEFAULT_CONFIG_JSON from "../../ubiquibot-config-default.json"; + const CONFIG_REPO = "ubiquibot-config"; -const KEY_PATH = ".github/ubiquibot-config.yml"; +const CONFIG_PATH = ".github/ubiquibot-config.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", }, @@ -84,11 +85,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; @@ -130,12 +126,12 @@ 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 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 +} diff --git a/ubiquibot-config-default.yml b/ubiquibot-config-default.yml deleted file mode 100644 index 5b0c70ac9..000000000 --- a/ubiquibot-config-default.yml +++ /dev/null @@ -1,44 +0,0 @@ ---- -evm-network-id: 1 -price-multiplier: 1000 -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 -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