Skip to content

Commit

Permalink
chore: update config (ubiquity#847)
Browse files Browse the repository at this point in the history
* chore: update config

* chore: update config

* chore: update config

* chore: update config

* chore: update config

* chore: update config

* test: update config
  • Loading branch information
molecula451 authored Oct 2, 2023
1 parent 062dee5 commit f0b3ac9
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 55 deletions.
26 changes: 12 additions & 14 deletions src/bindings/config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import ms from "ms";

import { BotConfig, BotConfigSchema, LogLevel } from "../types";
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";
Expand Down Expand Up @@ -37,6 +29,12 @@ export const loadConfig = async (context: Context): Promise<BotConfig> => {
openAIKey,
openAITokenLimit,
newContributorGreeting,
timeRangeForMaxIssueEnabled,
timeRangeForMaxIssue,
permitBaseUrl,
botDelay,
followUpTime,
disqualifyTime,
} = await getWideConfig(context);

const publicKey = await getScalarKey(process.env.X25519_PRIVATE_KEY);
Expand Down Expand Up @@ -64,25 +62,25 @@ export const loadConfig = async (context: Context): Promise<BotConfig> => {
rpc: rpc,
privateKey: privateKey,
paymentToken: paymentToken,
permitBaseUrl: process.env.PERMIT_BASE_URL || DEFAULT_PERMIT_BASE_URL,
permitBaseUrl: process.env.PERMIT_BASE_URL || permitBaseUrl,
},
unassign: {
timeRangeForMaxIssue: process.env.DEFAULT_TIME_RANGE_FOR_MAX_ISSUE
? Number(process.env.DEFAULT_TIME_RANGE_FOR_MAX_ISSUE)
: DEFAULT_TIME_RANGE_FOR_MAX_ISSUE,
: timeRangeForMaxIssue,
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),
disqualifyTime: ms(process.env.DISQUALIFY_TIME || DEFAULT_DISQUALIFY_TIME),
: timeRangeForMaxIssueEnabled,
followUpTime: ms(process.env.FOLLOW_UP_TIME || followUpTime),
disqualifyTime: ms(process.env.DISQUALIFY_TIME || disqualifyTime),
},
supabase: {
url: process.env.SUPABASE_URL ?? "",
key: process.env.SUPABASE_KEY ?? "",
},
telegram: {
token: process.env.TELEGRAM_BOT_TOKEN ?? "",
delay: process.env.TELEGRAM_BOT_DELAY ? Number(process.env.TELEGRAM_BOT_DELAY) : DEFAULT_BOT_DELAY,
delay: process.env.TELEGRAM_BOT_DELAY ? Number(process.env.TELEGRAM_BOT_DELAY) : botDelay,
},
logNotification: {
url: process.env.LOG_WEBHOOK_BOT_URL || "",
Expand Down
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 "./shared";
export * from "./strings";
export * from "./abis";
export * from "./ubiquibot-config-default";
31 changes: 0 additions & 31 deletions src/configs/shared.ts

This file was deleted.

6 changes: 6 additions & 0 deletions src/configs/ubiquibot-config-default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ export const DefaultConfig: MergedConfig = {
organization: true,
},
staleBountyTime: "0d",
timeRangeForMaxIssue: 24, //24
timeRangeForMaxIssueEnabled: false,
permitBaseUrl: "https://pay.ubq.fi",
botDelay: 100, // 100ms
followUpTime: "4 days",
disqualifyTime: "7 days",
newContributorGreeting: {
enabled: true,
header:
Expand Down
5 changes: 3 additions & 2 deletions src/handlers/comment/handlers/assign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { deadLinePrefix } from "../../shared";
import { getWalletAddress, getWalletMultiplier } from "../../../adapters/supabase";
import { tableComment } from "./table";
import { bountyInfo } from "../../wildcard";
import { ASSIGN_COMMAND_ENABLED, GLOBAL_STRINGS } from "../../../configs";
import { GLOBAL_STRINGS } from "../../../configs";
import { isParentIssue } from "../../pricing";

export const assign = async (body: string) => {
Expand All @@ -19,6 +19,7 @@ export const assign = async (body: string) => {
const id = organization?.id || repository?.id; // repository?.id as fallback

const staleBounty = config.assign.staleBountyTime;
const startEnabled = config.command.find((command) => command.name === "start");

logger.info(`Received '/start' command from user: ${payload.sender.login}, body: ${body}`);
const issue = (_payload as Payload).issue;
Expand All @@ -28,7 +29,7 @@ export const assign = async (body: string) => {
return "Skipping '/start' because of no issue instance";
}

if (!ASSIGN_COMMAND_ENABLED) {
if (!startEnabled?.enabled) {
logger.info(`Ignore '/start' command from user: ASSIGN_COMMAND_ENABLED config is set false`);
return GLOBAL_STRINGS.assignCommandDisabledComment;
}
Expand Down
9 changes: 5 additions & 4 deletions src/handlers/comment/handlers/help.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { userCommands } from ".";
import { getBotContext, getLogger } from "../../../bindings";
import { ASSIGN_COMMAND_ENABLED } from "../../../configs";
import { getBotConfig, getBotContext, getLogger } from "../../../bindings";
import { IssueType, Payload } from "../../../types";
import { IssueCommentCommands } from "../commands";

Expand Down Expand Up @@ -28,13 +27,15 @@ export const listAvailableCommands = async (body: string) => {
};

export const generateHelpMenu = () => {
const config = getBotConfig();
const startEnabled = config.command.find((command) => command.name === "start");
let helpMenu = "### Available commands\n```";
const commands = userCommands();
commands.map((command) => {
// if first command, add a new line
if (command.id === commands[0].id) {
helpMenu += `\n`;
if (!ASSIGN_COMMAND_ENABLED) return;
if (!startEnabled) return;
}
helpMenu += `- ${command.id}: ${command.description}`;
// if not last command, add a new line (fixes too much space below)
Expand All @@ -43,6 +44,6 @@ export const generateHelpMenu = () => {
}
});

if (!ASSIGN_COMMAND_ENABLED) helpMenu += "```\n***_To assign yourself to an issue, please open a draft pull request that is linked to it._***";
if (!startEnabled) helpMenu += "```\n***_To assign yourself to an issue, please open a draft pull request that is linked to it._***";
return helpMenu;
};
8 changes: 7 additions & 1 deletion src/helpers/label.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { Context } from "probot";
import { getBotConfig, getBotContext, getLogger } from "../bindings";
import { COLORS } from "../configs";
import { calculateBountyPrice } from "../handlers";
import { Label, Payload } from "../types";
import { deleteLabel } from "./issue";
import { calculateWeight } from "../helpers";

// cspell:disable
export const COLORS = {
default: "ededed",
price: "1f883d",
};
// cspell:enable

export const listLabelsForRepo = async (per_page?: number, page?: number): Promise<Label[]> => {
const context = getBotContext();
const payload = context.payload as Payload;
Expand Down
3 changes: 1 addition & 2 deletions src/helpers/payout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/

import { Static } from "@sinclair/typebox";
import { DEFAULT_RPC_ENDPOINT } from "../configs";
import { PayoutConfigSchema } from "../types";
import { getUserPermission } from "./issue";
import { getBotContext, getLogger } from "../bindings";
Expand All @@ -21,7 +20,7 @@ import { getAccessLevel } from "../adapters/supabase";
// available tokens for payouts
const PAYMENT_TOKEN_PER_NETWORK: Record<string, { rpc: string; token: string }> = {
"1": {
rpc: DEFAULT_RPC_ENDPOINT,
rpc: "https://rpc-bot.ubq.fi/v1/mainnet",
token: "0x6B175474E89094C44Da98b954EedeAC495271d0F", // DAI
},
"100": {
Expand Down
6 changes: 6 additions & 0 deletions src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,12 @@ export const MergedConfigSchema = Type.Object({
openAITokenLimit: Type.Optional(Type.Number()),
staleBountyTime: Type.String(),
newContributorGreeting: NewContributorGreetingSchema,
timeRangeForMaxIssue: Type.Number(),
timeRangeForMaxIssueEnabled: Type.Boolean(),
permitBaseUrl: Type.String(),
botDelay: Type.Number(),
followUpTime: Type.String(),
disqualifyTime: Type.String(),
});

export type MergedConfig = Static<typeof MergedConfigSchema>;
6 changes: 6 additions & 0 deletions src/utils/private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ export const getWideConfig = async (context: Context) => {
openAITokenLimit: mergedConfigData.openAITokenLimit,
staleBountyTime: mergedConfigData.staleBountyTime,
newContributorGreeting: mergedConfigData.newContributorGreeting,
timeRangeForMaxIssue: mergedConfigData.timeRangeForMaxIssue,
timeRangeForMaxIssueEnabled: mergedConfigData.timeRangeForMaxIssueEnabled,
permitBaseUrl: mergedConfigData.permitBaseUrl,
botDelay: mergedConfigData.botDelay,
followUpTime: mergedConfigData.followUpTime,
disqualifyTime: mergedConfigData.disqualifyTime,
};

return configData;
Expand Down

0 comments on commit f0b3ac9

Please sign in to comment.