@taiga-ui/auto-changelog-config 0.494.0 → 0.495.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taiga-ui/auto-changelog-config",
3
- "version": "0.494.0",
3
+ "version": "0.495.0",
4
4
  "description": "Taiga UI auto-changelog config",
5
5
  "keywords": [
6
6
  "auto-changelog"
@@ -7,15 +7,15 @@
7
7
  {{#commit-parser merges commits}}
8
8
 
9
9
  {{#commit-list this heading='### ⚠️ BREAKING CHANGES' message='^(feat|fix|perf)(\([^)]*\))!:' }}
10
- - {{#replaceCommit}}{{subject}}{{/replaceCommit}}{{#if pullRequest}}{{#if pullRequest.href}} ([#{{pullRequest.id}}]({{pullRequest.href}})){{else}} (#{{pullRequest.id}}){{/if}}{{/if}}{{#if commitHash}}{{#if commitHref}} [({{commitHash}})]({{commitHref}}){{else}} ({{commitHash}}){{/if}}{{/if}}
10
+ - {{changelogEntry}}
11
11
  {{/commit-list}}
12
12
 
13
13
  {{#commit-list this heading='### 🚀 Features' message='^feat:|^feat\(' exclude='^(feat|fix|perf)(\([^)]*\))!:'}}
14
- - {{#replaceCommit}}{{subject}}{{/replaceCommit}}{{#if pullRequest}}{{#if pullRequest.href}} ([#{{pullRequest.id}}]({{pullRequest.href}})){{else}} (#{{pullRequest.id}}){{/if}}{{/if}}{{#if commitHash}}{{#if commitHref}} [({{commitHash}})]({{commitHref}}){{else}} ({{commitHash}}){{/if}}{{/if}}
14
+ - {{changelogEntry}}
15
15
  {{/commit-list}}
16
16
 
17
17
  {{#commit-list this heading='### 🐞 Bug Fixes' message='^fix:|^fix\(' exclude='^(feat|fix|perf)(\([^)]*\))!:'}}
18
- - {{#replaceCommit}}{{subject}}{{/replaceCommit}}{{#if pullRequest}}{{#if pullRequest.href}} ([#{{pullRequest.id}}]({{pullRequest.href}})){{else}} (#{{pullRequest.id}}){{/if}}{{/if}}{{#if commitHash}}{{#if commitHref}} [({{commitHash}})]({{commitHref}}){{else}} ({{commitHash}}){{/if}}{{/if}}
18
+ - {{changelogEntry}}
19
19
  {{/commit-list}}
20
20
 
21
21
  {{/commit-parser}}
package/setup.js CHANGED
@@ -3,6 +3,15 @@ module.exports = function (Handlebars) {
3
3
  const firstNonEmptyString = (...values) =>
4
4
  values.map((value) => String(value ?? '').trim()).find(Boolean) ?? '';
5
5
 
6
+ const escape = (value) => Handlebars.escapeExpression(String(value ?? ''));
7
+
8
+ const createMarkdownLink = (text, href) => {
9
+ const safeText = escape(text);
10
+ const safeHref = escape(href);
11
+
12
+ return href ? `[${safeText}](${safeHref})` : safeText;
13
+ };
14
+
6
15
  const getPullRequestId = (href) => {
7
16
  const [, id = ''] =
8
17
  String(href ?? '').match(
@@ -23,6 +32,9 @@ module.exports = function (Handlebars) {
23
32
  String(href ?? ''),
24
33
  );
25
34
 
35
+ const isCommitHref = (href) =>
36
+ /\/commit\/[a-f\d]{7,40}(?:$|[/?#])/.test(String(href ?? ''));
37
+
26
38
  const getCommitHashFromHref = (href) => {
27
39
  const [, hash = ''] =
28
40
  String(href ?? '').match(/\/commit\/([a-f\d]{7,40})(?:$|[/?#])/) ?? [];
@@ -37,10 +49,39 @@ module.exports = function (Handlebars) {
37
49
  return repositoryHref;
38
50
  };
39
51
 
52
+ const normalizePullRequest = (commit, subject) => {
53
+ const pullRequest = commit.pullRequest ?? {};
54
+
55
+ const href =
56
+ [pullRequest.href, commit.pullRequestHref, commit.href]
57
+ .map((value) => firstNonEmptyString(value))
58
+ .find(isPullRequestHref) ?? '';
59
+
60
+ const id = firstNonEmptyString(
61
+ pullRequest.id,
62
+ pullRequest.number,
63
+ getPullRequestId(href),
64
+ getPullRequestIdFromText(subject),
65
+ getPullRequestIdFromText(commit.message),
66
+ getPullRequestIdFromText(commit.title),
67
+ );
68
+
69
+ if (!id) {
70
+ return;
71
+ }
72
+
73
+ return {
74
+ ...pullRequest,
75
+ id,
76
+ author: pullRequest.author ?? commit.author,
77
+ href,
78
+ };
79
+ };
80
+
40
81
  const getCommitHref = (commit, pullRequest) => {
41
82
  const href = firstNonEmptyString(commit.commitHref, commit.href);
42
83
 
43
- if (href.includes('/commit/')) {
84
+ if (isCommitHref(href)) {
44
85
  return href;
45
86
  }
46
87
 
@@ -51,7 +92,7 @@ module.exports = function (Handlebars) {
51
92
  );
52
93
 
53
94
  const repositoryHref = getRepositoryHref(
54
- firstNonEmptyString(pullRequest?.href, href),
95
+ firstNonEmptyString(commit.repositoryHref, href, pullRequest?.href),
55
96
  );
56
97
 
57
98
  return hash && repositoryHref ? `${repositoryHref}/commit/${hash}` : '';
@@ -65,33 +106,6 @@ module.exports = function (Handlebars) {
65
106
  String(commit.hash ?? '').slice(0, 7),
66
107
  ).slice(0, 7);
67
108
 
68
- const normalizePullRequest = (commit, subject) => {
69
- const pullRequest = commit.pullRequest ?? {};
70
- const href = [pullRequest.href, commit.pullRequestHref, commit.href]
71
- .map(firstNonEmptyString)
72
- .find(isPullRequestHref);
73
-
74
- const id = firstNonEmptyString(
75
- pullRequest.id,
76
- pullRequest.number,
77
- getPullRequestId(href),
78
- getPullRequestIdFromText(subject),
79
- getPullRequestIdFromText(commit.message),
80
- getPullRequestIdFromText(commit.title),
81
- );
82
-
83
- if (!id) {
84
- return;
85
- }
86
-
87
- return {
88
- ...pullRequest,
89
- id,
90
- author: pullRequest.author ?? commit.author,
91
- href: href ?? '',
92
- };
93
- };
94
-
95
109
  const normalizeCommit = (commit) => {
96
110
  const subject = firstNonEmptyString(
97
111
  commit.subject,
@@ -116,10 +130,10 @@ module.exports = function (Handlebars) {
116
130
 
117
131
  const getCommitKey = (commit) =>
118
132
  firstNonEmptyString(
119
- commit.pullRequest?.id && `pr:${commit.pullRequest.id}`,
120
- commit.hash && `hash:${commit.hash}`,
121
- commit.commitHash && `hash:${commit.commitHash}`,
122
- commit.subject && `subject:${commit.subject}`,
133
+ commit.pullRequest?.id ? `pr:${commit.pullRequest.id}` : '',
134
+ commit.hash ? `hash:${commit.hash}` : '',
135
+ commit.commitHash ? `hash:${commit.commitHash}` : '',
136
+ commit.subject ? `subject:${commit.subject}` : '',
123
137
  );
124
138
 
125
139
  const mergePullRequests = (left, right) => {
@@ -157,6 +171,52 @@ module.exports = function (Handlebars) {
157
171
  subject: firstNonEmptyString(left.subject, right.subject),
158
172
  });
159
173
 
174
+ const formatCommitTitle = (subject) => {
175
+ const commit =
176
+ /^(?:build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)\s?(?:\((?<scope>[^)]*)\))?!?: (?<title>.*)$/;
177
+
178
+ const string = String(subject ?? '').trim();
179
+ const {scope = '', title = ''} = commit.exec(string)?.groups ?? {};
180
+ const cleanTitle = title.replace(/\s\(#\d+\)\s*$/, '');
181
+
182
+ if (!cleanTitle) {
183
+ return escape(string || 'empty commit name');
184
+ }
185
+
186
+ return scope
187
+ ? `**${escape(scope.toLowerCase())}**: ${escape(cleanTitle)}`
188
+ : escape(cleanTitle);
189
+ };
190
+
191
+ const formatPullRequestReference = (commit) => {
192
+ const pullRequest = commit.pullRequest;
193
+
194
+ if (!pullRequest?.id) {
195
+ return '';
196
+ }
197
+
198
+ const link = createMarkdownLink(`#${pullRequest.id}`, pullRequest.href);
199
+
200
+ return `(${link})`;
201
+ };
202
+
203
+ const formatCommitReference = (commit) => {
204
+ if (!commit.commitHash) {
205
+ return '';
206
+ }
207
+
208
+ return createMarkdownLink(`(${commit.commitHash})`, commit.commitHref);
209
+ };
210
+
211
+ const formatChangelogEntry = (commit) =>
212
+ [
213
+ formatCommitTitle(commit.subject),
214
+ formatPullRequestReference(commit),
215
+ formatCommitReference(commit),
216
+ ]
217
+ .filter(Boolean)
218
+ .join(' ');
219
+
160
220
  const getCommitAuthor = (commit) =>
161
221
  commit.pullRequest?.author?.login ??
162
222
  commit.pullRequest?.user?.login ??
@@ -225,15 +285,19 @@ module.exports = function (Handlebars) {
225
285
  });
226
286
 
227
287
  Handlebars.registerHelper('replaceCommit', function (context) {
228
- const commit =
229
- /^(?:build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)\s?(?:\((?<scope>[^)]*)\))?!?: (?<title>.*)$/;
288
+ return new Handlebars.SafeString(formatCommitTitle(context.fn(this)));
289
+ });
230
290
 
231
- const string = String(context.fn(this)).trim();
232
- const {scope = '', title = ''} = commit.exec(string)?.groups ?? {};
233
- const cleanTitle = title.replace(/\s\(#\d+\)\s*$/, '');
234
- const result = scope ? `**${scope.toLowerCase()}**: ${cleanTitle}` : cleanTitle;
291
+ Handlebars.registerHelper('pullRequestLink', function () {
292
+ return new Handlebars.SafeString(formatPullRequestReference(this));
293
+ });
294
+
295
+ Handlebars.registerHelper('commitLink', function () {
296
+ return new Handlebars.SafeString(formatCommitReference(this));
297
+ });
235
298
 
236
- return result || string || 'empty commit name';
299
+ Handlebars.registerHelper('changelogEntry', function () {
300
+ return new Handlebars.SafeString(formatChangelogEntry(this));
237
301
  });
238
302
 
239
303
  Handlebars.registerHelper('replaceTitle', function (context) {
package/template.hbs CHANGED
@@ -7,15 +7,15 @@
7
7
  {{#commit-parser merges commits}}
8
8
 
9
9
  {{#commit-list this heading='### ⚠️ BREAKING CHANGES' message='^(feat|fix|perf)(\([^)]*\))!:' }}
10
- - {{#replaceCommit}}{{subject}}{{/replaceCommit}}{{#if pullRequest}}{{#if pullRequest.href}} ([#{{pullRequest.id}}]({{pullRequest.href}})){{else}} (#{{pullRequest.id}}){{/if}}{{/if}}{{#if commitHash}}{{#if commitHref}} [({{commitHash}})]({{commitHref}}){{else}} ({{commitHash}}){{/if}}{{/if}}
10
+ - {{changelogEntry}}
11
11
  {{/commit-list}}
12
12
 
13
13
  {{#commit-list this heading='### 🚀 Features' message='^feat:|^feat\(' exclude='^(feat|fix|perf)(\([^)]*\))!:'}}
14
- - {{#replaceCommit}}{{subject}}{{/replaceCommit}}{{#if pullRequest}}{{#if pullRequest.href}} ([#{{pullRequest.id}}]({{pullRequest.href}})){{else}} (#{{pullRequest.id}}){{/if}}{{/if}}{{#if commitHash}}{{#if commitHref}} [({{commitHash}})]({{commitHref}}){{else}} ({{commitHash}}){{/if}}{{/if}}
14
+ - {{changelogEntry}}
15
15
  {{/commit-list}}
16
16
 
17
17
  {{#commit-list this heading='### 🐞 Bug Fixes' message='^fix:|^fix\(' exclude='^(feat|fix|perf)(\([^)]*\))!:'}}
18
- - {{#replaceCommit}}{{subject}}{{/replaceCommit}}{{#if pullRequest}}{{#if pullRequest.href}} ([#{{pullRequest.id}}]({{pullRequest.href}})){{else}} (#{{pullRequest.id}}){{/if}}{{/if}}{{#if commitHash}}{{#if commitHref}} [({{commitHash}})]({{commitHref}}){{else}} ({{commitHash}}){{/if}}{{/if}}
18
+ - {{changelogEntry}}
19
19
  {{/commit-list}}
20
20
 
21
21
  {{/commit-parser}}