fix(ci): resolve PR number for fork PR plugin uploads#2040
Conversation
The upload-pr-plugin workflow_run job failed at 'Resolve workflow run context' for fork PRs. GitHub leaves workflow_run.pull_requests empty for fork-originated runs, and listPullRequestsAssociatedWithCommit returns nothing because the head commit lives in the fork, not the base repo, so it hit core.setFailed. Match the run's head_sha against open PRs (pr.head.sha is the fork commit) before falling back to the commits API.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
WalkthroughThe upload workflow now resolves pull requests from workflow runs using associated PR metadata, open PR head SHA matching for fork cases, and a head-SHA-based commit lookup fallback. ChangesWorkflow pull request resolution
Estimated code review effort: 2 (Simple) | ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.github/workflows/upload-pr-plugin.yml:
- Around line 54-62: Wrap the listPullRequestsAssociatedWithCommit call in the
fallback block around prNumber in a try/catch, allowing unknown fork commit or
HTTP 422 errors to be ignored so execution reaches the existing core.setFailed
handling when no PR number is resolved.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 58220149-1312-4020-b50f-f7632cb2537c
📒 Files selected for processing (1)
.github/workflows/upload-pr-plugin.yml
| // Last resort: only finds same-repo commits. | ||
| if (!prNumber) { | ||
| const prs = await github.rest.repos.listPullRequestsAssociatedWithCommit({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| commit_sha: workflowRun.head_sha, | ||
| commit_sha: headSha, | ||
| }); | ||
| prNumber = prs.data[0]?.number; | ||
| } |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Handle potential API errors for unknown commits.
If the commit originated from a fork and the PR is no longer open (e.g., closed or force-pushed), prNumber will remain unresolved after checking the open PRs. The script will then fall back to listPullRequestsAssociatedWithCommit, which will throw an HTTP 422 error if the base repository doesn't recognize the fork commit SHA. This will cause the script to crash with an unhandled exception instead of gracefully falling through to your core.setFailed logic at the end.
Wrap the API call in a try/catch block to handle this edge case gracefully.
🛠️ Proposed fix
// Last resort: only finds same-repo commits.
if (!prNumber) {
- const prs = await github.rest.repos.listPullRequestsAssociatedWithCommit({
- owner: context.repo.owner,
- repo: context.repo.repo,
- commit_sha: headSha,
- });
- prNumber = prs.data[0]?.number;
+ try {
+ const prs = await github.rest.repos.listPullRequestsAssociatedWithCommit({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ commit_sha: headSha,
+ });
+ prNumber = prs.data[0]?.number;
+ } catch (error) {
+ core.warning(`Could not look up commit in base repository: ${error.message}`);
+ }
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Last resort: only finds same-repo commits. | |
| if (!prNumber) { | |
| const prs = await github.rest.repos.listPullRequestsAssociatedWithCommit({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| commit_sha: workflowRun.head_sha, | |
| commit_sha: headSha, | |
| }); | |
| prNumber = prs.data[0]?.number; | |
| } | |
| // Last resort: only finds same-repo commits. | |
| if (!prNumber) { | |
| try { | |
| const prs = await github.rest.repos.listPullRequestsAssociatedWithCommit({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| commit_sha: headSha, | |
| }); | |
| prNumber = prs.data[0]?.number; | |
| } catch (error) { | |
| core.warning(`Could not look up commit in base repository: ${error.message}`); | |
| } | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.github/workflows/upload-pr-plugin.yml around lines 54 - 62, Wrap the
listPullRequestsAssociatedWithCommit call in the fallback block around prNumber
in a try/catch, allowing unknown fork commit or HTTP 422 errors to be ignored so
execution reaches the existing core.setFailed handling when no PR number is
resolved.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2040 +/- ##
=======================================
Coverage 52.77% 52.77%
=======================================
Files 1035 1035
Lines 72060 72060
Branches 8303 8298 -5
=======================================
Hits 38031 38031
Misses 33903 33903
Partials 126 126 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
This plugin has been deployed to Cloudflare R2 and is available for testing. |
🔄 PR Merged - Plugin Redirected to StagingThis PR has been merged and the preview plugin has been updated to redirect to the staging version. For users testing this PR:
Staging URL: Thank you for testing! 🚀 |
Fixes CLD-727 — https://linear.app/lime-technology/issue/CLD-727
Summary
The
upload-pr-plugin.ymlworkflow_runjob — the fork-safe path that publishes the PR preview plugin to Cloudflare — fails at its first step, "Resolve workflow run context", for any PR opened from a fork/clone. Same-repo PRs are unaffected.Confirmed against real failed runs (e.g. run
28615830670): only that step failed; every downstream step was skipped.Root cause
workflow_run.pull_requestsempty for fork-originated runs.listPullRequestsAssociatedWithCommitalso returns nothing, because the head commit lives in the fork, notunraid/api.core.setFailed('Unable to resolve a pull request…').Same-repo PRs populate
pull_requestsdirectly, which is why they work and forks don't.Fix
Add a middle resolution step: when
pull_requestsis empty, list open PRs on the base repo and matchpr.head.sha === workflow_run.head_sha.pr.head.shais the fork's commit SHA, so this resolves cross-repo where the commits API can't. The commits-API call is kept as a last resort.Everything downstream already works for forks — the CI artifact lives on the base repo's run, and the
workflow_runjob carries the base repo's secrets andpull-requests: writetoken — so this single step was the only blocker.Testing
Validated the workflow YAML parses. End-to-end behavior only runs in GitHub Actions on a real fork PR; verifiable on the next fork PR.