mirror of
https://github.com/par274/sharpemu.git
synced 2026-07-23 11:19:01 +08:00
[CI] Fix PR artifact-links comment for fork PRs (#227)
The workflow resolved the PR from workflow_run.pull_requests or the head commit, both of which come back empty for PRs from forks — so it logged "No open PR for this build" and never commented. Resolve the PR by its head "owner:branch" (from workflow_run.head_repository/head_branch), which works for forks, keeping the commit-association path as a fallback.
This commit is contained in:
committed by
GitHub
parent
3da7ae7d70
commit
de7973af55
@@ -39,21 +39,36 @@ jobs:
|
|||||||
const run = context.payload.workflow_run;
|
const run = context.payload.workflow_run;
|
||||||
const { owner, repo } = context.repo;
|
const { owner, repo } = context.repo;
|
||||||
|
|
||||||
// Fork PRs leave workflow_run.pull_requests empty, so fall back to
|
// Resolve the PR. Same-repo PRs are in workflow_run.pull_requests, but
|
||||||
// resolving the PR from the build's head commit.
|
// fork PRs leave it empty AND their head commit is not on a base-repo
|
||||||
|
// branch, so listPullRequestsAssociatedWithCommit misses them too. Match
|
||||||
|
// the open PR by its head "owner:branch" instead, which works for forks.
|
||||||
let prNumber;
|
let prNumber;
|
||||||
if (run.pull_requests && run.pull_requests.length > 0) {
|
if (run.pull_requests && run.pull_requests.length > 0) {
|
||||||
prNumber = run.pull_requests[0].number;
|
prNumber = run.pull_requests[0].number;
|
||||||
} else {
|
} else {
|
||||||
const prs = await github.rest.repos.listPullRequestsAssociatedWithCommit({
|
let candidates = [];
|
||||||
owner, repo, commit_sha: run.head_sha,
|
const headOwner = run.head_repository && run.head_repository.owner
|
||||||
});
|
? run.head_repository.owner.login
|
||||||
const open = prs.data.find(pr => pr.state === 'open');
|
: null;
|
||||||
if (!open) {
|
if (headOwner && run.head_branch) {
|
||||||
|
const byHead = await github.rest.pulls.list({
|
||||||
|
owner, repo, state: 'open',
|
||||||
|
head: `${headOwner}:${run.head_branch}`, per_page: 10,
|
||||||
|
});
|
||||||
|
candidates = byHead.data;
|
||||||
|
}
|
||||||
|
if (candidates.length === 0) {
|
||||||
|
const byCommit = await github.rest.repos.listPullRequestsAssociatedWithCommit({
|
||||||
|
owner, repo, commit_sha: run.head_sha,
|
||||||
|
});
|
||||||
|
candidates = byCommit.data.filter(pr => pr.state === 'open');
|
||||||
|
}
|
||||||
|
if (candidates.length === 0) {
|
||||||
core.info('No open PR for this build; nothing to comment.');
|
core.info('No open PR for this build; nothing to comment.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
prNumber = open.number;
|
prNumber = candidates[0].number;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect the per-platform artifacts the build produced.
|
// Collect the per-platform artifacts the build produced.
|
||||||
|
|||||||
Reference in New Issue
Block a user