Skip to content

Commit 6a048ba

Browse files
feat(discord): Improve release announcement formatting
This commit introduces a new function, `formatLauncherVersion`, to parse the release title and format it more clearly for Discord announcements. The new format extracts the app name, version, and build number, transforming a title like `- AppName ‧ (1.11.2.6)` into `AppName 1.11.2 Build 6`. Additionally, the calculation for the `Content-Length` header in the webhook request has been corrected to use `Buffer.byteLength(payload)` instead of `payload.length` to ensure accurate byte counting for the JSON payload.
1 parent b45c844 commit 6a048ba

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

post-discord-release.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,23 @@ function getReleaseTitle(tag) {
108108
});
109109
}
110110

111+
function formatLauncherVersion(input) {
112+
// Extract version inside parentheses: (1.11.2.6)
113+
const versionMatch = input.match(/\(([\d.]+)\)/);
114+
if (!versionMatch) return null;
115+
116+
const fullVersion = versionMatch[1]; // "1.11.2.6"
117+
const versionParts = fullVersion.split("."); // ["1","11","2","6"]
118+
const build = versionParts.pop(); // "6"
119+
const version = versionParts.join("."); // "1.11.2"
120+
121+
// Extract the app name before the "‧"
122+
const nameMatch = input.match(/-\s*(.*?)\s*/);
123+
const appName = nameMatch ? nameMatch[1] : "Unknown";
124+
125+
return `${appName} ${version} Build ${build}`;
126+
}
127+
111128
// Main async function
112129
(async () => {
113130
try {
@@ -140,7 +157,7 @@ function getReleaseTitle(tag) {
140157
const releaseTitle = await getReleaseTitle(latestTag);
141158

142159
// Build Discord message
143-
let discordMessage = `## ${releaseTitle}\n\n`;
160+
let discordMessage = `## ${formatLauncherVersion(releaseTitle)}\n\n`;
144161

145162
for (const group of GROUP_ORDER) {
146163
if (!groups[group] || groups[group].length === 0) continue;
@@ -166,7 +183,7 @@ function getReleaseTitle(tag) {
166183
method: "POST",
167184
headers: {
168185
"Content-Type": "application/json",
169-
"Content-Length": payload.length,
186+
"Content-Length": Buffer.byteLength(payload),
170187
},
171188
};
172189

0 commit comments

Comments
 (0)