Skip to content

Comments

fix: Ensure installation ID is set correctly in GitHub payload handling#64

Open
eldadfux wants to merge 2 commits intomainfrom
fix-missing-null-safety
Open

fix: Ensure installation ID is set correctly in GitHub payload handling#64
eldadfux wants to merge 2 commits intomainfrom
fix-missing-null-safety

Conversation

@eldadfux
Copy link
Member

@eldadfux eldadfux commented Feb 22, 2026

Summary of what was wrong and what was changed:
Cause of the warnings
Line 634 was using $payload['installation']['id'] with no checks.
So you got:
"Trying to access array offset on null" when $payload['installation'] was null.
"Undefined array key 'installation'" when the payload had no installation key.
That can happen for non–GitHub App webhooks (e.g. repo webhooks) or for some event types that don’t send an installation object.

Summary by CodeRabbit

  • Bug Fixes
    • Webhook payload parsing made more tolerant for GitHub events with missing fields, reducing notice errors and improving stability.
    • HTTP response/header handling for Gitea operations now safely defaults missing values to prevent notices and ensure consistent behavior.

@coderabbitai
Copy link

coderabbitai bot commented Feb 22, 2026

No actionable comments were generated in the recent review. 🎉


Walkthrough

The diff adds defensive guards for missing keys in src/VCS/Adapter/Git/GitHub.php: nested webhook payload accesses now use isset checks with default fallbacks (empty strings) for installation, repository, owner, author, head commit, pull_request fields and related URLs/flags; external determination for PRs now derives from head/base login comparison. No function signatures or error handling changes. In src/VCS/Adapter/Git/Gitea.php, header status-code reads were changed to use isset(...) ? ... : 0 to default missing/null headers to 0.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title specifically mentions 'installation ID' and 'GitHub payload handling,' which aligns with the primary objective of adding null-safety checks to prevent warnings when accessing the installation key. While the changes also include similar guards in other files (Gitea.php) and for other fields, the main focus is on the GitHub adapter's payload handling.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-missing-null-safety

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 and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/VCS/Adapter/Git/GitHub.php (1)

634-634: Consider using ?? for consistency with the rest of the function.

The isset() ternary is functionally correct, but the function already uses the null-coalescing operator everywhere else (e.g., lines 641–652, 693–704). Since PHP's ?? has identical semantics to isset($x) ? $x : null for chained array accesses, this could be simplified:

♻️ Proposed simplification
-        $installationId = strval(isset($payload['installation']['id']) ? $payload['installation']['id'] : '');
+        $installationId = (string) ($payload['installation']['id'] ?? '');
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/VCS/Adapter/Git/GitHub.php` at line 634, Replace the ternary with the
null-coalescing operator for consistency: when building $installationId from
$payload use the ?? operator to fall back to an empty string and cast to string
(keep the variable name $installationId and the $payload array reference so the
change is localized to the same assignment site in the GitHub adapter function).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/VCS/Adapter/Git/GitHub.php`:
- Line 634: Replace the ternary with the null-coalescing operator for
consistency: when building $installationId from $payload use the ?? operator to
fall back to an empty string and cast to string (keep the variable name
$installationId and the $payload array reference so the change is localized to
the same assignment site in the GitHub adapter function).

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.

1 participant