Only accept correct change IDs in "Created a revert ..." messages

A user has reported a malformed revert message resulting in an error
popup. So let's make sure that change IDs are valid.

Release-Notes: skip
Google-Bug-Id: b/294786166
Change-Id: Ifa3d3a94712a2424364b17fd31b0337a528aea1a
diff --git a/polygerrit-ui/app/models/change/related-changes-model_test.ts b/polygerrit-ui/app/models/change/related-changes-model_test.ts
index 295f284..0bf7a76 100644
--- a/polygerrit-ui/app/models/change/related-changes-model_test.ts
+++ b/polygerrit-ui/app/models/change/related-changes-model_test.ts
@@ -270,7 +270,8 @@
         messages: [
           {
             ...createChangeMessage(),
-            message: 'Created a revert of this change as 123',
+            message:
+              'Created a revert of this change as If02ca1cd494579d6bb92a157bf1819e3689cd6b1',
             tag: MessageTag.TAG_REVERT as ReviewInputTag,
           },
         ],
diff --git a/polygerrit-ui/app/utils/message-util.ts b/polygerrit-ui/app/utils/message-util.ts
index 5acdf33..c70ccb1 100644
--- a/polygerrit-ui/app/utils/message-util.ts
+++ b/polygerrit-ui/app/utils/message-util.ts
@@ -7,7 +7,7 @@
 import {ChangeId, ChangeMessageInfo} from '../types/common';
 
 function getRevertChangeIdFromMessage(msg: ChangeMessageInfo): ChangeId {
-  const REVERT_REGEX = /^Created a revert of this change as (.*)$/;
+  const REVERT_REGEX = /^Created a revert of this change as (I[0-9a-f]{40})$/;
   const changeId = msg.message.match(REVERT_REGEX)?.[1];
   if (!changeId) throw new Error('revert changeId not found');
   return changeId as ChangeId;
diff --git a/polygerrit-ui/app/utils/message-util_test.ts b/polygerrit-ui/app/utils/message-util_test.ts
index 22a5e4d..ca82818 100644
--- a/polygerrit-ui/app/utils/message-util_test.ts
+++ b/polygerrit-ui/app/utils/message-util_test.ts
@@ -14,12 +14,8 @@
     const messages = [
       {
         ...createChangeMessage(),
-        message: 'Created a revert of this change as 123',
-        tag: MessageTag.TAG_REVERT as ReviewInputTag,
-      },
-      {
-        ...createChangeMessage(),
-        message: 'Created a revert of this change as xyz',
+        message:
+          'Created a revert of this change as If02ca1cd494579d6bb92a157bf1819e3689cd6b1',
         tag: MessageTag.TAG_REVERT as ReviewInputTag,
       },
       {
@@ -30,8 +26,7 @@
     ];
 
     assert.deepEqual(getRevertCreatedChangeIds(messages), [
-      '123' as ChangeId,
-      'xyz' as ChangeId,
+      'If02ca1cd494579d6bb92a157bf1819e3689cd6b1' as ChangeId,
     ]);
   });
 });