Skip to content

Commit 00db428

Browse files
committed
docs: change the changelog commits format
See angular#11740 for an example of how it looks. Fixes angular#11740
1 parent 60c20f2 commit 00db428

File tree

4 files changed

+107
-37
lines changed

4 files changed

+107
-37
lines changed

scripts/changelog.ts

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { JsonObject, logging } from '@angular-devkit/core';
1010
import * as fs from 'fs';
1111
import * as path from 'path';
1212
import * as semver from 'semver';
13+
import { packages } from '../lib/packages';
1314

1415
const changelogTemplate = require('./templates/changelog').default;
1516

@@ -86,6 +87,7 @@ export default function(args: ChangelogOptions, logger: logging.Logger) {
8687
...args,
8788
include: (x: string, v: {}) => require('./' + path.join('templates', x)).default(v),
8889
commits,
90+
packages,
8991
});
9092

9193
if (args.stdout || !githubToken) {

scripts/templates/changelog-feat.ejs

+31-15
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,36 @@
44
}
55
66
const shortSha = hash && hash.slice(0, 7);
7-
%>| <%# Commit: %><%
7+
%>
8+
<tr>
9+
<%# Commit: %>
10+
<td><%
811
if (shortSha) {
9-
%>[![Bug Fix](https://img.shields.io/badge/<%= shortSha %>-feat-yellow.svg)](https://github.com/angular/angular-cli/commit/<%= hash %>)<%
10-
} %><%
11-
%>| <%# Desc: %><%= subject
12-
%>| <%# Notes: %><%
13-
for (const reference of references) {
14-
if (!reference.action || !reference.issue) {
15-
continue;
16-
}
12+
%>
13+
<a href="https://github.com/angular/angular-cli/commit/<%= hash %>"><img
14+
align="top"
15+
title="Bug Fix" src="https://img.shields.io/badge/<%= shortSha %>-feat-blue.svg" />
16+
</a><%
17+
} %>
18+
</td>
1719

18-
const issue = reference.issue;
19-
const owner = reference.owner || 'angular';
20-
const repository = reference.repository || 'angular-cli';
21-
%>[Closes #<%= issue %>](https://github.com/<%= owner %>/<%= repository %>/issues/<%= issue %>)<%
22-
}
23-
%>
20+
<%# Desc: %>
21+
<td><%= subject %></td>
22+
23+
<%# Notes: %>
24+
<td><%
25+
for (const reference of references) {
26+
if (!reference.action || !reference.issue) {
27+
continue;
28+
}
29+
30+
const issue = reference.issue;
31+
const owner = reference.owner || 'angular';
32+
const repository = reference.repository || 'angular-cli';
33+
%>
34+
<a href="https://github.com/<%= owner %>/<%= repository %>/issues/<%= issue %>">
35+
[Closes #<%= issue %>]<br />
36+
</a>
37+
<% } %>
38+
</td>
39+
</tr>

scripts/templates/changelog-fix.ejs

+32-15
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,37 @@
44
}
55
66
const shortSha = hash && hash.slice(0, 7);
7-
%>| <%# Commit: %><%
7+
%>
8+
<tr>
9+
<%# Commit: %>
10+
<td><%
811
if (shortSha) {
9-
%>[![Bug Fix](https://img.shields.io/badge/<%= shortSha %>-fix-green.svg)](https://github.com/angular/angular-cli/commit/<%= hash %>)<%
10-
} %><%
11-
%>| <%# Desc: %><%= subject
12-
%>| <%# Notes: %><%
13-
for (const reference of references) {
14-
if (!reference.action || !reference.issue) {
15-
continue;
16-
}
12+
%>
13+
<a href="https://github.com/angular/angular-cli/commit/<%= hash %>"><img
14+
align="top"
15+
title="Feature" src="https://img.shields.io/badge/<%= shortSha %>-fix-green.svg" />
16+
</a><%
17+
} %>
18+
</td>
1719

18-
const issue = reference.issue;
19-
const owner = reference.owner || 'angular';
20-
const repository = reference.repository || 'angular-cli';
21-
%>[Closes #<%= issue %>](https://github.com/<%= owner %>/<%= repository %>/issues/<%= issue %>)<%
22-
}
23-
%>
20+
<%# Desc: %>
21+
<td><%= subject %></td>
22+
23+
<%# Notes: %>
24+
<td><%
25+
for (const reference of references) {
26+
if (!reference.action || !reference.issue) {
27+
continue;
28+
}
29+
30+
const issue = reference.issue;
31+
const owner = reference.owner || 'angular';
32+
const repository = reference.repository || 'angular-cli';
33+
%>
34+
35+
<a href="https://github.com/<%= owner %>/<%= repository %>/issues/<%= issue %>">
36+
[Closes #<%= issue %>]<br />
37+
</a>
38+
<% } %>
39+
</td>
40+
</tr>

scripts/templates/changelog.ejs

+42-7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
{
44
from: 'v1.2.3',
55
to: 'v1.2.4',
6+
packages: { /* The PackageInfoMap from "lib/packages.ts" */
67
// For a commit with description:
78
// ------------------------------------------------------
89
// feat(@angular/pwa): add something to this
@@ -29,12 +30,30 @@
2930
],
3031
} ]
3132
}
32-
%># Commits
33+
%><%
34+
// Sort those packages to the top, in those orders. Others will be sorted alphabetically.
35+
const CUSTOM_SORT_ORDER = [
36+
'@angular/cli',
37+
'@schematics/angular',
38+
'@angular-devkit/architect-cli',
39+
'@angular-devkit/schematics-cli',
40+
];
41+
%>
42+
# Commits
43+
44+
<table>
45+
<tbody>
3346
<%
3447
// Get unique scopes.
3548
const scopes = commits.map(x => x.scope)
3649
.sort()
37-
.filter((v, i, a) => v !== a[i - 1]);
50+
.filter((v, i, a) => v !== a[i - 1])
51+
.sort((a, b) => {
52+
// Sort using the sorting order above, or against each others if undefined.
53+
const aOrder = CUSTOM_SORT_ORDER.indexOf(a);
54+
const bOrder = CUSTOM_SORT_ORDER.indexOf(b);
55+
return aOrder == -1 ? bOrder == -1 ? (a || '').localeCompare(b || '') : 1 : aOrder - bOrder;
56+
});
3857
3958
for (const scope of scopes) {
4059
const scopeCommits = commits
@@ -45,19 +64,35 @@
4564
continue;
4665
}
4766
%>
48-
## `<%= scope || 'Misc' %>`
49-
50-
| Commit | Description | Notes |
51-
|:------:| ----------- | -----:|
67+
<tr><td colspan=3><h3><%
68+
if (scope) {
69+
%><%= scope %> (<%= packages[scope].version %>)<%
70+
} else {
71+
%>Misc<%
72+
}
73+
%></h3></td></tr>
74+
<tr>
75+
<td><b>Commit</b>
76+
<td><b>Description</b>
77+
<td><b>Notes</b>
78+
</tr>
5279
<%
80+
let nbRows = 0;
5381
for (const commit of scopeCommits) {
82+
nbRows++;
5483
switch (commit.type) {
5584
case 'fix': %><%= include('./changelog-fix', commit) %><% break;
5685
case 'feat': %><%= include('./changelog-feat', commit) %><% break;
5786
}
5887
}
59-
%>
88+
89+
// Add an empty row to get the alternating colors in sync.
90+
if (scope != scopes[scopes.length - 1] && nbRows % 2) { %>
91+
<tr></tr>
92+
<% } %>
6093
<% } %>
94+
</tbody>
95+
</table>
6196
6297
----
6398

0 commit comments

Comments
 (0)