Skip to content

Commit 62d974f

Browse files
committed
pr feedback
1 parent f039074 commit 62d974f

3 files changed

Lines changed: 11 additions & 20 deletions

File tree

gitopscli/commands/create_pr_preview.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ def create_pr_preview_command(
4545

4646
apps_git.checkout(pr_branch)
4747
logging.info("App repo PR branch %s checkout successful", pr_branch)
48-
preview_id = hashlib.sha256(pr_branch.encode("utf-8")).hexdigest()[:8]
4948
git_hash = apps_git.get_last_commit_hash()
5049
create_preview_command(
5150
username,
@@ -57,8 +56,8 @@ def create_pr_preview_command(
5756
git_provider,
5857
git_provider_url,
5958
git_hash,
60-
preview_id,
61-
create_deployment_replaced_callback(parent_id, pr_id),
59+
hashlib.sha256(pr_branch.encode("utf-8")).hexdigest()[:8],
60+
create_deployment_already_up_to_date_callback(parent_id, pr_id),
6261
create_deployment_exist_callback(parent_id, pr_id, pr_branch),
6362
create_deployment_new_callback(parent_id, pr_id, pr_branch),
6463
)
@@ -67,16 +66,16 @@ def create_pr_preview_command(
6766
delete_tmp_dir(root_tmp_dir)
6867

6968

70-
def create_deployment_replaced_callback(parent_id, pr_id):
71-
def deployment_replaced_callback(apps_git, new_image_tag):
69+
def create_deployment_already_up_to_date_callback(parent_id, pr_id):
70+
def deployment_already_up_to_date_callback(apps_git, new_image_tag):
7271
logging.info("The image tag %s has already been deployed. Doing nothing.", new_image_tag)
7372
pr_comment_text = f"""
7473
The version `{new_image_tag}` has already been deployed. Nothing to do here.
7574
"""
7675
logging.info("Creating PullRequest comment for pr with id %s and content: %s", pr_id, pr_comment_text)
7776
apps_git.add_pull_request_comment(pr_id, pr_comment_text, parent_id)
7877

79-
return deployment_replaced_callback
78+
return deployment_already_up_to_date_callback
8079

8180

8281
def create_deployment_new_callback(parent_id, pr_id, pr_branch):

gitopscli/commands/create_preview.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def create_preview_command(
2424
git_provider_url,
2525
git_hash,
2626
preview_id,
27-
deployment_replaced_callback=None,
27+
deployment_already_up_to_date_callback=None,
2828
deployment_exists_callback=None,
2929
deployment_new_callback=None,
3030
):
@@ -86,14 +86,13 @@ def create_preview_command(
8686
root_git,
8787
gitops_config.application_name,
8888
)
89-
new_image_tag = apps_git.get_last_commit_hash()
90-
logging.info("Using image tag from last app repo commit: %s", new_image_tag)
89+
logging.info("Using image tag from last app repo commit: %s", git_hash)
9190
route_host = None
9291
value_replaced = False
9392
for replacement in gitops_config.replacements:
9493
route_host, value_replaced = __replace_value(
9594
gitops_config,
96-
new_image_tag,
95+
git_hash,
9796
new_preview_folder_name,
9897
replacement,
9998
root_git,
@@ -102,8 +101,8 @@ def create_preview_command(
102101
value_replaced,
103102
)
104103
if not value_replaced:
105-
if deployment_replaced_callback:
106-
deployment_replaced_callback(apps_git, new_image_tag)
104+
if deployment_already_up_to_date_callback:
105+
deployment_already_up_to_date_callback(apps_git, git_hash)
107106
return
108107

109108
if branch_preview_env_already_exist:

gitopscli/commands/delete_preview.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,4 @@ def delete_preview_command(
7878

7979
finally:
8080
delete_tmp_dir(apps_tmp_dir)
81-
delete_tmp_dir(root_tmp_dir)
82-
83-
84-
def __create_tmp_dir():
85-
tmp_dir = f"/tmp/gitopscli/{uuid.uuid4()}"
86-
os.makedirs(tmp_dir)
87-
logging.info("Created directory %s", tmp_dir)
88-
return tmp_dir
81+
delete_tmp_dir(root_tmp_dir)

0 commit comments

Comments
 (0)