From 82642d0e97d23787417a337786f450330f570da6 Mon Sep 17 00:00:00 2001 From: Zane Helton Date: Sun, 29 Jun 2025 03:56:01 -0400 Subject: [PATCH] Capitalize `ref_type` when using in embed The GitHub API provides `ref_type` as lowercase. For consistency, this adds a utility function and makes use of it when formatting the `create` event from GitHub. tag => Tag branch => Branch --- src/api/routes/webhooks/#webhook_id/#token/index.ts | 3 ++- src/util/util/String.ts | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/api/routes/webhooks/#webhook_id/#token/index.ts b/src/api/routes/webhooks/#webhook_id/#token/index.ts index 3dfe514f..692e20d6 100644 --- a/src/api/routes/webhooks/#webhook_id/#token/index.ts +++ b/src/api/routes/webhooks/#webhook_id/#token/index.ts @@ -15,6 +15,7 @@ import { handleFile, ValidateName, EmbedType, + capitalize, } from "@spacebar/util"; import { NextFunction, Request, Response, Router } from "express"; import { HTTPError } from "lambert-server"; @@ -284,7 +285,7 @@ function transformGitHubToDiscord( username: "GitHub", embeds: [ { - title: `➕ ${payload.ref_type} created in ${payload.repository?.full_name}`, + title: `➕ ${capitalize(payload.ref_type)} created in ${payload.repository?.full_name}`, type: EmbedType.rich, description: `A new ${payload.ref_type} named \`${payload.ref}\` was created`, color: 0x7289da, diff --git a/src/util/util/String.ts b/src/util/util/String.ts index 1000ebe9..171bc3b6 100644 --- a/src/util/util/String.ts +++ b/src/util/util/String.ts @@ -22,3 +22,13 @@ export function trimSpecial(str?: string): string { if (!str) return ""; return str.replace(SPECIAL_CHAR, "").trim(); } + +/** + * Capitalizes the first letter of a string. + * @param str The string to capitalize. + * @returns The capitalized string. + */ +export function capitalize(str: string): string { + if (!str) return ""; + return str.charAt(0).toUpperCase() + str.slice(1); +}