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

Refactor config #512

Merged
merged 10 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/ubiquibot-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ priority-labels:
- name: "Priority: 4 (Emergency)"
weight: 5
auto-pay-mode: true
analytics-mode: true
comment-incentives: true
max-concurrent-bounties: 2
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>"

4 changes: 2 additions & 2 deletions src/bindings/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const loadConfig = async (context: Context): Promise<BotConfig> => {
priorityLabels,
commentElementPricing,
autoPayMode,
analyticsMode,
disableAnalytics,
bountyHunterMax,
incentiveMode,
networkId,
Expand Down Expand Up @@ -62,7 +62,7 @@ export const loadConfig = async (context: Context): Promise<BotConfig> => {
},
mode: {
autoPayMode: autoPayMode,
analyticsMode: analyticsMode,
disableAnalytics: disableAnalytics,
incentiveMode: incentiveMode,
},
assign: {
Expand Down
6 changes: 3 additions & 3 deletions src/handlers/wildcard/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ export const bountyInfo = (
export const collectAnalytics = async (): Promise<void> => {
const logger = getLogger();
const {
mode: { analyticsMode },
mode: { disableAnalytics },
} = getBotConfig();
if (!analyticsMode) {
logger.info(`Skipping to collect analytics, reason: mode=${analyticsMode}`);
if (disableAnalytics) {
logger.info(`Skipping to collect analytics, reason: mode=${disableAnalytics}`);
return;
}
logger.info("Collecting analytics information...");
Expand Down
6 changes: 3 additions & 3 deletions src/handlers/wildcard/weekly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const SEVEN_DAYS = 604800; // 7 days in seconds
export const checkWeeklyUpdate = async () => {
const { log } = getBotContext();
const {
mode: { analyticsMode },
mode: { disableAnalytics },
} = getBotConfig();
if (!analyticsMode) {
log.info(`Skipping to collect the weekly analytics, reason: mode=${analyticsMode}`);
if (disableAnalytics) {
log.info(`Skipping to collect the weekly analytics, reason: mode=${disableAnalytics}`);
return;
}
const curTime = Date.now() / 1000;
Expand Down
2 changes: 1 addition & 1 deletion src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const UnassignConfigSchema = Type.Object({

export const ModeSchema = Type.Object({
autoPayMode: Type.Boolean(),
analyticsMode: Type.Boolean(),
disableAnalytics: Type.Boolean(),
incentiveMode: Type.Boolean(),
});

Expand Down
24 changes: 12 additions & 12 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ export const getAutoPayMode = (parsedRepo?: WideRepoConfig, parsedOrg?: WideOrgC
};

export const getAnalyticsMode = (parsedRepo: WideRepoConfig | undefined, parsedOrg: WideOrgConfig | undefined): boolean => {
if (parsedRepo && parsedRepo["analytics-mode"] && typeof parsedRepo["analytics-mode"] === "boolean") {
return parsedRepo["analytics-mode"];
} else if (parsedOrg && parsedOrg["analytics-mode"] && typeof parsedOrg["analytics-mode"] === "boolean") {
return parsedOrg["analytics-mode"];
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;
}
Expand All @@ -93,20 +93,20 @@ export const getPromotionComment = (parsedRepo: WideRepoConfig | undefined, pars
};

export const getIncentiveMode = (parsedRepo?: WideRepoConfig, parsedOrg?: WideOrgConfig): boolean => {
if (parsedRepo && parsedRepo["incentive-mode"] && typeof parsedRepo["incentive-mode"] === "boolean") {
return parsedRepo["incentive-mode"];
} else if (parsedOrg && parsedOrg["incentive-mode"] && typeof parsedOrg["incentive-mode"] === "boolean") {
return parsedOrg["incentive-mode"];
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;
}
};

export const getBountyHunterMax = (parsedRepo: WideRepoConfig | undefined, parsedOrg: WideOrgConfig | undefined): number => {
if (parsedRepo && parsedRepo["max-concurrent-bounties"] && !Number.isNaN(Number(parsedRepo["max-concurrent-bounties"]))) {
return Number(parsedRepo["max-concurrent-bounties"]);
} else if (parsedOrg && parsedOrg["max-concurrent-bounties"] && !Number.isNaN(Number(parsedOrg["max-concurrent-bounties"]))) {
return Number(parsedOrg["max-concurrent-bounties"]);
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;
}
Expand Down
8 changes: 4 additions & 4 deletions src/utils/private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ export interface WideConfig {
"priority-labels"?: WideLabel[];
"auto-pay-mode"?: boolean;
"promotion-comment"?: string;
"analytics-mode"?: boolean;
"incentive-mode"?: boolean;
"max-concurrent-bounties"?: number;
"disable-analytics"?: boolean;
"comment-incentives"?: boolean;
"max-concurrent-assigns"?: number;
"comment-element-pricing"?: Record<string, number>;
}

Expand Down Expand Up @@ -135,7 +135,7 @@ export const getWideConfig = async (context: Context) => {
timeLabels: getTimeLabels(parsedRepo, parsedOrg),
priorityLabels: getPriorityLabels(parsedRepo, parsedOrg),
autoPayMode: getAutoPayMode(parsedRepo, parsedOrg),
analyticsMode: getAnalyticsMode(parsedRepo, parsedOrg),
disableAnalytics: getAnalyticsMode(parsedRepo, parsedOrg),
bountyHunterMax: getBountyHunterMax(parsedRepo, parsedOrg),
incentiveMode: getIncentiveMode(parsedRepo, parsedOrg),
commentElementPricing: getCommentItemPrice(parsedRepo, parsedOrg),
Expand Down