Improve PR resolution logic for web flasher link comments
This commit is contained in:
@@ -38,20 +38,21 @@ jobs:
|
|||||||
const run = context.payload.workflow_run;
|
const run = context.payload.workflow_run;
|
||||||
const { owner, repo } = context.repo;
|
const { owner, repo } = context.repo;
|
||||||
|
|
||||||
// Resolve the PR number (run.pull_requests is empty for fork PRs)
|
// Resolve the PR by matching the run's head SHA against the repo's open
|
||||||
let prNumber = run.pull_requests?.[0]?.number;
|
// PRs. workflow_run.pull_requests is empty for fork PRs, and
|
||||||
if (!prNumber) {
|
// listPullRequestsAssociatedWithCommit won't return an open fork PR by
|
||||||
const { data: prs } = await github.rest.repos.listPullRequestsAssociatedWithCommit({
|
// its head commit — but pulls.list includes fork PRs. Matching on head
|
||||||
owner, repo, commit_sha: run.head_sha,
|
// SHA also enforces that the run is for the PR's current commit, so stale
|
||||||
});
|
// re-runs of an outdated commit won't match.
|
||||||
prNumber = (prs.find((pr) => pr.head.sha === run.head_sha) ?? prs[0])?.number;
|
const openPrs = await github.paginate(github.rest.pulls.list, {
|
||||||
}
|
owner, repo, state: 'open', per_page: 100,
|
||||||
if (!prNumber) {
|
});
|
||||||
core.info('No pull request associated with this run; skipping.');
|
const pr = openPrs.find((p) => p.head.sha === run.head_sha);
|
||||||
|
if (!pr) {
|
||||||
|
core.info(`No open pull request matches commit ${run.head_sha}; skipping.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const prNumber = pr.number;
|
||||||
const { data: pr } = await github.rest.pulls.get({ owner, repo, pull_number: prNumber });
|
|
||||||
|
|
||||||
// Only comment on PRs authored by members of the organization.
|
// Only comment on PRs authored by members of the organization.
|
||||||
// author_association MEMBER is computed by GitHub and reflects org
|
// author_association MEMBER is computed by GitHub and reflects org
|
||||||
@@ -61,14 +62,6 @@ jobs:
|
|||||||
core.info(`Author association ${pr.author_association} is not an org member; skipping.`);
|
core.info(`Author association ${pr.author_association} is not an org member; skipping.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (pr.state !== 'open') {
|
|
||||||
core.info('Pull request is not open; skipping.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (pr.head.sha !== run.head_sha) {
|
|
||||||
core.info('Run is for an outdated commit; skipping.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Require at least one per-arch firmware artifact from gather-artifacts
|
// Require at least one per-arch firmware artifact from gather-artifacts
|
||||||
const artifacts = await github.paginate(github.rest.actions.listWorkflowRunArtifacts, {
|
const artifacts = await github.paginate(github.rest.actions.listWorkflowRunArtifacts, {
|
||||||
|
|||||||
Reference in New Issue
Block a user