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
This commit is contained in:
Zane Helton 2025-06-29 03:56:01 -04:00
parent 77dd481742
commit 82642d0e97
2 changed files with 12 additions and 1 deletions

View File

@ -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,

View File

@ -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);
}