Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

feat: default config #383

Merged
merged 10 commits into from
Jul 31, 2023
1 change: 0 additions & 1 deletion src/configs/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from "./price";
export * from "./shared";
export * from "./strings";
export * from "./abis";
64 changes: 0 additions & 64 deletions src/configs/price.ts

This file was deleted.

59 changes: 32 additions & 27 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,133 +1,138 @@
import { DEFAULT_NETWORK_ID, DefaultPriceConfig } from "../configs";
import { CommentElementPricing } from "../types";
import { WideLabel, WideOrgConfig, WideRepoConfig } from "./private";

export const getNetworkId = (parsedRepo: WideRepoConfig | undefined, parsedOrg: WideOrgConfig | undefined): number => {
interface Configs {
parsedRepo?: WideRepoConfig;
parsedOrg?: WideOrgConfig;
parsedDefault: WideRepoConfig;
}
rndquu marked this conversation as resolved.
Show resolved Hide resolved

export const getNetworkId = ({ parsedRepo, parsedOrg, parsedDefault }: Configs): number => {
if (parsedRepo && parsedRepo["evm-network-id"] && !Number.isNaN(Number(parsedRepo["evm-network-id"]))) {
return Number(parsedRepo["evm-network-id"]);
} else if (parsedOrg && parsedOrg["evm-network-id"] && !Number.isNaN(Number(parsedOrg["evm-network-id"]))) {
return Number(parsedOrg["evm-network-id"]);
} else {
return DEFAULT_NETWORK_ID;
return Number(parsedDefault["evm-network-id"]);
}
};

export const getBaseMultiplier = (parsedRepo: WideRepoConfig | undefined, parsedOrg: WideOrgConfig | undefined): number => {
export const getBaseMultiplier = ({ parsedRepo, parsedOrg, parsedDefault }: Configs): number => {
if (parsedRepo && parsedRepo["price-multiplier"] && !Number.isNaN(Number(parsedRepo["price-multiplier"]))) {
return Number(parsedRepo["price-multiplier"]);
} else if (parsedOrg && parsedOrg["price-multiplier"] && !Number.isNaN(Number(parsedOrg["price-multiplier"]))) {
return Number(parsedOrg["price-multiplier"]);
} else {
return Number(DefaultPriceConfig["baseMultiplier"]);
return Number(parsedDefault["price-multiplier"]);
}
};

export const getCreatorMultiplier = (parsedRepo: WideRepoConfig | undefined, parsedOrg: WideOrgConfig | undefined): number => {
export const getCreatorMultiplier = ({ parsedRepo, parsedOrg, parsedDefault }: Configs): number => {
if (parsedRepo && parsedRepo["issue-creator-multiplier"] && !Number.isNaN(Number(parsedRepo["issue-creator-multiplier"]))) {
return Number(parsedRepo["issue-creator-multiplier"]);
} else if (parsedOrg && parsedOrg["issue-creator-multiplier"] && !Number.isNaN(Number(parsedOrg["issue-creator-multiplier"]))) {
return Number(parsedOrg["issue-creator-multiplier"]);
} else {
return Number(DefaultPriceConfig["issueCreatorMultiplier"]);
return Number(parsedDefault["issue-creator-multiplier"]);
}
};

export const getTimeLabels = (parsedRepo: WideRepoConfig | undefined, parsedOrg: WideOrgConfig | undefined): WideLabel[] => {
export const getTimeLabels = ({ parsedRepo, parsedOrg, parsedDefault }: Configs): WideLabel[] => {
if (parsedRepo && parsedRepo["time-labels"] && Array.isArray(parsedRepo["time-labels"]) && parsedRepo["time-labels"].length > 0) {
return parsedRepo["time-labels"];
} else if (parsedOrg && parsedOrg["time-labels"] && Array.isArray(parsedOrg["time-labels"]) && parsedOrg["time-labels"].length > 0) {
return parsedOrg["time-labels"];
} else {
return DefaultPriceConfig["timeLabels"];
return parsedDefault["time-labels"] as WideLabel[];
}
};

export const getPriorityLabels = (parsedRepo: WideRepoConfig | undefined, parsedOrg: WideOrgConfig | undefined): WideLabel[] => {
export const getPriorityLabels = ({ parsedRepo, parsedOrg, parsedDefault }: Configs): WideLabel[] => {
if (parsedRepo && parsedRepo["priority-labels"] && Array.isArray(parsedRepo["priority-labels"]) && parsedRepo["priority-labels"].length > 0) {
return parsedRepo["priority-labels"];
} else if (parsedOrg && parsedOrg["priority-labels"] && Array.isArray(parsedOrg["priority-labels"]) && parsedOrg["priority-labels"].length > 0) {
return parsedOrg["priority-labels"];
} else {
return DefaultPriceConfig["priorityLabels"];
return parsedDefault["priority-labels"] as WideLabel[];
}
};

export const getCommentItemPrice = (parsedRepo: WideRepoConfig | undefined, parsedOrg: WideOrgConfig | undefined): CommentElementPricing => {
export const getCommentItemPrice = ({ parsedRepo, parsedOrg, parsedDefault }: Configs): CommentElementPricing => {
if (parsedRepo && parsedRepo["comment-element-pricing"]) {
return parsedRepo["comment-element-pricing"];
} else if (parsedOrg && parsedOrg["comment-element-pricing"]) {
return parsedOrg["comment-element-pricing"];
} else {
return DefaultPriceConfig["commentElementPricing"];
return parsedDefault["comment-element-pricing"] as CommentElementPricing;
}
};

export const getAutoPayMode = (parsedRepo?: WideRepoConfig, parsedOrg?: WideOrgConfig): boolean => {
export const getAutoPayMode = ({ parsedRepo, parsedOrg, parsedDefault }: Configs): boolean => {
if (parsedRepo && parsedRepo["auto-pay-mode"] && typeof parsedRepo["auto-pay-mode"] === "boolean") {
return parsedRepo["auto-pay-mode"];
} else if (parsedOrg && parsedOrg["auto-pay-mode"] && typeof parsedOrg["auto-pay-mode"] === "boolean") {
return parsedOrg["auto-pay-mode"];
} else {
return true;
return parsedDefault["auto-pay-mode"] as boolean;
}
};

export const getAnalyticsMode = (parsedRepo: WideRepoConfig | undefined, parsedOrg: WideOrgConfig | undefined): boolean => {
export const getAnalyticsMode = ({ parsedRepo, parsedOrg, parsedDefault }: Configs): boolean => {
if (parsedRepo && parsedRepo["disable-analytics"] && typeof parsedRepo["disable-analytics"] === "boolean") {
return parsedRepo["disable-analytics"];
} else if (parsedOrg && parsedOrg["disable-analytics"] && typeof parsedOrg["disable-analytics"] === "boolean") {
return parsedOrg["disable-analytics"];
} else {
return false;
return parsedDefault["disable-analytics"] as boolean;
}
};

export const getPromotionComment = (parsedRepo: WideRepoConfig | undefined, parsedOrg: WideOrgConfig | undefined): string => {
export const getPromotionComment = ({ parsedRepo, parsedOrg, parsedDefault }: Configs): string => {
if (parsedRepo && parsedRepo["promotion-comment"] && typeof parsedRepo["promotion-comment"] === "string") {
return parsedRepo["promotion-comment"];
} else if (parsedOrg && parsedOrg["promotion-comment"] && typeof parsedOrg["promotion-comment"] === "string") {
return parsedOrg["promotion-comment"];
} else {
return "\n<h6>If you enjoy the DevPool experience, please follow <a href='https://github.com/ubiquity'>Ubiquity on GitHub</a> and star <a href='https://github.com/ubiquity/devpool-directory'>this repo</a> to show your support. It helps a lot!</h6>";
return parsedDefault["promotion-comment"] as string;
}
};

export const getIncentiveMode = (parsedRepo?: WideRepoConfig, parsedOrg?: WideOrgConfig): boolean => {
export const getIncentiveMode = ({ parsedRepo, parsedOrg, parsedDefault }: Configs): boolean => {
if (parsedRepo && parsedRepo["comment-incentives"] && typeof parsedRepo["comment-incentives"] === "boolean") {
return parsedRepo["comment-incentives"];
} else if (parsedOrg && parsedOrg["comment-incentives"] && typeof parsedOrg["comment-incentives"] === "boolean") {
return parsedOrg["comment-incentives"];
} else {
return false;
return parsedDefault["comment-incentives"] as boolean;
}
};

export const getBountyHunterMax = (parsedRepo: WideRepoConfig | undefined, parsedOrg: WideOrgConfig | undefined): number => {
export const getBountyHunterMax = ({ parsedRepo, parsedOrg, parsedDefault }: Configs): number => {
if (parsedRepo && parsedRepo["max-concurrent-assigns"] && !Number.isNaN(Number(parsedRepo["max-concurrent-assigns"]))) {
return Number(parsedRepo["max-concurrent-assigns"]);
} else if (parsedOrg && parsedOrg["max-concurrent-assigns"] && !Number.isNaN(Number(parsedOrg["max-concurrent-assigns"]))) {
return Number(parsedOrg["max-concurrent-assigns"]);
} else {
return 2;
return Number(parsedDefault["max-concurrent-assigns"]);
}
};

export const getDefaultLabels = (parsedRepo: WideRepoConfig | undefined, parsedOrg: WideOrgConfig | undefined): string[] => {
export const getDefaultLabels = ({ parsedRepo, parsedOrg, parsedDefault }: Configs): string[] => {
if (parsedRepo && parsedRepo["default-labels"]) {
return parsedRepo["default-labels"];
} else if (parsedOrg && parsedOrg["default-labels"]) {
return parsedOrg["default-labels"];
} else {
return [];
return parsedDefault["default-labels"] as string[];
}
};

export const getRegisterWalletWithVerification = (parsedRepo: WideRepoConfig | undefined, parsedOrg: WideOrgConfig | undefined): boolean => {
export const getRegisterWalletWithVerification = ({ parsedRepo, parsedOrg, parsedDefault }: Configs): boolean => {
if (parsedRepo && parsedRepo["register-wallet-with-verification"] && typeof parsedRepo["register-wallet-with-verification"] === "boolean") {
return Boolean(parsedRepo["register-wallet-with-verification"]);
} else if (parsedOrg && parsedOrg["register-wallet-with-verification"] && typeof parsedOrg["register-wallet-with-verification"] === "boolean") {
return Boolean(parsedOrg["register-wallet-with-verification"]);
} else {
return false;
return Boolean(parsedDefault["register-wallet-with-verification"]);
}
};
42 changes: 25 additions & 17 deletions src/utils/private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import _sodium from "libsodium-wrappers";
import YAML from "yaml";
import { Payload } from "../types";
import { Context } from "probot";
import { readFileSync } from "fs";
import {
getAnalyticsMode,
getAutoPayMode,
Expand Down Expand Up @@ -71,10 +72,10 @@ export interface WideOrgConfig extends WideConfig {
"private-key-encrypted"?: string;
}

export const parseYAML = async (data?: string): Promise<WideConfig | undefined> => {
export const parseYAML = (data?: string): WideConfig | undefined => {
try {
if (data) {
const parsedData = await YAML.parse(data);
const parsedData = YAML.parse(data);
return parsedData ?? undefined;
}
return undefined;
Expand All @@ -83,6 +84,11 @@ export const parseYAML = async (data?: string): Promise<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<string | undefined> => {
try {
await _sodium.ready;
Expand Down Expand Up @@ -127,25 +133,27 @@ export const getWideConfig = async (context: Context) => {
const orgConfig = await getConfigSuperset(context, "org");
const repoConfig = await getConfigSuperset(context, "repo");

const parsedOrg: WideOrgConfig | undefined = await parseYAML(orgConfig);
const parsedRepo: WideRepoConfig | undefined = await parseYAML(repoConfig);
const parsedOrg: WideOrgConfig | undefined = parseYAML(orgConfig);
const parsedRepo: WideRepoConfig | undefined = parseYAML(repoConfig);
const parsedDefault: WideRepoConfig = getDefaultConfig();
const privateKeyDecrypted = parsedOrg && parsedOrg[KEY_NAME] ? await getPrivateKey(parsedOrg[KEY_NAME]) : undefined;

const configs = { parsedRepo, parsedOrg, parsedDefault };
const configData = {
networkId: getNetworkId(parsedRepo, parsedOrg),
networkId: getNetworkId(configs),
privateKey: privateKeyDecrypted ?? "",
baseMultiplier: getBaseMultiplier(parsedRepo, parsedOrg),
issueCreatorMultiplier: getCreatorMultiplier(parsedRepo, parsedOrg),
timeLabels: getTimeLabels(parsedRepo, parsedOrg),
priorityLabels: getPriorityLabels(parsedRepo, parsedOrg),
autoPayMode: getAutoPayMode(parsedRepo, parsedOrg),
disableAnalytics: getAnalyticsMode(parsedRepo, parsedOrg),
bountyHunterMax: getBountyHunterMax(parsedRepo, parsedOrg),
incentiveMode: getIncentiveMode(parsedRepo, parsedOrg),
commentElementPricing: getCommentItemPrice(parsedRepo, parsedOrg),
defaultLabels: getDefaultLabels(parsedRepo, parsedOrg),
promotionComment: getPromotionComment(parsedRepo, parsedOrg),
registerWalletWithVerification: getRegisterWalletWithVerification(parsedRepo, parsedOrg),
baseMultiplier: getBaseMultiplier(configs),
issueCreatorMultiplier: getCreatorMultiplier(configs),
timeLabels: getTimeLabels(configs),
priorityLabels: getPriorityLabels(configs),
autoPayMode: getAutoPayMode(configs),
disableAnalytics: getAnalyticsMode(configs),
bountyHunterMax: getBountyHunterMax(configs),
incentiveMode: getIncentiveMode(configs),
commentElementPricing: getCommentItemPrice(configs),
defaultLabels: getDefaultLabels(configs),
promotionComment: getPromotionComment(configs),
registerWalletWithVerification: getRegisterWalletWithVerification(configs),
};

return configData;
Expand Down
44 changes: 44 additions & 0 deletions ubiquibot-config-default.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
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
0x4007 marked this conversation as resolved.
Show resolved Hide resolved
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
0x4007 marked this conversation as resolved.
Show resolved Hide resolved
auto-pay-mode: true
0x4007 marked this conversation as resolved.
Show resolved Hide resolved
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<h6>If you enjoy the DevPool experience, please follow <a href='https://github.com/ubiquity'>Ubiquity on GitHub</a> and star <a href='https://github.com/ubiquity/devpool-directory'>this repo</a> to show your support. It helps a lot!</h6>"
register-wallet-with-verification: false