2024-06-10 12:12:02 +00:00
|
|
|
"""CI projects."""
|
2024-06-10 16:16:19 +00:00
|
|
|
|
2024-06-09 18:04:29 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2024-06-10 12:22:07 +00:00
|
|
|
import os
|
2024-06-09 16:09:53 +00:00
|
|
|
from pathlib import Path
|
2024-06-10 16:16:19 +00:00
|
|
|
from urllib.parse import urljoin
|
2024-04-27 14:14:03 +00:00
|
|
|
|
|
|
|
GROUP_AND_NAME = [
|
2024-06-08 21:56:21 +00:00
|
|
|
"GITHUB_REPOSITORY",
|
|
|
|
"CI_PROJECT_PATH",
|
2024-04-27 14:14:03 +00:00
|
|
|
]
|
|
|
|
SERVER_URL = [
|
2024-06-08 21:56:21 +00:00
|
|
|
"GITHUB_SERVER_URL",
|
|
|
|
"CI_SERVER_URL",
|
2024-04-27 14:14:03 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2024-04-27 13:32:33 +00:00
|
|
|
class Projects:
|
2024-06-10 12:22:07 +00:00
|
|
|
def __init__(self: Projects) -> None:
|
|
|
|
self.environment = os.environ
|
2024-04-27 14:14:03 +00:00
|
|
|
# group, name
|
|
|
|
for variable in GROUP_AND_NAME:
|
2024-04-27 15:09:51 +00:00
|
|
|
if value := self.environment.get(variable, None):
|
2024-06-09 16:41:20 +00:00
|
|
|
path = Path(value)
|
2024-06-10 16:34:11 +00:00
|
|
|
self.group = str(path.parent)
|
2024-06-09 16:41:20 +00:00
|
|
|
self.name = path.name
|
2024-04-27 14:14:03 +00:00
|
|
|
# url
|
|
|
|
for variable in SERVER_URL:
|
2024-04-27 15:09:51 +00:00
|
|
|
if value := self.environment.get(variable, None):
|
2024-06-10 16:16:19 +00:00
|
|
|
self.url = urljoin(value, self.group)
|
2024-06-10 19:10:51 +00:00
|
|
|
|
|
|
|
def __str__(self: Projects) -> str:
|
2024-06-10 19:29:11 +00:00
|
|
|
return f"""\
|
2024-06-10 19:10:51 +00:00
|
|
|
group = {self.group}
|
|
|
|
name = {self.name}
|
|
|
|
url = {self.url}
|
|
|
|
"""
|