Skip to content

Commit

Permalink
chore: changed time format output
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlementlegen committed Dec 6, 2024
1 parent 0df59e3 commit 6e2c288
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
Binary file modified bun.lockb
Binary file not shown.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
"dotenv": "16.4.5",
"hono": "^4.6.12",
"luxon": "3.4.4",
"ms": "2.1.3",
"pretty-ms": "^9.2.0"
"ms": "2.1.3"
},
"devDependencies": {
"@commitlint/cli": "19.3.0",
Expand Down
14 changes: 14 additions & 0 deletions src/handlers/time-format.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export function formatMillisecondsToDaysAndHours(milliseconds: number): string {
if (milliseconds <= 0) {
return "0 days and 0 hours";
}
const days = Math.floor(milliseconds / (1000 * 60 * 60 * 24));
const hours = Math.floor((milliseconds % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
if (days === 0) {
return `${hours} ${hours === 1 ? "hour" : "hours"}`;
} else if (hours === 0) {
return `${days} ${days === 1 ? "day" : "days"}`;
} else {
return `${days} ${days === 1 ? "day" : "days"} and ${hours} ${hours === 1 ? "hour" : "hours"}`;
}
}
6 changes: 3 additions & 3 deletions src/handlers/watch-user-activity.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { RestEndpointMethodTypes } from "@octokit/rest";
import { postComment } from "@ubiquity-os/plugin-sdk";
import prettyMilliseconds from "pretty-ms";
import { getWatchedRepos } from "../helpers/get-watched-repos";
import { parsePriorityLabel } from "../helpers/task-metadata";
import { updateTaskReminder } from "../helpers/task-update";
import { ListForOrg } from "../types/github-types";
import { ContextPlugin } from "../types/plugin-input";
import { formatMillisecondsToDaysAndHours } from "./time-format";

type IssueType = RestEndpointMethodTypes["issues"]["listForRepo"]["response"]["data"]["0"];

Expand All @@ -29,9 +29,9 @@ export async function watchUserActivity(context: ContextPlugin) {
if (context.config.pullRequestRequired) {
message.push(`- Be sure to link a pull-request before the first reminder to avoid disqualification.`);
}
message.push(`- Reminders will be sent every ${prettyMilliseconds(context.config.warning / priorityValue, { verbose: true })} if there is no activity.`);
message.push(`- Reminders will be sent every \`${formatMillisecondsToDaysAndHours(context.config.warning / priorityValue)}\` if there is no activity.`);
message.push(
`- Assignees will be disqualified after ${prettyMilliseconds(context.config.disqualification / priorityValue, { verbose: true })} of inactivity.`
`- Assignees will be disqualified after \`${formatMillisecondsToDaysAndHours(context.config.disqualification / priorityValue)}\` of inactivity.`
);
const log = logger.error(message.map((o) => `> ${o}`).join("\n"));
log.logMessage.diff = log.logMessage.raw;
Expand Down

0 comments on commit 6e2c288

Please sign in to comment.