roll_util: Look up CLs by hash not Change-Id

Sometimes a cherry-pick will preserve an existing Change-Id so recipes
can't use it to uniquely identify a CL. Instead of looking up the CL by
Change-Id just use the commit hash which should uniquely identify any
CL.

Change-Id: If39fbb51c8ebbe523a466969a1d8db595b22ee8d
Reviewed-on: https://pigweed-review.googlesource.com/c/infra/recipes/+/42420
Reviewed-by: Marc-Antoine Ruel <maruel@google.com>
Commit-Queue: Rob Mohr <mohrr@google.com>
diff --git a/recipe_modules/roll_util/api.py b/recipe_modules/roll_util/api.py
index c78a851..667d4b7 100644
--- a/recipe_modules/roll_util/api.py
+++ b/recipe_modules/roll_util/api.py
@@ -138,17 +138,28 @@
                     .split('\0')
                 ):
                     hash, author, message = commit.split('\n', 2)
-                    match = re.search(r'Change-Id: (I\w+)', message)
                     owner = None
                     reviewers = []
-                    if match:
-                        change_id = match.group(1)
+
+                    full_host = '{}-review.googlesource.com'.format(
+                        self.gerrit_name
+                    )
+
+                    changes = self._api.gerrit.change_query(
+                        'get change-id',
+                        'commit:{}'.format(hash),
+                        host=full_host,
+                        test_data=self._api.json.test_api.output(
+                            [{'_number': 12345}]
+                        ),
+                    ).json.output
+
+                    if changes and len(changes) == 1:
+                        number = changes[0]['_number']
                         step = self._api.gerrit.change_details(
-                            'get {}'.format(change_id),
-                            change_id,
-                            host='{}-review.googlesource.com'.format(
-                                self.gerrit_name
-                            ),
+                            'get {}'.format(number),
+                            number,
+                            host=full_host,
                             test_data=self._api.json.test_api.output(
                                 {
                                     'owner': {'email': 'owner@example.com'},