@jsenv/github-pull-request-impact 1.6.9 → 1.7.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/README.md +1 -1
- package/package.json +8 -23
- package/src/commentGitHubPullRequestImpact.js +31 -30
- package/src/internal/createGitHubPullRequestCommentText.js +11 -2
- package/src/internal/exec.js +2 -2
- package/src/internal/github_rest_api.js +2 -2
- package/src/internal/renderGeneratedByText.js +8 -2
- package/src/main.js +6 -0
- package/src/readGitHubWorkflowEnv.js +1 -1
- package/main.js +0 -6
package/README.md
CHANGED
|
@@ -10,4 +10,4 @@ This repository publishes `@jsenv/github-pull-request-impact` on NPM. This packa
|
|
|
10
10
|
|
|
11
11
|
- [@jsenv/performance-impact](../jsenv-performance-impact)
|
|
12
12
|
- [@jsenv/file-size-impact](../jsenv-file-size-impact)
|
|
13
|
-
- [@jsenv/lighthouse-
|
|
13
|
+
- [@jsenv/lighthouse-impact](../jsenv-lighthouse-impact)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/github-pull-request-impact",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "Report pull request impact on something",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -23,35 +23,20 @@
|
|
|
23
23
|
"type": "module",
|
|
24
24
|
"exports": {
|
|
25
25
|
".": {
|
|
26
|
-
"import": "./main.js"
|
|
26
|
+
"import": "./src/main.js"
|
|
27
27
|
},
|
|
28
28
|
"./*": "./*"
|
|
29
29
|
},
|
|
30
|
-
"main": "./main.js",
|
|
30
|
+
"main": "./src/main.js",
|
|
31
31
|
"files": [
|
|
32
|
-
"/src/"
|
|
33
|
-
"/main.js"
|
|
32
|
+
"/src/"
|
|
34
33
|
],
|
|
35
34
|
"scripts": {
|
|
36
|
-
"
|
|
37
|
-
"importmap": "node ./script/importmap/importmap.mjs",
|
|
38
|
-
"test": "node ./script/test/test.mjs",
|
|
39
|
-
"test-with-coverage": "npm run test -- --coverage",
|
|
40
|
-
"prettier": "prettier --write ."
|
|
35
|
+
"test": "node ./scripts/test.mjs"
|
|
41
36
|
},
|
|
42
37
|
"dependencies": {
|
|
43
|
-
"@jsenv/
|
|
44
|
-
"@jsenv/
|
|
45
|
-
"
|
|
46
|
-
},
|
|
47
|
-
"devDependencies": {
|
|
48
|
-
"@jsenv/assert": "2.4.1",
|
|
49
|
-
"@jsenv/core": "25.3.0",
|
|
50
|
-
"@jsenv/eslint-config": "16.0.9",
|
|
51
|
-
"@jsenv/importmap-eslint-resolver": "5.2.5",
|
|
52
|
-
"@jsenv/importmap-node-module": "5.1.3",
|
|
53
|
-
"eslint": "8.7.0",
|
|
54
|
-
"eslint-plugin-import": "2.25.4",
|
|
55
|
-
"prettier": "2.5.1"
|
|
38
|
+
"@jsenv/fetch": "1.1.2",
|
|
39
|
+
"@jsenv/filesystem": "4.1.0",
|
|
40
|
+
"@jsenv/log": "2.1.0"
|
|
56
41
|
}
|
|
57
42
|
}
|
|
@@ -4,11 +4,9 @@
|
|
|
4
4
|
* @jsenv/file-size-impact, @jsenv/performance-impact and @jsenv/lighthouse-score-impact
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} from "@jsenv/filesystem"
|
|
11
|
-
import { createLogger } from "@jsenv/logger"
|
|
7
|
+
import { fileURLToPath } from "node:url"
|
|
8
|
+
import { assertAndNormalizeDirectoryUrl } from "@jsenv/filesystem"
|
|
9
|
+
import { createLogger } from "@jsenv/log"
|
|
12
10
|
|
|
13
11
|
import * as githubRESTAPI from "./internal/github_rest_api.js"
|
|
14
12
|
import { exec } from "./internal/exec.js"
|
|
@@ -19,7 +17,7 @@ export const commentGitHubPullRequestImpact = async ({
|
|
|
19
17
|
logLevel,
|
|
20
18
|
commandLogs = false,
|
|
21
19
|
infoLogs = true,
|
|
22
|
-
|
|
20
|
+
rootDirectoryUrl,
|
|
23
21
|
|
|
24
22
|
githubToken,
|
|
25
23
|
repositoryOwner,
|
|
@@ -33,7 +31,7 @@ export const commentGitHubPullRequestImpact = async ({
|
|
|
33
31
|
createCommentForVersionMismatch = jsenvCreateCommentForVersionMismatch,
|
|
34
32
|
createCommentForComparison = jsenvCreateCommentForComparison,
|
|
35
33
|
generatedByLink = {
|
|
36
|
-
url: "https://github.com/jsenv/github-pull-request-impact",
|
|
34
|
+
url: "https://github.com/jsenv/workflow/tree/main/packages/jsenv-github-pull-request-impact",
|
|
37
35
|
text: "@jsenv/github-pull-request-impact",
|
|
38
36
|
},
|
|
39
37
|
runLink,
|
|
@@ -41,7 +39,7 @@ export const commentGitHubPullRequestImpact = async ({
|
|
|
41
39
|
|
|
42
40
|
catchError = false,
|
|
43
41
|
}) => {
|
|
44
|
-
|
|
42
|
+
rootDirectoryUrl = assertAndNormalizeDirectoryUrl(rootDirectoryUrl)
|
|
45
43
|
if (typeof collectInfo !== "function") {
|
|
46
44
|
throw new TypeError(
|
|
47
45
|
`collectInfo must be a function but received ${collectInfo}`,
|
|
@@ -83,7 +81,7 @@ export const commentGitHubPullRequestImpact = async ({
|
|
|
83
81
|
logger,
|
|
84
82
|
commandLogs,
|
|
85
83
|
infoLogs,
|
|
86
|
-
|
|
84
|
+
rootDirectoryUrl,
|
|
87
85
|
|
|
88
86
|
githubToken,
|
|
89
87
|
repositoryOwner,
|
|
@@ -111,7 +109,7 @@ const commentPrImpact = async ({
|
|
|
111
109
|
logger,
|
|
112
110
|
infoLogs,
|
|
113
111
|
commandLogs,
|
|
114
|
-
|
|
112
|
+
rootDirectoryUrl,
|
|
115
113
|
|
|
116
114
|
githubToken,
|
|
117
115
|
repositoryOwner,
|
|
@@ -130,10 +128,10 @@ const commentPrImpact = async ({
|
|
|
130
128
|
|
|
131
129
|
catchError,
|
|
132
130
|
}) => {
|
|
133
|
-
const
|
|
131
|
+
const execCommandInRootDirectory = (command) => {
|
|
134
132
|
logger.info(`> ${command}`)
|
|
135
133
|
return exec(command, {
|
|
136
|
-
cwd:
|
|
134
|
+
cwd: fileURLToPath(rootDirectoryUrl),
|
|
137
135
|
onLog: (string) => {
|
|
138
136
|
if (commandLogs) {
|
|
139
137
|
logger.info(string)
|
|
@@ -254,15 +252,15 @@ const commentPrImpact = async ({
|
|
|
254
252
|
let beforeMergeInfo
|
|
255
253
|
try {
|
|
256
254
|
// cannot use depth=1 arg otherwise git merge might have merge conflicts
|
|
257
|
-
await
|
|
255
|
+
await execCommandInRootDirectory(
|
|
258
256
|
`git fetch --no-tags --prune origin ${pullRequestBase}`,
|
|
259
257
|
)
|
|
260
|
-
await
|
|
258
|
+
await execCommandInRootDirectory(
|
|
261
259
|
`git reset --hard origin/${pullRequestBase}`,
|
|
262
260
|
)
|
|
263
261
|
beforeMergeInfo = await collectInfo({
|
|
264
262
|
beforeMerge: true,
|
|
265
|
-
|
|
263
|
+
execCommandInRootDirectory,
|
|
266
264
|
})
|
|
267
265
|
if (infoLogs) {
|
|
268
266
|
logger.debug(debugBeforeMergeInfo(beforeMergeInfo))
|
|
@@ -285,13 +283,13 @@ const commentPrImpact = async ({
|
|
|
285
283
|
try {
|
|
286
284
|
// buildCommand might generate files that could conflict when doing the merge
|
|
287
285
|
// reset to avoid potential merge conflicts
|
|
288
|
-
await
|
|
286
|
+
await execCommandInRootDirectory(
|
|
289
287
|
`git reset --hard origin/${pullRequestBase}`,
|
|
290
288
|
)
|
|
291
289
|
// Avoid "The following untracked working tree files would be overwritten by merge" error
|
|
292
|
-
await
|
|
290
|
+
await execCommandInRootDirectory(`git clean -d -f .`)
|
|
293
291
|
// cannot use depth=1 arg otherwise git merge might have merge conflicts
|
|
294
|
-
await
|
|
292
|
+
await execCommandInRootDirectory(
|
|
295
293
|
`git fetch --no-tags --prune origin ${headRef}`,
|
|
296
294
|
)
|
|
297
295
|
// ensure there is user.email + user.name required to perform git merge command
|
|
@@ -299,20 +297,25 @@ const commentPrImpact = async ({
|
|
|
299
297
|
|
|
300
298
|
const restoreGitUserEmail = await ensureGitConfig("user.email", {
|
|
301
299
|
valueIfMissing: "you@example.com",
|
|
302
|
-
|
|
300
|
+
execCommandInRootDirectory,
|
|
303
301
|
})
|
|
304
302
|
const restoreGitUserName = await ensureGitConfig("user.name", {
|
|
305
303
|
valueIfMissing: "Your Name",
|
|
306
|
-
|
|
304
|
+
execCommandInRootDirectory,
|
|
307
305
|
})
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
306
|
+
// could we use https://stackoverflow.com/a/6283843 ?
|
|
307
|
+
try {
|
|
308
|
+
await execCommandInRootDirectory(
|
|
309
|
+
`git merge FETCH_HEAD --allow-unrelated-histories --no-ff --no-commit`,
|
|
310
|
+
)
|
|
311
|
+
} catch (e) {
|
|
312
|
+
throw new Error(`git merge command failed (is there a merge conflict?)`)
|
|
313
|
+
}
|
|
311
314
|
await restoreGitUserEmail()
|
|
312
315
|
await restoreGitUserName()
|
|
313
316
|
afterMergeInfo = await collectInfo({
|
|
314
317
|
afterMerge: true,
|
|
315
|
-
|
|
318
|
+
execCommandInRootDirectory,
|
|
316
319
|
})
|
|
317
320
|
if (infoLogs) {
|
|
318
321
|
logger.debug(debugAfterMergeInfo(afterMergeInfo))
|
|
@@ -359,17 +362,15 @@ const commentPrImpact = async ({
|
|
|
359
362
|
|
|
360
363
|
const ensureGitConfig = async (
|
|
361
364
|
name,
|
|
362
|
-
{
|
|
365
|
+
{ execCommandInRootDirectory, valueIfMissing },
|
|
363
366
|
) => {
|
|
364
367
|
try {
|
|
365
|
-
await
|
|
368
|
+
await execCommandInRootDirectory(`git config ${name}`)
|
|
366
369
|
return () => {}
|
|
367
370
|
} catch (e) {
|
|
368
|
-
await
|
|
369
|
-
`git config ${name} "${valueIfMissing}"`,
|
|
370
|
-
)
|
|
371
|
+
await execCommandInRootDirectory(`git config ${name} "${valueIfMissing}"`)
|
|
371
372
|
return async () => {
|
|
372
|
-
await
|
|
373
|
+
await execCommandInRootDirectory(`git config --unset ${name}`)
|
|
373
374
|
}
|
|
374
375
|
}
|
|
375
376
|
}
|
|
@@ -36,7 +36,14 @@ export const createGitHubPullRequestCommentText = ({
|
|
|
36
36
|
})
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
const truncateComment = ({
|
|
39
|
+
const truncateComment = ({
|
|
40
|
+
commentLength,
|
|
41
|
+
maxLength,
|
|
42
|
+
header,
|
|
43
|
+
warnings,
|
|
44
|
+
body,
|
|
45
|
+
footer,
|
|
46
|
+
}) => {
|
|
40
47
|
const warningsWithTruncateWarning = [
|
|
41
48
|
...warnings,
|
|
42
49
|
`**Warning:** The comment body was truncated to fit GitHub limit on comment length.
|
|
@@ -69,7 +76,9 @@ For the record the full comment length was ${commentLength} bytes.`,
|
|
|
69
76
|
|
|
70
77
|
const composeCommentText = ({ header, warnings, body, footer }) => {
|
|
71
78
|
const warningsAsText = composeWarningsText(warnings)
|
|
72
|
-
const parts = [header, warningsAsText, body, footer].filter(
|
|
79
|
+
const parts = [header, warningsAsText, body, footer].filter(
|
|
80
|
+
(string) => string.length > 0,
|
|
81
|
+
)
|
|
73
82
|
|
|
74
83
|
return parts.join(`
|
|
75
84
|
|
package/src/internal/exec.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { fetchUrl } from "@jsenv/fetch"
|
|
2
2
|
|
|
3
3
|
export const GET = async ({ url, githubToken, headers }) => {
|
|
4
4
|
return sendHttpRequest({
|
|
@@ -72,7 +72,7 @@ const sendHttpRequest = async ({
|
|
|
72
72
|
}) => {
|
|
73
73
|
let response
|
|
74
74
|
try {
|
|
75
|
-
response = await
|
|
75
|
+
response = await fetchUrl(url, {
|
|
76
76
|
method,
|
|
77
77
|
headers: {
|
|
78
78
|
...(typeof body === "undefined"
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
export const renderGeneratedByText = ({
|
|
1
|
+
export const renderGeneratedByText = ({
|
|
2
|
+
generatedByLink,
|
|
3
|
+
runLink,
|
|
4
|
+
commitLink,
|
|
5
|
+
}) => {
|
|
2
6
|
if (runLink && typeof runLink !== "object") {
|
|
3
7
|
console.warn(
|
|
4
8
|
`runLink ignored because it should be an object with {url, text}, received ${runLink}`,
|
|
@@ -9,7 +13,9 @@ export const renderGeneratedByText = ({ generatedByLink, runLink, commitLink })
|
|
|
9
13
|
const parts = [
|
|
10
14
|
`Generated by <a href="${generatedByLink.url}">${generatedByLink.text}</a>`,
|
|
11
15
|
...(runLink ? [`during <a href="${runLink.url}">${runLink.text}</a>`] : []),
|
|
12
|
-
...(commitLink
|
|
16
|
+
...(commitLink
|
|
17
|
+
? [`on <a href="${commitLink.url}">${commitLink.text}</a>`]
|
|
18
|
+
: []),
|
|
13
19
|
]
|
|
14
20
|
|
|
15
21
|
return `<sub>
|
package/src/main.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { readGitHubWorkflowEnv } from "./readGitHubWorkflowEnv.js"
|
|
2
|
+
export { commentGitHubPullRequestImpact } from "./commentGitHubPullRequestImpact.js"
|
|
3
|
+
|
|
4
|
+
// not planned to be documented but can be useful
|
|
5
|
+
// to get a github comment from a { warnings, body } object
|
|
6
|
+
export { createGitHubPullRequestCommentText } from "./internal/createGitHubPullRequestCommentText.js"
|
package/main.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { readGitHubWorkflowEnv } from "./src/readGitHubWorkflowEnv.js"
|
|
2
|
-
export { commentGitHubPullRequestImpact } from "./src/commentGitHubPullRequestImpact.js"
|
|
3
|
-
|
|
4
|
-
// not planned to be documented but can be useful
|
|
5
|
-
// to get a github comment from a { warnings, body } object
|
|
6
|
-
export { createGitHubPullRequestCommentText } from "./src/internal/createGitHubPullRequestCommentText.js"
|