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

Commit

Permalink
fix: typescript errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Venoox committed Jun 16, 2023
1 parent ce1a237 commit 653fa8d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 15 deletions.
52 changes: 42 additions & 10 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CommentElementPricing } from "../types";
import { WideLabel, WideOrgConfig, WideRepoConfig } from "./private";

export const getChainId = (parsedRepo?: WideRepoConfig, parsedOrg?: WideOrgConfig, parsedDefaultConfig?: WideRepoConfig): number => {
export const getChainId = (parsedRepo: WideRepoConfig | undefined, parsedOrg: WideOrgConfig | undefined, parsedDefaultConfig: WideRepoConfig): number => {
if (parsedRepo && parsedRepo["chain-id"] && !Number.isNaN(Number(parsedRepo["chain-id"]))) {
return Number(parsedRepo["chain-id"]);
} else if (parsedOrg && parsedOrg["chain-id"] && !Number.isNaN(Number(parsedOrg["chain-id"]))) {
Expand All @@ -11,7 +11,11 @@ export const getChainId = (parsedRepo?: WideRepoConfig, parsedOrg?: WideOrgConfi
}
};

export const getBaseMultiplier = (parsedRepo?: WideRepoConfig, parsedOrg?: WideOrgConfig, parsedDefaultConfig?: WideRepoConfig): number => {
export const getBaseMultiplier = (
parsedRepo: WideRepoConfig | undefined,
parsedOrg: WideOrgConfig | undefined,
parsedDefaultConfig: WideRepoConfig
): number => {
if (parsedRepo && parsedRepo["base-multiplier"] && !Number.isNaN(Number(parsedRepo["base-multiplier"]))) {
return Number(parsedRepo["base-multiplier"]);
} else if (parsedOrg && parsedOrg["base-multiplier"] && !Number.isNaN(Number(parsedOrg["base-multiplier"]))) {
Expand All @@ -21,7 +25,11 @@ export const getBaseMultiplier = (parsedRepo?: WideRepoConfig, parsedOrg?: WideO
}
};

export const getCreatorMultiplier = (parsedRepo?: WideRepoConfig, parsedOrg?: WideOrgConfig, parsedDefaultConfig?: WideRepoConfig): number => {
export const getCreatorMultiplier = (
parsedRepo: WideRepoConfig | undefined,
parsedOrg: WideOrgConfig | undefined,
parsedDefaultConfig: WideRepoConfig
): 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"]))) {
Expand All @@ -31,7 +39,11 @@ export const getCreatorMultiplier = (parsedRepo?: WideRepoConfig, parsedOrg?: Wi
}
};

export const getTimeLabels = (parsedRepo?: WideRepoConfig, parsedOrg?: WideOrgConfig, parsedDefaultConfig?: WideRepoConfig): WideLabel[] => {
export const getTimeLabels = (
parsedRepo: WideRepoConfig | undefined,
parsedOrg: WideOrgConfig | undefined,
parsedDefaultConfig: WideRepoConfig
): 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) {
Expand All @@ -41,7 +53,11 @@ export const getTimeLabels = (parsedRepo?: WideRepoConfig, parsedOrg?: WideOrgCo
}
};

export const getPriorityLabels = (parsedRepo?: WideRepoConfig, parsedOrg?: WideOrgConfig, parsedDefaultConfig?: WideRepoConfig): WideLabel[] => {
export const getPriorityLabels = (
parsedRepo: WideRepoConfig | undefined,
parsedOrg: WideOrgConfig | undefined,
parsedDefaultConfig: WideRepoConfig
): 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) {
Expand All @@ -51,7 +67,11 @@ export const getPriorityLabels = (parsedRepo?: WideRepoConfig, parsedOrg?: WideO
}
};

export const getCommentItemPrice = (parsedRepo?: WideRepoConfig, parsedOrg?: WideOrgConfig, parsedDefaultConfig?: WideRepoConfig): CommentElementPricing => {
export const getCommentItemPrice = (
parsedRepo: WideRepoConfig | undefined,
parsedOrg: WideOrgConfig | undefined,
parsedDefaultConfig: WideRepoConfig
): CommentElementPricing => {
if (parsedRepo && parsedRepo["comment-element-pricing"]) {
return parsedRepo["comment-element-pricing"];
} else if (parsedOrg && parsedOrg["comment-element-pricing"]) {
Expand All @@ -61,7 +81,7 @@ export const getCommentItemPrice = (parsedRepo?: WideRepoConfig, parsedOrg?: Wid
}
};

export const getAutoPayMode = (parsedRepo?: WideRepoConfig, parsedOrg?: WideOrgConfig, parsedDefaultConfig?: WideRepoConfig): boolean => {
export const getAutoPayMode = (parsedRepo: WideRepoConfig | undefined, parsedOrg: WideOrgConfig | undefined, parsedDefaultConfig: WideRepoConfig): 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") {
Expand All @@ -71,7 +91,11 @@ export const getAutoPayMode = (parsedRepo?: WideRepoConfig, parsedOrg?: WideOrgC
}
};

export const getAnalyticsMode = (parsedRepo?: WideRepoConfig, parsedOrg?: WideOrgConfig, parsedDefaultConfig?: WideRepoConfig): boolean => {
export const getAnalyticsMode = (
parsedRepo: WideRepoConfig | undefined,
parsedOrg: WideOrgConfig | undefined,
parsedDefaultConfig: WideRepoConfig
): 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") {
Expand All @@ -81,7 +105,11 @@ export const getAnalyticsMode = (parsedRepo?: WideRepoConfig, parsedOrg?: WideOr
}
};

export const getIncentiveMode = (parsedRepo?: WideRepoConfig, parsedOrg?: WideOrgConfig, parsedDefaultConfig?: WideRepoConfig): boolean => {
export const getIncentiveMode = (
parsedRepo: WideRepoConfig | undefined,
parsedOrg: WideOrgConfig | undefined,
parsedDefaultConfig: WideRepoConfig
): 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") {
Expand All @@ -91,7 +119,11 @@ export const getIncentiveMode = (parsedRepo?: WideRepoConfig, parsedOrg?: WideOr
}
};

export const getBountyHunterMax = (parsedRepo?: WideRepoConfig, parsedOrg?: WideOrgConfig, parsedDefaultConfig?: WideRepoConfig): number => {
export const getBountyHunterMax = (
parsedRepo: WideRepoConfig | undefined,
parsedOrg: WideOrgConfig | undefined,
parsedDefaultConfig: WideRepoConfig
): 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"]))) {
Expand Down
8 changes: 3 additions & 5 deletions src/utils/private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ export const getConfigSuperset = async (context: Context, type: "org" | "repo"):
}
};



export interface WideLabel {
name: string;
weight: number;
Expand Down Expand Up @@ -85,9 +83,9 @@ export const getDefaultConfig = (): WideRepoConfig | undefined => {
const defaultConfig = readFileSync(`${__dirname}/../../ubiquibot-config-default.yml`, "utf8");
return parseYAML(defaultConfig) as WideRepoConfig;
} catch (error: any) {
return undefined
return undefined;
}
}
};

export const getPrivateKey = async (cipherText: string): Promise<string | undefined> => {
try {
Expand Down Expand Up @@ -135,7 +133,7 @@ export const getWideConfig = async (context: Context) => {

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

const configData = {
Expand Down

0 comments on commit 653fa8d

Please sign in to comment.