Skip to content

Guard against null getTitle(); send same comment body to each Jira issue - #9

Open
tosfos wants to merge 2 commits into
mainfrom
fix-getTitle-null-and-comment-body
Open

Guard against null getTitle(); send same comment body to each Jira issue#9
tosfos wants to merge 2 commits into
mainfrom
fix-getTitle-null-and-comment-body

Conversation

@tosfos

@tosfos tosfos commented Feb 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Two fixes in PageSaveComplete hook handler:

  1. Null getTitle(): WikiPage::getTitle() can return null in edge cases. We now check and return early in onPageSaveComplete, and defensively in getDiffLink() return '' when title is null, avoiding a fatal when calling getFullText() or getFullURL().

  2. 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

  • src/Hooks.php: Early return when $wikiPage->getTitle() is null; build $commentBody once and pass it to each sendToJira() call; in getDiffLink() null-check title and return '' when null.

Testing

  • php -l src/Hooks.php passes.

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.

@tosfos

tosfos commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

SLOP-51 SLOP-52

tosfos and others added 2 commits July 10, 2026 14:22
- 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.
@tosfos
tosfos force-pushed the fix-getTitle-null-and-comment-body branch from b74a55c to 03f3e82 Compare July 10, 2026 19:11
@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved page-save reliability when a page has no title.
    • Jira comments now consistently include the page title, diff link, and author when added to multiple issues.
    • Prevented unnecessary replacement of the HTTP connection, improving request handling and stability.
  • Tests
    • Added coverage for posting identical comment content to multiple Jira issues.
    • Improved test isolation to prevent shared connection state from affecting results.

Walkthrough

Hooks 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.

Changes

Jira comment dispatch

Layer / File(s) Summary
Hook dispatch and title handling
src/Hooks.php
The HTTP client is nullable and lazily initialized; page-save handling exits when no title exists, builds one reusable comment body, and applies defensive title handling to diff links.
Dispatch validation and test isolation
tests/phpunit/integration/HooksIntegrationTest.php, tests/phpunit/unit/HooksUnitTest.php
Tests reset the shared client after execution, while integration coverage verifies identical comment bodies and the expected Jira endpoints for multiple issues.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the two main changes: null title handling and reusing the same Jira comment body per issue.
Description check ✅ Passed The description matches the changeset and explains both fixes and the added test coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 win

Check the Jira response code before returning success. MultiHttpClient::run() returns a response map even for 4xx/5xx responses, so sendToJira() can report success when Jira rejects the comment. Return false unless 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 value

Rename $summary parameter to reflect its actual content.

sendToJira now receives $commentBody from onPageSaveComplete, but the parameter is still named $summary and 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

📥 Commits

Reviewing files that changed from the base of the PR and between b5692cf and 03f3e82.

📒 Files selected for processing (3)
  • src/Hooks.php
  • tests/phpunit/integration/HooksIntegrationTest.php
  • tests/phpunit/unit/HooksUnitTest.php

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