@taiga-ui/auto-changelog-config 0.495.0 → 0.497.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.495.0",
3
+ "version": "0.497.0",
4
4
  "description": "Taiga UI auto-changelog config",
5
5
  "keywords": [
6
6
  "auto-changelog"
package/setup.js CHANGED
@@ -3,14 +3,12 @@ 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 ?? ''));
6
+ const toArray = (value) => (Array.isArray(value) ? value : []);
7
7
 
8
- const createMarkdownLink = (text, href) => {
9
- const safeText = escape(text);
10
- const safeHref = escape(href);
8
+ const escape = (value) => Handlebars.escapeExpression(String(value ?? ''));
11
9
 
12
- return href ? `[${safeText}](${safeHref})` : safeText;
13
- };
10
+ const commitPattern =
11
+ /^(?:build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)\s?(?:\((?<scope>[^)]*)\))?!?: (?<title>.*)$/;
14
12
 
15
13
  const getPullRequestId = (href) => {
16
14
  const [, id = ''] =
@@ -27,43 +25,17 @@ module.exports = function (Handlebars) {
27
25
  return id;
28
26
  };
29
27
 
30
- const isPullRequestHref = (href) =>
31
- /\/(?:pull|merge_requests|pull-requests)\/\d+(?:$|[/?#])/.test(
32
- String(href ?? ''),
33
- );
34
-
35
- const isCommitHref = (href) =>
36
- /\/commit\/[a-f\d]{7,40}(?:$|[/?#])/.test(String(href ?? ''));
37
-
38
- const getCommitHashFromHref = (href) => {
39
- const [, hash = ''] =
40
- String(href ?? '').match(/\/commit\/([a-f\d]{7,40})(?:$|[/?#])/) ?? [];
41
-
42
- return hash;
43
- };
44
-
45
- const getRepositoryHref = (href) => {
46
- const [, repositoryHref = ''] =
47
- String(href ?? '').match(/^(https?:\/\/[^/]+\/[^/]+\/[^/]+)(?:\/|$)/) ?? [];
48
-
49
- return repositoryHref;
50
- };
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) ?? '';
28
+ const getPullRequest = (merge, subject) => {
29
+ const href = firstNonEmptyString(merge.href, merge.pullRequest?.href);
59
30
 
60
31
  const id = firstNonEmptyString(
61
- pullRequest.id,
62
- pullRequest.number,
32
+ merge.id,
33
+ merge.number,
34
+ merge.pullRequest?.id,
35
+ merge.pullRequest?.number,
63
36
  getPullRequestId(href),
37
+ getPullRequestIdFromText(merge.message),
64
38
  getPullRequestIdFromText(subject),
65
- getPullRequestIdFromText(commit.message),
66
- getPullRequestIdFromText(commit.title),
67
39
  );
68
40
 
69
41
  if (!id) {
@@ -71,112 +43,69 @@ module.exports = function (Handlebars) {
71
43
  }
72
44
 
73
45
  return {
74
- ...pullRequest,
75
46
  id,
76
- author: pullRequest.author ?? commit.author,
77
47
  href,
78
48
  };
79
49
  };
80
50
 
81
- const getCommitHref = (commit, pullRequest) => {
82
- const href = firstNonEmptyString(commit.commitHref, commit.href);
51
+ const getPullRequestFromCommit = (commit) => {
52
+ const subject = firstNonEmptyString(commit.subject, commit.message);
53
+ const id = getPullRequestIdFromText(subject);
83
54
 
84
- if (isCommitHref(href)) {
85
- return href;
55
+ if (!id) {
56
+ return;
86
57
  }
87
58
 
88
- const hash = firstNonEmptyString(
89
- commit.hash,
90
- commit.shorthash,
91
- getCommitHashFromHref(href),
92
- );
93
-
94
- const repositoryHref = getRepositoryHref(
95
- firstNonEmptyString(commit.repositoryHref, href, pullRequest?.href),
96
- );
97
-
98
- return hash && repositoryHref ? `${repositoryHref}/commit/${hash}` : '';
59
+ return {id};
99
60
  };
100
61
 
101
- const getCommitHash = (commit, commitHref) =>
102
- firstNonEmptyString(
103
- commit.commitHash,
104
- commit.shorthash,
105
- getCommitHashFromHref(commitHref),
106
- String(commit.hash ?? '').slice(0, 7),
107
- ).slice(0, 7);
108
-
109
- const normalizeCommit = (commit) => {
110
- const subject = firstNonEmptyString(
111
- commit.subject,
112
- commit.pullRequest?.title,
113
- commit.title,
114
- commit.message,
115
- );
116
-
117
- const pullRequest = normalizePullRequest(commit, subject);
118
- const commitHref = getCommitHref(commit, pullRequest);
119
- const commitHash = getCommitHash(commit, commitHref);
62
+ const normalizeMerge = (merge) => {
63
+ const commit = merge.commit ?? {};
64
+ const subject = firstNonEmptyString(commit.subject, merge.message);
120
65
 
121
66
  return {
122
67
  ...commit,
123
- commitHash,
124
- commitHref,
125
- message: firstNonEmptyString(commit.message, subject),
126
- pullRequest,
68
+ href: firstNonEmptyString(commit.href),
69
+ pullRequest: getPullRequest(merge, subject),
70
+ shorthash: firstNonEmptyString(commit.shorthash, merge.shorthash),
127
71
  subject,
128
72
  };
129
73
  };
130
74
 
75
+ const normalizeCommit = (commit) => ({
76
+ ...commit,
77
+ href: firstNonEmptyString(commit.href),
78
+ pullRequest: commit.pullRequest ?? getPullRequestFromCommit(commit),
79
+ shorthash: firstNonEmptyString(commit.shorthash),
80
+ subject: firstNonEmptyString(commit.subject, commit.message),
81
+ });
82
+
131
83
  const getCommitKey = (commit) =>
132
84
  firstNonEmptyString(
133
85
  commit.pullRequest?.id ? `pr:${commit.pullRequest.id}` : '',
134
86
  commit.hash ? `hash:${commit.hash}` : '',
135
- commit.commitHash ? `hash:${commit.commitHash}` : '',
136
- commit.subject ? `subject:${commit.subject}` : '',
87
+ commit.shorthash ? `hash:${commit.shorthash}` : '',
88
+ commit.href,
89
+ commit.subject,
137
90
  );
138
91
 
139
- const mergePullRequests = (left, right) => {
140
- if (!left && !right) {
141
- return;
142
- }
143
-
144
- if (!left) {
145
- return right;
146
- }
147
-
148
- if (!right) {
149
- return left;
150
- }
92
+ const uniqueCommits = (commits) => [
93
+ ...commits
94
+ .reduce((map, commit) => {
95
+ const key = getCommitKey(commit);
151
96
 
152
- return {
153
- ...left,
154
- ...right,
155
- id: firstNonEmptyString(left.id, right.id),
156
- author: left.author ?? right.author,
157
- href: firstNonEmptyString(left.href, right.href),
158
- };
159
- };
97
+ if (key && !map.has(key)) {
98
+ map.set(key, commit);
99
+ }
160
100
 
161
- const mergeCommits = (left, right) => ({
162
- ...left,
163
- ...right,
164
- commitHash: firstNonEmptyString(left.commitHash, right.commitHash),
165
- commitHref: firstNonEmptyString(left.commitHref, right.commitHref),
166
- hash: firstNonEmptyString(left.hash, right.hash),
167
- href: firstNonEmptyString(left.href, right.href),
168
- message: firstNonEmptyString(left.message, right.message),
169
- pullRequest: mergePullRequests(left.pullRequest, right.pullRequest),
170
- shorthash: firstNonEmptyString(left.shorthash, right.shorthash),
171
- subject: firstNonEmptyString(left.subject, right.subject),
172
- });
101
+ return map;
102
+ }, new Map())
103
+ .values(),
104
+ ];
173
105
 
174
106
  const formatCommitTitle = (subject) => {
175
- const commit =
176
- /^(?:build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)\s?(?:\((?<scope>[^)]*)\))?!?: (?<title>.*)$/;
177
-
178
107
  const string = String(subject ?? '').trim();
179
- const {scope = '', title = ''} = commit.exec(string)?.groups ?? {};
108
+ const {scope = '', title = ''} = commitPattern.exec(string)?.groups ?? {};
180
109
  const cleanTitle = title.replace(/\s\(#\d+\)\s*$/, '');
181
110
 
182
111
  if (!cleanTitle) {
@@ -195,17 +124,21 @@ module.exports = function (Handlebars) {
195
124
  return '';
196
125
  }
197
126
 
198
- const link = createMarkdownLink(`#${pullRequest.id}`, pullRequest.href);
127
+ const text = `#${escape(pullRequest.id)}`;
199
128
 
200
- return `(${link})`;
129
+ return pullRequest.href
130
+ ? `([${text}](${escape(pullRequest.href)}))`
131
+ : `(${text})`;
201
132
  };
202
133
 
203
134
  const formatCommitReference = (commit) => {
204
- if (!commit.commitHash) {
135
+ if (!commit.shorthash) {
205
136
  return '';
206
137
  }
207
138
 
208
- return createMarkdownLink(`(${commit.commitHash})`, commit.commitHref);
139
+ const text = `(${escape(commit.shorthash)})`;
140
+
141
+ return commit.href ? `[${text}](${escape(commit.href)})` : text;
209
142
  };
210
143
 
211
144
  const formatChangelogEntry = (commit) =>
@@ -217,85 +150,18 @@ module.exports = function (Handlebars) {
217
150
  .filter(Boolean)
218
151
  .join(' ');
219
152
 
220
- const getCommitAuthor = (commit) =>
221
- commit.pullRequest?.author?.login ??
222
- commit.pullRequest?.user?.login ??
223
- commit.author?.login ??
224
- commit.user?.login ??
225
- commit.pullRequest?.author ??
226
- commit.author ??
227
- '';
228
-
229
- const isGithubLogin = (name) => /^[a-z\d](?:[a-z\d-]{0,37}[a-z\d])?$/i.test(name);
230
-
231
- const normalizeContributor = (author) => {
232
- const name = String(author).trim().replace(/^@/, '');
233
- const lowerName = name.toLowerCase();
234
-
235
- const isBot =
236
- lowerName.endsWith('[bot]') ||
237
- lowerName.endsWith('-bot') ||
238
- lowerName === 'dependabot' ||
239
- lowerName === 'renovatebot' ||
240
- lowerName === 'github-actions' ||
241
- lowerName === 'renovate' ||
242
- lowerName === 'gemini-code-assist';
243
-
244
- if (!name || isBot || !isGithubLogin(name)) {
245
- return '';
246
- }
247
-
248
- return `@${name}`;
249
- };
250
-
251
- const formatContributors = (contributors) => {
252
- if (contributors.length === 1) {
253
- return contributors[0];
254
- }
255
-
256
- if (contributors.length === 2) {
257
- return `${contributors[0]} and ${contributors[1]}`;
258
- }
259
-
260
- return `${contributors.slice(0, -1).join(', ')} and ${
261
- contributors[contributors.length - 1]
262
- }`;
263
- };
264
-
265
- Handlebars.registerHelper('commit-parser', function (...args) {
266
- const options = args.pop();
267
-
268
- const commits = args.flat().filter(Boolean).map(normalizeCommit);
269
-
270
- const unique = commits.reduce((map, commit) => {
271
- const key = getCommitKey(commit);
153
+ Handlebars.registerHelper('commit-parser', function (merges, commits, options) {
154
+ const commitsFromMerges = toArray(merges).map(normalizeMerge);
155
+ const directCommits = toArray(commits).map(normalizeCommit);
156
+ const result = uniqueCommits(commitsFromMerges.concat(directCommits));
272
157
 
273
- if (!key) {
274
- return map;
275
- }
276
-
277
- const previous = map.get(key);
278
-
279
- map.set(key, previous ? mergeCommits(previous, commit) : commit);
280
-
281
- return map;
282
- }, new Map());
283
-
284
- return options.fn([...unique.values()]);
158
+ return options.fn(result);
285
159
  });
286
160
 
287
161
  Handlebars.registerHelper('replaceCommit', function (context) {
288
162
  return new Handlebars.SafeString(formatCommitTitle(context.fn(this)));
289
163
  });
290
164
 
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
- });
298
-
299
165
  Handlebars.registerHelper('changelogEntry', function () {
300
166
  return new Handlebars.SafeString(formatChangelogEntry(this));
301
167
  });
@@ -305,25 +171,4 @@ module.exports = function (Handlebars) {
305
171
 
306
172
  return string.replace(/^v/, '');
307
173
  });
308
-
309
- Handlebars.registerHelper('contributors', function (...args) {
310
- const options = args.pop();
311
-
312
- const commits = args.flat().filter(Boolean).map(normalizeCommit);
313
-
314
- const contributors = [
315
- ...new Set(
316
- commits.map(getCommitAuthor).map(normalizeContributor).filter(Boolean),
317
- ),
318
- ];
319
-
320
- if (!contributors.length) {
321
- return '';
322
- }
323
-
324
- return options.fn({
325
- contributors,
326
- text: `Thanks ${formatContributors(contributors)}!`,
327
- });
328
- });
329
174
  };
package/template.hbs CHANGED
@@ -18,6 +18,10 @@
18
18
  - {{changelogEntry}}
19
19
  {{/commit-list}}
20
20
 
21
+ {{#commit-list this heading='### ⚡ Performance Improvements' message='^perf:|^perf\(' exclude='^(feat|fix|perf)(\([^)]*\))!:'}}
22
+ - {{changelogEntry}}
23
+ {{/commit-list}}
24
+
21
25
  {{/commit-parser}}
22
26
 
23
27
  {{/each}}
@@ -1,29 +0,0 @@
1
- {{! prettier-ignore }}
2
- {{#each releases}}
3
- {{#if tag}}
4
- ##{{#unless major}}#{{/unless}} [{{#replaceTitle}}{{title}}{{/replaceTitle}}]({{href}}) ({{isoDate}})
5
- {{/if}}
6
-
7
- {{#commit-parser merges commits}}
8
-
9
- {{#commit-list this heading='### ⚠️ BREAKING CHANGES' message='^(feat|fix|perf)(\([^)]*\))!:' }}
10
- - {{changelogEntry}}
11
- {{/commit-list}}
12
-
13
- {{#commit-list this heading='### 🚀 Features' message='^feat:|^feat\(' exclude='^(feat|fix|perf)(\([^)]*\))!:'}}
14
- - {{changelogEntry}}
15
- {{/commit-list}}
16
-
17
- {{#commit-list this heading='### 🐞 Bug Fixes' message='^fix:|^fix\(' exclude='^(feat|fix|perf)(\([^)]*\))!:'}}
18
- - {{changelogEntry}}
19
- {{/commit-list}}
20
-
21
- {{/commit-parser}}
22
-
23
- {{#contributors commits merges}}
24
- ### Contributors
25
-
26
- {{text}}
27
- {{/contributors}}
28
-
29
- {{/each}}