ci/ci_run_n_monitor: move get_gitlab_pipeline_from_url() to gitlab_common

Move this code to gitlab_common since it can be re-used by other
scripts.

Signed-off-by: Helen Koike <helen.koike@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25793>
This commit is contained in:
Helen Koike
2023-10-18 17:09:48 -03:00
committed by Marge Bot
parent ce200669b1
commit 9e8cbc8e91
2 changed files with 19 additions and 11 deletions

View File

@@ -12,6 +12,9 @@ import time
from typing import Optional
GITLAB_URL = "https://gitlab.freedesktop.org"
def pretty_duration(seconds):
"""Pretty print duration"""
hours, rem = divmod(seconds, 3600)
@@ -23,6 +26,19 @@ def pretty_duration(seconds):
return f"{seconds:0.0f}s"
def get_gitlab_pipeline_from_url(gl, pipeline_url):
assert pipeline_url.startswith(GITLAB_URL)
url_path = pipeline_url[len(GITLAB_URL) :]
url_path_components = url_path.split("/")
project_name = "/".join(url_path_components[1:3])
assert url_path_components[3] == "-"
assert url_path_components[4] == "pipelines"
pipeline_id = int(url_path_components[5])
cur_project = gl.projects.get(project_name)
pipe = cur_project.pipelines.get(pipeline_id)
return pipe, cur_project
def get_gitlab_project(glab, name: str):
"""Finds a specified gitlab project for given user"""
if "/" in name: