-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathchangelog-custom-renders.ts
More file actions
90 lines (75 loc) · 3.16 KB
/
changelog-custom-renders.ts
File metadata and controls
90 lines (75 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { ChangelogEntry, PackageChangelogRenderInfo } from 'beachball';
import { getPrNumber, repoDetails } from './github-functions';
const repoUrl = `https://github.com/${repoDetails.owner}/${repoDetails.repo}`;
function renderHeader(renderInfo: PackageChangelogRenderInfo): string {
const {
newVersionChangelog: { version, date },
previousJson
} = renderInfo;
// Link to the tag on github
const header = `[${version}](${repoUrl}/tree/${version})`;
// Also include a compare link to the previous version if available
const previousVersion = previousJson?.entries?.[0]?.version;
const compareLink = version && previousVersion ? ` \n[Compare changes](${repoUrl}/compare/${previousVersion}...${version})` : '';
return `## ${header}\n\n${date.toUTCString()}${compareLink}`;
}
async function renderEntry(entry: ChangelogEntry): Promise<string> {
// Link to the PR for this changelog entry (or the commit if PR isn't found)
const prNumber = await getPrNumber(entry['commit']);
const commitLink = prNumber ? `[PR #${prNumber}](${repoUrl}/pull/${prNumber})` : `[commit](${repoUrl}/commit/${entry['commit']})`;
const commitComment = `- ${entry['comment']} (${commitLink} by ${entry['author']})\n`
return commitComment;
}
async function renderSubsection(title: string, entries: ChangelogEntry[]): Promise<string> {
let subsection = `### ${title}\n`;
for (const entry of entries) {
subsection += await renderEntry(entry);
}
return subsection;
}
function filterByArea(list: ChangelogEntry[], area: string) {
let filteredByArea = list.filter((entry) => {
return entry['area'] === area
});
return filteredByArea;
}
function filterUnknown(list: ChangelogEntry[]) {
let unknown = list.filter((entry) => {
return entry['area'] === undefined
});
return unknown;
}
export async function renderPackageChangelog(renderInfo: PackageChangelogRenderInfo): Promise<string> {
let changelog = '';
let features: ChangelogEntry[] = [];
let improvements: ChangelogEntry[] = [];
let bugs: ChangelogEntry[] = [];
let storybookChanges: ChangelogEntry[] = [];
let unknowns: ChangelogEntry[] = [];
changelog = renderHeader(renderInfo) + '\n\n';
for (const [changetype, entries] of Object.entries(renderInfo.newVersionChangelog.comments)) {
if (entries.length > 0) {
features = features.concat(filterByArea(entries, 'feature'));
improvements = improvements.concat(filterByArea(entries, 'improvement'));
bugs = bugs.concat(filterByArea(entries, 'fix'));
storybookChanges = storybookChanges.concat(filterByArea(entries, 'storybook'));
unknowns = unknowns.concat(filterUnknown(entries));
}
}
if (features.length > 0) {
changelog += await renderSubsection('Features', features);
}
if (improvements.length > 0) {
changelog += await renderSubsection('Improvements', improvements);
}
if (bugs.length > 0) {
changelog += await renderSubsection('Bug Fixes', bugs);
}
if (storybookChanges.length > 0) {
changelog += await renderSubsection('Storybook Changes', storybookChanges);
}
if (unknowns.length > 0) {
changelog += await renderSubsection('Other Changes', unknowns);
}
return changelog;
};