From 309dfb0e9a1f88beca0c2947952ddc363ca37317 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Thu, 12 Jan 2023 15:26:38 -0600 Subject: [PATCH] Fix announcements CI actions when 2000+ characters (#5844) * fix(ci): handle announcements >= 2000 characters * chore: support multiple branches Co-authored-by: Nate Moore --- scripts/notify/index.js | 51 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/scripts/notify/index.js b/scripts/notify/index.js index fa699372a..1d8c4288a 100755 --- a/scripts/notify/index.js +++ b/scripts/notify/index.js @@ -2,7 +2,8 @@ import { globby as glob } from 'globby'; import { fileURLToPath } from 'node:url'; import { readFile } from 'node:fs/promises'; -const baseUrl = new URL('https://github.com/withastro/astro/blob/main/'); +const { GITHUB_REF = 'main' } = process.env; +const baseUrl = new URL(`https://github.com/withastro/astro/blob/${GITHUB_REF}/`); const emojis = ['šŸŽ‰', 'šŸ„³', 'šŸš€', 'šŸ§‘ā€šŸš€', 'šŸŽŠ', 'šŸ†', 'āœ…', 'šŸ¤©', 'šŸ¤–', 'šŸ™Œ']; const descriptors = [ @@ -45,6 +46,19 @@ const verbs = [ 'ā€“ from our family to yours.', 'ā€“ go forth and build!', ]; +const extraVerbs = [ + 'new', + 'here', + 'released', + 'freshly made', + 'going out', + 'hitting the registry', + 'available', + 'live now', + 'hot and fresh', + 'for you', + 'comin\' atcha', +] function item(items) { return items[Math.floor(Math.random() * items.length)]; @@ -102,15 +116,40 @@ async function run() { const descriptor = item(descriptors); const verb = item(verbs); + let message = ''; + if (packages.length === 1) { const { name, version, url } = packages[0]; - console.log( - `${emoji} \`${name}@${version}\` ${singularlize(verb)}\nRead the [release notes ā†’](<${url}>)` - ); + message += `${emoji} \`${name}@${version}\` ${singularlize(verb)}\nRead the [release notes ā†’](<${url}>)\n` } else { - console.log(`${emoji} Some ${descriptor} ${pluralize(verb)}\n`); + message += `${emoji} Some ${descriptor} ${pluralize(verb)}\n\n`; for (const { name, version, url } of packages) { - console.log(`ā€¢ \`${name}@${version}\` Read the [release notes ā†’](<${url}>)`); + message += `ā€¢ \`${name}@${version}\` Read the [release notes ā†’](<${url}>)\n`; + } + } + + if (message.length < 2000) { + console.log(message); + } else { + const { name, version, url } = packages.find(pkg => pkg.name === 'astro') ?? packages[0]; + message = `${emoji} Some ${descriptor} ${pluralize(verb)}\n\n`; + message += `ā€¢ \`${name}@${version}\` Read the [release notes ā†’](<${url}>)\n` + + message += `\nAlso ${item(extraVerbs)}:` + + const remainingPackages = packages.filter(p => p.name !== name); + for (const { name, version, url } of remainingPackages) { + message += `\nā€¢ \`${name}@${version}\``; + } + + if (message.length < 2000) { + console.log(message); + } else { + message = `${emoji} Some ${descriptor} ${pluralize(verb)}\n\n`; + message += `ā€¢ \`${name}@${version}\` Read the [release notes ā†’](<${url}>)\n` + + message += `\n\nAlso ${item(extraVerbs)}: ${remainingPackages.length} other packages!`; + console.log(message); } } }