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

Commit

Permalink
feat: configurable promotion comment
Browse files Browse the repository at this point in the history
  • Loading branch information
wannacfuture committed Jul 17, 2023
1 parent d817e4a commit 3a3ad05
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/ubiquibot-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ priority-labels:
auto-pay-mode: true
analytics-mode: 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: 4 additions & 0 deletions src/bindings/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const loadConfig = async (context: Context): Promise<BotConfig> => {
incentiveMode,
chainId,
issueCreatorMultiplier,
promotionComment,
} = await getWideConfig(context);

const publicKey = await getScalarKey(process.env.X25519_PRIVATE_KEY);
Expand All @@ -37,6 +38,9 @@ export const loadConfig = async (context: Context): Promise<BotConfig> => {
priorityLabels,
commentElementPricing,
},
comments: {
promotionComment: promotionComment,
},
payout: {
chainId: chainId,
rpc: rpc,
Expand Down
1 change: 0 additions & 1 deletion src/configs/strings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export const GLOBAL_STRINGS = {
unassignComment: "Releasing the bounty back to dev pool because the allocated duration already ended!",
askUpdate: "Do you have any updates",
promotionComment: `\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/handlers/comment/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { multiplier } from "./multiplier";
import { addCommentToIssue, createLabel, addLabelToIssue } from "../../../helpers";
import { getBotContext } from "../../../bindings";
import { handleIssueClosed } from "../../payout";
import { GLOBAL_STRINGS } from "../../../configs";

export * from "./assign";
export * from "./wallet";
Expand Down Expand Up @@ -42,11 +41,12 @@ export const commentParser = (body: string): IssueCommentCommands[] => {

export const issueClosedCallback = async (): Promise<void> => {
const { payload: _payload } = getBotContext();
const { comments } = getBotConfig();
const issue = (_payload as Payload).issue;
if (!issue) return;
try {
const comment = await handleIssueClosed();
if (comment) await addCommentToIssue(comment + GLOBAL_STRINGS.promotionComment, issue.number);
if (comment) await addCommentToIssue(comment + comments.promotionComment, issue.number);
} catch (err: unknown) {
return await addCommentToIssue(`Error: ${err}`, issue.number);
}
Expand Down
5 changes: 5 additions & 0 deletions src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ export const SodiumSchema = Type.Object({
privateKey: Type.String(),
});

export const CommentsSchema = Type.Object({
promotionComment: Type.String(),
});

export const BotConfigSchema = Type.Object({
log: LogConfigSchema,
price: PriceConfigSchema,
Expand All @@ -72,6 +76,7 @@ export const BotConfigSchema = Type.Object({
mode: ModeSchema,
assign: AssignSchema,
sodium: SodiumSchema,
comments: CommentsSchema,
});

export type BotConfig = Static<typeof BotConfigSchema>;
10 changes: 10 additions & 0 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ export const getAnalyticsMode = (parsedRepo: WideRepoConfig | undefined, parsedO
}
};

export const getPromotionComment = (parsedRepo: WideRepoConfig | undefined, parsedOrg: WideOrgConfig | undefined): 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 "";
}
};

export const getIncentiveMode = (parsedRepo?: WideRepoConfig, parsedOrg?: WideOrgConfig): boolean => {
if (parsedRepo && parsedRepo["incentive-mode"] && typeof parsedRepo["incentive-mode"] === "boolean") {
return parsedRepo["incentive-mode"];
Expand Down
3 changes: 3 additions & 0 deletions src/utils/private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
getPriorityLabels,
getTimeLabels,
getCommentItemPrice,
getPromotionComment,
} from "./helpers";

const CONFIG_REPO = "ubiquibot-config";
Expand Down Expand Up @@ -53,6 +54,7 @@ export interface WideConfig {
"time-labels"?: WideLabel[];
"priority-labels"?: WideLabel[];
"auto-pay-mode"?: boolean;
"promotion-comment"?: string;
"analytics-mode"?: boolean;
"incentive-mode"?: boolean;
"max-concurrent-bounties"?: number;
Expand Down Expand Up @@ -137,6 +139,7 @@ export const getWideConfig = async (context: Context) => {
bountyHunterMax: getBountyHunterMax(parsedRepo, parsedOrg),
incentiveMode: getIncentiveMode(parsedRepo, parsedOrg),
commentElementPricing: getCommentItemPrice(parsedRepo, parsedOrg),
promotionComment: getPromotionComment(parsedRepo, parsedOrg),
};

return configData;
Expand Down

0 comments on commit 3a3ad05

Please sign in to comment.