spcd/cd/project.py

43 lines
1,008 B
Python
Raw Normal View History

2024-06-10 12:12:02 +00:00
"""CI project."""
2024-06-10 18:17:37 +00:00
2024-06-09 18:04:29 +00:00
from __future__ import annotations
2024-06-09 16:09:53 +00:00
from pathlib import Path
2024-06-09 18:04:29 +00:00
from typing import TYPE_CHECKING
2024-06-10 18:47:35 +00:00
from urllib.parse import urljoin
2024-06-09 18:04:29 +00:00
if TYPE_CHECKING:
from cd.projects import Projects
2024-04-27 14:14:03 +00:00
BRANCH = [
2024-06-08 21:56:21 +00:00
"GITHUB_REF_NAME",
"CI_COMMIT_BRANCH",
2024-04-27 14:14:03 +00:00
]
NAME = [
2024-06-08 21:56:21 +00:00
"GITHUB_REPOSITORY",
"CI_PROJECT_PATH",
2024-04-27 14:14:03 +00:00
]
2024-05-29 22:21:42 +00:00
ROOT = [
2024-06-08 21:56:21 +00:00
"GITHUB_WORKSPACE",
"CI_PROJECT_DIR",
2024-05-29 22:21:42 +00:00
]
2024-04-27 14:14:03 +00:00
2024-04-27 13:32:33 +00:00
class Project:
2024-06-09 18:04:29 +00:00
def __init__(self: Project, projects: Projects) -> None:
2024-04-27 15:09:51 +00:00
self.projects = projects
2024-04-27 14:14:03 +00:00
# branch
for variable in BRANCH:
2024-04-27 15:09:51 +00:00
if value := projects.environment.get(variable, None):
2024-04-27 14:14:03 +00:00
self.branch = value
# name
for variable in NAME:
2024-04-27 15:09:51 +00:00
if value := projects.environment.get(variable, None):
2024-06-09 16:09:53 +00:00
self.name = Path(value).name
2024-05-29 22:21:42 +00:00
# root
for variable in ROOT:
if value := projects.environment.get(variable, None):
self.root = value
2024-04-27 15:09:51 +00:00
# url
2024-06-10 18:17:37 +00:00
self.url = urljoin(projects.url, self.name)