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:
@@ -27,17 +27,17 @@ import gitlab
|
|||||||
from colorama import Fore, Style
|
from colorama import Fore, Style
|
||||||
from gitlab_common import (
|
from gitlab_common import (
|
||||||
get_gitlab_project,
|
get_gitlab_project,
|
||||||
|
get_gitlab_pipeline_from_url,
|
||||||
read_token,
|
read_token,
|
||||||
wait_for_pipeline,
|
wait_for_pipeline,
|
||||||
pretty_duration,
|
pretty_duration,
|
||||||
|
GITLAB_URL,
|
||||||
)
|
)
|
||||||
from gitlab_gql import GitlabGQL, create_job_needs_dag, filter_dag, print_dag
|
from gitlab_gql import GitlabGQL, create_job_needs_dag, filter_dag, print_dag
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from gitlab_gql import Dag
|
from gitlab_gql import Dag
|
||||||
|
|
||||||
GITLAB_URL = "https://gitlab.freedesktop.org"
|
|
||||||
|
|
||||||
REFRESH_WAIT_LOG = 10
|
REFRESH_WAIT_LOG = 10
|
||||||
REFRESH_WAIT_JOBS = 6
|
REFRESH_WAIT_JOBS = 6
|
||||||
|
|
||||||
@@ -366,15 +366,7 @@ if __name__ == "__main__":
|
|||||||
REV: str = args.rev
|
REV: str = args.rev
|
||||||
|
|
||||||
if args.pipeline_url:
|
if args.pipeline_url:
|
||||||
assert args.pipeline_url.startswith(GITLAB_URL)
|
pipe, cur_project = get_gitlab_pipeline_from_url(gl, args.pipeline_url)
|
||||||
url_path = args.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)
|
|
||||||
REV = pipe.sha
|
REV = pipe.sha
|
||||||
else:
|
else:
|
||||||
mesa_project = gl.projects.get("mesa/mesa")
|
mesa_project = gl.projects.get("mesa/mesa")
|
||||||
|
@@ -12,6 +12,9 @@ import time
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
|
||||||
|
GITLAB_URL = "https://gitlab.freedesktop.org"
|
||||||
|
|
||||||
|
|
||||||
def pretty_duration(seconds):
|
def pretty_duration(seconds):
|
||||||
"""Pretty print duration"""
|
"""Pretty print duration"""
|
||||||
hours, rem = divmod(seconds, 3600)
|
hours, rem = divmod(seconds, 3600)
|
||||||
@@ -23,6 +26,19 @@ def pretty_duration(seconds):
|
|||||||
return f"{seconds:0.0f}s"
|
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):
|
def get_gitlab_project(glab, name: str):
|
||||||
"""Finds a specified gitlab project for given user"""
|
"""Finds a specified gitlab project for given user"""
|
||||||
if "/" in name:
|
if "/" in name:
|
||||||
|
Reference in New Issue
Block a user