fix: Ensure installation ID is set correctly in GitHub payload handling#64
fix: Ensure installation ID is set correctly in GitHub payload handling#64
Conversation
|
No actionable comments were generated in the recent review. 🎉 WalkthroughThe 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)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 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 toisset($x) ? $x : nullfor 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).
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