Skip to content
Closed
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: 1 addition & 1 deletion tools/continuous-delivery/src/sendMessageAboutRelease.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export async function sendMessageAboutRelease(version: string, lastVersionChange
log('Sending message to internal Slack...');

try {
const title = `New release ${version} is here!`;
const title = `:whale2: Semcore Release v${version.replace(/^v/, '')}`;
const body = makeMessageFromChangelogs(lastVersionChangelogs, false);

await sendMessage({
Expand Down
51 changes: 30 additions & 21 deletions tools/continuous-delivery/src/utils/slackIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,28 @@ import axios from 'axios';
import type { ChangelogChangeLabel, ChangelogItem } from './changelog';

const type2SectionLabel: Record<string, string> = {
added: ':white_check_mark: ADDED',
changed: ':recycle: CHANGED',
fixed: ':hammer_and_wrench: FIXED',
removed: ':wastebasket: REMOVED',
break: ':interrobang: BREAK',
added: ':sparkles: Added',
changed: ':arrows_counterclockwise: Changed',
fixed: ':ladybug: Fixed',
removed: ':wastebasket: Removed',
break: ':warning: Break',
};

export const makeMessageFromChangelogs = (changelogs: ChangelogItem[], withVersions: boolean) =>
changelogs.map((item) => bodyTemplate(item, withVersions)).join('\n');

const titleTemplate = (name: string, version: string | null) =>
`\n-------- \n:black_heart: *${name}* ${version ? `v${version}` : ''} \n\n`;
const formatComponentDisplayName = (component: string): string => {
const name = component.replace(/^@semcore\//i, '');

if (!name) {
return component;
}

return name.charAt(0).toUpperCase() + name.slice(1);
};

const getSectionTitle = (label: string): string =>
type2SectionLabel[label.toLowerCase()] ?? label.toUpperCase();

const bodyTemplate = (changeItem: ChangelogItem, withVersions: boolean) => {
const sections: Partial<{ [label in NonNullable<ChangelogChangeLabel>]: string[] }> = {};
Expand All @@ -25,20 +35,19 @@ const bodyTemplate = (changeItem: ChangelogItem, withVersions: boolean) => {
}
}

return (
titleTemplate(changeItem.component, withVersions ? changeItem.version : null) +
Object.entries(sections)
.map(([label, changeDescriptions]) => {
const title = label in type2SectionLabel ? type2SectionLabel[label] : label.toUpperCase();

return (
title +
'\n' +
changeDescriptions.map((changeDescription) => `- ${changeDescription}`).join('\n')
);
})
.join('\n')
);
const versionSuffix =
withVersions && changeItem.version ? ` v${changeItem.version}` : '';
const header = `- - -\n*${formatComponentDisplayName(changeItem.component)}*${versionSuffix}`;
const sectionsText = Object.entries(sections)
.map(([label, changeDescriptions]) => {
const title = getSectionTitle(label);
const lines = changeDescriptions.join('\n');

return lines ? `${title}\n${lines}` : title;
})
.join('\n');

return sectionsText ? `${header}\n${sectionsText}` : header;
};

export const sendMessage = async ({
Expand Down
Loading