1
0
Fork 0
mirror of https://github.com/dorny/test-reporter.git synced 2026-03-22 07:52:14 +01:00

Merge pull request #673 from azchohfi/improveWorkflowRun

This commit is contained in:
Jozef Izso 2026-03-02 13:28:11 +01:00 committed by GitHub
commit 7ede0263a4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 25 additions and 2 deletions

View file

@ -1,5 +1,8 @@
# Changelog # Changelog
## 2.6.0
* Fix: For `workflow_run` events, resolve the commit of the check run from related pull request head commits first (matching `workflow_run.head_branch`, then first PR), and fall back to `workflow_run.head_sha` for non-PR runs https://github.com/dorny/test-reporter/pull/673
## 2.5.0 ## 2.5.0
* Feature: Add Nette Tester support with `tester-junit` reporter https://github.com/dorny/test-reporter/pull/707 * Feature: Add Nette Tester support with `tester-junit` reporter https://github.com/dorny/test-reporter/pull/707
* Maintenance: Bump actions/upload-artifact from 5 to 6 https://github.com/dorny/test-reporter/pull/695 * Maintenance: Bump actions/upload-artifact from 5 to 6 https://github.com/dorny/test-reporter/pull/695

12
dist/index.js generated vendored
View file

@ -2947,8 +2947,18 @@ function getCheckRunContext() {
if (!event.workflow_run) { if (!event.workflow_run) {
throw new Error("Event of type 'workflow_run' is missing 'workflow_run' field"); throw new Error("Event of type 'workflow_run' is missing 'workflow_run' field");
} }
const prs = event.workflow_run.pull_requests ?? [];
// For `workflow_run`, we want to report against the PR commit when possible so annotations land
// on the contributor's changes. Prefer the PR whose `head.ref` matches `workflow_run.head_branch`,
// then fall back to the first PR head SHA, and finally to `workflow_run.head_sha` for non-PR runs.
const prShaMatch = prs.find(pr => pr.head?.ref === event.workflow_run.head_branch)?.head?.sha;
const prShaFirst = prs[0]?.head?.sha;
const sha = prShaMatch ?? prShaFirst ?? event.workflow_run.head_sha;
if (!sha) {
throw new Error('Unable to resolve SHA from workflow_run (no PR head.sha or head_sha)');
}
return { return {
sha: event.workflow_run.head_commit.id, sha,
runId: event.workflow_run.id runId: event.workflow_run.id
}; };
} }

View file

@ -13,8 +13,18 @@ export function getCheckRunContext(): {sha: string; runId: number} {
if (!event.workflow_run) { if (!event.workflow_run) {
throw new Error("Event of type 'workflow_run' is missing 'workflow_run' field") throw new Error("Event of type 'workflow_run' is missing 'workflow_run' field")
} }
const prs = event.workflow_run.pull_requests ?? []
// For `workflow_run`, we want to report against the PR commit when possible so annotations land
// on the contributor's changes. Prefer the PR whose `head.ref` matches `workflow_run.head_branch`,
// then fall back to the first PR head SHA, and finally to `workflow_run.head_sha` for non-PR runs.
const prShaMatch = prs.find(pr => pr.head?.ref === event.workflow_run.head_branch)?.head?.sha
const prShaFirst = prs[0]?.head?.sha
const sha = prShaMatch ?? prShaFirst ?? event.workflow_run.head_sha
if (!sha) {
throw new Error('Unable to resolve SHA from workflow_run (no PR head.sha or head_sha)')
}
return { return {
sha: event.workflow_run.head_commit.id, sha,
runId: event.workflow_run.id runId: event.workflow_run.id
} }
} }