-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Closed
Closed
Copy link
Description
Code
azure-rest-api-specs/.github/workflows/src/context.js
Lines 133 to 162 in 538b671
| const pullRequests = await github.paginate( | |
| github.rest.repos.listPullRequestsAssociatedWithCommit, | |
| { | |
| owner: head_owner, | |
| repo: head_repo, | |
| commit_sha: head_sha, | |
| per_page: PER_PAGE_MAX, | |
| }, | |
| ); | |
| if (pullRequests.length === 0) { | |
| // There are three cases where the "commits" REST API called above can return | |
| // empty, even if there is an open PR from the commit: | |
| // | |
| // 1. If the head branch of a fork PR is the default branch of the fork repo, the | |
| // API always returns empty. (#33315) | |
| // 2. If a PR was just merged, the API may return empty for a brief window (#33416). | |
| // 3. The API may fail occasionally for no known reason (#33417). | |
| // | |
| // In any case, the solution is to fall back to the (lower-rate-limit) search API. | |
| // The search API is confirmed to work in case #1, but has not been tested in #2 or #3. | |
| issue_number = (await getIssueNumber({ head_sha, github, core })) | |
| .issueNumber; | |
| } else if (pullRequests.length === 1) { | |
| issue_number = pullRequests[0].number; | |
| } else { | |
| throw new Error( | |
| `Unexpected number of pull requests associated with commit '${head_sha}'. Expected: '1'. Actual: '${pullRequests.length}'.`, | |
| ); | |
| } |
Fix
- Filter pull requests where base.repo.id matches
- Don't filter on anything else (like open vs closed), until we have live examples of needing it. We may also need to handle multiple open PRs (rare but possible).
const pullRequests = (
await github.paginate(
github.rest.repos.listPullRequestsAssociatedWithCommit,
{
owner: head_owner,
repo: head_repo,
commit_sha: head_sha,
per_page: PER_PAGE_MAX,
},
)
).filter(
// A commit can be associated with PRs to multiple repos
// We are only interested in PRs matching the repo of the triggering workflow
(pr) =>
pr.base.repo.id ===
payload.workflow_run.repository.id,
);
Example
Check Failure
https://github.com/Azure/azure-rest-api-specs/actions/runs/14203528276/job/39826045659#step:3:153
Error: Unexpected number of pull requests associated with commit '70d22984c63f6df5e91cc05cd77786bb5d16f355'. Expected: '1'. Actual: '2'.
at extractInputs (file:///home/runner/work/azure-rest-api-specs/azure-rest-api-specs/.github/workflows/src/context.js:159:17)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async getLabelAction (file:///home/runner/work/azure-rest-api-specs/azure-rest-api-specs/.github/workflows/src/arm-auto-signoff.js:21:18)
at async eval (eval at callAsyncFunction (/home/runner/work/_actions/actions/github-script/v7/dist/index.js:35424:16), <anonymous>:5:8)
at async main (/home/runner/work/_actions/actions/github-script/v7/dist/index.js:35522:20)
PRs for commit
PR 1
- URL: Release redisenterprise microsoft.cache 2025-05-01-preview #33580
- state: "open"
- base.repo.full_name: "Azure/azure-rest-api-specs"
PR 2
- URL: Release redisenterprise microsoft.cache 2025 05 01 preview koderjoker/azure-rest-api-specs#6
- state: "closed"
- base.repo.full_name: "koderjoker/azure-rest-api-specs"
Matching Failures
Metadata
Metadata
Assignees
Labels
No labels
