Skip to content

Commit 9748e49

Browse files
Merge pull request #92 from baloise/fix-delete-preview-on-master
fix(delete-preview): fix bug when pushing directly to master + improve error log
2 parents 080fc64 + 0b4fe09 commit 9748e49

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

gitopscli/commands/delete_preview.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ def delete_preview_command(
4343

4444
apps_git.checkout("master")
4545
logging.info("App repo branch master checkout successful")
46-
gitops_config = GitOpsConfig(apps_git.get_full_file_path(".gitops.config.yaml"))
46+
try:
47+
gitops_config = GitOpsConfig(apps_git.get_full_file_path(".gitops.config.yaml"))
48+
except FileNotFoundError as ex:
49+
raise GitOpsException(f"Couldn't find .gitops.config.yaml") from ex
4750
logging.info("Read GitOpsConfig: %s", gitops_config)
4851

4952
root_git = create_git(
@@ -60,10 +63,13 @@ def delete_preview_command(
6063
root_git.checkout("master")
6164
logging.info("Config repo branch master checkout successful")
6265

63-
config_branch = f"gitopscli-delete-preview-{str(uuid.uuid4())[:8]}" if create_pr else "master"
66+
if create_pr:
67+
config_branch = f"gitopscli-delete-preview-{str(uuid.uuid4())[:8]}"
68+
root_git.new_branch(config_branch)
69+
logging.info("Created branch %s in config repo", config_branch)
70+
else:
71+
config_branch = "master"
6472

65-
root_git.new_branch(config_branch)
66-
logging.info("Created branch %s in config repo", config_branch)
6773
shortened_branch_hash = hashlib.sha256(branch.encode("utf-8")).hexdigest()[:8]
6874
logging.info("Hashed branch %s to hash: %s", branch, shortened_branch_hash)
6975
preview_folder_name = gitops_config.application_name + "-" + shortened_branch_hash + "-preview"

0 commit comments

Comments
 (0)