summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorGuilherme Gallo <guilherme.gallo@collabora.com>2024-01-22 20:10:04 -0300
committerGuilherme Gallo <guilherme.gallo@collabora.com>2024-01-26 00:37:05 -0300
commit708a26c6074c47476c608ea8d08d9dc8d968efa1 (patch)
tree03678a584df8b48fcfd18eed910ce77deb2d4ee3 /bin
parent50fcea9c34b17e391bb8c5adc021bb13d03a20e2 (diff)
bin/ci: Move get_token_from_default_dir to common
Moved the `get_token_from_default_dir` method to a common module for shared use between `gitlab_gql.py` and `ci_run_n_monitor.py`. This migration facilitates better code organization and potential future reuse. Signed-off-by: Guilherme Gallo <guilherme.gallo@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27206>
Diffstat (limited to 'bin')
-rw-r--r--bin/ci/gitlab_common.py25
-rwxr-xr-xbin/ci/gitlab_gql.py14
2 files changed, 24 insertions, 15 deletions
diff --git a/bin/ci/gitlab_common.py b/bin/ci/gitlab_common.py
index d7ba607771f..57f6c696215 100644
--- a/bin/ci/gitlab_common.py
+++ b/bin/ci/gitlab_common.py
@@ -3,16 +3,17 @@
# Authors:
# Tomeu Vizoso <tomeu.vizoso@collabora.com>
# David Heidelberg <david.heidelberg@collabora.com>
+# Guilherme Gallo <guilherme.gallo@collabora.com>
#
# SPDX-License-Identifier: MIT
'''Shared functions between the scripts.'''
import os
import time
-from typing import Optional
-
+from pathlib import Path
GITLAB_URL = "https://gitlab.freedesktop.org"
+TOKEN_DIR = Path(os.getenv("XDG_CONFIG_HOME") or Path.home() / ".config")
def pretty_duration(seconds):
@@ -50,6 +51,26 @@ def get_gitlab_project(glab, name: str):
return glab.projects.get(project_path)
+def get_token_from_default_dir() -> str:
+ """
+ Retrieves the GitLab token from the default directory.
+
+ Returns:
+ str: The path to the GitLab token file.
+
+ Raises:
+ FileNotFoundError: If the token file is not found.
+ """
+ token_file = TOKEN_DIR / "gitlab-token"
+ try:
+ return str(token_file.resolve())
+ except FileNotFoundError as ex:
+ print(
+ f"Could not find {token_file}, please provide a token file as an argument"
+ )
+ raise ex
+
+
def read_token(token_arg: Optional[str]) -> str:
"""pick token from args or file"""
if token_arg:
diff --git a/bin/ci/gitlab_gql.py b/bin/ci/gitlab_gql.py
index 503a9cc64ce..0e5bc0f5193 100755
--- a/bin/ci/gitlab_gql.py
+++ b/bin/ci/gitlab_gql.py
@@ -9,7 +9,6 @@ from collections import OrderedDict
from copy import deepcopy
from dataclasses import dataclass, field
from itertools import accumulate
-from os import getenv
from pathlib import Path
from subprocess import check_output
from textwrap import dedent
@@ -17,6 +16,7 @@ from typing import Any, Iterable, Optional, Pattern, TypedDict, Union
import yaml
from filecache import DAY, filecache
+from gitlab_common import get_token_from_default_dir
from gql import Client, gql
from gql.transport.requests import RequestsHTTPTransport
from graphql import DocumentNode
@@ -34,18 +34,6 @@ Dag = dict[str, DagNode]
StageSeq = OrderedDict[str, set[str]]
-TOKEN_DIR = Path(getenv("XDG_CONFIG_HOME") or Path.home() / ".config")
-
-
-def get_token_from_default_dir() -> str:
- token_file = TOKEN_DIR / "gitlab-token"
- try:
- return str(token_file.resolve())
- except FileNotFoundError as ex:
- print(
- f"Could not find {token_file}, please provide a token file as an argument"
- )
- raise ex
def get_project_root_dir():