ci/marge_queue: add pretty_dutation()
authorHelen Koike <helen.koike@collabora.com>
Fri, 20 Oct 2023 22:29:13 +0000 (19:29 -0300)
committerMarge Bot <emma+marge@anholt.net>
Tue, 24 Oct 2023 12:57:14 +0000 (12:57 +0000)
Add pretty_duration() function that prints time in format 6m23s and use
it for marge_queue.

Signed-of-by: Helen Koike <helen.koike@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25822>

bin/ci/gitlab_common.py
bin/ci/marge_queue.py

index 758f81b..04afa87 100644 (file)
@@ -12,6 +12,17 @@ import time
 from typing import Optional
 
 
+def pretty_duration(seconds):
+    """Pretty print duration"""
+    hours, rem = divmod(seconds, 3600)
+    minutes, seconds = divmod(rem, 60)
+    if hours:
+        return f"{hours:0.0f}h{minutes:0.0f}m{seconds:0.0f}s"
+    if minutes:
+        return f"{minutes:0.0f}m{seconds:0.0f}s"
+    return f"{seconds:0.0f}s"
+
+
 def get_gitlab_project(glab, name: str):
     """Finds a specified gitlab project for given user"""
     if "/" in name:
index ef9edec..5455047 100755 (executable)
@@ -16,7 +16,7 @@ from datetime import datetime, timezone
 from dateutil import parser
 
 import gitlab
-from gitlab_common import read_token
+from gitlab_common import read_token, pretty_duration
 
 REFRESH_WAIT = 30
 MARGE_BOT_USER_ID = 9716
@@ -52,8 +52,10 @@ if __name__ == "__main__":
         for mr in mrs:
             updated = parser.parse(mr.updated_at)
             now = datetime.now(timezone.utc)
-            diff = str(now - updated).split('.', maxsplit=1)[0]
-            print(f"{diff} | \u001b]8;;{mr.web_url}\u001b\\{mr.title}\u001b]8;;\u001b\\")
+            diff = (now - updated).total_seconds()
+            print(
+                f"⛭ \u001b]8;;{mr.web_url}\u001b\\{mr.title}\u001b]8;;\u001b\\ ({pretty_duration(diff)})"
+            )
 
         print("Job waiting: " + str(jobs_num))