@icebreakers/changelog-github 1.0.2 → 2.0.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/dist/index.cjs +43 -17
- package/dist/index.d.cts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +43 -17
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -36,6 +36,7 @@ const FALLBACK_USER_RE = /@([^\]]+)/;
|
|
|
36
36
|
const CODE_FENCE_RE = /^\s*```/;
|
|
37
37
|
const LIST_LIKE_RE = /^\s*(?:[-*+]\s+|\d+[.)]\s+)/;
|
|
38
38
|
const PARAGRAPH_BREAK_RE = /\n\s*\n/;
|
|
39
|
+
const GITHUB_METADATA_ERROR_RE = /GitHub|fetch|parse|Premature close|network|socket|ECONNRESET|ETIMEDOUT|EAI_AGAIN/i;
|
|
39
40
|
function resolveReleaseType(type) {
|
|
40
41
|
if (type && type in releaseTypeMap) return type;
|
|
41
42
|
return "none";
|
|
@@ -43,14 +44,43 @@ function resolveReleaseType(type) {
|
|
|
43
44
|
function assertRepo(options) {
|
|
44
45
|
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
46
|
}
|
|
47
|
+
function formatCommitLink(repo, commit) {
|
|
48
|
+
return `[\`${commit.slice(0, 7)}\`](https://github.com/${repo}/commit/${commit})`;
|
|
49
|
+
}
|
|
50
|
+
function emptyLinks() {
|
|
51
|
+
return {
|
|
52
|
+
commit: null,
|
|
53
|
+
pull: null,
|
|
54
|
+
user: null
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function isOptionalGitHubMetadataError(error) {
|
|
58
|
+
if (!(error instanceof Error)) return false;
|
|
59
|
+
return GITHUB_METADATA_ERROR_RE.test(error.message);
|
|
60
|
+
}
|
|
61
|
+
async function getOptionalInfo(request) {
|
|
62
|
+
try {
|
|
63
|
+
return await (0, _changesets_get_github_info.getInfo)(request);
|
|
64
|
+
} catch (error) {
|
|
65
|
+
if (isOptionalGitHubMetadataError(error)) return null;
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async function getOptionalInfoFromPullRequest(request) {
|
|
70
|
+
try {
|
|
71
|
+
return await (0, _changesets_get_github_info.getInfoFromPullRequest)(request);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
if (isOptionalGitHubMetadataError(error)) return null;
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
46
77
|
async function collectDependencyReferences(changesets, repo) {
|
|
47
78
|
const references = await Promise.all(changesets.map(async (cs) => {
|
|
48
79
|
if (!cs.commit) return null;
|
|
49
|
-
|
|
80
|
+
return (await getOptionalInfo({
|
|
50
81
|
repo,
|
|
51
82
|
commit: cs.commit
|
|
52
|
-
});
|
|
53
|
-
return links.commit;
|
|
83
|
+
}))?.links.commit ?? formatCommitLink(repo, cs.commit);
|
|
54
84
|
}));
|
|
55
85
|
return [...new Set(references.filter((link) => Boolean(link)))];
|
|
56
86
|
}
|
|
@@ -165,26 +195,22 @@ function parseSummary(summary) {
|
|
|
165
195
|
}
|
|
166
196
|
async function resolveLinks(repo, parsed, changesetCommit) {
|
|
167
197
|
if (parsed.prNumber !== void 0) {
|
|
168
|
-
const
|
|
198
|
+
const links = (await getOptionalInfoFromPullRequest({
|
|
169
199
|
repo,
|
|
170
200
|
pull: parsed.prNumber
|
|
171
|
-
});
|
|
172
|
-
if (parsed.commitRef) links.commit =
|
|
201
|
+
}))?.links ?? emptyLinks();
|
|
202
|
+
if (parsed.commitRef) links.commit = formatCommitLink(repo, parsed.commitRef);
|
|
173
203
|
return links;
|
|
174
204
|
}
|
|
175
205
|
const commitToUse = parsed.commitRef ?? changesetCommit;
|
|
176
|
-
if (commitToUse) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
return {
|
|
184
|
-
commit: null,
|
|
185
|
-
pull: null,
|
|
186
|
-
user: null
|
|
206
|
+
if (commitToUse) return (await getOptionalInfo({
|
|
207
|
+
repo,
|
|
208
|
+
commit: commitToUse
|
|
209
|
+
}))?.links ?? {
|
|
210
|
+
...emptyLinks(),
|
|
211
|
+
commit: formatCommitLink(repo, commitToUse)
|
|
187
212
|
};
|
|
213
|
+
return emptyLinks();
|
|
188
214
|
}
|
|
189
215
|
function buildUserMentions(users, fallbackUser) {
|
|
190
216
|
if (users.length > 0) return normalizeUserMentions(users);
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as _$_changesets_types0 from "@changesets/types";
|
|
2
1
|
import { ChangelogFunctions } from "@changesets/types";
|
|
3
2
|
|
|
4
3
|
//#region src/index.d.ts
|
|
@@ -14,6 +13,6 @@ declare function formatHeadline(raw: string): {
|
|
|
14
13
|
breaking: boolean;
|
|
15
14
|
};
|
|
16
15
|
declare const changelogFunctions: ChangelogFunctions;
|
|
17
|
-
declare const getDependencyReleaseLine:
|
|
16
|
+
declare const getDependencyReleaseLine: import("@changesets/types").GetDependencyReleaseLine, getReleaseLine: import("@changesets/types").GetReleaseLine;
|
|
18
17
|
//#endregion
|
|
19
18
|
export { changelogFunctions as default, formatHeadline, getDependencyReleaseLine, getReleaseLine, parseConventionalHeadline };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as _$_changesets_types0 from "@changesets/types";
|
|
2
1
|
import { ChangelogFunctions } from "@changesets/types";
|
|
3
2
|
|
|
4
3
|
//#region src/index.d.ts
|
|
@@ -14,6 +13,6 @@ declare function formatHeadline(raw: string): {
|
|
|
14
13
|
breaking: boolean;
|
|
15
14
|
};
|
|
16
15
|
declare const changelogFunctions: ChangelogFunctions;
|
|
17
|
-
declare const getDependencyReleaseLine:
|
|
16
|
+
declare const getDependencyReleaseLine: import("@changesets/types").GetDependencyReleaseLine, getReleaseLine: import("@changesets/types").GetReleaseLine;
|
|
18
17
|
//#endregion
|
|
19
18
|
export { changelogFunctions as default, formatHeadline, getDependencyReleaseLine, getReleaseLine, parseConventionalHeadline };
|
package/dist/index.js
CHANGED
|
@@ -33,6 +33,7 @@ const FALLBACK_USER_RE = /@([^\]]+)/;
|
|
|
33
33
|
const CODE_FENCE_RE = /^\s*```/;
|
|
34
34
|
const LIST_LIKE_RE = /^\s*(?:[-*+]\s+|\d+[.)]\s+)/;
|
|
35
35
|
const PARAGRAPH_BREAK_RE = /\n\s*\n/;
|
|
36
|
+
const GITHUB_METADATA_ERROR_RE = /GitHub|fetch|parse|Premature close|network|socket|ECONNRESET|ETIMEDOUT|EAI_AGAIN/i;
|
|
36
37
|
function resolveReleaseType(type) {
|
|
37
38
|
if (type && type in releaseTypeMap) return type;
|
|
38
39
|
return "none";
|
|
@@ -40,14 +41,43 @@ function resolveReleaseType(type) {
|
|
|
40
41
|
function assertRepo(options) {
|
|
41
42
|
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
43
|
}
|
|
44
|
+
function formatCommitLink(repo, commit) {
|
|
45
|
+
return `[\`${commit.slice(0, 7)}\`](https://github.com/${repo}/commit/${commit})`;
|
|
46
|
+
}
|
|
47
|
+
function emptyLinks() {
|
|
48
|
+
return {
|
|
49
|
+
commit: null,
|
|
50
|
+
pull: null,
|
|
51
|
+
user: null
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function isOptionalGitHubMetadataError(error) {
|
|
55
|
+
if (!(error instanceof Error)) return false;
|
|
56
|
+
return GITHUB_METADATA_ERROR_RE.test(error.message);
|
|
57
|
+
}
|
|
58
|
+
async function getOptionalInfo(request) {
|
|
59
|
+
try {
|
|
60
|
+
return await getInfo(request);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
if (isOptionalGitHubMetadataError(error)) return null;
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async function getOptionalInfoFromPullRequest(request) {
|
|
67
|
+
try {
|
|
68
|
+
return await getInfoFromPullRequest(request);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
if (isOptionalGitHubMetadataError(error)) return null;
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
43
74
|
async function collectDependencyReferences(changesets, repo) {
|
|
44
75
|
const references = await Promise.all(changesets.map(async (cs) => {
|
|
45
76
|
if (!cs.commit) return null;
|
|
46
|
-
|
|
77
|
+
return (await getOptionalInfo({
|
|
47
78
|
repo,
|
|
48
79
|
commit: cs.commit
|
|
49
|
-
});
|
|
50
|
-
return links.commit;
|
|
80
|
+
}))?.links.commit ?? formatCommitLink(repo, cs.commit);
|
|
51
81
|
}));
|
|
52
82
|
return [...new Set(references.filter((link) => Boolean(link)))];
|
|
53
83
|
}
|
|
@@ -162,26 +192,22 @@ function parseSummary(summary) {
|
|
|
162
192
|
}
|
|
163
193
|
async function resolveLinks(repo, parsed, changesetCommit) {
|
|
164
194
|
if (parsed.prNumber !== void 0) {
|
|
165
|
-
const
|
|
195
|
+
const links = (await getOptionalInfoFromPullRequest({
|
|
166
196
|
repo,
|
|
167
197
|
pull: parsed.prNumber
|
|
168
|
-
});
|
|
169
|
-
if (parsed.commitRef) links.commit =
|
|
198
|
+
}))?.links ?? emptyLinks();
|
|
199
|
+
if (parsed.commitRef) links.commit = formatCommitLink(repo, parsed.commitRef);
|
|
170
200
|
return links;
|
|
171
201
|
}
|
|
172
202
|
const commitToUse = parsed.commitRef ?? changesetCommit;
|
|
173
|
-
if (commitToUse) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
return {
|
|
181
|
-
commit: null,
|
|
182
|
-
pull: null,
|
|
183
|
-
user: null
|
|
203
|
+
if (commitToUse) return (await getOptionalInfo({
|
|
204
|
+
repo,
|
|
205
|
+
commit: commitToUse
|
|
206
|
+
}))?.links ?? {
|
|
207
|
+
...emptyLinks(),
|
|
208
|
+
commit: formatCommitLink(repo, commitToUse)
|
|
184
209
|
};
|
|
210
|
+
return emptyLinks();
|
|
185
211
|
}
|
|
186
212
|
function buildUserMentions(users, fallbackUser) {
|
|
187
213
|
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": "
|
|
4
|
+
"version": "2.0.0",
|
|
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,7 +34,7 @@
|
|
|
34
34
|
"dist"
|
|
35
35
|
],
|
|
36
36
|
"engines": {
|
|
37
|
-
"node": "
|
|
37
|
+
"node": ">=22.12.0"
|
|
38
38
|
},
|
|
39
39
|
"tsd": {
|
|
40
40
|
"directory": "test-d",
|