release-it 15.9.2 → 15.10.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.
@@ -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.2",
3
+ "version": "15.10.0",
4
4
  "description": "Generic CLI tool to automate versioning and package publishing related tasks.",
5
5
  "keywords": [
6
6
  "build",
@@ -49,7 +49,6 @@
49
49
  ],
50
50
  "scripts": {
51
51
  "lint": "eslint lib test",
52
- "knip": "knip",
53
52
  "format": "prettier --write \"{lib,test}/**/*.js\"",
54
53
  "test": "ava --no-worker-threads",
55
54
  "release": "./bin/release-it.js"
@@ -71,11 +70,12 @@
71
70
  "got": "12.6.0",
72
71
  "inquirer": "9.1.5",
73
72
  "is-ci": "3.0.1",
73
+ "issue-parser": "6.0.0",
74
74
  "lodash": "4.17.21",
75
75
  "mime-types": "2.1.35",
76
76
  "new-github-release-url": "2.0.0",
77
77
  "node-fetch": "3.3.1",
78
- "open": "9.0.0",
78
+ "open": "9.1.0",
79
79
  "ora": "6.3.0",
80
80
  "os-name": "5.1.0",
81
81
  "promise.allsettled": "1.0.6",
@@ -90,17 +90,16 @@
90
90
  "devDependencies": {
91
91
  "@octokit/request-error": "3.0.3",
92
92
  "ava": "5.2.0",
93
- "eslint": "8.36.0",
93
+ "eslint": "8.37.0",
94
94
  "eslint-config-prettier": "8.8.0",
95
95
  "eslint-plugin-ava": "14.0.0",
96
96
  "eslint-plugin-import": "2.27.5",
97
97
  "eslint-plugin-prettier": "4.2.1",
98
- "knip": "2.1.1",
99
98
  "mock-fs": "5.2.0",
100
99
  "mock-stdio": "1.0.3",
101
100
  "nock": "13.3.0",
102
101
  "prettier": "2.8.7",
103
- "sinon": "15.0.2",
102
+ "sinon": "15.0.3",
104
103
  "strip-ansi": "7.0.1"
105
104
  },
106
105
  "engines": {