Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions gitopscli/commands/delete_preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ def delete_preview_command(

apps_git.checkout("master")
logging.info("App repo branch master checkout successful")
gitops_config = GitOpsConfig(apps_git.get_full_file_path(".gitops.config.yaml"))
try:
gitops_config = GitOpsConfig(apps_git.get_full_file_path(".gitops.config.yaml"))
except FileNotFoundError as ex:
raise GitOpsException(f"Couldn't find .gitops.config.yaml") from ex
logging.info("Read GitOpsConfig: %s", gitops_config)

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

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

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