Skip to content

fix(ci): resolve PR number for fork PR plugin uploads#2040

Merged
elibosley merged 1 commit into
mainfrom
fix/fork-pr-plugin-number-resolution
Jul 14, 2026
Merged

fix(ci): resolve PR number for fork PR plugin uploads#2040
elibosley merged 1 commit into
mainfrom
fix/fork-pr-plugin-number-resolution

Conversation

@SimonFair

@SimonFair SimonFair commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Fixes CLD-727 — https://linear.app/lime-technology/issue/CLD-727

Summary

The upload-pr-plugin.yml workflow_run job — 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

  • GitHub leaves workflow_run.pull_requests empty for fork-originated runs.
  • The existing fallback listPullRequestsAssociatedWithCommit also returns nothing, because the head commit lives in the fork, not unraid/api.
  • So the step hits core.setFailed('Unable to resolve a pull request…').

Same-repo PRs populate pull_requests directly, which is why they work and forks don't.

Fix

Add a middle resolution step: when pull_requests is empty, list open PRs on the base repo and match pr.head.sha === workflow_run.head_sha. pr.head.sha is 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_run job carries the base repo's secrets and pull-requests: write token — 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.

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.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The 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.

Changes

Workflow pull request resolution

Layer / File(s) Summary
Resolve workflow run context
.github/workflows/upload-pr-plugin.yml
The script captures headSha, initializes the PR number from associated workflow-run pull requests, searches open PRs by matching head SHA when associations are absent, and uses headSha for the final commit-to-PR lookup.

Estimated code review effort: 2 (Simple) | ~10 minutes

Poem

I’m a rabbit with a workflow key,
Finding the PR where it ought to be.
By head SHA trails I hop and trace,
Even forked paths reveal their place.
The upload runs with cleaner pace.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main CI fix: resolving PR numbers for fork-originated plugin uploads.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/fork-pr-plugin-number-resolution

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2679fda and 14c33fc.

📒 Files selected for processing (1)
  • .github/workflows/upload-pr-plugin.yml

Comment on lines +54 to 62
// 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;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 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.

Suggested change
// 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

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 52.77%. Comparing base (2679fda) to head (14c33fc).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

Copy link
Copy Markdown
Contributor

This plugin has been deployed to Cloudflare R2 and is available for testing.
Download it at this URL:

https://preview.dl.unraid.net/unraid-api/tag/PR2040/dynamix.unraid.net.plg

@elibosley elibosley merged commit a086778 into main Jul 14, 2026
13 checks passed
@elibosley elibosley deleted the fix/fork-pr-plugin-number-resolution branch July 14, 2026 15:27
@github-actions

Copy link
Copy Markdown
Contributor

🔄 PR Merged - Plugin Redirected to Staging

This PR has been merged and the preview plugin has been updated to redirect to the staging version.

For users testing this PR:

  • Your plugin will automatically update to the staging version on the next update check
  • The staging version includes all merged changes from this PR
  • No manual intervention required

Staging URL:

https://preview.dl.unraid.net/unraid-api/dynamix.unraid.net.plg

Thank you for testing! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants