Update checks pleaseFixMessage to avoid duplicating summary and message.

The generated "Please fix" message now only includes the result's
message once if the summary and message are identical. Otherwise, it
includes both the summary and the message, separated by a double
newline.

Google-Bug-Id: b/511010429
Release-Notes: skip
Change-Id: I2173c08f9c73901ac40cb861acc3cc6f64899bd3
diff --git a/polygerrit-ui/app/models/checks/checks-util.ts b/polygerrit-ui/app/models/checks/checks-util.ts
index 343ab9e..aaabe67 100644
--- a/polygerrit-ui/app/models/checks/checks-util.ts
+++ b/polygerrit-ui/app/models/checks/checks-util.ts
@@ -95,10 +95,12 @@
   }
 }
 
-function pleaseFixMessage(result: RunResult) {
-  return `Please fix this ${result.category} reported by ${result.checkName}: ${result.summary}
-
-${result.message}`;
+export function pleaseFixMessage(result: RunResult) {
+  const message =
+    result.summary === result.message
+      ? result.message
+      : `${result.summary}\n\n${result.message}`;
+  return `Please fix this ${result.category} reported by ${result.checkName}: ${message}`;
 }
 
 /**
diff --git a/polygerrit-ui/app/models/checks/checks-util_test.ts b/polygerrit-ui/app/models/checks/checks-util_test.ts
index 2473d45..7226528 100644
--- a/polygerrit-ui/app/models/checks/checks-util_test.ts
+++ b/polygerrit-ui/app/models/checks/checks-util_test.ts
@@ -11,6 +11,7 @@
   AttemptChoice,
   computeIsExpandable,
   LATEST_ATTEMPT,
+  pleaseFixMessage,
   rectifyFix,
   reportAiAgentCommentDraft,
   reportAiAgentGetAIFix,
@@ -19,7 +20,7 @@
   toComment,
 } from './checks-util';
 import {Interaction} from '../../constants/reporting';
-import {Fix, Replacement} from '../../api/checks';
+import {Category, Fix, Replacement} from '../../api/checks';
 import {PROVIDED_FIX_ID} from '../../utils/comment-util';
 import {CommentRange, RevisionPatchSetNum} from '../../api/rest-api';
 import {ReportingService} from '../../services/gr-reporting/gr-reporting';
@@ -353,4 +354,34 @@
       assert.isFalse(reportInteractionStub.called);
     });
   });
+
+  suite('pleaseFixMessage', () => {
+    test('when summary and message are the same', () => {
+      const result: RunResult = {
+        ...createRunResult(),
+        category: Category.WARNING,
+        checkName: 'test-check-name',
+        summary: 'this is the warning text',
+        message: 'this is the warning text',
+      };
+      assert.equal(
+        pleaseFixMessage(result),
+        'Please fix this WARNING reported by test-check-name: this is the warning text'
+      );
+    });
+
+    test('when summary and message are not the same', () => {
+      const result: RunResult = {
+        ...createRunResult(),
+        category: Category.ERROR,
+        checkName: 'test-check-name',
+        summary: 'this is the summary text',
+        message: 'this is the message body text',
+      };
+      assert.equal(
+        pleaseFixMessage(result),
+        'Please fix this ERROR reported by test-check-name: this is the summary text\n\nthis is the message body text'
+      );
+    });
+  });
 });