From c3cbee968f982cbb4a669994491765615848b02a Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sat, 27 Apr 2024 16:14:03 +0200 Subject: [PATCH] draft --- cd/project.py | 23 +++++++++++++++++++++-- cd/projects.py | 21 ++++++++++++++++++++- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/cd/project.py b/cd/project.py index 8ee7c56..4a734c9 100644 --- a/cd/project.py +++ b/cd/project.py @@ -1,3 +1,22 @@ +from os import path + +BRANCH = [ + 'GITHUB_REF_NAME', + 'CI_COMMIT_BRANCH', +] +NAME = [ + 'GITHUB_REPOSITORY', + 'CI_PROJECT_PATH', +] + + class Project: - def __init__(self): - pass + def __init__(self, environment): + # branch + for variable in BRANCH: + if value := environment.get(variable, None): + self.branch = value + # name + for variable in NAME: + if value := environment.get(variable, None): + self.name = path.basename(value) diff --git a/cd/projects.py b/cd/projects.py index 96f57bf..d3b0581 100644 --- a/cd/projects.py +++ b/cd/projects.py @@ -1,3 +1,22 @@ +from os import path + +GROUP_AND_NAME = [ + 'GITHUB_REPOSITORY', + 'CI_PROJECT_PATH', +] +SERVER_URL = [ + 'GITHUB_SERVER_URL', + 'CI_SERVER_URL', +] + + class Projects: def __init__(self, environment): - self.env = environment + # group, name + for variable in GROUP_AND_NAME: + if value := environment.get(variable, None): + self.group, self.name = path.split(value) + # url + for variable in SERVER_URL: + if value := environment.get(variable, None): + self.url = path.join(value, self.group)