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

Commit

Permalink
fix: conditional
Browse files Browse the repository at this point in the history
removed null and storing time with number
  • Loading branch information
Keyrxng committed Sep 7, 2023
1 parent 03a78ac commit edbbe97
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/bindings/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const loadConfig = async (context: Context): Promise<BotConfig> => {
command: commandSettings,
assign: {
bountyHunterMax: bountyHunterMax,
staleBountyTime: staleBountyTime ? String(ms(staleBountyTime)) : "0",
staleBountyTime: ms(staleBountyTime),
},
sodium: {
privateKey: process.env.X25519_PRIVATE_KEY ?? "",
Expand Down
16 changes: 12 additions & 4 deletions src/handlers/comment/handlers/assign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const assign = async (body: string) => {

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

const staleBounty = Number(config.assign.staleBountyTime);
const staleBounty = config.assign.staleBountyTime;

logger.info(`Received '/start' command from user: ${payload.sender.login}, body: ${body}`);
const issue = (_payload as Payload).issue;
Expand Down Expand Up @@ -112,9 +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 staleToDays = Math.floor(staleBounty / (1000 * 60 * 60 * 24));
const isBountyStale = staleBounty == 0 ? null : staleToDays > days ? false : true;
let days;
Number;
let staleToDays;
Number;
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;
}

// double check whether the assign message has been already posted or not
logger.info(`Creating an issue comment: ${comment.commit}`);
Expand Down
6 changes: 2 additions & 4 deletions src/handlers/comment/handlers/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ export const tableComment = ({
multiplier?: string;
reason?: string;
bounty?: string;
isBountyStale?: boolean | null;
isBountyStale?: boolean;
days?: number;
}) => {
return `
<code>
<table>
${
isBountyStale == null
? null
: isBountyStale
isBountyStale
? `<td>Warning!</td> <td>This task was created over ${days} days ago. Please confirm that this issue specification is accurate before starting.</td>`
: ``
}
Expand Down
2 changes: 1 addition & 1 deletion src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const ModeSchema = Type.Object({

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

export const LogConfigSchema = Type.Object({
Expand Down
2 changes: 1 addition & 1 deletion ubiquibot-config-default.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"disable-analytics": false,
"comment-incentives": false,
"register-wallet-with-verification": false,
"stale-bounty-time": "30d",
"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

0 comments on commit edbbe97

Please sign in to comment.