spcd/spcd/project.py
Marc Beninca 94e85a8f36
Some checks failed
/ job (push) Failing after 50s
ruff/format
2024-08-19 18:18:16 +02:00

55 lines
1.3 KiB
Python

"""Continuous Integration project."""
from __future__ import annotations
from pathlib import Path
from typing import TYPE_CHECKING
from spcd.util import add_url_path
if TYPE_CHECKING:
from spcd.projects import Projects
BRANCH = [
"GITHUB_REF_NAME",
"CI_COMMIT_BRANCH",
]
NAME = [
"GITHUB_REPOSITORY",
"CI_PROJECT_PATH",
]
ROOT = [
"GITHUB_WORKSPACE",
"CI_PROJECT_DIR",
]
class Project:
"""Current project."""
def __init__(self: Project, projects: Projects) -> None:
"""Set projects, branch, name, root & url."""
self.projects = projects
# branch
for variable in BRANCH:
if value := projects.environment.get(variable, None):
self.branch = value
# name
for variable in NAME:
if value := projects.environment.get(variable, None):
self.name = Path(value).name
# root
for variable in ROOT:
if value := projects.environment.get(variable, None):
self.root = value
# url
self.url = add_url_path(projects.url, self.name)
def __str__(self: Project) -> str:
"""List branch, name, root & url."""
return f"""\
branch = {self.branch}
name = {self.name}
root = {self.root}
url = {self.url}
"""