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
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/bindings/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? String(ms(staleBountyTime)) : "0",
Keyrxng marked this conversation as resolved.
Show resolved Hide resolved
},
sodium: {
privateKey: process.env.X25519_PRIVATE_KEY ?? "",
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 = Number(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 days = Math.floor((new Date().getTime() - new Date(issue.created_at).getTime()) / (1000 * 60 * 60 * 24));
const isBountyStale = staleBounty == 0 ? null : staleBounty > days ? false : true;
Keyrxng 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
16 changes: 11 additions & 5 deletions src/handlers/comment/handlers/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,27 @@ export const tableComment = ({
multiplier,
reason,
bounty,
isBountyStale,
days,
}: {
deadline: string;
wallet: string;
multiplier?: string;
reason?: string;
bounty?: string;
isBountyStale?: boolean | null;
rndquu marked this conversation as resolved.
Show resolved Hide resolved
days?: number;
}) => {
return `
<code>

<table>
<tr>
<td></td>
<td></td>
</tr>
${
isBountyStale == null
? null
Keyrxng marked this conversation as resolved.
Show resolved Hide resolved
: isBountyStale
? `<td>Warning!</td> <td>This task was created over ${days} days ago. Please confirm that this issue specification is accurate before starting.</td>`
whilefoo marked this conversation as resolved.
Show resolved Hide resolved
: ``
}
<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.String(),
});

export const LogConfigSchema = Type.Object({
Expand Down
2 changes: 2 additions & 0 deletions src/utils/private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,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 +185,7 @@ export const getWideConfig = async (context: Context) => {
defaultLabels: getDefaultLabels(configs),
promotionComment: getPromotionComment(configs),
registerWalletWithVerification: getRegisterWalletWithVerification(configs),
staleBountyTime: parsedDefault["stale-bounty-time"],
Keyrxng marked this conversation as resolved.
Show resolved Hide resolved
};

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": "30d",
"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
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1968,10 +1968,10 @@
dependencies:
cross-fetch "^3.1.5"

"@supabase/realtime-js@^2.7.3":
version "2.7.3"
resolved "https://registry.yarnpkg.com/@supabase/realtime-js/-/realtime-js-2.7.3.tgz#cbcb84181add681ab99c87032bfe88101c6863b3"
integrity sha512-c7TzL81sx2kqyxsxcDduJcHL9KJdCOoKimGP6lQSqiZKX42ATlBZpWbyy9KFGFBjAP4nyopMf5JhPi2ZH9jyNw==
"@supabase/realtime-js@^2.7.4":
version "2.7.4"
resolved "https://registry.yarnpkg.com/@supabase/realtime-js/-/realtime-js-2.7.4.tgz#de41195bd3f2cdd6db82d9f93c4c5b8fae9f809b"
integrity sha512-FzSzs1k9ruh/uds5AJ95Nc3beiMCCIhougExJ3O98CX1LMLAKUKFy5FivKLvcNhXnNfUEL0XUfGMb4UH2J7alg==
dependencies:
"@types/phoenix" "^1.5.4"
"@types/websocket" "^1.0.3"
Expand All @@ -1984,15 +1984,15 @@
dependencies:
cross-fetch "^3.1.5"

"@supabase/supabase-js@^2.32.0":
version "2.32.0"
resolved "https://registry.yarnpkg.com/@supabase/supabase-js/-/supabase-js-2.32.0.tgz#863c636d83232c6a2e9ba5932e0d7c1bf80bc436"
integrity sha512-1ShFhuOI5Du7604nlCelBsRD61daXk2O0qwjumoz35bqrYThnSPPtpJqZOHw6Mg6o7mLjIInYLh/DBlh8UvzRg==
"@supabase/supabase-js@^2.4.0":
version "2.33.1"
resolved "https://registry.yarnpkg.com/@supabase/supabase-js/-/supabase-js-2.33.1.tgz#2407861afe63c2817d030514c87a745f78dfe68a"
integrity sha512-jA00rquPTppPOHpBB6KABW98lfg0gYXcuGqP3TB1iiduznRVsi3GGk2qBKXPDLMYSe0kRlQp5xCwWWthaJr8eA==
dependencies:
"@supabase/functions-js" "^2.1.0"
"@supabase/gotrue-js" "^2.46.1"
"@supabase/postgrest-js" "^1.8.0"
"@supabase/realtime-js" "^2.7.3"
"@supabase/realtime-js" "^2.7.4"
"@supabase/storage-js" "^2.5.1"
cross-fetch "^3.1.5"

Expand Down