aboutsummaryrefslogtreecommitdiffstats
path: root/gerrit_api.py
diff options
context:
space:
mode:
authorDaniel Smith <daniel.smith@qt.io>2024-07-24 11:03:06 +0200
committerDaniel Smith <daniel.smith@qt.io>2024-07-24 11:04:35 +0200
commitd6752d1912619a52b44dbbe9ef3714386c98a01c (patch)
tree0b2400252230dfd6707db2738ebbf83c0b699696 /gerrit_api.py
Initial Commit of Qt Binary Size Bot
Diffstat (limited to 'gerrit_api.py')
-rw-r--r--gerrit_api.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/gerrit_api.py b/gerrit_api.py
new file mode 100644
index 0000000..356e3e6
--- /dev/null
+++ b/gerrit_api.py
@@ -0,0 +1,28 @@
+# Copyright (C) 2024 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+""" Gerrit API wrapper module for Qt purposes """
+from pygerrit2.rest import GerritRestAPI
+
+
+class GerritApiException(Exception):
+ """ Exception class """
+
+
+# pylint: disable=R0903
+class GerritApi():
+ """ Gerrit API wrapper class for Qt purposes """
+
+ def __init__(self, gerrit_server) -> None:
+ self._server_url = 'https://' + gerrit_server
+
+ def get_coin_task_id(self, sha) -> str:
+ """ Fetches COIN task id from gerrit review comments """
+ client = GerritRestAPI(url=self._server_url)
+
+ messages = client.get('changes/' + sha + '/messages')
+
+ for message in messages:
+ if "Continuous Integration: Passed" in message["message"]:
+ return message["message"].split("tasks/", 1)[1].split("\n")[0]
+
+ raise GerritApiException(f'Gerrit comment from COIN not found from {messages}')