@graphcommerce/changeset-changelog 0.0.2 → 0.0.3-canary.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @graphcommerce/changeset-changelog
2
2
 
3
+ ## 0.0.3-canary.0
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1718](https://github.com/graphcommerce-org/graphcommerce/pull/1718) [`7cc186513`](https://github.com/graphcommerce-org/graphcommerce/commit/7cc186513e100eb85856fc194740a279bc6e5605) - Removed the 'Thanks!' from the release notes, make it more subtle ([@paales](https://github.com/paales))
8
+
3
9
  ## 0.0.2
4
10
 
5
11
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1,11 +1,73 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const changelog_github_1 = __importDefault(require("@changesets/changelog-github"));
3
+ const get_github_info_1 = require("@changesets/get-github-info");
7
4
  const changelogFunctions = {
8
5
  getDependencyReleaseLine: () => Promise.resolve(''),
9
- getReleaseLine: changelog_github_1.default.getReleaseLine,
6
+ getReleaseLine: async (changeset, type, options) => {
7
+ if (!options || !options.repo) {
8
+ throw new Error('Please provide a repo to this changelog generator like this:\n"changelog": ["@changesets/changelog-github", { "repo": "org/repo" }]');
9
+ }
10
+ let prFromSummary;
11
+ let commitFromSummary;
12
+ const usersFromSummary = [];
13
+ const replacedChangelog = changeset.summary
14
+ .replace(/^\s*(?:pr|pull|pull\s+request):\s*#?(\d+)/im, (_, pr) => {
15
+ const num = Number(pr);
16
+ if (!Number.isNaN(num))
17
+ prFromSummary = num;
18
+ return '';
19
+ })
20
+ .replace(/^\s*commit:\s*([^\s]+)/im, (_, commit) => {
21
+ commitFromSummary = commit;
22
+ return '';
23
+ })
24
+ .replace(/^\s*(?:author|user):\s*@?([^\s]+)/gim, (_, user) => {
25
+ usersFromSummary.push(user);
26
+ return '';
27
+ })
28
+ .trim();
29
+ const [firstLine, ...futureLines] = replacedChangelog.split('\n').map((l) => l.trimRight());
30
+ const linksNew = await (async () => {
31
+ if (prFromSummary !== undefined) {
32
+ let { links } = await (0, get_github_info_1.getInfoFromPullRequest)({
33
+ repo: options.repo,
34
+ pull: prFromSummary,
35
+ });
36
+ if (commitFromSummary) {
37
+ links = {
38
+ ...links,
39
+ commit: `[\`${commitFromSummary}\`](https://github.com/${options.repo}/commit/${commitFromSummary})`,
40
+ };
41
+ }
42
+ return links;
43
+ }
44
+ const commitToFetchFrom = commitFromSummary || changeset.commit;
45
+ if (commitToFetchFrom) {
46
+ const { links } = await (0, get_github_info_1.getInfo)({
47
+ repo: options.repo,
48
+ commit: commitToFetchFrom,
49
+ });
50
+ return links;
51
+ }
52
+ return {
53
+ commit: null,
54
+ pull: null,
55
+ user: null,
56
+ };
57
+ })();
58
+ const users = usersFromSummary.length
59
+ ? usersFromSummary
60
+ .filter((u) => !u.startsWith('apps'))
61
+ .map((userFromSummary) => `[@${userFromSummary}](https://github.com/${userFromSummary})`)
62
+ .join(', ')
63
+ : linksNew.user;
64
+ const prefix = [
65
+ linksNew.pull === null ? '' : ` ${linksNew.pull}`,
66
+ linksNew.commit === null ? '' : ` ${linksNew.commit}`,
67
+ ].join('');
68
+ return `\n\n-${prefix ? `${prefix} -` : ''} ${firstLine}\n${futureLines
69
+ .map((l) => ` ${l}`)
70
+ .join('\n')} (${users})`;
71
+ },
10
72
  };
11
73
  exports.default = changelogFunctions;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/changeset-changelog",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "0.0.2",
5
+ "version": "0.0.3-canary.0",
6
6
  "main": "dist/index.js",
7
7
  "typings": "dist/index.d.ts",
8
8
  "scripts": {
package/src/index.ts CHANGED
@@ -1,8 +1,82 @@
1
1
  import githubDefault from '@changesets/changelog-github'
2
+ import { getInfo, getInfoFromPullRequest } from '@changesets/get-github-info'
2
3
 
3
4
  const changelogFunctions: typeof githubDefault = {
4
5
  getDependencyReleaseLine: () => Promise.resolve(''),
5
- getReleaseLine: githubDefault.getReleaseLine,
6
+ getReleaseLine: async (changeset, type, options) => {
7
+ if (!options || !options.repo) {
8
+ throw new Error(
9
+ 'Please provide a repo to this changelog generator like this:\n"changelog": ["@changesets/changelog-github", { "repo": "org/repo" }]',
10
+ )
11
+ }
12
+
13
+ let prFromSummary: number | undefined
14
+ let commitFromSummary: string | undefined
15
+ const usersFromSummary: string[] = []
16
+
17
+ const replacedChangelog = changeset.summary
18
+ .replace(/^\s*(?:pr|pull|pull\s+request):\s*#?(\d+)/im, (_, pr) => {
19
+ const num = Number(pr)
20
+ if (!Number.isNaN(num)) prFromSummary = num
21
+ return ''
22
+ })
23
+ .replace(/^\s*commit:\s*([^\s]+)/im, (_, commit) => {
24
+ commitFromSummary = commit
25
+ return ''
26
+ })
27
+ .replace(/^\s*(?:author|user):\s*@?([^\s]+)/gim, (_, user: string) => {
28
+ usersFromSummary.push(user)
29
+ return ''
30
+ })
31
+ .trim()
32
+
33
+ const [firstLine, ...futureLines] = replacedChangelog.split('\n').map((l) => l.trimRight())
34
+
35
+ const linksNew = await (async () => {
36
+ if (prFromSummary !== undefined) {
37
+ let { links } = await getInfoFromPullRequest({
38
+ repo: options.repo,
39
+ pull: prFromSummary,
40
+ })
41
+ if (commitFromSummary) {
42
+ links = {
43
+ ...links,
44
+ commit: `[\`${commitFromSummary}\`](https://github.com/${options.repo}/commit/${commitFromSummary})`,
45
+ }
46
+ }
47
+ return links
48
+ }
49
+ const commitToFetchFrom = commitFromSummary || changeset.commit
50
+ if (commitToFetchFrom) {
51
+ const { links } = await getInfo({
52
+ repo: options.repo,
53
+ commit: commitToFetchFrom,
54
+ })
55
+ return links
56
+ }
57
+ return {
58
+ commit: null,
59
+ pull: null,
60
+ user: null,
61
+ }
62
+ })()
63
+
64
+ const users = usersFromSummary.length
65
+ ? usersFromSummary
66
+ .filter((u) => !u.startsWith('apps'))
67
+ .map((userFromSummary) => `[@${userFromSummary}](https://github.com/${userFromSummary})`)
68
+ .join(', ')
69
+ : linksNew.user
70
+
71
+ const prefix = [
72
+ linksNew.pull === null ? '' : ` ${linksNew.pull}`,
73
+ linksNew.commit === null ? '' : ` ${linksNew.commit}`,
74
+ ].join('')
75
+
76
+ return `\n\n-${prefix ? `${prefix} -` : ''} ${firstLine}\n${futureLines
77
+ .map((l) => ` ${l}`)
78
+ .join('\n')} (${users})`
79
+ },
6
80
  }
7
81
 
8
82
  export default changelogFunctions