[PR #13836] fix(github): add null safety for headRepository/baseRepository access #14836

Open
opened 2026-02-16 18:19:35 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/13836

State: open
Merged: No


Summary

Fixes a crash that occurs when headRepository or baseRepository are null when processing PRs, particularly in fork PR scenarios.

The Bug

Error reported in #13812:

null is not an object (evaluating 'prData.headRepository.nameWithOwner')

This occurs when:

  • OpenCode is configured to respond to GitHub Actions events
  • A PR from a fork triggers the action
  • GitHub API doesn't populate headRepository (deleted fork, permissions, etc.)

The Fix

Used optional chaining and early variable extraction:

// Before (crashes):
if (prData.headRepository.nameWithOwner === prData.baseRepository.nameWithOwner)

// After (safe):
const headRepo = prData.headRepository?.nameWithOwner
const baseRepo = prData.baseRepository?.nameWithOwner
if (headRepo && baseRepo && headRepo === baseRepo)

Added explicit error handling for missing repository data:

  • Clear error message when repository information is unavailable
  • Additional validation in checkoutForkBranch function

Impact

Fork PRs no longer cause crashes
Safe handling of partial GitHub API responses
Clear error messages for debugging
No changes to type definitions - purely runtime safety

Fixes #13812

🤖 Generated with Claude Code

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/13836 **State:** open **Merged:** No --- ## Summary Fixes a crash that occurs when `headRepository` or `baseRepository` are null when processing PRs, particularly in fork PR scenarios. ## The Bug Error reported in #13812: ``` null is not an object (evaluating 'prData.headRepository.nameWithOwner') ``` This occurs when: - OpenCode is configured to respond to GitHub Actions events - A PR from a fork triggers the action - GitHub API doesn't populate `headRepository` (deleted fork, permissions, etc.) ## The Fix **Used optional chaining** and early variable extraction: ```typescript // Before (crashes): if (prData.headRepository.nameWithOwner === prData.baseRepository.nameWithOwner) // After (safe): const headRepo = prData.headRepository?.nameWithOwner const baseRepo = prData.baseRepository?.nameWithOwner if (headRepo && baseRepo && headRepo === baseRepo) ``` **Added explicit error handling** for missing repository data: - Clear error message when repository information is unavailable - Additional validation in checkoutForkBranch function ## Impact ✅ Fork PRs no longer cause crashes ✅ Safe handling of partial GitHub API responses ✅ Clear error messages for debugging ✅ No changes to type definitions - purely runtime safety Fixes #13812 🤖 Generated with [Claude Code](https://claude.com/claude-code)
yindo added the pull-request label 2026-02-16 18:19:35 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14836