release-it 15.9.3 → 15.10.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/README.md CHANGED
@@ -20,19 +20,6 @@ system, and hooks to execute any command you need to test, build, and/or publish
20
20
  [![Action Status](https://github.com/release-it/release-it/workflows/Cross-OS%20Tests/badge.svg)](https://github.com/release-it/release-it/actions)
21
21
  [![npm version](https://badge.fury.io/js/release-it.svg)](https://www.npmjs.com/package/release-it)
22
22
 
23
- ## Announcement
24
-
25
- The latest major version is v15, supporting Node.js 14 and up (as Node.js v12 is EOL). Use release-it v14 for
26
- environments running Node.js v10 and v12. Also see [CHANGELOG.md](./CHANGELOG.md).
27
-
28
- ## Links
29
-
30
- - See [CHANGELOG.md](./CHANGELOG.md) for major/breaking updates, and
31
- [releases](https://github.com/release-it/release-it/releases) for a detailed version history.
32
- - To **contribute**, please read [CONTRIBUTING.md](./.github/CONTRIBUTING.md) first.
33
- - Please [open an issue](https://github.com/release-it/release-it/issues/new) if anything is missing or unclear in this
34
- documentation.
35
-
36
23
  ## Installation
37
24
 
38
25
  Although release-it is a **generic** release tool, most projects use it for projects with npm packages. The recommended
@@ -56,66 +43,45 @@ npm install -D release-it
56
43
  "release": "release-it"
57
44
  },
58
45
  "devDependencies": {
59
- "release-it": "*"
46
+ "release-it": "^15.10.0"
60
47
  }
61
48
  }
62
49
  ```
63
50
 
64
- Now you can run `npm run release` from the command line (put release-it arguments behind the `-- `):
65
-
66
- ```bash
67
- npm run release
68
- npm run release -- minor --ci
69
- ```
70
-
71
- ### Global Installation
72
-
73
- #### Using npx or npm
51
+ ## Usage
74
52
 
75
- Use npx to run release-it directly from anywhere:
53
+ Run release-it from the root of the project using either `npm run` or `npx`:
76
54
 
77
55
  ```bash
56
+ npm run release
78
57
  npx release-it
79
58
  ```
80
59
 
81
- Or use npm to install and run release-it globally:
82
-
83
- ```bash
84
- npm install -g release-it
85
- ```
86
-
87
- #### Using Homebrew
88
-
89
- ```bash
90
- brew install release-it
91
- ```
92
-
93
- ## Usage
94
-
95
- Release a new version:
60
+ You will be prompted to select the new version, and more prompts will follow based on your configuration.
96
61
 
97
- ```bash
98
- release-it
99
- ```
62
+ ## Yarn
100
63
 
101
- You will be prompted to select the new version, and more prompts will follow based on your configuration.
64
+ Using Yarn? Please see the [npm section on Yarn](./docs/npm.md#yarn).
102
65
 
103
- Run release-it from the root of the project to prevent potential issues.
66
+ ## Global Installation
104
67
 
105
- ## Dry Runs
68
+ Per-project installation as shown above is recommended, but global installs are supported as well:
106
69
 
107
- Use `--dry-run` to show the interactivity and the commands it _would_ execute.
70
+ - From npm: `npm install -g release-it`
71
+ - From Homebrew: `brew install release-it`
108
72
 
109
- See [Dry Runs](./docs/dry-runs.md) for more details.
73
+ ## GitHub Actions
110
74
 
111
- To print the next version without releasing anything, add the `--release-version` flag.
75
+ Want to use release-it with GitHub Actions to fully automate the whole process? Enjoy this great walk-through:
76
+ [How to use GitHub Actions & Release-It to Easily Release Your Code](https://www.youtube.com/watch?v=7pBcuT7j_A0) (by
77
+ [David from Kodaps](https://twitter.com/KodapsAcademy)).
112
78
 
113
- To print the changelog without releasing anything, add the `--changelog` flag.
79
+ See [Continuous Integration environments](./docs/ci.md) for more details.
114
80
 
115
81
  ## Configuration
116
82
 
117
83
  Out of the box, release-it has sane defaults, and [plenty of options](./config/release-it.json) to configure it. Most
118
- projects use a `.release-it.json` in the project root, or a `release-it` property in `package.json`.
84
+ projects use a `.release-it.json` file in the project root, or a `release-it` property in `package.json`.
119
85
 
120
86
  → See [Configuration](./docs/configuration.md) for more details.
121
87
 
@@ -198,7 +164,8 @@ changelog serves as the release notes for the GitHub or GitLab release.
198
164
 
199
165
  The [default command](./config/release-it.json) is based on `git log ...`. This setting (`git.changelog`) can be
200
166
  overridden. To further customize the release notes for the GitHub or GitLab release, there's `github.releaseNotes` or
201
- `gitlab.releaseNotes`. Make sure any of these commands output the changelog to `stdout`. Plugins are available for:
167
+ `gitlab.releaseNotes`. Make sure any of these commands output the changelog to `stdout`. Note that release-it by default
168
+ is agnostic to commit message conventions. Plugins are available for:
202
169
 
203
170
  - GitHub and GitLab Releases
204
171
  - auto-changelog
@@ -296,6 +263,24 @@ release-it --'hooks.after:release="echo Successfully released ${name} v${version
296
263
 
297
264
  Using Inquirer.js inside custom hook scripts might cause issues (since release-it also uses this itself).
298
265
 
266
+ ## Dry Runs
267
+
268
+ Use `--dry-run` to show the interactivity and the commands it _would_ execute.
269
+
270
+ → See [Dry Runs](./docs/dry-runs.md) for more details.
271
+
272
+ To print the next version without releasing anything, add the `--release-version` flag.
273
+
274
+ To print the changelog without releasing anything, add the `--changelog` flag.
275
+
276
+ ## Troubleshooting & debugging
277
+
278
+ - With `release-it --verbose` (or `-V`), release-it prints the output of every user-defined [hook](#hooks).
279
+ - With `release-it -VV`, release-it also prints the output of every internal command.
280
+ - Use `NODE_DEBUG=release-it:* release-it [...]` to print configuration and more error details.
281
+
282
+ Use `verbose: 2` in a configuration file to have the equivalent of `-VV` on the command line.
283
+
299
284
  ## Plugins
300
285
 
301
286
  Since v11, release-it can be extended in many, many ways. Here are some plugins:
@@ -317,22 +302,6 @@ Internally, release-it uses its own plugin architecture (for Git, GitHub, GitLab
317
302
 
318
303
  → See [plugins](./docs/plugins.md) for documentation to write plugins.
319
304
 
320
- ## Distribution repository
321
-
322
- Deprecated. Please see [distribution repository](./docs/recipes/distribution-repo.md) for more details.
323
-
324
- ## Metrics
325
-
326
- In release-it v15, anonymous metrics have been removed from the codebase and no data is sent or stored anywhere.
327
-
328
- ## Troubleshooting & debugging
329
-
330
- - With `release-it --verbose` (or `-V`), release-it prints the output of every user-defined [hook](#hooks).
331
- - With `release-it -VV`, release-it also prints the output of every internal command.
332
- - Use `NODE_DEBUG=release-it:* release-it [...]` to print configuration and more error details.
333
-
334
- Use `verbose: 2` in a configuration file to have the equivalent of `-VV` on the command line.
335
-
336
305
  ## Use release-it programmatically
337
306
 
338
307
  While mostly used as a CLI tool, release-it can be used as a dependency to integrate in your own scripts. See
@@ -361,6 +330,19 @@ While mostly used as a CLI tool, release-it can be used as a dependency to integ
361
330
  - [Repositories that depend on release-it](https://github.com/release-it/release-it/network/dependents)
362
331
  - GitHub search for [path:\*\*/.release-it.json](https://github.com/search?q=path%3A**%2F.release-it.json&type=code)
363
332
 
333
+ ## Legacy Node.js
334
+
335
+ The latest major version is v15, supporting Node.js 14 and up (as Node.js v12 is EOL). Use release-it v14 for
336
+ environments running Node.js v10 and v12. Also see [CHANGELOG.md](./CHANGELOG.md).
337
+
338
+ ## Links
339
+
340
+ - See [CHANGELOG.md](./CHANGELOG.md) for major/breaking updates, and
341
+ [releases](https://github.com/release-it/release-it/releases) for a detailed version history.
342
+ - To **contribute**, please read [CONTRIBUTING.md](./.github/CONTRIBUTING.md) first.
343
+ - Please [open an issue](https://github.com/release-it/release-it/issues/new) if anything is missing or unclear in this
344
+ documentation.
345
+
364
346
  ## License
365
347
 
366
348
  [MIT](./LICENSE)
@@ -47,7 +47,12 @@
47
47
  "timeout": 0,
48
48
  "proxy": null,
49
49
  "skipChecks": false,
50
- "web": false
50
+ "web": false,
51
+ "comments": {
52
+ "submit": false,
53
+ "issue": ":rocket: _This issue has been resolved in v${version}. See [${releaseName}](${releaseUrl}) for release notes._",
54
+ "pr": ":rocket: _This pull request is included in v${version}. See [${releaseName}](${releaseUrl}) for release notes._"
55
+ }
51
56
  },
52
57
  "gitlab": {
53
58
  "release": false,
@@ -12,6 +12,7 @@ import ProxyAgent from 'proxy-agent';
12
12
  import { format, parseVersion, readJSON, e } from '../../util.js';
13
13
  import Release from '../GitRelease.js';
14
14
  import prompts from './prompts.js';
15
+ import { getCommitsFromChangelog, getResolvedIssuesFromChangelog, searchQueries } from './util.js';
15
16
 
16
17
  const pkg = readJSON(new URL('../../../package.json', import.meta.url));
17
18
 
@@ -142,7 +143,8 @@ class GitHub extends Release {
142
143
  } else {
143
144
  const release = async () => {
144
145
  await this[publishMethod]();
145
- return this.uploadAssets();
146
+ await this.uploadAssets();
147
+ return isUpdate ? Promise.resolve() : this.commentOnResolvedItems();
146
148
  };
147
149
  return this.step({ task: release, label: `GitHub ${type} release`, prompt: 'release' });
148
150
  }
@@ -362,6 +364,37 @@ class GitHub extends Release {
362
364
  }
363
365
  });
364
366
  }
367
+
368
+ async commentOnResolvedItems() {
369
+ const { isDryRun } = this.config;
370
+ const { owner, project: repo } = this.getContext('repo');
371
+ const { changelog } = this.config.getContext();
372
+ const { comments } = this.options;
373
+ const { submit, issue, pr } = comments;
374
+ const context = this.getContext();
375
+
376
+ if (!submit || !changelog || isDryRun) return;
377
+
378
+ const shas = getCommitsFromChangelog(changelog);
379
+ const searchResults = await Promise.all(searchQueries(this.client, owner, repo, shas));
380
+ const mergedPullRequests = searchResults.flatMap(items => items.map(item => ({ type: 'pr', number: item.number })));
381
+
382
+ const host = 'https://' + (this.options.host || this.getContext('repo.host'));
383
+ const resolvedIssues = getResolvedIssuesFromChangelog(host, owner, repo, changelog);
384
+
385
+ for (const item of [...resolvedIssues, ...mergedPullRequests]) {
386
+ const { type, number } = item;
387
+ const comment = format(format(type === 'pr' ? pr : issue, context), context);
388
+ const url = `${host}/${owner}/${repo}/${type === 'pr' ? 'pull' : 'issues'}/${number}`;
389
+
390
+ try {
391
+ await this.client.issues.createComment({ owner, repo, issue_number: number, body: comment });
392
+ this.log.log(`● Commented on ${url}`);
393
+ } catch (error) {
394
+ this.log.log(`✕ Failed to comment on ${url}`);
395
+ }
396
+ }
397
+ }
365
398
  }
366
399
 
367
400
  export default GitHub;
@@ -0,0 +1,39 @@
1
+ // Totally much borrowed from https://github.com/semantic-release/github/blob/master/lib/success.js
2
+ import issueParser from 'issue-parser';
3
+
4
+ const getSearchQueries = (base, commits, separator = '+') => {
5
+ return commits.reduce((searches, commit) => {
6
+ const lastSearch = searches[searches.length - 1];
7
+ if (lastSearch && lastSearch.length + commit.length <= 256 - separator.length) {
8
+ searches[searches.length - 1] = `${lastSearch}${separator}${commit}`;
9
+ } else {
10
+ searches.push(`${base}${separator}${commit}`);
11
+ }
12
+
13
+ return searches;
14
+ }, []);
15
+ };
16
+
17
+ export const searchQueries = (client, owner, repo, shas) =>
18
+ getSearchQueries(`repo:${owner}/${repo}+type:pr+is:merged`, shas).map(
19
+ async q => (await client.search.issuesAndPullRequests({ q })).data.items
20
+ );
21
+
22
+ export const getCommitsFromChangelog = changelog => {
23
+ const regex = /\(([a-f0-9]{7,})\)/i;
24
+ return changelog.split('\n').flatMap(message => {
25
+ const match = message.match(regex);
26
+ if (match) return match[1];
27
+ return [];
28
+ });
29
+ };
30
+
31
+ export const getResolvedIssuesFromChangelog = (host, owner, repo, changelog) => {
32
+ const parser = issueParser('github', { hosts: [host] });
33
+ return changelog
34
+ .split('\n')
35
+ .map(parser)
36
+ .flatMap(parsed => parsed.actions.close)
37
+ .filter(action => !action.slug || action.slug === `${owner}/${repo}`)
38
+ .map(action => ({ type: 'issue', number: parseInt(action.issue, 10) }));
39
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "release-it",
3
- "version": "15.9.3",
3
+ "version": "15.10.1",
4
4
  "description": "Generic CLI tool to automate versioning and package publishing related tasks.",
5
5
  "keywords": [
6
6
  "build",
@@ -70,11 +70,12 @@
70
70
  "got": "12.6.0",
71
71
  "inquirer": "9.1.5",
72
72
  "is-ci": "3.0.1",
73
+ "issue-parser": "6.0.0",
73
74
  "lodash": "4.17.21",
74
75
  "mime-types": "2.1.35",
75
76
  "new-github-release-url": "2.0.0",
76
77
  "node-fetch": "3.3.1",
77
- "open": "9.0.0",
78
+ "open": "9.1.0",
78
79
  "ora": "6.3.0",
79
80
  "os-name": "5.1.0",
80
81
  "promise.allsettled": "1.0.6",
@@ -89,7 +90,7 @@
89
90
  "devDependencies": {
90
91
  "@octokit/request-error": "3.0.3",
91
92
  "ava": "5.2.0",
92
- "eslint": "8.36.0",
93
+ "eslint": "8.37.0",
93
94
  "eslint-config-prettier": "8.8.0",
94
95
  "eslint-plugin-ava": "14.0.0",
95
96
  "eslint-plugin-import": "2.27.5",
@@ -98,7 +99,7 @@
98
99
  "mock-stdio": "1.0.3",
99
100
  "nock": "13.3.0",
100
101
  "prettier": "2.8.7",
101
- "sinon": "15.0.2",
102
+ "sinon": "15.0.3",
102
103
  "strip-ansi": "7.0.1"
103
104
  },
104
105
  "engines": {