@taiga-ui/auto-changelog-config 0.492.0 → 0.494.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.492.0",
3
+ "version": "0.494.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}} ([#{{pullRequest.id}}]({{pullRequest.href}})){{/if}} [({{shorthash}})]({{href}})
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}}
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}} ([#{{pullRequest.id}}]({{pullRequest.href}})){{/if}} [({{shorthash}})]({{href}})
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}}
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}} ([#{{pullRequest.id}}]({{pullRequest.href}})){{/if}} [({{shorthash}})]({{href}})
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}}
19
19
  {{/commit-list}}
20
20
 
21
21
  {{/commit-parser}}
package/setup.js CHANGED
@@ -1,21 +1,187 @@
1
1
  /* eslint-disable @typescript-eslint/no-invalid-this */
2
2
  module.exports = function (Handlebars) {
3
+ const firstNonEmptyString = (...values) =>
4
+ values.map((value) => String(value ?? '').trim()).find(Boolean) ?? '';
5
+
6
+ const getPullRequestId = (href) => {
7
+ const [, id = ''] =
8
+ String(href ?? '').match(
9
+ /\/(?:pull|merge_requests|pull-requests)\/(\d+)(?:$|[/?#])/,
10
+ ) ?? [];
11
+
12
+ return id;
13
+ };
14
+
15
+ const getPullRequestIdFromText = (text) => {
16
+ const [, id = ''] = String(text ?? '').match(/\s\(#(\d+)\)\s*$/) ?? [];
17
+
18
+ return id;
19
+ };
20
+
21
+ const isPullRequestHref = (href) =>
22
+ /\/(?:pull|merge_requests|pull-requests)\/\d+(?:$|[/?#])/.test(
23
+ String(href ?? ''),
24
+ );
25
+
26
+ const getCommitHashFromHref = (href) => {
27
+ const [, hash = ''] =
28
+ String(href ?? '').match(/\/commit\/([a-f\d]{7,40})(?:$|[/?#])/) ?? [];
29
+
30
+ return hash;
31
+ };
32
+
33
+ const getRepositoryHref = (href) => {
34
+ const [, repositoryHref = ''] =
35
+ String(href ?? '').match(/^(https?:\/\/[^/]+\/[^/]+\/[^/]+)(?:\/|$)/) ?? [];
36
+
37
+ return repositoryHref;
38
+ };
39
+
40
+ const getCommitHref = (commit, pullRequest) => {
41
+ const href = firstNonEmptyString(commit.commitHref, commit.href);
42
+
43
+ if (href.includes('/commit/')) {
44
+ return href;
45
+ }
46
+
47
+ const hash = firstNonEmptyString(
48
+ commit.hash,
49
+ commit.shorthash,
50
+ getCommitHashFromHref(href),
51
+ );
52
+
53
+ const repositoryHref = getRepositoryHref(
54
+ firstNonEmptyString(pullRequest?.href, href),
55
+ );
56
+
57
+ return hash && repositoryHref ? `${repositoryHref}/commit/${hash}` : '';
58
+ };
59
+
60
+ const getCommitHash = (commit, commitHref) =>
61
+ firstNonEmptyString(
62
+ commit.commitHash,
63
+ commit.shorthash,
64
+ getCommitHashFromHref(commitHref),
65
+ String(commit.hash ?? '').slice(0, 7),
66
+ ).slice(0, 7);
67
+
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
+ const normalizeCommit = (commit) => {
96
+ const subject = firstNonEmptyString(
97
+ commit.subject,
98
+ commit.pullRequest?.title,
99
+ commit.title,
100
+ commit.message,
101
+ );
102
+
103
+ const pullRequest = normalizePullRequest(commit, subject);
104
+ const commitHref = getCommitHref(commit, pullRequest);
105
+ const commitHash = getCommitHash(commit, commitHref);
106
+
107
+ return {
108
+ ...commit,
109
+ commitHash,
110
+ commitHref,
111
+ message: firstNonEmptyString(commit.message, subject),
112
+ pullRequest,
113
+ subject,
114
+ };
115
+ };
116
+
117
+ const getCommitKey = (commit) =>
118
+ 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}`,
123
+ );
124
+
125
+ const mergePullRequests = (left, right) => {
126
+ if (!left && !right) {
127
+ return;
128
+ }
129
+
130
+ if (!left) {
131
+ return right;
132
+ }
133
+
134
+ if (!right) {
135
+ return left;
136
+ }
137
+
138
+ return {
139
+ ...left,
140
+ ...right,
141
+ id: firstNonEmptyString(left.id, right.id),
142
+ author: left.author ?? right.author,
143
+ href: firstNonEmptyString(left.href, right.href),
144
+ };
145
+ };
146
+
147
+ const mergeCommits = (left, right) => ({
148
+ ...left,
149
+ ...right,
150
+ commitHash: firstNonEmptyString(left.commitHash, right.commitHash),
151
+ commitHref: firstNonEmptyString(left.commitHref, right.commitHref),
152
+ hash: firstNonEmptyString(left.hash, right.hash),
153
+ href: firstNonEmptyString(left.href, right.href),
154
+ message: firstNonEmptyString(left.message, right.message),
155
+ pullRequest: mergePullRequests(left.pullRequest, right.pullRequest),
156
+ shorthash: firstNonEmptyString(left.shorthash, right.shorthash),
157
+ subject: firstNonEmptyString(left.subject, right.subject),
158
+ });
159
+
3
160
  const getCommitAuthor = (commit) =>
4
161
  commit.pullRequest?.author?.login ??
162
+ commit.pullRequest?.user?.login ??
163
+ commit.author?.login ??
164
+ commit.user?.login ??
5
165
  commit.pullRequest?.author ??
6
166
  commit.author ??
7
167
  '';
8
168
 
169
+ const isGithubLogin = (name) => /^[a-z\d](?:[a-z\d-]{0,37}[a-z\d])?$/i.test(name);
170
+
9
171
  const normalizeContributor = (author) => {
10
- const name = String(author).trim().replace(/^@/, '') ?? '';
172
+ const name = String(author).trim().replace(/^@/, '');
173
+ const lowerName = name.toLowerCase();
11
174
 
12
175
  const isBot =
13
- name.endsWith('bot') ||
14
- name.endsWith('[bot]') ||
15
- name === 'github-actions' ||
16
- name === 'renovate';
176
+ lowerName.endsWith('[bot]') ||
177
+ lowerName.endsWith('-bot') ||
178
+ lowerName === 'dependabot' ||
179
+ lowerName === 'renovatebot' ||
180
+ lowerName === 'github-actions' ||
181
+ lowerName === 'renovate' ||
182
+ lowerName === 'gemini-code-assist';
17
183
 
18
- if (!name || isBot) {
184
+ if (!name || isBot || !isGithubLogin(name)) {
19
185
  return '';
20
186
  }
21
187
 
@@ -39,33 +205,39 @@ module.exports = function (Handlebars) {
39
205
  Handlebars.registerHelper('commit-parser', function (...args) {
40
206
  const options = args.pop();
41
207
 
42
- const commits = args.flat().filter(Boolean);
208
+ const commits = args.flat().filter(Boolean).map(normalizeCommit);
43
209
 
44
- const unique = [
45
- ...new Map(
46
- commits.map((commit) => [
47
- commit.hash ?? commit.shorthash ?? commit.href ?? commit.subject,
48
- commit,
49
- ]),
50
- ).values(),
51
- ];
210
+ const unique = commits.reduce((map, commit) => {
211
+ const key = getCommitKey(commit);
212
+
213
+ if (!key) {
214
+ return map;
215
+ }
216
+
217
+ const previous = map.get(key);
218
+
219
+ map.set(key, previous ? mergeCommits(previous, commit) : commit);
220
+
221
+ return map;
222
+ }, new Map());
52
223
 
53
- return options.fn(unique);
224
+ return options.fn([...unique.values()]);
54
225
  });
55
226
 
56
227
  Handlebars.registerHelper('replaceCommit', function (context) {
57
228
  const commit =
58
229
  /^(?:build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)\s?(?:\((?<scope>[^)]*)\))?!?: (?<title>.*)$/;
59
230
 
60
- const string = String(context.fn(this));
231
+ const string = String(context.fn(this)).trim();
61
232
  const {scope = '', title = ''} = commit.exec(string)?.groups ?? {};
62
- const result = scope ? `**${scope.toLowerCase()}**: ${title}` : title;
233
+ const cleanTitle = title.replace(/\s\(#\d+\)\s*$/, '');
234
+ const result = scope ? `**${scope.toLowerCase()}**: ${cleanTitle}` : cleanTitle;
63
235
 
64
- return result || 'empty commit name';
236
+ return result || string || 'empty commit name';
65
237
  });
66
238
 
67
239
  Handlebars.registerHelper('replaceTitle', function (context) {
68
- const string = String(context.fn(this));
240
+ const string = String(context.fn(this)).trim();
69
241
 
70
242
  return string.replace(/^v/, '');
71
243
  });
@@ -73,7 +245,7 @@ module.exports = function (Handlebars) {
73
245
  Handlebars.registerHelper('contributors', function (...args) {
74
246
  const options = args.pop();
75
247
 
76
- const commits = args.flat().filter(Boolean);
248
+ const commits = args.flat().filter(Boolean).map(normalizeCommit);
77
249
 
78
250
  const contributors = [
79
251
  ...new Set(
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}} ([#{{pullRequest.id}}]({{pullRequest.href}})){{/if}} [({{shorthash}})]({{href}})
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}}
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}} ([#{{pullRequest.id}}]({{pullRequest.href}})){{/if}} [({{shorthash}})]({{href}})
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}}
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}} ([#{{pullRequest.id}}]({{pullRequest.href}})){{/if}} [({{shorthash}})]({{href}})
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}}
19
19
  {{/commit-list}}
20
20
 
21
21
  {{/commit-parser}}