@@ -51880,35 +51880,78 @@ async function sendWebhook(inp) {
5188051880 const updatedRelease = await api.rest.repos.getRelease({ owner, repo, release_id: releaseResponse.data.id });
5188151881 const tag = updatedRelease.data.tag_name;
5188251882 const thumbnail = `https://opengraph.githubassets.com/1/${owner}/${repo}/releases/tag/${tag}`;
51883- let assets = '';
51883+ // Prepare Asset Fields (Split if > 1024)
51884+ let assetLines = [];
5188451885 for (const asset of updatedRelease.data.assets) {
51885- assets += `- :page_facing_up: [${asset.name}](${asset.browser_download_url})\n` ;
51886+ assetLines.push( `- :page_facing_up: [${asset.name}](${asset.browser_download_url})`) ;
5188651887 }
51887- assets += `- :package: [Source code (zip)](${updatedRelease.data.zipball_url})\n`;
51888- assets += `- :package: [Source code (tar.gz)](${updatedRelease.data.tarball_url})\n`;
51888+ assetLines.push(`- :package: [Source code (zip)](${updatedRelease.data.zipball_url})`);
51889+ assetLines.push(`- :package: [Source code (tar.gz)](${updatedRelease.data.tarball_url})`);
51890+ const assetFields = [];
51891+ let currentAssetChunk = '';
51892+ for (const line of assetLines) {
51893+ if (currentAssetChunk.length + line.length + 1 > 1024) {
51894+ assetFields.push({ name: 'Assets', value: currentAssetChunk, inline: false });
51895+ currentAssetChunk = '';
51896+ }
51897+ currentAssetChunk += line + '\n';
51898+ }
51899+ if (currentAssetChunk) {
51900+ assetFields.push({ name: 'Assets', value: currentAssetChunk, inline: false });
51901+ }
51902+ // Prepare Static Fields
5188951903 const time = Math.floor(new Date(updatedRelease.data.created_at).getTime() / 1000);
51890- const author = updatedRelease.data.author.type === 'User' ? updatedRelease.data.author.login : updatedRelease.data.author.login.replace('[bot]', '');
5189151904 const sha = inputs.changes[inputs.changes.length - 1].commit.slice(0, 7);
5189251905 const statusEmoji = failed ? ':red_circle:' : ':green_circle:';
5189351906 const status = failed ? 'Failed' : 'Success';
5189451907 const runID = process.env.GITHUB_RUN_ID;
51908+ const staticFields = [
51909+ { name: '', value: `:watch: <t:${time}:R>`, inline: true },
51910+ { name: '', value: `:label: [${tag}](${url}/${owner}/${repo}/tree/${tag})`, inline: true },
51911+ { name: '', value: `:lock_with_ink_pen: [${sha}](${url}/${owner}/${repo}/commit/${sha})`, inline: true },
51912+ { name: '', value: `${statusEmoji} [${status}](${url}/${owner}/${repo}/actions/runs/${runID})`, inline: true }
51913+ ];
51914+ // Enforce Field Count Limit (Max 25)
51915+ // We have 4 static fields, leaving 21 slots for assets
51916+ if (assetFields.length > 21) {
51917+ assetFields.length = 21;
51918+ }
51919+ const allFields = [...assetFields, ...staticFields];
51920+ // Truncate & Calculate Sizes
51921+ // Author Name: Max 256
51922+ const embedAuthorName = `${owner}/${repo}`.substring(0, 256);
51923+ // Title: Max 256
51924+ const embedTitle = inputs.release.name.substring(0, 256);
51925+ // Footer: Max 2048
51926+ let author = updatedRelease.data.author.type === 'User' ? updatedRelease.data.author.login : updatedRelease.data.author.login.replace('[bot]', '');
51927+ const embedFooterText = `Released by ${author}`.substring(0, 2048);
51928+ // Calculate current used size (excluding description)
51929+ let currentTotalSize = 0;
51930+ currentTotalSize += embedAuthorName.length;
51931+ currentTotalSize += embedTitle.length;
51932+ currentTotalSize += embedFooterText.length;
51933+ for (const f of allFields) {
51934+ currentTotalSize += (f.name.length || 0) + (f.value.length || 0);
51935+ }
51936+ // Description: Max 4096, but Total Embed must be <= 6000
51937+ const availableForDesc = 6000 - currentTotalSize;
51938+ const maxDesc = Math.min(4096, availableForDesc);
51939+ const description = (inputs.release.body || '').substring(0, Math.max(0, maxDesc));
5189551940 const embed = new dist.Embed()
5189651941 .setTimestamp()
5189751942 .setAuthor({
51898- name: `${owner}/${repo}` ,
51943+ name: embedAuthorName ,
5189951944 url: `${url}/${owner}/${repo}`,
5190051945 icon_url: `${url}/${owner}.png`
5190151946 })
5190251947 .setColor(color)
51903- .setTitle(inputs.release.name )
51948+ .setTitle(embedTitle )
5190451949 .setUrl(updatedRelease.data.html_url)
51905- .setDescription(inputs.release.body.substring(0, 4000))
51906- .addField({ name: 'Assets', value: assets, inline: false })
51907- .addField({ name: '', value: `:watch: <t:${time}:R>`, inline: true })
51908- .addField({ name: '', value: `:label: [${tag}](${url}/${owner}/${repo}/tree/${tag})`, inline: true })
51909- .addField({ name: '', value: `:lock_with_ink_pen: [${sha}](${url}/${owner}/${repo}/commit/${sha})`, inline: true })
51910- .addField({ name: '', value: `${statusEmoji} [${status}](${url}/${owner}/${repo}/actions/runs/${runID})`, inline: true })
51911- .setFooter({ text: `Released by ${author}`, icon_url: updatedRelease.data.author.avatar_url });
51950+ .setDescription(description)
51951+ .setFooter({ text: embedFooterText, icon_url: updatedRelease.data.author.avatar_url });
51952+ for (const field of allFields) {
51953+ embed.addField(field);
51954+ }
5191251955 if (thumbnail) {
5191351956 embed.setImage({ url: thumbnail });
5191451957 }
0 commit comments