mirror of
https://github.com/ReCloudStudio/WebHooker.git
synced 2026-09-22 16:11:29 +00:00
feat: migrate to Nuxt 4 (Nitro) and Tailwind CSS v3
This commit is contained in:
parent
f4959eebf8
commit
b139712a91
166 changed files with 19790 additions and 5539 deletions
83
server/lib/formatters/milestone.ts
Normal file
83
server/lib/formatters/milestone.ts
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
import type { NeutralMessage, NeutralAuthor } from "../types";
|
||||
import { GITHUB_COLORS } from "./colors";
|
||||
import { emojiPrefix, type T, buildMessage } from "./helpers";
|
||||
|
||||
export function formatMilestone(
|
||||
payload: Record<string, unknown>,
|
||||
repo: string | undefined,
|
||||
author: NeutralAuthor,
|
||||
t: T,
|
||||
showEmoji: boolean,
|
||||
): NeutralMessage {
|
||||
const action = (payload.action as string) ?? "created";
|
||||
const milestone = payload.milestone as {
|
||||
title?: string;
|
||||
number?: number;
|
||||
state?: string;
|
||||
open_issues?: number;
|
||||
closed_issues?: number;
|
||||
due_on?: string;
|
||||
html_url?: string;
|
||||
};
|
||||
|
||||
const al = t("actions." + action) ?? action;
|
||||
const stateEmoji = milestone.state === "closed" ? "✅" : "🔵";
|
||||
const em = (e: string): string => emojiPrefix(e, showEmoji);
|
||||
|
||||
const fields: Array<{ name: string; value: string; inline?: boolean }> = [];
|
||||
|
||||
if (milestone.title) {
|
||||
fields.push({
|
||||
name: t("fields.milestone"),
|
||||
value: milestone.title,
|
||||
inline: true,
|
||||
});
|
||||
}
|
||||
|
||||
if (milestone.number) {
|
||||
fields.push({
|
||||
name: t("fields.number"),
|
||||
value: `#${milestone.number}`,
|
||||
inline: true,
|
||||
});
|
||||
}
|
||||
|
||||
if (milestone.open_issues != null && milestone.closed_issues != null) {
|
||||
const total = milestone.open_issues + milestone.closed_issues;
|
||||
const pct = total > 0 ? Math.round((milestone.closed_issues / total) * 100) : 0;
|
||||
const bar = pct >= 75 ? "🟢🟢🟢" : pct >= 50 ? "🟡🟡" : pct > 0 ? "🟠" : "⬜";
|
||||
fields.push({
|
||||
name: t("fields.progress"),
|
||||
value: `${bar} ${milestone.closed_issues}/${total} (${pct}%)`,
|
||||
inline: false,
|
||||
});
|
||||
}
|
||||
|
||||
if (milestone.due_on) {
|
||||
fields.push({
|
||||
name: t("fields.due"),
|
||||
value: milestone.due_on.split("T")[0] ?? "",
|
||||
inline: true,
|
||||
});
|
||||
}
|
||||
|
||||
return buildMessage(
|
||||
{
|
||||
author,
|
||||
title: t("events.milestone.title", {
|
||||
repo: repo ?? t("common.repository"),
|
||||
emoji: em(stateEmoji),
|
||||
action: al,
|
||||
title: milestone.title ?? t("common.unknown"),
|
||||
}),
|
||||
url: milestone.html_url,
|
||||
color:
|
||||
milestone.state === "closed"
|
||||
? GITHUB_COLORS.milestone_closed
|
||||
: GITHUB_COLORS.milestone_opened,
|
||||
fields: fields.length > 0 ? fields : undefined,
|
||||
},
|
||||
t,
|
||||
repo,
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue