mirror of
https://github.com/Elysola/WebHooker.git
synced 2026-11-20 17:13:49 +00:00
fix(formatter): link branch and tag titles
This commit is contained in:
7 files changed
+45
-8
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import type { NeutralMessage, NeutralAuthor } from "../types";
|
||||
import { GITHUB_COLORS } from "./colors";
|
||||
import { branchLink, emojiPrefix, tagLink, type T, buildMessage, repoBaseUrl } from "./helpers";
|
||||
import { branchLink, emojiPrefix, refUrl, tagLink, type T, buildMessage, repoBaseUrl } from "./helpers";
|
||||
|
||||
export function formatCreate(
|
||||
payload: Record<string, unknown>,
|
||||
@@ -13,6 +13,7 @@ export function formatCreate(
|
||||
const ref = (payload.ref as string) ?? t("common.unknown");
|
||||
const baseUrl = repoBaseUrl(payload, repo);
|
||||
const refText = refType === "tag" ? tagLink(baseUrl, ref) : branchLink(baseUrl, ref);
|
||||
const url = refUrl(baseUrl, ref, refType === "tag" ? "tag" : "branch");
|
||||
|
||||
const emoji = refType === "tag" ? "🏷️" : "🌿";
|
||||
const em = (e: string): string => emojiPrefix(e, showEmoji);
|
||||
@@ -46,8 +47,9 @@ export function formatCreate(
|
||||
repo: repo ?? t("common.repository"),
|
||||
emoji: em(emoji),
|
||||
type: refType,
|
||||
ref: refText,
|
||||
ref,
|
||||
}),
|
||||
url,
|
||||
color: GITHUB_COLORS.create,
|
||||
fields,
|
||||
},
|
||||
@@ -66,7 +68,7 @@ export function formatDelete(
|
||||
const refType = (payload.ref_type as string) ?? "branch";
|
||||
const ref = (payload.ref as string) ?? t("common.unknown");
|
||||
const baseUrl = repoBaseUrl(payload, repo);
|
||||
const refText = refType === "tag" ? tagLink(baseUrl, ref) : branchLink(baseUrl, ref);
|
||||
const url = refUrl(baseUrl, ref, refType === "tag" ? "tag" : "branch");
|
||||
|
||||
const emoji = refType === "tag" ? "🏷️" : "🌿";
|
||||
const em = (e: string): string => emojiPrefix(e, showEmoji);
|
||||
@@ -78,8 +80,9 @@ export function formatDelete(
|
||||
repo: repo ?? t("common.repository"),
|
||||
emoji: em(emoji),
|
||||
type: refType,
|
||||
ref: refText,
|
||||
ref,
|
||||
}),
|
||||
url,
|
||||
color: GITHUB_COLORS.delete,
|
||||
},
|
||||
t,
|
||||
|
||||
@@ -83,6 +83,19 @@ export function tagLink(baseUrl: string | undefined, tag: string, label?: string
|
||||
: `\`${display}\``;
|
||||
}
|
||||
|
||||
/** URL for a branch or tag, when the repository base URL is available. */
|
||||
export function refUrl(
|
||||
baseUrl: string | undefined,
|
||||
ref: string,
|
||||
type: "branch" | "tag",
|
||||
): string | undefined {
|
||||
if (!baseUrl) return undefined;
|
||||
const clean = ref.replace("refs/heads/", "").replace("refs/tags/", "");
|
||||
return type === "tag"
|
||||
? `${baseUrl}/releases/tag/${encodeRefPath(clean)}`
|
||||
: `${baseUrl}/tree/${encodeRefPath(clean)}`;
|
||||
}
|
||||
|
||||
/* ---- Content size limits (mirror the Discord embed limits) ---- */
|
||||
export const MAX_TITLE = 256;
|
||||
export const MAX_DESCRIPTION = 4096;
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
branchLink,
|
||||
emojiPrefix,
|
||||
MAX_COMMIT_SUBJECT,
|
||||
refUrl,
|
||||
tagLink,
|
||||
type T,
|
||||
buildMessage,
|
||||
@@ -49,8 +50,9 @@ export function formatPush(
|
||||
repo: repo ?? t("common.repository"),
|
||||
emoji: em(isTagPush ? "🏷️" : "🌿"),
|
||||
type: refType,
|
||||
ref: isTagPush ? tagLink(baseUrl, rawRef, ref) : branchLink(baseUrl, rawRef, ref),
|
||||
ref,
|
||||
}),
|
||||
url: refUrl(baseUrl, rawRef, refType),
|
||||
color: GITHUB_COLORS.delete,
|
||||
},
|
||||
t,
|
||||
@@ -71,8 +73,9 @@ export function formatPush(
|
||||
repo: repo ?? t("common.repository"),
|
||||
emoji: em(isTagPush ? "🏷️" : "🌿"),
|
||||
type: refType,
|
||||
ref: isTagPush ? tagLink(baseUrl, cleanRef) : branchLink(baseUrl, cleanRef),
|
||||
ref: cleanRef,
|
||||
}),
|
||||
url: refUrl(baseUrl, cleanRef, refType),
|
||||
color: GITHUB_COLORS.create,
|
||||
},
|
||||
t,
|
||||
|
||||
Reference in new issue
Block a user