Skip to content

Commit 1efb61f

Browse files
committed
# - test fix
1 parent 628faa4 commit 1efb61f

File tree

3 files changed

+21
-25
lines changed

3 files changed

+21
-25
lines changed

main.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
#!/usr/bin/env python3
22

3-
import os
43
import sys
54

6-
from git import Repo
7-
85
from src.actions.actions import RMKCLIExecutor
96
from src.actions.init_project import ProjectInitializer, GETTenant
107
from src.credentials.cluster_provider_credentials import Credentials
@@ -22,17 +19,10 @@
2219

2320
"""Retrieve GitHub Action environment variables"""
2421
github_context = GitHubContext.from_env()
25-
26-
print(f"TEST: {github_context}")
27-
28-
repo = Repo(".")
29-
30-
print(repo.active_branch.name)
31-
3222
print(f"Current branch: {github_context.ref_name}")
3323

3424
"""Determine the project environment based on the repository branch"""
35-
environment = ExtendedEnvironmentSelector().select_environment(github_context.ref_name)
25+
environment = ExtendedEnvironmentSelector().select_environment(github_context)
3626
print(f"Current environment: {environment}")
3727

3828
"""Validate environment-specific constraints"""

src/select_environment/allowed_environments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
class AllowEnvironments:
5-
def __init__(self, args: Namespace, environment: str, ):
5+
def __init__(self, args: Namespace, environment: str):
66
self.args = args
77
self.environment = environment
88

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import re
22

33
from abc import ABC, abstractmethod
4-
from argparse import Namespace
4+
from git import Repo
5+
6+
from src.utils.github_environment_variables import GitHubContext
57

68

79
class EnvironmentSelectorInterface(ABC):
810
@abstractmethod
9-
def select_environment(self, branch_name: str) -> str:
11+
def select_environment(self, github_context: GitHubContext) -> str:
1012
pass
1113

1214

@@ -26,25 +28,29 @@ class EnvironmentSelector(EnvironmentSelectorInterface):
2628
SELECT_ALL_BRANCHES = fr"{SELECT_FEATURE_BRANCHES}|{SELECT_RELEASE_BRANCHES}"
2729
SELECT_ORIGIN_ALL_BRANCHES = fr"{SELECT_ORIGIN_FEATURE_BRANCHES}|{SELECT_ORIGIN_RELEASE_BRANCHES}"
2830

29-
def select_environment(self, branch_name: str) -> str:
30-
if re.match(r"^(develop|staging|production)$", branch_name, re.IGNORECASE):
31-
return branch_name
31+
def select_environment(self, github_context: GitHubContext) -> str:
32+
if re.match(r"^(develop|staging|production)$", github_context.ref_name, re.IGNORECASE):
33+
return github_context.ref_name
3234

33-
if re.match(EnvironmentSelector.SELECT_FEATURE_BRANCHES, branch_name, re.IGNORECASE):
35+
if re.match(EnvironmentSelector.SELECT_FEATURE_BRANCHES, github_context.ref_name, re.IGNORECASE):
3436
return "develop"
3537

36-
if re.match(EnvironmentSelector.SELECT_RELEASE_BRANCHES, branch_name, re.IGNORECASE):
37-
if re.search(EnvironmentSelector.SEMVER_REGEXP, branch_name, re.IGNORECASE):
38-
if "-rc" in branch_name:
38+
if re.match(EnvironmentSelector.SELECT_RELEASE_BRANCHES, github_context.ref_name, re.IGNORECASE):
39+
if re.search(EnvironmentSelector.SEMVER_REGEXP, github_context.ref_name, re.IGNORECASE):
40+
if "-rc" in github_context.ref_name:
3941
return "staging"
4042
return "production"
4143
return "staging"
4244

43-
raise ValueError(f"environment '{branch_name}' not allowed for environment selection")
45+
raise ValueError(f"environment '{github_context.ref_name}' not allowed for environment selection")
4446

4547

4648
class ExtendedEnvironmentSelector(EnvironmentSelector):
47-
def select_environment(self, branch_name: str) -> str:
48-
if branch_name.startswith("hotfix/"):
49+
def select_environment(self, github_context: GitHubContext) -> str:
50+
if github_context.event_name == "pull_request":
51+
repo = Repo(".")
52+
github_context.ref_name = repo.active_branch.name
53+
54+
if github_context.ref_name.startswith("hotfix/"):
4955
return "production"
50-
return super().select_environment(branch_name)
56+
return super().select_environment(github_context)

0 commit comments

Comments
 (0)