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
4 changes: 3 additions & 1 deletion src/bindings/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ms from "ms";

import { BotConfig, BotConfigSchema } from "../types";
import { DEFAULT_BOT_DELAY, DEFAULT_DISQUALIFY_TIME, DEFAULT_FOLLOWUP_TIME, DEFAULT_PERMIT_BASE_URL } from "../configs";
import { DEFAULT_BOT_DELAY, DEFAULT_DISQUALIFY_TIME, DEFAULT_FOLLOWUP_TIME, DEFAULT_PERMIT_BASE_URL, STALE_BOUNTY_TIME } from "../configs";
import { getPayoutConfigByNetworkId } from "../helpers";
import { ajv } from "../utils";
import { Context } from "probot";
Expand All @@ -26,6 +26,7 @@ export const loadConfig = async (context: Context): Promise<BotConfig> => {
commandSettings,
assistivePricing,
registerWalletWithVerification,
staleBountyTime,
} = await getWideConfig(context);

const publicKey = await getScalarKey(process.env.X25519_PRIVATE_KEY);
Expand Down Expand Up @@ -76,6 +77,7 @@ export const loadConfig = async (context: Context): Promise<BotConfig> => {
command: commandSettings,
assign: {
bountyHunterMax: bountyHunterMax,
staleBountyTime: staleBountyTime ? staleBountyTime : ms(STALE_BOUNTY_TIME),
},
sodium: {
privateKey: process.env.X25519_PRIVATE_KEY ?? "",
Expand Down
1 change: 1 addition & 0 deletions src/configs/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const ASSIGN_COMMAND_ENABLED = true;
*/
export const DEFAULT_FOLLOWUP_TIME = "4 days"; // 4 days
export const DEFAULT_DISQUALIFY_TIME = "7 days"; // 7 days
export const STALE_BOUNTY_TIME = "30d"; // 30 days

export const DEFAULT_NETWORK_ID = 1; // ethereum
export const DEFAULT_RPC_ENDPOINT = "https://rpc-bot.ubq.fi/v1/mainnet";
Expand Down
8 changes: 7 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,17 @@ export const assign = async (body: string) => {
await addAssignees(issue.number, [payload.sender.login]);
}

const isBountyStale = new Date().getTime() - new Date(issue.created_at).getTime() > staleBounty;
const days = Math.floor((new Date().getTime() - new Date(issue.created_at).getTime()) / (1000 * 60 * 60 * 24));

// 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
13 changes: 10 additions & 3 deletions src/handlers/comment/handlers/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,27 @@ 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>
<td>Ready to begin?</td>
${
!isBountyStale
? `<td>You can start right away!</td>`
: `<td>This task was created over ${days} days ago. Please verify that it is still current before starting work.</td>`
}
</tr>
<tr>
<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
4 changes: 4 additions & 0 deletions src/utils/private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
} from "./helpers";

import DEFAULT_CONFIG_JSON from "../../ubiquibot-config-default.json";
import { STALE_BOUNTY_TIME } from "../configs";
import ms from "ms";

const CONFIG_REPO = "ubiquibot-config";
const CONFIG_PATH = ".github/ubiquibot-config.yml";
Expand Down Expand Up @@ -82,6 +84,7 @@ export interface WideConfig {
"comment-incentives"?: boolean;
"assistive-pricing"?: boolean;
"max-concurrent-assigns"?: number;
"stale-bounty-time"?: string;
incentives?: Incentives;
"default-labels"?: string[];
"register-wallet-with-verification"?: boolean;
Expand Down Expand Up @@ -184,6 +187,7 @@ export const getWideConfig = async (context: Context) => {
defaultLabels: getDefaultLabels(configs),
promotionComment: getPromotionComment(configs),
registerWalletWithVerification: getRegisterWalletWithVerification(configs),
staleBountyTime: parsedDefault["stale-bounty-time"] == "0" ? ms(STALE_BOUNTY_TIME) : parsedDefault["stale-bounty-time"],
};

return configData;
Expand Down
17 changes: 9 additions & 8 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": 42060,
rndquu marked this conversation as resolved.
Show resolved Hide resolved
"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 Expand Up @@ -62,35 +63,35 @@
"command-settings": [
{
"name": "start",
"enabled": false
"enabled": true
},
{
"name": "stop",
"enabled": false
"enabled": true
},
{
"name": "wallet",
"enabled": false
"enabled": true
},
{
"name": "payout",
"enabled": false
"enabled": true
},
{
"name": "multiplier",
"enabled": false
"enabled": true
},
{
"name": "query",
"enabled": false
"enabled": true
},
{
"name": "allow",
"enabled": false
"enabled": true
},
{
"name": "autopay",
"enabled": false
"enabled": true
}
],
"incentives": {
Expand Down