Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion .github/workflows/upload-pr-plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,30 @@ jobs:
script: |
const workflowRun = context.payload.workflow_run;
const runId = workflowRun.id;
const headSha = workflowRun.head_sha;

// Same-repo PRs populate this directly.
let prNumber = workflowRun.pull_requests?.[0]?.number;

// Fork PRs leave pull_requests empty. Match the run's head commit
// against open PRs; pr.head.sha is the fork commit, so this works
// across repositories where the commits API cannot.
if (!prNumber) {
const pulls = await github.paginate(github.rest.pulls.list, {
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
per_page: 100,
});
prNumber = pulls.find((pr) => pr.head.sha === headSha)?.number;
}

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

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.

Expand Down
Loading