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

Commit

Permalink
Merge pull request #522 from wannacfuture/feat/consolidate-promotion-…
Browse files Browse the repository at this point in the history
…message

feat: configurable promotion message
  • Loading branch information
0x4007 authored Jul 17, 2023
2 parents 7e597ec + 3a3ad05 commit e196a5b
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 2 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,
networkId,
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: {
networkId: networkId,
rpc: rpc,
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/comment/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +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();
const promotionCommnet = `\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>`;
if (comment) await addCommentToIssue(comment + promotionCommnet, 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 e196a5b

Please sign in to comment.