@jsenv/github-pull-request-impact 1.7.1 → 1.7.3
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 +3 -3
- package/package.json +5 -5
- package/src/commentGitHubPullRequestImpact.js +117 -117
- package/src/internal/createGitHubPullRequestCommentText.js +22 -22
- package/src/internal/exec.js +10 -10
- package/src/internal/github_rest_api.js +27 -27
- package/src/internal/renderGeneratedByText.js +5 -5
- package/src/main.js +3 -3
- package/src/readGitHubWorkflowEnv.js +36 -36
package/README.md
CHANGED
|
@@ -8,6 +8,6 @@ Under construction.
|
|
|
8
8
|
|
|
9
9
|
This repository publishes `@jsenv/github-pull-request-impact` on NPM. This package is reused internally by:
|
|
10
10
|
|
|
11
|
-
- [@jsenv/performance-impact](../
|
|
12
|
-
- [@jsenv/file-size-impact](../
|
|
13
|
-
- [@jsenv/lighthouse-impact](../
|
|
11
|
+
- [@jsenv/performance-impact](../performance-impact)
|
|
12
|
+
- [@jsenv/file-size-impact](../file-size-impact)
|
|
13
|
+
- [@jsenv/lighthouse-impact](../lighthouse-impact)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/github-pull-request-impact",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.3",
|
|
4
4
|
"description": "Report pull request impact on something",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
13
|
"url": "https://github.com/jsenv/workflow",
|
|
14
|
-
"directory": "packages/
|
|
14
|
+
"directory": "packages/github-pull-request-impact"
|
|
15
15
|
},
|
|
16
16
|
"engines": {
|
|
17
17
|
"node": ">=16.13.0"
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"test": "node ./scripts/test.mjs"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@jsenv/fetch": "1.1.
|
|
38
|
-
"@jsenv/filesystem": "4.
|
|
39
|
-
"@jsenv/log": "3.
|
|
37
|
+
"@jsenv/fetch": "1.1.41",
|
|
38
|
+
"@jsenv/filesystem": "4.3.2",
|
|
39
|
+
"@jsenv/log": "3.4.1"
|
|
40
40
|
}
|
|
41
41
|
}
|
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
* @jsenv/file-size-impact, @jsenv/performance-impact and @jsenv/lighthouse-score-impact
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { fileURLToPath } from "node:url"
|
|
8
|
-
import { assertAndNormalizeDirectoryUrl } from "@jsenv/filesystem"
|
|
9
|
-
import { createLogger } from "@jsenv/log"
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
import { assertAndNormalizeDirectoryUrl } from "@jsenv/filesystem";
|
|
9
|
+
import { createLogger } from "@jsenv/log";
|
|
10
10
|
|
|
11
|
-
import * as githubRESTAPI from "./internal/github_rest_api.js"
|
|
12
|
-
import { exec } from "./internal/exec.js"
|
|
13
|
-
import { renderGeneratedByText } from "./internal/renderGeneratedByText.js"
|
|
14
|
-
import { createGitHubPullRequestCommentText } from "./internal/createGitHubPullRequestCommentText.js"
|
|
11
|
+
import * as githubRESTAPI from "./internal/github_rest_api.js";
|
|
12
|
+
import { exec } from "./internal/exec.js";
|
|
13
|
+
import { renderGeneratedByText } from "./internal/renderGeneratedByText.js";
|
|
14
|
+
import { createGitHubPullRequestCommentText } from "./internal/createGitHubPullRequestCommentText.js";
|
|
15
15
|
|
|
16
16
|
export const commentGitHubPullRequestImpact = async ({
|
|
17
17
|
logLevel,
|
|
@@ -31,7 +31,7 @@ export const commentGitHubPullRequestImpact = async ({
|
|
|
31
31
|
createCommentForVersionMismatch = jsenvCreateCommentForVersionMismatch,
|
|
32
32
|
createCommentForComparison = jsenvCreateCommentForComparison,
|
|
33
33
|
generatedByLink = {
|
|
34
|
-
url: "https://github.com/jsenv/workflow/tree/main/packages/
|
|
34
|
+
url: "https://github.com/jsenv/workflow/tree/main/packages/github-pull-request-impact",
|
|
35
35
|
text: "@jsenv/github-pull-request-impact",
|
|
36
36
|
},
|
|
37
37
|
runLink,
|
|
@@ -39,42 +39,42 @@ export const commentGitHubPullRequestImpact = async ({
|
|
|
39
39
|
|
|
40
40
|
catchError = false,
|
|
41
41
|
}) => {
|
|
42
|
-
rootDirectoryUrl = assertAndNormalizeDirectoryUrl(rootDirectoryUrl)
|
|
42
|
+
rootDirectoryUrl = assertAndNormalizeDirectoryUrl(rootDirectoryUrl);
|
|
43
43
|
if (typeof collectInfo !== "function") {
|
|
44
44
|
throw new TypeError(
|
|
45
45
|
`collectInfo must be a function but received ${collectInfo}`,
|
|
46
|
-
)
|
|
46
|
+
);
|
|
47
47
|
}
|
|
48
48
|
if (typeof commentIdentifier !== "string") {
|
|
49
49
|
throw new TypeError(
|
|
50
50
|
`commentIdentifier must be a string but received ${commentIdentifier}`,
|
|
51
|
-
)
|
|
51
|
+
);
|
|
52
52
|
}
|
|
53
53
|
if (typeof githubToken !== "string") {
|
|
54
54
|
throw new TypeError(
|
|
55
55
|
`githubToken must be a string but received ${githubToken}`,
|
|
56
|
-
)
|
|
56
|
+
);
|
|
57
57
|
}
|
|
58
58
|
if (typeof repositoryOwner !== "string") {
|
|
59
59
|
throw new TypeError(
|
|
60
60
|
`repositoryOwner must be a string but received ${repositoryOwner}`,
|
|
61
|
-
)
|
|
61
|
+
);
|
|
62
62
|
}
|
|
63
63
|
if (typeof repositoryName !== "string") {
|
|
64
64
|
throw new TypeError(
|
|
65
65
|
`repositoryName must be a string but received ${repositoryName}`,
|
|
66
|
-
)
|
|
66
|
+
);
|
|
67
67
|
}
|
|
68
|
-
pullRequestNumber = String(pullRequestNumber)
|
|
68
|
+
pullRequestNumber = String(pullRequestNumber);
|
|
69
69
|
if (typeof pullRequestNumber !== "string") {
|
|
70
70
|
throw new TypeError(
|
|
71
71
|
`pullRequestNumber must be a string but received ${pullRequestNumber}`,
|
|
72
|
-
)
|
|
72
|
+
);
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
const logger = createLogger({ logLevel })
|
|
75
|
+
const logger = createLogger({ logLevel });
|
|
76
76
|
|
|
77
|
-
let cleanup = () => {}
|
|
77
|
+
let cleanup = () => {};
|
|
78
78
|
|
|
79
79
|
try {
|
|
80
80
|
return await commentPrImpact({
|
|
@@ -99,11 +99,11 @@ export const commentGitHubPullRequestImpact = async ({
|
|
|
99
99
|
commitInGeneratedByInfo,
|
|
100
100
|
|
|
101
101
|
catchError,
|
|
102
|
-
})
|
|
102
|
+
});
|
|
103
103
|
} finally {
|
|
104
|
-
cleanup()
|
|
104
|
+
cleanup();
|
|
105
105
|
}
|
|
106
|
-
}
|
|
106
|
+
};
|
|
107
107
|
|
|
108
108
|
const commentPrImpact = async ({
|
|
109
109
|
logger,
|
|
@@ -129,28 +129,28 @@ const commentPrImpact = async ({
|
|
|
129
129
|
catchError,
|
|
130
130
|
}) => {
|
|
131
131
|
const execCommandInRootDirectory = (command) => {
|
|
132
|
-
logger.info(`> ${command}`)
|
|
132
|
+
logger.info(`> ${command}`);
|
|
133
133
|
return exec(command, {
|
|
134
134
|
cwd: fileURLToPath(rootDirectoryUrl),
|
|
135
135
|
onLog: (string) => {
|
|
136
136
|
if (commandLogs) {
|
|
137
|
-
logger.info(string)
|
|
137
|
+
logger.info(string);
|
|
138
138
|
}
|
|
139
139
|
},
|
|
140
140
|
onErrorLog: (string) => logger.error(string),
|
|
141
|
-
})
|
|
142
|
-
}
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
143
|
|
|
144
|
-
const pullApiUrl = `https://api.github.com/repos/${repositoryOwner}/${repositoryName}/pulls/${pullRequestNumber}
|
|
144
|
+
const pullApiUrl = `https://api.github.com/repos/${repositoryOwner}/${repositoryName}/pulls/${pullRequestNumber}`;
|
|
145
145
|
// https://developer.github.com/v3/pulls/#get-a-pull-request
|
|
146
|
-
logger.debug(`get pull request ${pullApiUrl}`)
|
|
146
|
+
logger.debug(`get pull request ${pullApiUrl}`);
|
|
147
147
|
const pullRequest = await githubRESTAPI.GET({
|
|
148
148
|
url: pullApiUrl,
|
|
149
149
|
githubToken,
|
|
150
|
-
})
|
|
151
|
-
const pullRequestHtmlUrl = pullRequest.html_url
|
|
152
|
-
const pullRequestBase = pullRequest.base.ref
|
|
153
|
-
const pullRequestHead = pullRequest.head.ref
|
|
150
|
+
});
|
|
151
|
+
const pullRequestHtmlUrl = pullRequest.html_url;
|
|
152
|
+
const pullRequestBase = pullRequest.base.ref;
|
|
153
|
+
const pullRequestHead = pullRequest.head.ref;
|
|
154
154
|
|
|
155
155
|
/*
|
|
156
156
|
Adds a commit-sha hidden at the top of the comment body:
|
|
@@ -160,8 +160,8 @@ const commentPrImpact = async ({
|
|
|
160
160
|
was not updated (It happened to me several times).
|
|
161
161
|
*/
|
|
162
162
|
const commentHeader = `${commentIdentifier}
|
|
163
|
-
<!-- head-commit-sha=${pullRequest.head.sha}
|
|
164
|
-
const commentWarnings = []
|
|
163
|
+
<!-- head-commit-sha=${pullRequest.head.sha} -->`;
|
|
164
|
+
const commentWarnings = [];
|
|
165
165
|
const commentFooter = renderGeneratedByText({
|
|
166
166
|
generatedByLink,
|
|
167
167
|
runLink,
|
|
@@ -171,179 +171,179 @@ const commentPrImpact = async ({
|
|
|
171
171
|
text: shortenCommiSha(pullRequest.head.sha),
|
|
172
172
|
}
|
|
173
173
|
: null,
|
|
174
|
-
})
|
|
174
|
+
});
|
|
175
175
|
|
|
176
|
-
logger.debug(`searching comment in pull request ${pullRequestHtmlUrl}`)
|
|
177
|
-
const pullRequestCommentApiUrl = pullRequest.comments_url
|
|
176
|
+
logger.debug(`searching comment in pull request ${pullRequestHtmlUrl}`);
|
|
177
|
+
const pullRequestCommentApiUrl = pullRequest.comments_url;
|
|
178
178
|
const comments = await githubRESTAPI.GET({
|
|
179
179
|
url: pullRequestCommentApiUrl,
|
|
180
180
|
githubToken,
|
|
181
|
-
})
|
|
181
|
+
});
|
|
182
182
|
const existingComment = comments.find(({ body }) =>
|
|
183
183
|
body.includes(commentIdentifier),
|
|
184
|
-
)
|
|
184
|
+
);
|
|
185
185
|
if (existingComment) {
|
|
186
|
-
logger.debug(`comment found at ${existingComment.html_url}.`)
|
|
186
|
+
logger.debug(`comment found at ${existingComment.html_url}.`);
|
|
187
187
|
} else {
|
|
188
|
-
logger.debug(`no existing comment found`)
|
|
188
|
+
logger.debug(`no existing comment found`);
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
const patchOrPostComment = async (commentInfo) => {
|
|
192
|
-
let commentParts
|
|
192
|
+
let commentParts;
|
|
193
193
|
if (typeof commentInfo === "string") {
|
|
194
194
|
commentParts = {
|
|
195
195
|
header: commentHeader,
|
|
196
196
|
warnings: commentWarnings,
|
|
197
197
|
body: commentInfo,
|
|
198
198
|
footer: commentFooter,
|
|
199
|
-
}
|
|
199
|
+
};
|
|
200
200
|
} else {
|
|
201
201
|
commentParts = {
|
|
202
202
|
header: commentHeader,
|
|
203
203
|
warnings: [...commentWarnings, ...(commentInfo.warnings || [])],
|
|
204
204
|
body: commentInfo.body,
|
|
205
205
|
footer: commentFooter,
|
|
206
|
-
}
|
|
206
|
+
};
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
-
const commentBody = createGitHubPullRequestCommentText(commentParts)
|
|
209
|
+
const commentBody = createGitHubPullRequestCommentText(commentParts);
|
|
210
210
|
|
|
211
211
|
if (existingComment) {
|
|
212
212
|
if (existingComment.body === commentBody) {
|
|
213
|
-
logger.info(`existing comment body is the same -> skip comment PATCH`)
|
|
214
|
-
return existingComment
|
|
213
|
+
logger.info(`existing comment body is the same -> skip comment PATCH`);
|
|
214
|
+
return existingComment;
|
|
215
215
|
}
|
|
216
|
-
logger.info(`updating comment at ${existingComment.html_url}`)
|
|
216
|
+
logger.info(`updating comment at ${existingComment.html_url}`);
|
|
217
217
|
const comment = await githubRESTAPI.PATCH({
|
|
218
218
|
url: `https://api.github.com/repos/${repositoryOwner}/${repositoryName}/issues/comments/${existingComment.id}`,
|
|
219
219
|
githubToken,
|
|
220
220
|
body: { body: commentBody },
|
|
221
|
-
})
|
|
222
|
-
logger.info("comment updated")
|
|
223
|
-
return comment
|
|
221
|
+
});
|
|
222
|
+
logger.info("comment updated");
|
|
223
|
+
return comment;
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
-
logger.info(`creating comment`)
|
|
226
|
+
logger.info(`creating comment`);
|
|
227
227
|
const comment = await githubRESTAPI.POST({
|
|
228
228
|
url: `https://api.github.com/repos/${repositoryOwner}/${repositoryName}/issues/${pullRequestNumber}/comments`,
|
|
229
229
|
githubToken,
|
|
230
230
|
body: { body: commentBody },
|
|
231
|
-
})
|
|
232
|
-
logger.info(`comment created at ${comment.html_url}`)
|
|
233
|
-
return comment
|
|
234
|
-
}
|
|
231
|
+
});
|
|
232
|
+
logger.info(`comment created at ${comment.html_url}`);
|
|
233
|
+
return comment;
|
|
234
|
+
};
|
|
235
235
|
|
|
236
236
|
const isFork =
|
|
237
|
-
pullRequest.base.repo.full_name !== pullRequest.head.repo.full_name
|
|
237
|
+
pullRequest.base.repo.full_name !== pullRequest.head.repo.full_name;
|
|
238
238
|
const isInPullRequestWorkflow =
|
|
239
|
-
process.env.GITHUB_EVENT_NAME === "pull_request"
|
|
239
|
+
process.env.GITHUB_EVENT_NAME === "pull_request";
|
|
240
240
|
if (isFork && isInPullRequestWorkflow) {
|
|
241
|
-
logger.warn(formatGithubTokenNotAllowedToCommentWarning())
|
|
241
|
+
logger.warn(formatGithubTokenNotAllowedToCommentWarning());
|
|
242
242
|
}
|
|
243
243
|
|
|
244
|
-
let headRef
|
|
244
|
+
let headRef;
|
|
245
245
|
if (isFork) {
|
|
246
246
|
// https://github.community/t/checkout-a-branch-from-a-fork/276/2
|
|
247
|
-
headRef = `refs/pull/${pullRequestNumber}/merge
|
|
247
|
+
headRef = `refs/pull/${pullRequestNumber}/merge`;
|
|
248
248
|
} else {
|
|
249
|
-
headRef = pullRequestHead
|
|
249
|
+
headRef = pullRequestHead;
|
|
250
250
|
}
|
|
251
251
|
|
|
252
|
-
let beforeMergeInfo
|
|
252
|
+
let beforeMergeInfo;
|
|
253
253
|
try {
|
|
254
254
|
// cannot use depth=1 arg otherwise git merge might have merge conflicts
|
|
255
255
|
await execCommandInRootDirectory(
|
|
256
256
|
`git fetch --no-tags --prune origin ${pullRequestBase}`,
|
|
257
|
-
)
|
|
257
|
+
);
|
|
258
258
|
await execCommandInRootDirectory(
|
|
259
259
|
`git reset --hard origin/${pullRequestBase}`,
|
|
260
|
-
)
|
|
260
|
+
);
|
|
261
261
|
beforeMergeInfo = await collectInfo({
|
|
262
262
|
beforeMerge: true,
|
|
263
263
|
execCommandInRootDirectory,
|
|
264
|
-
})
|
|
264
|
+
});
|
|
265
265
|
if (infoLogs) {
|
|
266
|
-
logger.debug(debugBeforeMergeInfo(beforeMergeInfo))
|
|
266
|
+
logger.debug(debugBeforeMergeInfo(beforeMergeInfo));
|
|
267
267
|
}
|
|
268
268
|
} catch (error) {
|
|
269
|
-
logger.error(error.stack)
|
|
269
|
+
logger.error(error.stack);
|
|
270
270
|
const comment = await patchOrPostComment(
|
|
271
271
|
createCommentForBeforeMergeError(error, {
|
|
272
272
|
pullRequestHead,
|
|
273
273
|
pullRequestBase,
|
|
274
274
|
}),
|
|
275
|
-
)
|
|
275
|
+
);
|
|
276
276
|
if (catchError) {
|
|
277
|
-
return { error, comment }
|
|
277
|
+
return { error, comment };
|
|
278
278
|
}
|
|
279
|
-
throw error
|
|
279
|
+
throw error;
|
|
280
280
|
}
|
|
281
281
|
|
|
282
|
-
let afterMergeInfo
|
|
282
|
+
let afterMergeInfo;
|
|
283
283
|
try {
|
|
284
284
|
// buildCommand might generate files that could conflict when doing the merge
|
|
285
285
|
// reset to avoid potential merge conflicts
|
|
286
286
|
await execCommandInRootDirectory(
|
|
287
287
|
`git reset --hard origin/${pullRequestBase}`,
|
|
288
|
-
)
|
|
288
|
+
);
|
|
289
289
|
// Avoid "The following untracked working tree files would be overwritten by merge" error
|
|
290
|
-
await execCommandInRootDirectory(`git clean -d -f .`)
|
|
290
|
+
await execCommandInRootDirectory(`git clean -d -f .`);
|
|
291
291
|
// cannot use depth=1 arg otherwise git merge might have merge conflicts
|
|
292
292
|
await execCommandInRootDirectory(
|
|
293
293
|
`git fetch --no-tags --prune origin ${headRef}`,
|
|
294
|
-
)
|
|
294
|
+
);
|
|
295
295
|
// ensure there is user.email + user.name required to perform git merge command
|
|
296
296
|
// without them git would complain that it does not know who we are
|
|
297
297
|
|
|
298
298
|
const restoreGitUserEmail = await ensureGitConfig("user.email", {
|
|
299
299
|
valueIfMissing: "you@example.com",
|
|
300
300
|
execCommandInRootDirectory,
|
|
301
|
-
})
|
|
301
|
+
});
|
|
302
302
|
const restoreGitUserName = await ensureGitConfig("user.name", {
|
|
303
303
|
valueIfMissing: "Your Name",
|
|
304
304
|
execCommandInRootDirectory,
|
|
305
|
-
})
|
|
305
|
+
});
|
|
306
306
|
// could we use https://stackoverflow.com/a/6283843 ?
|
|
307
307
|
try {
|
|
308
308
|
await execCommandInRootDirectory(
|
|
309
309
|
`git merge FETCH_HEAD --allow-unrelated-histories --no-ff --no-commit`,
|
|
310
|
-
)
|
|
310
|
+
);
|
|
311
311
|
} catch (e) {
|
|
312
|
-
throw new Error(`git merge command failed (is there a merge conflict?)`)
|
|
312
|
+
throw new Error(`git merge command failed (is there a merge conflict?)`);
|
|
313
313
|
}
|
|
314
|
-
await restoreGitUserEmail()
|
|
315
|
-
await restoreGitUserName()
|
|
314
|
+
await restoreGitUserEmail();
|
|
315
|
+
await restoreGitUserName();
|
|
316
316
|
afterMergeInfo = await collectInfo({
|
|
317
317
|
afterMerge: true,
|
|
318
318
|
execCommandInRootDirectory,
|
|
319
|
-
})
|
|
319
|
+
});
|
|
320
320
|
if (infoLogs) {
|
|
321
|
-
logger.debug(debugAfterMergeInfo(afterMergeInfo))
|
|
321
|
+
logger.debug(debugAfterMergeInfo(afterMergeInfo));
|
|
322
322
|
}
|
|
323
323
|
} catch (error) {
|
|
324
|
-
logger.error(error.stack)
|
|
324
|
+
logger.error(error.stack);
|
|
325
325
|
const gitHubComment = await patchOrPostComment(
|
|
326
326
|
createCommentForAfterMergeError(error, {
|
|
327
327
|
pullRequestHead,
|
|
328
328
|
pullRequestBase,
|
|
329
329
|
}),
|
|
330
|
-
)
|
|
330
|
+
);
|
|
331
331
|
if (catchError) {
|
|
332
|
-
return { error, gitHubComment }
|
|
332
|
+
return { error, gitHubComment };
|
|
333
333
|
}
|
|
334
|
-
throw error
|
|
334
|
+
throw error;
|
|
335
335
|
}
|
|
336
336
|
|
|
337
|
-
const beforeMergeVersion = beforeMergeInfo.version
|
|
338
|
-
const afterMergeVersion = afterMergeInfo.version
|
|
337
|
+
const beforeMergeVersion = beforeMergeInfo.version;
|
|
338
|
+
const afterMergeVersion = afterMergeInfo.version;
|
|
339
339
|
if (beforeMergeVersion !== afterMergeInfo.version) {
|
|
340
340
|
const gitHubComment = await patchOrPostComment(
|
|
341
341
|
createCommentForVersionMismatch({
|
|
342
342
|
beforeMergeVersion,
|
|
343
343
|
afterMergeVersion,
|
|
344
344
|
}),
|
|
345
|
-
)
|
|
346
|
-
return { gitHubComment }
|
|
345
|
+
);
|
|
346
|
+
return { gitHubComment };
|
|
347
347
|
}
|
|
348
348
|
|
|
349
349
|
const commentForComparison = await createCommentForComparison({
|
|
@@ -354,55 +354,55 @@ const commentPrImpact = async ({
|
|
|
354
354
|
beforeMergeData: beforeMergeInfo.data,
|
|
355
355
|
afterMergeData: afterMergeInfo.data,
|
|
356
356
|
existingComment,
|
|
357
|
-
})
|
|
358
|
-
const gitHubComment = await patchOrPostComment(commentForComparison)
|
|
357
|
+
});
|
|
358
|
+
const gitHubComment = await patchOrPostComment(commentForComparison);
|
|
359
359
|
|
|
360
|
-
return { gitHubComment }
|
|
361
|
-
}
|
|
360
|
+
return { gitHubComment };
|
|
361
|
+
};
|
|
362
362
|
|
|
363
363
|
const ensureGitConfig = async (
|
|
364
364
|
name,
|
|
365
365
|
{ execCommandInRootDirectory, valueIfMissing },
|
|
366
366
|
) => {
|
|
367
367
|
try {
|
|
368
|
-
await execCommandInRootDirectory(`git config ${name}`)
|
|
369
|
-
return () => {}
|
|
368
|
+
await execCommandInRootDirectory(`git config ${name}`);
|
|
369
|
+
return () => {};
|
|
370
370
|
} catch (e) {
|
|
371
|
-
await execCommandInRootDirectory(`git config ${name} "${valueIfMissing}"`)
|
|
371
|
+
await execCommandInRootDirectory(`git config ${name} "${valueIfMissing}"`);
|
|
372
372
|
return async () => {
|
|
373
|
-
await execCommandInRootDirectory(`git config --unset ${name}`)
|
|
374
|
-
}
|
|
373
|
+
await execCommandInRootDirectory(`git config --unset ${name}`);
|
|
374
|
+
};
|
|
375
375
|
}
|
|
376
|
-
}
|
|
376
|
+
};
|
|
377
377
|
|
|
378
378
|
// https://docs.github.com/en/github/writing-on-github/working-with-advanced-formatting/autolinked-references-and-urls#commit-shas
|
|
379
379
|
const shortenCommiSha = (sha) => {
|
|
380
|
-
if (sha.includes("@")) return sha
|
|
381
|
-
return sha.slice(0, 7)
|
|
382
|
-
}
|
|
380
|
+
if (sha.includes("@")) return sha;
|
|
381
|
+
return sha.slice(0, 7);
|
|
382
|
+
};
|
|
383
383
|
|
|
384
384
|
const debugBeforeMergeInfo = (beforeMergeInfo) => {
|
|
385
385
|
return `
|
|
386
386
|
--- before merge info ---
|
|
387
387
|
${JSON.stringify(beforeMergeInfo, null, " ")}
|
|
388
388
|
|
|
389
|
-
|
|
390
|
-
}
|
|
389
|
+
`;
|
|
390
|
+
};
|
|
391
391
|
|
|
392
392
|
const debugAfterMergeInfo = (afterMergeInfo) => {
|
|
393
393
|
return `
|
|
394
394
|
--- after merge info ---
|
|
395
395
|
${JSON.stringify(afterMergeInfo, null, " ")}
|
|
396
396
|
|
|
397
|
-
|
|
398
|
-
}
|
|
397
|
+
`;
|
|
398
|
+
};
|
|
399
399
|
|
|
400
400
|
const formatGithubTokenNotAllowedToCommentWarning = () => {
|
|
401
401
|
return `The github token will certainly not be allowed to post comment in the pull request.
|
|
402
402
|
This is because pull request comes from a fork and your workflow is runned on "pull_request".
|
|
403
403
|
To fix this, change "pull_request" for "pull_request_target" in your workflow file.
|
|
404
|
-
See https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request_target
|
|
405
|
-
}
|
|
404
|
+
See https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request_target`;
|
|
405
|
+
};
|
|
406
406
|
|
|
407
407
|
const jsenvCreateBeforeMergeErrorComment = (
|
|
408
408
|
error,
|
|
@@ -414,8 +414,8 @@ const jsenvCreateBeforeMergeErrorComment = (
|
|
|
414
414
|
|
|
415
415
|
<pre>${error.stack}</pre>
|
|
416
416
|
|
|
417
|
-
|
|
418
|
-
}
|
|
417
|
+
---`;
|
|
418
|
+
};
|
|
419
419
|
|
|
420
420
|
const jsenvCreateCommentForAfterMergeError = (
|
|
421
421
|
error,
|
|
@@ -427,8 +427,8 @@ const jsenvCreateCommentForAfterMergeError = (
|
|
|
427
427
|
|
|
428
428
|
<pre>${error.stack}</pre>
|
|
429
429
|
|
|
430
|
-
|
|
431
|
-
}
|
|
430
|
+
---`;
|
|
431
|
+
};
|
|
432
432
|
|
|
433
433
|
const jsenvCreateCommentForVersionMismatch = ({
|
|
434
434
|
beforeMergeVersion,
|
|
@@ -442,8 +442,8 @@ Before merge data version: ${beforeMergeVersion}
|
|
|
442
442
|
<br />
|
|
443
443
|
After merge data version: ${afterMergeversion}
|
|
444
444
|
|
|
445
|
-
|
|
446
|
-
}
|
|
445
|
+
---`;
|
|
446
|
+
};
|
|
447
447
|
|
|
448
448
|
const jsenvCreateCommentForComparison = ({
|
|
449
449
|
beforeMergeInfo,
|
|
@@ -452,5 +452,5 @@ const jsenvCreateCommentForComparison = ({
|
|
|
452
452
|
return `--- before merge ---
|
|
453
453
|
${JSON.stringify(beforeMergeInfo, null, " ")}
|
|
454
454
|
--- after merge ---
|
|
455
|
-
${JSON.stringify(afterMergeInfo, null, " ")}
|
|
456
|
-
}
|
|
455
|
+
${JSON.stringify(afterMergeInfo, null, " ")}`;
|
|
456
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const GITHUB_MAX_COMMENT_LENGTH = 65536
|
|
1
|
+
const GITHUB_MAX_COMMENT_LENGTH = 65536;
|
|
2
2
|
|
|
3
3
|
export const createGitHubPullRequestCommentText = ({
|
|
4
4
|
header = "",
|
|
@@ -17,12 +17,12 @@ export const createGitHubPullRequestCommentText = ({
|
|
|
17
17
|
warnings,
|
|
18
18
|
body,
|
|
19
19
|
footer,
|
|
20
|
-
})
|
|
20
|
+
});
|
|
21
21
|
|
|
22
|
-
const commentLength = Buffer.byteLength(commentText)
|
|
22
|
+
const commentLength = Buffer.byteLength(commentText);
|
|
23
23
|
|
|
24
24
|
if (commentLength < maxLength) {
|
|
25
|
-
return commentText
|
|
25
|
+
return commentText;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
// on veut ajouter un warning + savoir combien de place il nous reste
|
|
@@ -33,8 +33,8 @@ export const createGitHubPullRequestCommentText = ({
|
|
|
33
33
|
warnings,
|
|
34
34
|
body,
|
|
35
35
|
footer,
|
|
36
|
-
})
|
|
37
|
-
}
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
38
|
|
|
39
39
|
const truncateComment = ({
|
|
40
40
|
commentLength,
|
|
@@ -49,45 +49,45 @@ const truncateComment = ({
|
|
|
49
49
|
`**Warning:** The comment body was truncated to fit GitHub limit on comment length.
|
|
50
50
|
As the body is truncated the message might be hard to read.
|
|
51
51
|
For the record the full comment length was ${commentLength} bytes.`,
|
|
52
|
-
]
|
|
52
|
+
];
|
|
53
53
|
|
|
54
54
|
const commentWithFakeBody = composeCommentText({
|
|
55
55
|
header,
|
|
56
56
|
warnings: warningsWithTruncateWarning,
|
|
57
57
|
body: "a",
|
|
58
58
|
footer,
|
|
59
|
-
})
|
|
60
|
-
const commentWithFakeBodyLength = Buffer.byteLength(commentWithFakeBody)
|
|
61
|
-
let bytesAvailableForBody = maxLength - commentWithFakeBodyLength
|
|
59
|
+
});
|
|
60
|
+
const commentWithFakeBodyLength = Buffer.byteLength(commentWithFakeBody);
|
|
61
|
+
let bytesAvailableForBody = maxLength - commentWithFakeBodyLength;
|
|
62
62
|
// add 1 because fake body had one letter
|
|
63
|
-
bytesAvailableForBody
|
|
63
|
+
bytesAvailableForBody++;
|
|
64
64
|
// remove byte length of `…` that is appended to the truncated body
|
|
65
|
-
bytesAvailableForBody -= Buffer.byteLength(`…`)
|
|
65
|
+
bytesAvailableForBody -= Buffer.byteLength(`…`);
|
|
66
66
|
|
|
67
|
-
const bodyTruncated = `${body.slice(0, bytesAvailableForBody)}
|
|
67
|
+
const bodyTruncated = `${body.slice(0, bytesAvailableForBody)}…`;
|
|
68
68
|
|
|
69
69
|
return composeCommentText({
|
|
70
70
|
header,
|
|
71
71
|
warnings: warningsWithTruncateWarning,
|
|
72
72
|
body: bodyTruncated,
|
|
73
73
|
footer,
|
|
74
|
-
})
|
|
75
|
-
}
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
76
|
|
|
77
77
|
const composeCommentText = ({ header, warnings, body, footer }) => {
|
|
78
|
-
const warningsAsText = composeWarningsText(warnings)
|
|
78
|
+
const warningsAsText = composeWarningsText(warnings);
|
|
79
79
|
const parts = [header, warningsAsText, body, footer].filter(
|
|
80
80
|
(string) => string.length > 0,
|
|
81
|
-
)
|
|
81
|
+
);
|
|
82
82
|
|
|
83
83
|
return parts.join(`
|
|
84
84
|
|
|
85
|
-
`)
|
|
86
|
-
}
|
|
85
|
+
`);
|
|
86
|
+
};
|
|
87
87
|
|
|
88
88
|
const composeWarningsText = (warnings) => {
|
|
89
89
|
if (warnings.length === 0) {
|
|
90
|
-
return ""
|
|
90
|
+
return "";
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
return `---
|
|
@@ -96,5 +96,5 @@ ${warnings.join(`
|
|
|
96
96
|
|
|
97
97
|
`)}
|
|
98
98
|
|
|
99
|
-
|
|
100
|
-
}
|
|
99
|
+
---`;
|
|
100
|
+
};
|
package/src/internal/exec.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { exec as nodeExec } from "node:child_process"
|
|
1
|
+
import { exec as nodeExec } from "node:child_process";
|
|
2
2
|
|
|
3
3
|
export const exec = (
|
|
4
4
|
command,
|
|
@@ -13,20 +13,20 @@ export const exec = (
|
|
|
13
13
|
},
|
|
14
14
|
(error, out) => {
|
|
15
15
|
if (error) {
|
|
16
|
-
reject(error)
|
|
16
|
+
reject(error);
|
|
17
17
|
} else {
|
|
18
|
-
resolve(out)
|
|
18
|
+
resolve(out);
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
|
-
)
|
|
21
|
+
);
|
|
22
22
|
|
|
23
23
|
commandProcess.stdout.on("data", (data) => {
|
|
24
|
-
onLog(data)
|
|
25
|
-
})
|
|
24
|
+
onLog(data);
|
|
25
|
+
});
|
|
26
26
|
commandProcess.stderr.on("data", (data) => {
|
|
27
27
|
// debug because this output is part of
|
|
28
28
|
// the error message generated by a failing npm publish
|
|
29
|
-
onErrorLog(data)
|
|
30
|
-
})
|
|
31
|
-
})
|
|
32
|
-
}
|
|
29
|
+
onErrorLog(data);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { fetchUrl } from "@jsenv/fetch"
|
|
1
|
+
import { fetchUrl } from "@jsenv/fetch";
|
|
2
2
|
|
|
3
3
|
export const GET = async ({ url, githubToken, headers }) => {
|
|
4
4
|
return sendHttpRequest({
|
|
@@ -10,13 +10,13 @@ export const GET = async ({ url, githubToken, headers }) => {
|
|
|
10
10
|
},
|
|
11
11
|
responseStatusHandlers: {
|
|
12
12
|
200: async (response) => {
|
|
13
|
-
const json = await response.json()
|
|
14
|
-
return json
|
|
13
|
+
const json = await response.json();
|
|
14
|
+
return json;
|
|
15
15
|
},
|
|
16
16
|
404: () => null,
|
|
17
17
|
},
|
|
18
|
-
})
|
|
19
|
-
}
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
20
|
|
|
21
21
|
export const POST = ({ url, body, githubToken, headers }) => {
|
|
22
22
|
return sendHttpRequest({
|
|
@@ -29,12 +29,12 @@ export const POST = ({ url, body, githubToken, headers }) => {
|
|
|
29
29
|
body: JSON.stringify(body),
|
|
30
30
|
responseStatusHandlers: {
|
|
31
31
|
201: async (response) => {
|
|
32
|
-
const json = await response.json()
|
|
33
|
-
return json
|
|
32
|
+
const json = await response.json();
|
|
33
|
+
return json;
|
|
34
34
|
},
|
|
35
35
|
},
|
|
36
|
-
})
|
|
37
|
-
}
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
38
|
|
|
39
39
|
export const PATCH = async ({ url, body, githubToken, headers }) => {
|
|
40
40
|
return sendHttpRequest({
|
|
@@ -47,21 +47,21 @@ export const PATCH = async ({ url, body, githubToken, headers }) => {
|
|
|
47
47
|
body: JSON.stringify(body),
|
|
48
48
|
responseStatusHandlers: {
|
|
49
49
|
200: async (response) => {
|
|
50
|
-
const json = await response.json()
|
|
51
|
-
return json
|
|
50
|
+
const json = await response.json();
|
|
51
|
+
return json;
|
|
52
52
|
},
|
|
53
53
|
},
|
|
54
|
-
})
|
|
55
|
-
}
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
56
|
|
|
57
57
|
const tokenToHeaders = (token) => {
|
|
58
58
|
if (!token) {
|
|
59
|
-
throw new Error(`missing token, request will not be authorized.`)
|
|
59
|
+
throw new Error(`missing token, request will not be authorized.`);
|
|
60
60
|
}
|
|
61
61
|
return {
|
|
62
62
|
authorization: `token ${token}`,
|
|
63
|
-
}
|
|
64
|
-
}
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
65
|
|
|
66
66
|
const sendHttpRequest = async ({
|
|
67
67
|
url,
|
|
@@ -70,7 +70,7 @@ const sendHttpRequest = async ({
|
|
|
70
70
|
body,
|
|
71
71
|
responseStatusHandlers = {},
|
|
72
72
|
}) => {
|
|
73
|
-
let response
|
|
73
|
+
let response;
|
|
74
74
|
try {
|
|
75
75
|
response = await fetchUrl(url, {
|
|
76
76
|
method,
|
|
@@ -81,7 +81,7 @@ const sendHttpRequest = async ({
|
|
|
81
81
|
...headers,
|
|
82
82
|
},
|
|
83
83
|
body,
|
|
84
|
-
})
|
|
84
|
+
});
|
|
85
85
|
} catch (error) {
|
|
86
86
|
throw new Error(`network error during request.
|
|
87
87
|
--- request method ---
|
|
@@ -89,15 +89,15 @@ ${method}
|
|
|
89
89
|
--- request url ---
|
|
90
90
|
${url}
|
|
91
91
|
--- error stack ---
|
|
92
|
-
${error.stack}`)
|
|
92
|
+
${error.stack}`);
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
const { status } = response
|
|
96
|
-
const responseStatusHandler = responseStatusHandlers[status]
|
|
95
|
+
const { status } = response;
|
|
96
|
+
const responseStatusHandler = responseStatusHandlers[status];
|
|
97
97
|
if (responseStatusHandler) {
|
|
98
|
-
return responseStatusHandler(response)
|
|
98
|
+
return responseStatusHandler(response);
|
|
99
99
|
}
|
|
100
|
-
const responseBodyAsJson = await response.json()
|
|
100
|
+
const responseBodyAsJson = await response.json();
|
|
101
101
|
const error = new Error(`unexpected response status.
|
|
102
102
|
--- response status ---
|
|
103
103
|
${response.status}
|
|
@@ -108,7 +108,7 @@ ${method}
|
|
|
108
108
|
--- request url ---
|
|
109
109
|
${url}
|
|
110
110
|
--- response json ---
|
|
111
|
-
${(JSON.stringify(responseBodyAsJson), null, " ")}`)
|
|
112
|
-
error.responseStatus = status
|
|
113
|
-
throw error
|
|
114
|
-
}
|
|
111
|
+
${(JSON.stringify(responseBodyAsJson), null, " ")}`);
|
|
112
|
+
error.responseStatus = status;
|
|
113
|
+
throw error;
|
|
114
|
+
};
|
|
@@ -6,8 +6,8 @@ export const renderGeneratedByText = ({
|
|
|
6
6
|
if (runLink && typeof runLink !== "object") {
|
|
7
7
|
console.warn(
|
|
8
8
|
`runLink ignored because it should be an object with {url, text}, received ${runLink}`,
|
|
9
|
-
)
|
|
10
|
-
runLink = null
|
|
9
|
+
);
|
|
10
|
+
runLink = null;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
const parts = [
|
|
@@ -16,9 +16,9 @@ export const renderGeneratedByText = ({
|
|
|
16
16
|
...(commitLink
|
|
17
17
|
? [`on <a href="${commitLink.url}">${commitLink.text}</a>`]
|
|
18
18
|
: []),
|
|
19
|
-
]
|
|
19
|
+
];
|
|
20
20
|
|
|
21
21
|
return `<sub>
|
|
22
22
|
${parts.join(` `)}
|
|
23
|
-
</sub
|
|
24
|
-
}
|
|
23
|
+
</sub>`;
|
|
24
|
+
};
|
package/src/main.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { readGitHubWorkflowEnv } from "./readGitHubWorkflowEnv.js"
|
|
2
|
-
export { commentGitHubPullRequestImpact } from "./commentGitHubPullRequestImpact.js"
|
|
1
|
+
export { readGitHubWorkflowEnv } from "./readGitHubWorkflowEnv.js";
|
|
2
|
+
export { commentGitHubPullRequestImpact } from "./commentGitHubPullRequestImpact.js";
|
|
3
3
|
|
|
4
4
|
// not planned to be documented but can be useful
|
|
5
5
|
// to get a github comment from a { warnings, body } object
|
|
6
|
-
export { createGitHubPullRequestCommentText } from "./internal/createGitHubPullRequestCommentText.js"
|
|
6
|
+
export { createGitHubPullRequestCommentText } from "./internal/createGitHubPullRequestCommentText.js";
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs"
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
2
|
|
|
3
3
|
export const readGitHubWorkflowEnv = () => {
|
|
4
|
-
const eventName = process.env.GITHUB_EVENT_NAME
|
|
4
|
+
const eventName = process.env.GITHUB_EVENT_NAME;
|
|
5
5
|
if (!eventName) {
|
|
6
6
|
throw new Error(
|
|
7
7
|
`missing process.env.GITHUB_EVENT_NAME, we are not in a github workflow`,
|
|
8
|
-
)
|
|
8
|
+
);
|
|
9
9
|
}
|
|
10
10
|
if (eventName !== "pull_request" && eventName !== "pull_request_target") {
|
|
11
|
-
throw new Error(`must be called only in a pull request`)
|
|
11
|
+
throw new Error(`must be called only in a pull request`);
|
|
12
12
|
}
|
|
13
|
-
const githubToken = process.env.GITHUB_TOKEN
|
|
13
|
+
const githubToken = process.env.GITHUB_TOKEN;
|
|
14
14
|
if (!githubToken) {
|
|
15
|
-
throw new Error(`missing githubToken`)
|
|
15
|
+
throw new Error(`missing githubToken`);
|
|
16
16
|
}
|
|
17
|
-
const githubRepository = process.env.GITHUB_REPOSITORY
|
|
17
|
+
const githubRepository = process.env.GITHUB_REPOSITORY;
|
|
18
18
|
if (!githubRepository) {
|
|
19
|
-
throw new Error(`missing process.env.GITHUB_REPOSITORY`)
|
|
19
|
+
throw new Error(`missing process.env.GITHUB_REPOSITORY`);
|
|
20
20
|
}
|
|
21
|
-
const [repositoryOwner, repositoryName] = githubRepository.split("/")
|
|
22
|
-
const pullRequestNumber = readPullRequestNumber()
|
|
23
|
-
const runId = process.env.GITHUB_RUN_ID
|
|
21
|
+
const [repositoryOwner, repositoryName] = githubRepository.split("/");
|
|
22
|
+
const pullRequestNumber = readPullRequestNumber();
|
|
23
|
+
const runId = process.env.GITHUB_RUN_ID;
|
|
24
24
|
const runLink = runId
|
|
25
25
|
? {
|
|
26
26
|
url: `https://github.com/${repositoryOwner}/${repositoryName}/actions/runs/${runId}`,
|
|
27
27
|
text: `${process.env.GITHUB_WORKFLOW || "workflow"}#${runId}`,
|
|
28
28
|
}
|
|
29
|
-
: undefined
|
|
29
|
+
: undefined;
|
|
30
30
|
return {
|
|
31
31
|
rootDirectoryUrl: process.env.GITHUB_WORKSPACE,
|
|
32
32
|
githubToken,
|
|
@@ -34,47 +34,47 @@ export const readGitHubWorkflowEnv = () => {
|
|
|
34
34
|
repositoryName,
|
|
35
35
|
pullRequestNumber,
|
|
36
36
|
runLink,
|
|
37
|
-
}
|
|
38
|
-
}
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
39
|
|
|
40
40
|
const readPullRequestNumber = () => {
|
|
41
|
-
const githubRef = process.env.GITHUB_REF
|
|
41
|
+
const githubRef = process.env.GITHUB_REF;
|
|
42
42
|
if (!githubRef) {
|
|
43
|
-
throw new Error(`missing process.env.GITHUB_REF`)
|
|
43
|
+
throw new Error(`missing process.env.GITHUB_REF`);
|
|
44
44
|
}
|
|
45
|
-
const pullRequestNumber = githubRefToPullRequestNumber(githubRef)
|
|
46
|
-
if (pullRequestNumber) return pullRequestNumber
|
|
45
|
+
const pullRequestNumber = githubRefToPullRequestNumber(githubRef);
|
|
46
|
+
if (pullRequestNumber) return pullRequestNumber;
|
|
47
47
|
// https://github.com/actions/checkout/issues/58#issuecomment-589447479
|
|
48
|
-
const githubEventFilePath = process.env.GITHUB_EVENT_PATH
|
|
48
|
+
const githubEventFilePath = process.env.GITHUB_EVENT_PATH;
|
|
49
49
|
if (githubEventFilePath) {
|
|
50
50
|
console.warn(`pull request number not found in process.env.GITHUB_REF, trying inside github event file.
|
|
51
51
|
--- process.env.GITHUB_REF ---
|
|
52
52
|
${githubRef}
|
|
53
53
|
--- github event file path ---
|
|
54
54
|
${githubEventFilePath}
|
|
55
|
-
`)
|
|
56
|
-
const githubEventFileContent = String(readFileSync(githubEventFilePath))
|
|
57
|
-
const githubEvent = JSON.parse(githubEventFileContent)
|
|
58
|
-
const pullRequestNumber = githubEvent.pull_request.number
|
|
59
|
-
console.warn(`pull request number found in the file: ${pullRequestNumber}`)
|
|
55
|
+
`);
|
|
56
|
+
const githubEventFileContent = String(readFileSync(githubEventFilePath));
|
|
57
|
+
const githubEvent = JSON.parse(githubEventFileContent);
|
|
58
|
+
const pullRequestNumber = githubEvent.pull_request.number;
|
|
59
|
+
console.warn(`pull request number found in the file: ${pullRequestNumber}`);
|
|
60
60
|
if (pullRequestNumber) {
|
|
61
|
-
return pullRequestNumber
|
|
61
|
+
return pullRequestNumber;
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
throw new Error(`cannot get pull request number from process.env.GITHUB_REF
|
|
65
65
|
--- process.env.GITHUB_REF ---
|
|
66
|
-
${githubRef}`)
|
|
67
|
-
}
|
|
66
|
+
${githubRef}`);
|
|
67
|
+
};
|
|
68
68
|
|
|
69
69
|
const githubRefToPullRequestNumber = (githubRef) => {
|
|
70
|
-
const pullPrefix = "refs/pull/"
|
|
71
|
-
const pullRequestNumberStartIndex = githubRef.indexOf(pullPrefix)
|
|
72
|
-
if (pullRequestNumberStartIndex === -1) return undefined
|
|
70
|
+
const pullPrefix = "refs/pull/";
|
|
71
|
+
const pullRequestNumberStartIndex = githubRef.indexOf(pullPrefix);
|
|
72
|
+
if (pullRequestNumberStartIndex === -1) return undefined;
|
|
73
73
|
const afterPull = githubRef.slice(
|
|
74
74
|
pullRequestNumberStartIndex + pullPrefix.length,
|
|
75
|
-
)
|
|
76
|
-
const slashAfterPullIndex = afterPull.indexOf("/")
|
|
77
|
-
if (slashAfterPullIndex === -1) return undefined
|
|
78
|
-
const pullRequestNumberString = afterPull.slice(0, slashAfterPullIndex)
|
|
79
|
-
return Number(pullRequestNumberString)
|
|
80
|
-
}
|
|
75
|
+
);
|
|
76
|
+
const slashAfterPullIndex = afterPull.indexOf("/");
|
|
77
|
+
if (slashAfterPullIndex === -1) return undefined;
|
|
78
|
+
const pullRequestNumberString = afterPull.slice(0, slashAfterPullIndex);
|
|
79
|
+
return Number(pullRequestNumberString);
|
|
80
|
+
};
|