Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(repo): Fix releases slack post [internal] #4824

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading