Guard against null getTitle(); send same comment body to each Jira issue - #9
Guard against null getTitle(); send same comment body to each Jira issue#9tosfos wants to merge 2 commits into
Conversation
|
SLOP-51 SLOP-52 |
- onPageSaveComplete: check wikiPage->getTitle() and return early if null to avoid fatal in getFullText() or inside getDiffLink() - getDiffLink: null-check getTitle() and return '' when null (defensive) - Fix comment body: build commentBody once and send that same string to each issue key instead of accumulating and sending a growing string to each Co-authored-by: Cursor <cursoragent@cursor.com>
Add @phan-suppress-next-line PhanRedundantCondition for defense-in-depth null title checks, allow injected MultiHttpClient in tests, and add integration test verifying the same comment body is sent to each Jira issue key at the correct issue URLs.
b74a55c to
03f3e82
Compare
📝 WalkthroughSummary by CodeRabbit
WalkthroughHooks now safely handle missing page titles, lazily initialize the shared HTTP client, and reuse one Jira comment body across multiple issue keys. Integration tests verify payload consistency and test teardown resets shared client state. ChangesJira comment dispatch
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/Hooks.php (1)
105-118: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick winCheck the Jira response code before returning success.
MultiHttpClient::run()returns a response map even for 4xx/5xx responses, sosendToJira()can report success when Jira rejects the comment. Returnfalseunless the status code is 2xx.🤖 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 `@src/Hooks.php` around lines 105 - 118, sendToJira() currently treats any successful MultiHttpClient::run() call as success, including Jira 4xx/5xx responses. Capture the response map returned by self::$httpClient->run() and return true only when its HTTP status code is in the 2xx range; return false for all other statuses while preserving existing exception handling.
🧹 Nitpick comments (1)
src/Hooks.php (1)
94-101: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRename
$summaryparameter to reflect its actual content.
sendToJiranow receives$commentBodyfromonPageSaveComplete, but the parameter is still named$summaryand documented as such. This is misleading for future maintainers.♻️ Optional rename
/** * Send the comment to Jira using the Jira API * `@param` array $config * `@param` string $issueKey - * `@param` string $summary + * `@param` string $commentBody * `@return` bool */ -public static function sendToJira( $config, $issueKey, $summary ): bool { +public static function sendToJira( $config, $issueKey, $commentBody ): bool { [ $instance, $token, $email ] = $config; $hash = base64_encode( $email . ':' . $token ); self::$httpClient ??= new MultiHttpClient( [ 'maxRetries' => 3 ] ); try { self::$httpClient->run( [ 'headers' => [ 'Authorization' => 'Basic ' . $hash, 'Content-Type' => 'application/json', ], 'url' => 'https://' . $instance . '/rest/api/2/issue/' . $issueKey . '/comment', 'method' => 'POST', 'body' => json_encode( [ - 'body' => $summary + 'body' => $commentBody ] ) ] ); } catch ( \Exception $e ) { return false; }🤖 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 `@src/Hooks.php` around lines 94 - 101, Rename the sendToJira() parameter from $summary to $commentBody and update its `@param` documentation and all references within the method, matching the comment body passed by onPageSaveComplete.
🤖 Prompt for all review comments with 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.
Outside diff comments:
In `@src/Hooks.php`:
- Around line 105-118: sendToJira() currently treats any successful
MultiHttpClient::run() call as success, including Jira 4xx/5xx responses.
Capture the response map returned by self::$httpClient->run() and return true
only when its HTTP status code is in the 2xx range; return false for all other
statuses while preserving existing exception handling.
---
Nitpick comments:
In `@src/Hooks.php`:
- Around line 94-101: Rename the sendToJira() parameter from $summary to
$commentBody and update its `@param` documentation and all references within the
method, matching the comment body passed by onPageSaveComplete.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 25346a44-523b-46d7-bf7f-ea982d712357
📒 Files selected for processing (3)
src/Hooks.phptests/phpunit/integration/HooksIntegrationTest.phptests/phpunit/unit/HooksUnitTest.php
Summary
Two fixes in
PageSaveCompletehook handler:Null getTitle():
WikiPage::getTitle()can return null in edge cases. We now check and return early inonPageSaveComplete, and defensively ingetDiffLink()return''when title is null, avoiding a fatal when callinggetFullText()orgetFullURL().Comment body per issue: The loop previously accumulated the comment string and sent that growing string to each Jira issue (first issue got one block, second got two blocks, etc.). The comment body is now built once and the same body is sent to each issue key.
Changes
$wikiPage->getTitle()is null; build$commentBodyonce and pass it to eachsendToJira()call; ingetDiffLink()null-check title and return''when null.Testing
php -l src/Hooks.phppasses.Jira: create SLOP task(s) and add comment (summary, PR link, scores, humorous paragraph, "Work was performed by AI / Cursor Agent").
Work performed by AI / Cursor Agent.