@icebreakers/changelog-github 1.0.2 → 2.0.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/dist/index.cjs CHANGED
@@ -2,9 +2,40 @@ Object.defineProperties(exports, {
2
2
  __esModule: { value: true },
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
+ let dotenv = require("dotenv");
5
6
  let _changesets_get_github_info = require("@changesets/get-github-info");
7
+ //#region src/github-info.ts
8
+ async function getInfo(options) {
9
+ const info = await (0, _changesets_get_github_info.getCommitInfo)(options);
10
+ if (!info) return;
11
+ return {
12
+ commit: info.commit.sha,
13
+ pull: info.pull?.number ?? null,
14
+ user: info.author?.login ?? null,
15
+ links: {
16
+ commit: info.commit.markdownLink,
17
+ pull: info.pull?.markdownLink ?? null,
18
+ user: info.author?.markdownLink ?? null
19
+ }
20
+ };
21
+ }
22
+ async function getInfoFromPullRequest(options) {
23
+ const info = await (0, _changesets_get_github_info.getPullRequestInfo)(options);
24
+ if (!info) return;
25
+ return {
26
+ commit: info.commit?.sha ?? null,
27
+ pull: info.pull.number,
28
+ user: info.author?.login ?? null,
29
+ links: {
30
+ commit: info.commit?.markdownLink ?? null,
31
+ pull: info.pull.markdownLink,
32
+ user: info.author?.markdownLink ?? null
33
+ }
34
+ };
35
+ }
36
+ //#endregion
6
37
  //#region src/index.ts
7
- (0, require("dotenv").config)();
38
+ (0, dotenv.config)();
8
39
  const releaseTypeMap = {
9
40
  major: {
10
41
  icon: "🚀",
@@ -36,6 +67,7 @@ const FALLBACK_USER_RE = /@([^\]]+)/;
36
67
  const CODE_FENCE_RE = /^\s*```/;
37
68
  const LIST_LIKE_RE = /^\s*(?:[-*+]\s+|\d+[.)]\s+)/;
38
69
  const PARAGRAPH_BREAK_RE = /\n\s*\n/;
70
+ const GITHUB_METADATA_ERROR_RE = /GitHub|fetch|parse|Premature close|network|socket|ECONNRESET|ETIMEDOUT|EAI_AGAIN/i;
39
71
  function resolveReleaseType(type) {
40
72
  if (type && type in releaseTypeMap) return type;
41
73
  return "none";
@@ -43,14 +75,43 @@ function resolveReleaseType(type) {
43
75
  function assertRepo(options) {
44
76
  if (!options || typeof options["repo"] !== "string" || options["repo"].trim().length === 0) throw new Error("Please provide a repo to this changelog generator like this:\n\"changelog\": [\"@icebreakers/changelog-github\", { \"repo\": \"org/repo\" }]");
45
77
  }
78
+ function formatCommitLink(repo, commit) {
79
+ return `[\`${commit.slice(0, 7)}\`](https://github.com/${repo}/commit/${commit})`;
80
+ }
81
+ function emptyLinks() {
82
+ return {
83
+ commit: null,
84
+ pull: null,
85
+ user: null
86
+ };
87
+ }
88
+ function isOptionalGitHubMetadataError(error) {
89
+ if (!(error instanceof Error)) return false;
90
+ return GITHUB_METADATA_ERROR_RE.test(error.message);
91
+ }
92
+ async function getOptionalInfo(request) {
93
+ try {
94
+ return await getInfo(request);
95
+ } catch (error) {
96
+ if (isOptionalGitHubMetadataError(error)) return null;
97
+ throw error;
98
+ }
99
+ }
100
+ async function getOptionalInfoFromPullRequest(request) {
101
+ try {
102
+ return await getInfoFromPullRequest(request);
103
+ } catch (error) {
104
+ if (isOptionalGitHubMetadataError(error)) return null;
105
+ throw error;
106
+ }
107
+ }
46
108
  async function collectDependencyReferences(changesets, repo) {
47
109
  const references = await Promise.all(changesets.map(async (cs) => {
48
110
  if (!cs.commit) return null;
49
- const { links } = await (0, _changesets_get_github_info.getInfo)({
111
+ return (await getOptionalInfo({
50
112
  repo,
51
113
  commit: cs.commit
52
- });
53
- return links.commit;
114
+ }))?.links.commit ?? formatCommitLink(repo, cs.commit);
54
115
  }));
55
116
  return [...new Set(references.filter((link) => Boolean(link)))];
56
117
  }
@@ -165,26 +226,22 @@ function parseSummary(summary) {
165
226
  }
166
227
  async function resolveLinks(repo, parsed, changesetCommit) {
167
228
  if (parsed.prNumber !== void 0) {
168
- const { links } = await (0, _changesets_get_github_info.getInfoFromPullRequest)({
229
+ const links = (await getOptionalInfoFromPullRequest({
169
230
  repo,
170
231
  pull: parsed.prNumber
171
- });
172
- if (parsed.commitRef) links.commit = `[\`${parsed.commitRef.slice(0, 7)}\`](https://github.com/${repo}/commit/${parsed.commitRef})`;
232
+ }))?.links ?? emptyLinks();
233
+ if (parsed.commitRef) links.commit = formatCommitLink(repo, parsed.commitRef);
173
234
  return links;
174
235
  }
175
236
  const commitToUse = parsed.commitRef ?? changesetCommit;
176
- if (commitToUse) {
177
- const { links } = await (0, _changesets_get_github_info.getInfo)({
178
- repo,
179
- commit: commitToUse
180
- });
181
- return links;
182
- }
183
- return {
184
- commit: null,
185
- pull: null,
186
- user: null
237
+ if (commitToUse) return (await getOptionalInfo({
238
+ repo,
239
+ commit: commitToUse
240
+ }))?.links ?? {
241
+ ...emptyLinks(),
242
+ commit: formatCommitLink(repo, commitToUse)
187
243
  };
244
+ return emptyLinks();
188
245
  }
189
246
  function buildUserMentions(users, fallbackUser) {
190
247
  if (users.length > 0) return normalizeUserMentions(users);
package/dist/index.d.cts CHANGED
@@ -1,6 +1,4 @@
1
- import * as _$_changesets_types0 from "@changesets/types";
2
1
  import { ChangelogFunctions } from "@changesets/types";
3
-
4
2
  //#region src/index.d.ts
5
3
  interface ConventionalHeadline {
6
4
  type?: string | undefined;
@@ -14,6 +12,6 @@ declare function formatHeadline(raw: string): {
14
12
  breaking: boolean;
15
13
  };
16
14
  declare const changelogFunctions: ChangelogFunctions;
17
- declare const getDependencyReleaseLine: _$_changesets_types0.GetDependencyReleaseLine, getReleaseLine: _$_changesets_types0.GetReleaseLine;
15
+ declare const getDependencyReleaseLine: import("@changesets/types").GetDependencyReleaseLine, getReleaseLine: import("@changesets/types").GetReleaseLine;
18
16
  //#endregion
19
17
  export { changelogFunctions as default, formatHeadline, getDependencyReleaseLine, getReleaseLine, parseConventionalHeadline };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,4 @@
1
- import * as _$_changesets_types0 from "@changesets/types";
2
1
  import { ChangelogFunctions } from "@changesets/types";
3
-
4
2
  //#region src/index.d.ts
5
3
  interface ConventionalHeadline {
6
4
  type?: string | undefined;
@@ -14,6 +12,6 @@ declare function formatHeadline(raw: string): {
14
12
  breaking: boolean;
15
13
  };
16
14
  declare const changelogFunctions: ChangelogFunctions;
17
- declare const getDependencyReleaseLine: _$_changesets_types0.GetDependencyReleaseLine, getReleaseLine: _$_changesets_types0.GetReleaseLine;
15
+ declare const getDependencyReleaseLine: import("@changesets/types").GetDependencyReleaseLine, getReleaseLine: import("@changesets/types").GetReleaseLine;
18
16
  //#endregion
19
17
  export { changelogFunctions as default, formatHeadline, getDependencyReleaseLine, getReleaseLine, parseConventionalHeadline };
package/dist/index.js CHANGED
@@ -1,5 +1,35 @@
1
- import { getInfo, getInfoFromPullRequest } from "@changesets/get-github-info";
2
1
  import { config } from "dotenv";
2
+ import { getCommitInfo, getPullRequestInfo } from "@changesets/get-github-info";
3
+ //#region src/github-info.ts
4
+ async function getInfo(options) {
5
+ const info = await getCommitInfo(options);
6
+ if (!info) return;
7
+ return {
8
+ commit: info.commit.sha,
9
+ pull: info.pull?.number ?? null,
10
+ user: info.author?.login ?? null,
11
+ links: {
12
+ commit: info.commit.markdownLink,
13
+ pull: info.pull?.markdownLink ?? null,
14
+ user: info.author?.markdownLink ?? null
15
+ }
16
+ };
17
+ }
18
+ async function getInfoFromPullRequest(options) {
19
+ const info = await getPullRequestInfo(options);
20
+ if (!info) return;
21
+ return {
22
+ commit: info.commit?.sha ?? null,
23
+ pull: info.pull.number,
24
+ user: info.author?.login ?? null,
25
+ links: {
26
+ commit: info.commit?.markdownLink ?? null,
27
+ pull: info.pull.markdownLink,
28
+ user: info.author?.markdownLink ?? null
29
+ }
30
+ };
31
+ }
32
+ //#endregion
3
33
  //#region src/index.ts
4
34
  config();
5
35
  const releaseTypeMap = {
@@ -33,6 +63,7 @@ const FALLBACK_USER_RE = /@([^\]]+)/;
33
63
  const CODE_FENCE_RE = /^\s*```/;
34
64
  const LIST_LIKE_RE = /^\s*(?:[-*+]\s+|\d+[.)]\s+)/;
35
65
  const PARAGRAPH_BREAK_RE = /\n\s*\n/;
66
+ const GITHUB_METADATA_ERROR_RE = /GitHub|fetch|parse|Premature close|network|socket|ECONNRESET|ETIMEDOUT|EAI_AGAIN/i;
36
67
  function resolveReleaseType(type) {
37
68
  if (type && type in releaseTypeMap) return type;
38
69
  return "none";
@@ -40,14 +71,43 @@ function resolveReleaseType(type) {
40
71
  function assertRepo(options) {
41
72
  if (!options || typeof options["repo"] !== "string" || options["repo"].trim().length === 0) throw new Error("Please provide a repo to this changelog generator like this:\n\"changelog\": [\"@icebreakers/changelog-github\", { \"repo\": \"org/repo\" }]");
42
73
  }
74
+ function formatCommitLink(repo, commit) {
75
+ return `[\`${commit.slice(0, 7)}\`](https://github.com/${repo}/commit/${commit})`;
76
+ }
77
+ function emptyLinks() {
78
+ return {
79
+ commit: null,
80
+ pull: null,
81
+ user: null
82
+ };
83
+ }
84
+ function isOptionalGitHubMetadataError(error) {
85
+ if (!(error instanceof Error)) return false;
86
+ return GITHUB_METADATA_ERROR_RE.test(error.message);
87
+ }
88
+ async function getOptionalInfo(request) {
89
+ try {
90
+ return await getInfo(request);
91
+ } catch (error) {
92
+ if (isOptionalGitHubMetadataError(error)) return null;
93
+ throw error;
94
+ }
95
+ }
96
+ async function getOptionalInfoFromPullRequest(request) {
97
+ try {
98
+ return await getInfoFromPullRequest(request);
99
+ } catch (error) {
100
+ if (isOptionalGitHubMetadataError(error)) return null;
101
+ throw error;
102
+ }
103
+ }
43
104
  async function collectDependencyReferences(changesets, repo) {
44
105
  const references = await Promise.all(changesets.map(async (cs) => {
45
106
  if (!cs.commit) return null;
46
- const { links } = await getInfo({
107
+ return (await getOptionalInfo({
47
108
  repo,
48
109
  commit: cs.commit
49
- });
50
- return links.commit;
110
+ }))?.links.commit ?? formatCommitLink(repo, cs.commit);
51
111
  }));
52
112
  return [...new Set(references.filter((link) => Boolean(link)))];
53
113
  }
@@ -162,26 +222,22 @@ function parseSummary(summary) {
162
222
  }
163
223
  async function resolveLinks(repo, parsed, changesetCommit) {
164
224
  if (parsed.prNumber !== void 0) {
165
- const { links } = await getInfoFromPullRequest({
225
+ const links = (await getOptionalInfoFromPullRequest({
166
226
  repo,
167
227
  pull: parsed.prNumber
168
- });
169
- if (parsed.commitRef) links.commit = `[\`${parsed.commitRef.slice(0, 7)}\`](https://github.com/${repo}/commit/${parsed.commitRef})`;
228
+ }))?.links ?? emptyLinks();
229
+ if (parsed.commitRef) links.commit = formatCommitLink(repo, parsed.commitRef);
170
230
  return links;
171
231
  }
172
232
  const commitToUse = parsed.commitRef ?? changesetCommit;
173
- if (commitToUse) {
174
- const { links } = await getInfo({
175
- repo,
176
- commit: commitToUse
177
- });
178
- return links;
179
- }
180
- return {
181
- commit: null,
182
- pull: null,
183
- user: null
233
+ if (commitToUse) return (await getOptionalInfo({
234
+ repo,
235
+ commit: commitToUse
236
+ }))?.links ?? {
237
+ ...emptyLinks(),
238
+ commit: formatCommitLink(repo, commitToUse)
184
239
  };
240
+ return emptyLinks();
185
241
  }
186
242
  function buildUserMentions(users, fallbackUser) {
187
243
  if (users.length > 0) return normalizeUserMentions(users);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@icebreakers/changelog-github",
3
3
  "type": "module",
4
- "version": "1.0.2",
4
+ "version": "2.0.1",
5
5
  "description": "Changesets GitHub changelog formatter for Icebreaker's dev-configs",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -34,21 +34,22 @@
34
34
  "dist"
35
35
  ],
36
36
  "engines": {
37
- "node": "^20.19.0 || >=22.12.0"
37
+ "node": ">=22.12.0"
38
38
  },
39
39
  "tsd": {
40
40
  "directory": "test-d",
41
41
  "compilerOptions": {
42
+ "module": "node16",
42
43
  "skipLibCheck": true
43
44
  }
44
45
  },
45
46
  "dependencies": {
46
- "@changesets/get-github-info": "^0.8.0",
47
- "@changesets/types": "^6.1.0",
47
+ "@changesets/get-github-info": "^1.0.0",
48
+ "@changesets/types": "^7.0.0",
48
49
  "dotenv": "^17.4.2"
49
50
  },
50
51
  "devDependencies": {
51
- "@changesets/parse": "^0.4.3"
52
+ "@changesets/parse": "^1.0.0"
52
53
  },
53
54
  "scripts": {
54
55
  "dev": "tsdown --watch --sourcemap",