testdriverai 7.2.80 → 7.2.81
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/interfaces/vitest-plugin.mjs +45 -1
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { execSync } from "child_process";
|
|
2
2
|
import crypto from "crypto";
|
|
3
|
+
import fs from "fs";
|
|
3
4
|
import { createRequire } from "module";
|
|
4
5
|
import path from "path";
|
|
5
6
|
import { postOrUpdateTestResults } from "../lib/github-comment.mjs";
|
|
@@ -1201,6 +1202,49 @@ function getGitInfo() {
|
|
|
1201
1202
|
// GitHub Comment Helper
|
|
1202
1203
|
// ============================================================================
|
|
1203
1204
|
|
|
1205
|
+
/**
|
|
1206
|
+
* Extract PR number from GitHub Actions environment
|
|
1207
|
+
* Checks multiple sources: env vars, event file, and GITHUB_REF
|
|
1208
|
+
* @returns {string|null} PR number or null if not found
|
|
1209
|
+
*/
|
|
1210
|
+
function extractPRNumber() {
|
|
1211
|
+
// Try direct environment variables first
|
|
1212
|
+
let prNumber =
|
|
1213
|
+
process.env.GITHUB_PR_NUMBER ||
|
|
1214
|
+
process.env.TD_GITHUB_PR ||
|
|
1215
|
+
process.env.PR_NUMBER;
|
|
1216
|
+
|
|
1217
|
+
if (prNumber) {
|
|
1218
|
+
return prNumber;
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
// Try to extract from GitHub Actions event path
|
|
1222
|
+
if (process.env.GITHUB_EVENT_PATH) {
|
|
1223
|
+
try {
|
|
1224
|
+
const eventData = JSON.parse(
|
|
1225
|
+
fs.readFileSync(process.env.GITHUB_EVENT_PATH, "utf8"),
|
|
1226
|
+
);
|
|
1227
|
+
if (eventData.pull_request?.number) {
|
|
1228
|
+
return String(eventData.pull_request.number);
|
|
1229
|
+
}
|
|
1230
|
+
} catch (err) {
|
|
1231
|
+
logger.debug("Could not read GitHub event file:", err.message);
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
// Try to extract from GITHUB_REF (refs/pull/123/merge or refs/pull/123/head)
|
|
1236
|
+
if (process.env.GITHUB_REF) {
|
|
1237
|
+
const match = process.env.GITHUB_REF.match(
|
|
1238
|
+
/refs\/pull\/(\d+)\/(merge|head)/,
|
|
1239
|
+
);
|
|
1240
|
+
if (match) {
|
|
1241
|
+
return match[1];
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
|
|
1245
|
+
return null;
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1204
1248
|
/**
|
|
1205
1249
|
* Post GitHub comment with test results if enabled
|
|
1206
1250
|
* Checks for GitHub token and PR number in environment variables
|
|
@@ -1220,7 +1264,7 @@ async function postGitHubCommentIfEnabled(testRunUrl, stats, completeData) {
|
|
|
1220
1264
|
|
|
1221
1265
|
// Check if GitHub comment posting is enabled
|
|
1222
1266
|
const githubToken = process.env.GITHUB_TOKEN || process.env.GH_TOKEN;
|
|
1223
|
-
const prNumber =
|
|
1267
|
+
const prNumber = extractPRNumber();
|
|
1224
1268
|
const commitSha = process.env.GITHUB_SHA || pluginState.gitInfo.commit;
|
|
1225
1269
|
|
|
1226
1270
|
// Only post if we have a token and either a PR number or commit SHA
|