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

fix: stale bounty #670

Merged
merged 12 commits into from
Sep 7, 2023
2 changes: 2 additions & 0 deletions src/bindings/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const loadConfig = async (context: Context): Promise<BotConfig> => {
commandSettings,
assistivePricing,
registerWalletWithVerification,
staleBountyTime,
enableAccessControl,
} = await getWideConfig(context);

Expand Down Expand Up @@ -90,6 +91,7 @@ export const loadConfig = async (context: Context): Promise<BotConfig> => {
command: commandSettings,
assign: {
bountyHunterMax: bountyHunterMax,
staleBountyTime: ms(staleBountyTime),
},
sodium: {
privateKey: process.env.X25519_PRIVATE_KEY ?? "",
Expand Down
15 changes: 14 additions & 1 deletion src/handlers/comment/handlers/assign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ export const assign = async (body: string) => {

const id = organization?.id || repository?.id; // repository?.id as fallback

const staleBounty = config.assign.staleBountyTime;

logger.info(`Received '/start' command from user: ${payload.sender.login}, body: ${body}`);
const issue = (_payload as Payload).issue;

if (!issue) {
logger.info(`Skipping '/start' because of no issue instance`);
return "Skipping '/start' because of no issue instance";
Expand Down Expand Up @@ -109,14 +112,24 @@ export const assign = async (body: string) => {
await addAssignees(issue.number, [payload.sender.login]);
}

let days: number | undefined;
let staleToDays: number | undefined;
let isBountyStale = false;

if (staleBounty !== 0) {
days = Math.floor((new Date().getTime() - new Date(issue.created_at).getTime()) / (1000 * 60 * 60 * 24));
staleToDays = Math.floor(staleBounty / (1000 * 60 * 60 * 24));
isBountyStale = staleToDays > days ? false : true;
whilefoo marked this conversation as resolved.
Show resolved Hide resolved
}

// double check whether the assign message has been already posted or not
logger.info(`Creating an issue comment: ${comment.commit}`);
const issueComments = await getAllIssueComments(issue.number);
const comments = issueComments.sort((a: Comment, b: Comment) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime());
const latestComment = comments.length > 0 ? comments[0].body : undefined;
if (latestComment && comment.commit != latestComment) {
const { multiplier, reason, bounty } = await getMultiplierInfoToDisplay(payload.sender.login, id?.toString(), issue);
return tableComment({ ...comment, multiplier, reason, bounty }) + comment.tips;
return tableComment({ ...comment, multiplier, reason, bounty, isBountyStale, days }) + comment.tips;
}
return;
};
Expand Down
14 changes: 9 additions & 5 deletions src/handlers/comment/handlers/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@ export const tableComment = ({
multiplier,
reason,
bounty,
isBountyStale,
days,
}: {
deadline: string;
wallet: string;
multiplier?: string;
reason?: string;
bounty?: string;
isBountyStale?: boolean;
days?: number;
}) => {
return `
<code>

<table>
<tr>
<td></td>
<td></td>
</tr>
${
isBountyStale
? `<tr><td>Warning!</td> <td>This task was created over ${days} days ago. Please confirm that this issue specification is accurate before starting.</td></tr>`
: ``
}
<tr>
<td>Deadline</td>
<td>${deadline}</td>
Expand Down
1 change: 1 addition & 0 deletions src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const ModeSchema = Type.Object({

export const AssignSchema = Type.Object({
bountyHunterMax: Type.Number(),
staleBountyTime: Type.Number(),
});

export const LogConfigSchema = Type.Object({
Expand Down
2 changes: 1 addition & 1 deletion src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ export const getNumericLevel = (level: Level) => {
default:
return -1; // Invalid level
}
};
};
4 changes: 3 additions & 1 deletion src/utils/private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export interface WideConfig {
"default-labels": string[];
"register-wallet-with-verification": boolean;
"enable-access-control": AccessControl;
"stale-bounty-time": string;
}

export type WideRepoConfig = WideConfig;
Expand Down Expand Up @@ -179,7 +180,8 @@ export const getWideConfig = async (context: Context) => {
defaultLabels: mergedConfigData["default-labels"],
promotionComment: mergedConfigData["promotion-comment"],
registerWalletWithVerification: mergedConfigData["register-wallet-with-verification"],
enableAccessControl: mergedConfigData["enable-access-control"]
enableAccessControl: mergedConfigData["enable-access-control"],
staleBountyTime: mergedConfigData["stale-bounty-time"],
};

return configData;
Expand Down
1 change: 1 addition & 0 deletions ubiquibot-config-default.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"disable-analytics": false,
"comment-incentives": false,
"register-wallet-with-verification": false,
"stale-bounty-time": "0d",
"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>",
"default-labels": [],
"time-labels": [
Expand Down
Loading