release-it 18.0.0 → 18.1.1
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/lib/plugin/GitRelease.js +7 -3
- package/lib/plugin/github/GitHub.js +39 -8
- package/package.json +1 -1
- package/schema/github.json +18 -0
- package/types/config.d.ts +1 -1
package/lib/plugin/GitRelease.js
CHANGED
|
@@ -18,7 +18,8 @@ class GitRelease extends GitBase {
|
|
|
18
18
|
'tagMatch',
|
|
19
19
|
'getLatestTagFromAllRefs',
|
|
20
20
|
'pushRepo',
|
|
21
|
-
'changelog'
|
|
21
|
+
'changelog',
|
|
22
|
+
'commit'
|
|
22
23
|
]);
|
|
23
24
|
return _.defaults(baseOptions, gitOptions);
|
|
24
25
|
}
|
|
@@ -31,7 +32,8 @@ class GitRelease extends GitBase {
|
|
|
31
32
|
async beforeRelease() {
|
|
32
33
|
const { releaseNotes: script } = this.options;
|
|
33
34
|
const { changelog } = this.config.getContext();
|
|
34
|
-
const releaseNotes =
|
|
35
|
+
const releaseNotes =
|
|
36
|
+
typeof script === 'function' || typeof script === 'string' ? await this.processReleaseNotes(script) : changelog;
|
|
35
37
|
this.setContext({ releaseNotes });
|
|
36
38
|
if (releaseNotes !== changelog) {
|
|
37
39
|
this.log.preview({ title: 'release notes', text: releaseNotes });
|
|
@@ -42,7 +44,9 @@ class GitRelease extends GitBase {
|
|
|
42
44
|
if (typeof script === 'function') {
|
|
43
45
|
const ctx = Object.assign({}, this.config.getContext(), { [this.namespace]: this.getContext() });
|
|
44
46
|
return script(ctx);
|
|
45
|
-
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (typeof script === 'string') {
|
|
46
50
|
return this.exec(script);
|
|
47
51
|
}
|
|
48
52
|
}
|
|
@@ -211,7 +211,7 @@ class GitHub extends Release {
|
|
|
211
211
|
}
|
|
212
212
|
}
|
|
213
213
|
|
|
214
|
-
getOctokitReleaseOptions(options = {}) {
|
|
214
|
+
async getOctokitReleaseOptions(options = {}) {
|
|
215
215
|
const { owner, project: repo } = this.getContext('repo');
|
|
216
216
|
const {
|
|
217
217
|
releaseName,
|
|
@@ -225,7 +225,12 @@ class GitHub extends Release {
|
|
|
225
225
|
const { version, releaseNotes, isUpdate } = this.getContext();
|
|
226
226
|
const { isPreRelease } = parseVersion(version);
|
|
227
227
|
const name = format(releaseName, this.config.getContext());
|
|
228
|
-
const
|
|
228
|
+
const releaseNotesObject = this.options.releaseNotes;
|
|
229
|
+
const body = autoGenerate
|
|
230
|
+
? isUpdate
|
|
231
|
+
? null
|
|
232
|
+
: ''
|
|
233
|
+
: truncateBody(releaseNotesObject?.commit ? await this.renderReleaseNotes(releaseNotesObject) : releaseNotes);
|
|
229
234
|
|
|
230
235
|
/**
|
|
231
236
|
* @type {CreateReleaseOptions}
|
|
@@ -254,7 +259,7 @@ class GitHub extends Release {
|
|
|
254
259
|
}
|
|
255
260
|
|
|
256
261
|
async createRelease() {
|
|
257
|
-
const options = this.getOctokitReleaseOptions();
|
|
262
|
+
const options = await this.getOctokitReleaseOptions();
|
|
258
263
|
const { isDryRun } = this.config;
|
|
259
264
|
|
|
260
265
|
this.log.exec(`octokit repos.createRelease "${options.name}" (${options.tag_name})`, { isDryRun });
|
|
@@ -350,11 +355,11 @@ class GitHub extends Release {
|
|
|
350
355
|
return `https://${host}/${repository}/releases/tag/${tagName}`;
|
|
351
356
|
}
|
|
352
357
|
|
|
353
|
-
generateWebUrl() {
|
|
358
|
+
async generateWebUrl() {
|
|
354
359
|
const host = this.options.host || this.getContext('repo.host');
|
|
355
360
|
const isGitHub = host === 'github.com';
|
|
356
361
|
|
|
357
|
-
const options = this.getOctokitReleaseOptions();
|
|
362
|
+
const options = await this.getOctokitReleaseOptions();
|
|
358
363
|
const url = newGithubReleaseUrl({
|
|
359
364
|
user: options.owner,
|
|
360
365
|
repo: options.repo,
|
|
@@ -369,7 +374,7 @@ class GitHub extends Release {
|
|
|
369
374
|
async createWebRelease() {
|
|
370
375
|
const { isCI } = this.config;
|
|
371
376
|
const { tagName } = this.config.getContext();
|
|
372
|
-
const url = this.generateWebUrl();
|
|
377
|
+
const url = await this.generateWebUrl();
|
|
373
378
|
if (isCI) {
|
|
374
379
|
this.setContext({ isReleased: true, releaseUrl: url });
|
|
375
380
|
} else {
|
|
@@ -380,10 +385,10 @@ class GitHub extends Release {
|
|
|
380
385
|
}
|
|
381
386
|
}
|
|
382
387
|
|
|
383
|
-
updateRelease() {
|
|
388
|
+
async updateRelease() {
|
|
384
389
|
const { isDryRun } = this.config;
|
|
385
390
|
const release_id = this.getContext('releaseId');
|
|
386
|
-
const options = this.getOctokitReleaseOptions({ release_id });
|
|
391
|
+
const options = await this.getOctokitReleaseOptions({ release_id });
|
|
387
392
|
|
|
388
393
|
this.log.exec(`octokit repos.updateRelease (${options.tag_name})`, { isDryRun });
|
|
389
394
|
|
|
@@ -438,6 +443,32 @@ class GitHub extends Release {
|
|
|
438
443
|
}
|
|
439
444
|
}
|
|
440
445
|
}
|
|
446
|
+
|
|
447
|
+
async getCommits() {
|
|
448
|
+
const { owner, project: repo } = this.getContext('repo');
|
|
449
|
+
const { latestTag } = this.config.getContext();
|
|
450
|
+
this.debug({ owner, repo, base: latestTag, head: 'HEAD' });
|
|
451
|
+
const { data } = await this.client.repos.compareCommits({ owner, repo, base: latestTag, head: 'HEAD' });
|
|
452
|
+
return data.commits;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
async renderReleaseNotes(releaseNotes) {
|
|
456
|
+
const { commit: template, excludeMatches = [] } = releaseNotes;
|
|
457
|
+
const commits = await this.getCommits();
|
|
458
|
+
|
|
459
|
+
if (this.options.commit) commits.pop();
|
|
460
|
+
|
|
461
|
+
return commits
|
|
462
|
+
.map(commit => {
|
|
463
|
+
commit.commit.subject = commit.commit.message.split('\n')[0];
|
|
464
|
+
const partial = template.replace(/(?<!\$)\{((?:[^{}]|\${[^}]+})+)\}/g, (_, block) => {
|
|
465
|
+
const rendered = format(block, commit);
|
|
466
|
+
return excludeMatches.some(match => rendered.includes(match)) ? '' : rendered;
|
|
467
|
+
});
|
|
468
|
+
return format(partial, commit);
|
|
469
|
+
})
|
|
470
|
+
.join('\n');
|
|
471
|
+
}
|
|
441
472
|
}
|
|
442
473
|
|
|
443
474
|
export default GitHub;
|
package/package.json
CHANGED
package/schema/github.json
CHANGED
|
@@ -14,6 +14,24 @@
|
|
|
14
14
|
"default": "Release ${version}"
|
|
15
15
|
},
|
|
16
16
|
"releaseNotes": {
|
|
17
|
+
"anyOf": [
|
|
18
|
+
{ "type": ["string", "null"] },
|
|
19
|
+
{
|
|
20
|
+
"type": "object",
|
|
21
|
+
"properties": {
|
|
22
|
+
"commit": {
|
|
23
|
+
"type": "string"
|
|
24
|
+
},
|
|
25
|
+
"excludeMatches": {
|
|
26
|
+
"type": "array",
|
|
27
|
+
"items": {
|
|
28
|
+
"type": "string"
|
|
29
|
+
},
|
|
30
|
+
"default": []
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
],
|
|
17
35
|
"default": null
|
|
18
36
|
},
|
|
19
37
|
"autoGenerate": {
|
package/types/config.d.ts
CHANGED
|
@@ -106,7 +106,7 @@ export interface Config {
|
|
|
106
106
|
releaseName?: string;
|
|
107
107
|
|
|
108
108
|
/** @default null */
|
|
109
|
-
releaseNotes?:
|
|
109
|
+
releaseNotes?: string | null | (() => string | Promise<string>) | { commit?: string; excludeMatches?: string[] };
|
|
110
110
|
|
|
111
111
|
/** @default false */
|
|
112
112
|
autoGenerate?: boolean;
|