@jsenv/github-pull-request-impact 1.6.8 → 1.6.11

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 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-score-impact](../jsenv-performance-impact)
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.6.8",
3
+ "version": "1.6.11",
4
4
  "description": "Report pull request impact on something",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -34,24 +34,13 @@
34
34
  ],
35
35
  "scripts": {
36
36
  "eslint": "npx eslint . --ext=.js,.mjs",
37
- "importmap": "node ./script/importmap/importmap.mjs",
38
37
  "test": "node ./script/test/test.mjs",
39
38
  "test-with-coverage": "npm run test -- --coverage",
40
39
  "prettier": "prettier --write ."
41
40
  },
42
41
  "dependencies": {
43
- "@jsenv/filesystem": "2.7.1",
42
+ "@jsenv/filesystem": "3.1.0",
44
43
  "@jsenv/logger": "4.0.1",
45
44
  "node-fetch": "2.6.7"
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"
56
45
  }
57
46
  }
@@ -19,7 +19,7 @@ export const commentGitHubPullRequestImpact = async ({
19
19
  logLevel,
20
20
  commandLogs = false,
21
21
  infoLogs = true,
22
- projectDirectoryUrl,
22
+ rootDirectoryUrl,
23
23
 
24
24
  githubToken,
25
25
  repositoryOwner,
@@ -33,7 +33,7 @@ export const commentGitHubPullRequestImpact = async ({
33
33
  createCommentForVersionMismatch = jsenvCreateCommentForVersionMismatch,
34
34
  createCommentForComparison = jsenvCreateCommentForComparison,
35
35
  generatedByLink = {
36
- url: "https://github.com/jsenv/github-pull-request-impact",
36
+ url: "https://github.com/jsenv/workflow/tree/main/packages/jsenv-github-pull-request-impact",
37
37
  text: "@jsenv/github-pull-request-impact",
38
38
  },
39
39
  runLink,
@@ -41,7 +41,7 @@ export const commentGitHubPullRequestImpact = async ({
41
41
 
42
42
  catchError = false,
43
43
  }) => {
44
- projectDirectoryUrl = assertAndNormalizeDirectoryUrl(projectDirectoryUrl)
44
+ rootDirectoryUrl = assertAndNormalizeDirectoryUrl(rootDirectoryUrl)
45
45
  if (typeof collectInfo !== "function") {
46
46
  throw new TypeError(
47
47
  `collectInfo must be a function but received ${collectInfo}`,
@@ -83,7 +83,7 @@ export const commentGitHubPullRequestImpact = async ({
83
83
  logger,
84
84
  commandLogs,
85
85
  infoLogs,
86
- projectDirectoryUrl,
86
+ rootDirectoryUrl,
87
87
 
88
88
  githubToken,
89
89
  repositoryOwner,
@@ -111,7 +111,7 @@ const commentPrImpact = async ({
111
111
  logger,
112
112
  infoLogs,
113
113
  commandLogs,
114
- projectDirectoryUrl,
114
+ rootDirectoryUrl,
115
115
 
116
116
  githubToken,
117
117
  repositoryOwner,
@@ -130,10 +130,10 @@ const commentPrImpact = async ({
130
130
 
131
131
  catchError,
132
132
  }) => {
133
- const execCommandInProjectDirectory = (command) => {
133
+ const execCommandInRootDirectory = (command) => {
134
134
  logger.info(`> ${command}`)
135
135
  return exec(command, {
136
- cwd: urlToFileSystemPath(projectDirectoryUrl),
136
+ cwd: urlToFileSystemPath(rootDirectoryUrl),
137
137
  onLog: (string) => {
138
138
  if (commandLogs) {
139
139
  logger.info(string)
@@ -177,7 +177,7 @@ const commentPrImpact = async ({
177
177
 
178
178
  logger.debug(`searching comment in pull request ${pullRequestHtmlUrl}`)
179
179
  const pullRequestCommentApiUrl = pullRequest.comments_url
180
- const comments = await pullApiUrl.GET({
180
+ const comments = await githubRESTAPI.GET({
181
181
  url: pullRequestCommentApiUrl,
182
182
  githubToken,
183
183
  })
@@ -254,15 +254,15 @@ const commentPrImpact = async ({
254
254
  let beforeMergeInfo
255
255
  try {
256
256
  // cannot use depth=1 arg otherwise git merge might have merge conflicts
257
- await execCommandInProjectDirectory(
257
+ await execCommandInRootDirectory(
258
258
  `git fetch --no-tags --prune origin ${pullRequestBase}`,
259
259
  )
260
- await execCommandInProjectDirectory(
260
+ await execCommandInRootDirectory(
261
261
  `git reset --hard origin/${pullRequestBase}`,
262
262
  )
263
263
  beforeMergeInfo = await collectInfo({
264
264
  beforeMerge: true,
265
- execCommandInProjectDirectory,
265
+ execCommandInRootDirectory,
266
266
  })
267
267
  if (infoLogs) {
268
268
  logger.debug(debugBeforeMergeInfo(beforeMergeInfo))
@@ -285,13 +285,13 @@ const commentPrImpact = async ({
285
285
  try {
286
286
  // buildCommand might generate files that could conflict when doing the merge
287
287
  // reset to avoid potential merge conflicts
288
- await execCommandInProjectDirectory(
288
+ await execCommandInRootDirectory(
289
289
  `git reset --hard origin/${pullRequestBase}`,
290
290
  )
291
291
  // Avoid "The following untracked working tree files would be overwritten by merge" error
292
- await execCommandInProjectDirectory(`git clean -d -f .`)
292
+ await execCommandInRootDirectory(`git clean -d -f .`)
293
293
  // cannot use depth=1 arg otherwise git merge might have merge conflicts
294
- await execCommandInProjectDirectory(
294
+ await execCommandInRootDirectory(
295
295
  `git fetch --no-tags --prune origin ${headRef}`,
296
296
  )
297
297
  // ensure there is user.email + user.name required to perform git merge command
@@ -299,20 +299,25 @@ const commentPrImpact = async ({
299
299
 
300
300
  const restoreGitUserEmail = await ensureGitConfig("user.email", {
301
301
  valueIfMissing: "you@example.com",
302
- execCommandInProjectDirectory,
302
+ execCommandInRootDirectory,
303
303
  })
304
304
  const restoreGitUserName = await ensureGitConfig("user.name", {
305
305
  valueIfMissing: "Your Name",
306
- execCommandInProjectDirectory,
306
+ execCommandInRootDirectory,
307
307
  })
308
- await execCommandInProjectDirectory(
309
- `git merge FETCH_HEAD --allow-unrelated-histories`,
310
- )
308
+ // could we use https://stackoverflow.com/a/6283843 ?
309
+ try {
310
+ await execCommandInRootDirectory(
311
+ `git merge FETCH_HEAD --allow-unrelated-histories --no-ff --no-commit`,
312
+ )
313
+ } catch (e) {
314
+ throw new Error(`git merge command failed (is there a merge conflict?)`)
315
+ }
311
316
  await restoreGitUserEmail()
312
317
  await restoreGitUserName()
313
318
  afterMergeInfo = await collectInfo({
314
319
  afterMerge: true,
315
- execCommandInProjectDirectory,
320
+ execCommandInRootDirectory,
316
321
  })
317
322
  if (infoLogs) {
318
323
  logger.debug(debugAfterMergeInfo(afterMergeInfo))
@@ -359,17 +364,17 @@ const commentPrImpact = async ({
359
364
 
360
365
  const ensureGitConfig = async (
361
366
  name,
362
- { execCommandInProjectDirectory, valueIfMissing },
367
+ { execCommandInRootDirectory, valueIfMissing },
363
368
  ) => {
364
369
  try {
365
- await execCommandInProjectDirectory(`git config ${name}`)
370
+ await execCommandInRootDirectory(`git config ${name}`)
366
371
  return () => {}
367
372
  } catch (e) {
368
- await execCommandInProjectDirectory(
373
+ await execCommandInRootDirectory(
369
374
  `git config ${name} "${valueIfMissing}"`,
370
375
  )
371
376
  return async () => {
372
- await execCommandInProjectDirectory(`git config --unset ${name}`)
377
+ await execCommandInRootDirectory(`git config --unset ${name}`)
373
378
  }
374
379
  }
375
380
  }
@@ -11,11 +11,11 @@ export const exec = (
11
11
  cwd,
12
12
  stdio: "silent",
13
13
  },
14
- (error) => {
14
+ (error, out) => {
15
15
  if (error) {
16
16
  reject(error)
17
17
  } else {
18
- resolve()
18
+ resolve(out)
19
19
  }
20
20
  },
21
21
  )
@@ -28,7 +28,7 @@ export const readGitHubWorkflowEnv = () => {
28
28
  }
29
29
  : undefined
30
30
  return {
31
- projectDirectoryUrl: process.env.GITHUB_WORKSPACE,
31
+ rootDirectoryUrl: process.env.GITHUB_WORKSPACE,
32
32
  githubToken,
33
33
  repositoryOwner,
34
34
  repositoryName,