Skip to content

Commit 2b296e6

Browse files
authored
chore(repo): Fix releases slack post [internal] (#4824)
1 parent a52029c commit 2b296e6

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

.changeset/sharp-vans-sit.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

scripts/notify.mjs

+32-8
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ const getReleaseChannel = version => {
5151
const slackFormatter = {
5252
generateChangelog: ({ packageData, releasePrUrl, pusher }) => {
5353
const markdown = text => ({ type: 'section', text: { type: 'mrkdwn', text } });
54-
const divider = () => ({ type: 'divider' });
5554
const header = text => ({ type: 'header', text: { type: 'plain_text', text } });
5655
const context = (imgUrl, text) => ({
5756
type: 'context',
@@ -64,22 +63,47 @@ const slackFormatter = {
6463

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

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

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

7975
return JSON.stringify({ blocks });
8076
},
8177
};
8278

79+
/**
80+
* @property {PackageData[]} packageData
81+
*/
82+
const createPackagesBody = packageData => {
83+
// The Slack API has a limitation of ~3000 characters per block and
84+
// also there is a limit on the number of blocks that can be sent in a single message.
85+
// So, we split the body into fragments of 10 packages each.
86+
const fragments = [];
87+
let body = '';
88+
let count = 0;
89+
for (const { name, version, changelogUrl } of packageData) {
90+
body += `• <${changelogUrl}|Changelog> - \`${name}@${version}\`\n`;
91+
count++;
92+
93+
if (count === 10) {
94+
fragments.push(body);
95+
body = '';
96+
count = 0;
97+
}
98+
}
99+
// This is the remaining
100+
if (body) {
101+
fragments.push(body);
102+
}
103+
104+
return fragments;
105+
};
106+
83107
/**
84108
* @type {Record<string, Formatter>}
85109
*/

0 commit comments

Comments
 (0)