@argos-ci/core 5.0.0 → 5.0.2
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.js +87 -17
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -238,11 +238,13 @@ var heroku_default = service3;
|
|
|
238
238
|
|
|
239
239
|
// src/ci-environment/services/github-actions.ts
|
|
240
240
|
import { existsSync, readFileSync } from "fs";
|
|
241
|
-
|
|
242
|
-
debug("Fetching pull request number from head sha", sha);
|
|
241
|
+
function getGitHubRepository({ env }) {
|
|
243
242
|
if (!env.GITHUB_REPOSITORY) {
|
|
244
243
|
throw new Error("GITHUB_REPOSITORY is missing");
|
|
245
244
|
}
|
|
245
|
+
return env.GITHUB_REPOSITORY;
|
|
246
|
+
}
|
|
247
|
+
function getGitHubToken({ env }) {
|
|
246
248
|
if (!env.GITHUB_TOKEN) {
|
|
247
249
|
if (!env.DISABLE_GITHUB_TOKEN_WARNING) {
|
|
248
250
|
console.log(
|
|
@@ -262,9 +264,39 @@ DISABLE_GITHUB_TOKEN_WARNING: true
|
|
|
262
264
|
}
|
|
263
265
|
return null;
|
|
264
266
|
}
|
|
267
|
+
return env.GITHUB_TOKEN;
|
|
268
|
+
}
|
|
269
|
+
function getGhAPIHeaders(ctx) {
|
|
270
|
+
const githubToken = getGitHubToken(ctx);
|
|
271
|
+
if (!githubToken) {
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
return {
|
|
275
|
+
Accept: "application/vnd.github+json",
|
|
276
|
+
Authorization: `Bearer ${githubToken}`,
|
|
277
|
+
"X-GitHub-Api-Version": "2022-11-28"
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
async function fetchGitHubAPI(ctx, url) {
|
|
281
|
+
const headers = getGhAPIHeaders(ctx);
|
|
282
|
+
if (!headers) {
|
|
283
|
+
return null;
|
|
284
|
+
}
|
|
285
|
+
const response = await fetch(url, {
|
|
286
|
+
headers,
|
|
287
|
+
signal: AbortSignal.timeout(1e4)
|
|
288
|
+
});
|
|
289
|
+
if (!response.ok) {
|
|
290
|
+
throw new Error(`Failed to fetch GitHub API: ${response.statusText}`);
|
|
291
|
+
}
|
|
292
|
+
return await response.json();
|
|
293
|
+
}
|
|
294
|
+
async function getPullRequestFromHeadSha(ctx, sha) {
|
|
295
|
+
debug("Fetching pull request details from head sha", sha);
|
|
296
|
+
const githubRepository = getGitHubRepository(ctx);
|
|
265
297
|
try {
|
|
266
298
|
const url = new URL(
|
|
267
|
-
`https://api.github.com/repos/${
|
|
299
|
+
`https://api.github.com/repos/${githubRepository}/pulls`
|
|
268
300
|
);
|
|
269
301
|
url.search = new URLSearchParams({
|
|
270
302
|
state: "open",
|
|
@@ -272,18 +304,10 @@ DISABLE_GITHUB_TOKEN_WARNING: true
|
|
|
272
304
|
per_page: "30",
|
|
273
305
|
page: "1"
|
|
274
306
|
}).toString();
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
Authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
|
|
279
|
-
"X-GitHub-Api-Version": "2022-11-28"
|
|
280
|
-
},
|
|
281
|
-
signal: AbortSignal.timeout(1e4)
|
|
282
|
-
});
|
|
283
|
-
if (!response.ok) {
|
|
284
|
-
throw new Error(`Failed to fetch pull requests: ${response.statusText}`);
|
|
307
|
+
const result = await fetchGitHubAPI(ctx, url);
|
|
308
|
+
if (!result) {
|
|
309
|
+
return null;
|
|
285
310
|
}
|
|
286
|
-
const result = await response.json();
|
|
287
311
|
if (result.length === 0) {
|
|
288
312
|
debug("Aborting because no pull request found");
|
|
289
313
|
return null;
|
|
@@ -296,7 +320,27 @@ DISABLE_GITHUB_TOKEN_WARNING: true
|
|
|
296
320
|
debug("Aborting because no pull request found");
|
|
297
321
|
return null;
|
|
298
322
|
} catch (error) {
|
|
299
|
-
debug("Error while fetching pull request from head sha", error);
|
|
323
|
+
debug("Error while fetching pull request details from head sha", error);
|
|
324
|
+
return null;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
async function getPullRequestFromPrNumber(ctx, prNumber) {
|
|
328
|
+
debug("Fetching pull request details from pull request number", prNumber);
|
|
329
|
+
const githubRepository = getGitHubRepository(ctx);
|
|
330
|
+
const headers = getGhAPIHeaders(ctx);
|
|
331
|
+
if (!headers) {
|
|
332
|
+
return null;
|
|
333
|
+
}
|
|
334
|
+
try {
|
|
335
|
+
return await fetchGitHubAPI(
|
|
336
|
+
ctx,
|
|
337
|
+
`https://api.github.com/repos/${githubRepository}/pulls/${prNumber}`
|
|
338
|
+
);
|
|
339
|
+
} catch (error) {
|
|
340
|
+
debug(
|
|
341
|
+
"Error while fetching pull request details from pull request number",
|
|
342
|
+
error
|
|
343
|
+
);
|
|
300
344
|
return null;
|
|
301
345
|
}
|
|
302
346
|
}
|
|
@@ -312,6 +356,14 @@ function getBranchFromContext(context) {
|
|
|
312
356
|
const matches = branchRegex.exec(env.GITHUB_REF);
|
|
313
357
|
return matches?.[1] ?? null;
|
|
314
358
|
}
|
|
359
|
+
function getPRNumberFromMergeGroupBranch(branch2) {
|
|
360
|
+
const prMatch = /queue\/[^/]*\/pr-(\d+)-/.exec(branch2);
|
|
361
|
+
if (prMatch) {
|
|
362
|
+
const prNumber = Number(prMatch[1]);
|
|
363
|
+
return prNumber;
|
|
364
|
+
}
|
|
365
|
+
return null;
|
|
366
|
+
}
|
|
315
367
|
function getBranchFromPayload(payload) {
|
|
316
368
|
if ("workflow_run" in payload && payload.workflow_run) {
|
|
317
369
|
return payload.workflow_run.head_branch;
|
|
@@ -386,7 +438,21 @@ var service4 = {
|
|
|
386
438
|
const vercelPayload = getVercelDeploymentPayload(payload);
|
|
387
439
|
const mergeGroupPayload = getMergeGroupPayload(payload);
|
|
388
440
|
const sha = getSha(context, vercelPayload);
|
|
389
|
-
const pullRequest =
|
|
441
|
+
const pullRequest = await (() => {
|
|
442
|
+
if (vercelPayload || !payload) {
|
|
443
|
+
return getPullRequestFromHeadSha(context, sha);
|
|
444
|
+
}
|
|
445
|
+
if (mergeGroupPayload) {
|
|
446
|
+
const prNumber = getPRNumberFromMergeGroupBranch(
|
|
447
|
+
mergeGroupPayload.merge_group.head_ref
|
|
448
|
+
);
|
|
449
|
+
if (!prNumber) {
|
|
450
|
+
return null;
|
|
451
|
+
}
|
|
452
|
+
return getPullRequestFromPrNumber(context, prNumber);
|
|
453
|
+
}
|
|
454
|
+
return getPullRequestFromPayload(payload);
|
|
455
|
+
})();
|
|
390
456
|
return {
|
|
391
457
|
commit: sha,
|
|
392
458
|
repository: getRepository3(context, payload),
|
|
@@ -395,7 +461,7 @@ var service4 = {
|
|
|
395
461
|
runId: env.GITHUB_RUN_ID || null,
|
|
396
462
|
runAttempt: env.GITHUB_RUN_ATTEMPT ? Number(env.GITHUB_RUN_ATTEMPT) : null,
|
|
397
463
|
nonce: `${env.GITHUB_RUN_ID}-${env.GITHUB_RUN_ATTEMPT}`,
|
|
398
|
-
branch: vercelPayload?.client_payload?.git?.ref || getBranchFromContext(context) || pullRequest?.head.ref || (payload ? getBranchFromPayload(payload) : null) || null,
|
|
464
|
+
branch: (mergeGroupPayload ? pullRequest?.head.ref : null) || vercelPayload?.client_payload?.git?.ref || getBranchFromContext(context) || pullRequest?.head.ref || (payload ? getBranchFromPayload(payload) : null) || null,
|
|
399
465
|
prNumber: pullRequest?.number || null,
|
|
400
466
|
prHeadCommit: pullRequest?.head.sha ?? null,
|
|
401
467
|
prBaseBranch: pullRequest?.base.ref ?? null,
|
|
@@ -816,6 +882,10 @@ var schema = {
|
|
|
816
882
|
env: "ARGOS_SKIPPED",
|
|
817
883
|
format: Boolean,
|
|
818
884
|
default: false
|
|
885
|
+
},
|
|
886
|
+
mergeQueue: {
|
|
887
|
+
format: Boolean,
|
|
888
|
+
default: false
|
|
819
889
|
}
|
|
820
890
|
};
|
|
821
891
|
function createConfig() {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@argos-ci/core",
|
|
3
3
|
"description": "Node.js SDK for visual testing with Argos.",
|
|
4
|
-
"version": "5.0.
|
|
4
|
+
"version": "5.0.2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"exports": {
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"lint": "eslint .",
|
|
68
68
|
"test": "vitest"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "c0561c96e1f820633037a87448791f4ed57e086a"
|
|
71
71
|
}
|