ci: Fix parse GitLab pipeline url
When the namespace have a dash, this method cannot recogniza properly the fields in a url. Better to use a regular expression quickly defining the fields. The exception raised, when the pattern is not recognized would help more the handler. Signed-off-by: Sergi Blanch Torne <sergi.blanch.torne@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29683>
This commit is contained in:

committed by
Marge Bot

parent
f1fdba2432
commit
b24dd1fa1c
@@ -43,15 +43,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):
|
def get_gitlab_pipeline_from_url(gl, pipeline_url) -> tuple:
|
||||||
assert pipeline_url.startswith(GITLAB_URL)
|
"""
|
||||||
url_path = pipeline_url[len(GITLAB_URL) :]
|
Extract the project and pipeline object from the url string
|
||||||
url_path_components = url_path.split("/")
|
:param gl: Gitlab object
|
||||||
project_name = "/".join(url_path_components[1:3])
|
:param pipeline_url: string with a url to a pipeline
|
||||||
assert url_path_components[3] == "-"
|
:return: ProjectPipeline, Project objects
|
||||||
assert url_path_components[4] == "pipelines"
|
"""
|
||||||
pipeline_id = int(url_path_components[5])
|
pattern = rf"^{GITLAB_URL}/(.*)/-/pipelines/([0-9]+)$"
|
||||||
cur_project = gl.projects.get(project_name)
|
match = re.match(pattern, pipeline_url)
|
||||||
|
if not match:
|
||||||
|
raise AssertionError(f"url {pipeline_url} doesn't follow the pattern {pattern}")
|
||||||
|
namespace_with_project, pipeline_id = match.groups()
|
||||||
|
cur_project = gl.projects.get(namespace_with_project)
|
||||||
pipe = cur_project.pipelines.get(pipeline_id)
|
pipe = cur_project.pipelines.get(pipeline_id)
|
||||||
return pipe, cur_project
|
return pipe, cur_project
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user