Skip to content

Commit

Permalink
chore(repo): Fix releases slack post [internal]
Browse files Browse the repository at this point in the history
  • Loading branch information
anagstef committed Dec 20, 2024
1 parent a52029c commit 81f243d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .changeset/sharp-vans-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
40 changes: 32 additions & 8 deletions scripts/notify.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ const getReleaseChannel = version => {
const slackFormatter = {
generateChangelog: ({ packageData, releasePrUrl, pusher }) => {
const markdown = text => ({ type: 'section', text: { type: 'mrkdwn', text } });
const divider = () => ({ type: 'divider' });
const header = text => ({ type: 'header', text: { type: 'plain_text', text } });
const context = (imgUrl, text) => ({
type: 'context',
Expand All @@ -64,22 +63,47 @@ const slackFormatter = {

const releaseChannel = getReleaseChannel(packageData?.[0]?.version);
blocks.push(header(`Javascript SDKs - ${releaseChannel} Release - ${new Date().toLocaleDateString('en-US')}`));
blocks.push(markdown(`All release PRs for this day can be found <${releasePrUrl}|here>.\nReleased packages:\n`));

let body = '';
for (const { name, version, changelogUrl } of packageData) {
body += `• <${changelogUrl}|Changelog> - \`${name}@${version}\`\n`;
}
createPackagesBody(packageData).forEach(body => {
blocks.push(markdown(body));
});

blocks.push(markdown(`All release PRs for this day can be found <${releasePrUrl}|here>.\nReleased packages:\n`));
blocks.push(markdown(body));
// blocks.push(divider());
blocks.push(markdown('\n'));
blocks.push(context(pusher.avatarUrl, `<${pusher.profileUrl}|*${pusher.username}*> triggered this release.`));

return JSON.stringify({ blocks });
},
};

/**
* @property {PackageData[]} packageData
*/
const createPackagesBody = packageData => {
// The Slack API has a limitation of ~3000 characters per block and
// also there is a limit on the number of blocks that can be sent in a single message.
// So, we split the body into fragments of 10 packages each.
const fragments = [];
let body = '';
let count = 0;
for (const { name, version, changelogUrl } of packageData) {
body += `• <${changelogUrl}|Changelog> - \`${name}@${version}\`\n`;
count++;

if (count === 10) {
fragments.push(body);
body = '';
count = 0;
}
}
// This is the remaining
if (body) {
fragments.push(body);
}

return fragments;
};

/**
* @type {Record<string, Formatter>}
*/
Expand Down

0 comments on commit 81f243d

Please sign in to comment.