Skip to content

fix: derive PR number and head SHA for issue_comment events in CLA status check#6

Merged
bashandbone merged 2 commits intofix/cla-assistant-issues-8608742043899548302from
copilot/sub-pr-5
Mar 9, 2026
Merged

fix: derive PR number and head SHA for issue_comment events in CLA status check#6
bashandbone merged 2 commits intofix/cla-assistant-issues-8608742043899548302from
copilot/sub-pr-5

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 9, 2026

In issue_comment events, context.payload.pull_request and context.sha are both undefined, causing the success status check to silently no-op and emit a malformed target_url.

Changes

  • PR number fallback: When context.payload.pull_request?.number is absent, fall back to context.payload.issue.number
  • SHA resolution: When SHA isn't in the payload, fetch it via github.rest.pulls.get using the resolved PR number
  • target_url guarded: Only set when prNumber is defined to avoid /pull/ trailing-slash URLs
let prNumber = context.payload.pull_request?.number;
let sha = context.payload.pull_request?.head?.sha;

if (!prNumber && context.payload.issue?.number) {
  prNumber = context.payload.issue.number;
}

if (!sha && prNumber) {
  const { data: pr } = await github.rest.pulls.get({
    owner: context.repo.owner,
    repo: context.repo.repo,
    pull_number: prNumber,
  });
  sha = pr.head.sha;
}

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

… check

Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>
Copilot AI changed the title [WIP] WIP fix CLA action bugs for exempt personnel and status checks fix: derive PR number and head SHA for issue_comment events in CLA status check Mar 9, 2026
@bashandbone bashandbone marked this pull request as ready for review March 9, 2026 18:03
Copilot AI review requested due to automatic review settings March 9, 2026 18:03
@bashandbone bashandbone merged commit 0f3c5cf into fix/cla-assistant-issues-8608742043899548302 Mar 9, 2026
2 checks passed
@bashandbone bashandbone deleted the copilot/sub-pr-5 branch March 9, 2026 18:03
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the reusable CLA check workflow’s “Create Success Status Check” step to correctly resolve the PR number and head SHA when the triggering event is issue_comment, where context.payload.pull_request and context.sha may be unavailable.

Changes:

  • Add PR number fallback from context.payload.issue.number when pull_request.number is missing.
  • Resolve head SHA by fetching the PR via github.rest.pulls.get when SHA isn’t present in the event payload.
  • Avoid generating malformed target_url values by only setting it when prNumber is defined.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

let prNumber = context.payload.pull_request?.number;
let sha = context.payload.pull_request?.head?.sha;

if (!prNumber && context.payload.issue?.number) {
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

issue_comment fires for both issues and PRs. Falling back to context.payload.issue.number without verifying that the issue is a PR (e.g., context.payload.issue.pull_request exists) can treat an issue number as a PR number, causing the subsequent pulls.get call to 404 and fail this job. Consider guarding the fallback so you only derive prNumber from issue.number when the issue is actually a PR, otherwise skip creating a status.

Suggested change
if (!prNumber && context.payload.issue?.number) {
// For issue_comment events, ensure the issue is actually a PR
// by checking for the presence of the pull_request field.
if (!prNumber && context.payload.issue?.pull_request) {

Copilot uses AI. Check for mistakes.
Comment on lines +251 to +256
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
});
sha = pr.head.sha;
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

The github.rest.pulls.get call is not wrapped in error handling. If the PR lookup fails (non-PR issue_comment, permission issue, API outage/rate limit), the script will throw and fail the workflow, potentially preventing the CLA success status from being set. Recommend catching errors around the fetch and logging + returning (or otherwise falling back) so this step degrades gracefully when SHA resolution is not possible.

Suggested change
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
});
sha = pr.head.sha;
try {
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
});
sha = pr.head.sha;
} catch (error) {
console.log(`Failed to fetch PR ${prNumber} for SHA resolution:`, error);
console.log('Skipping status check because SHA could not be resolved');
return;
}

Copilot uses AI. Check for mistakes.
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.

3 participants