Skip to content

Commit ea68717

Browse files
authored
Merge pull request #15 from Codeplain-ai/deploy-conformance-tests-git
Conformance tests git
2 parents c410847 + 6abc1b2 commit ea68717

File tree

7 files changed

+150
-223
lines changed

7 files changed

+150
-223
lines changed
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
verbose: true
2-
debug: true
32
unittests-script: ../../test_scripts/run_unittests_golang.sh
43
conformance-tests-script: ../../test_scripts/run_conformance_tests_golang.sh
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
unittests-script: ../../test_scripts/run_unittests_python.sh
22
conformance-tests-script: ../../test_scripts/run_conformance_tests_python.sh
3-
v: true # verbose flag, defaults to false if not set
4-
debug: true # debug flag, defaults to false if not set
3+
verbose: true # verbose flag, defaults to false if not set

file_utils.py

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,9 @@ def list_folders_in_directory(directory):
8585
return folders
8686

8787

88-
def delete_files_and_subfolders(directory, debug=False):
88+
def delete_files_and_subfolders(directory):
8989
total_files_deleted = 0
9090
total_folders_deleted = 0
91-
items_deleted = []
9291

9392
# Walk the directory in reverse order (bottom-up)
9493
for root, dirs, files in os.walk(directory, topdown=False):
@@ -97,25 +96,12 @@ def delete_files_and_subfolders(directory, debug=False):
9796
file_path = os.path.join(root, file)
9897
os.remove(file_path)
9998
total_files_deleted += 1
100-
if debug and len(items_deleted) < 10:
101-
items_deleted.append(f"Deleted file: {file_path}")
10299

103100
# Delete directories
104101
for dir_ in dirs:
105102
dir_path = os.path.join(root, dir_)
106103
os.rmdir(dir_path)
107104
total_folders_deleted += 1
108-
if debug and len(items_deleted) < 10:
109-
items_deleted.append(f"Deleted folder: {dir_path}")
110-
111-
# Print the results
112-
if debug:
113-
if total_files_deleted + total_folders_deleted > 10:
114-
print(f"Total files deleted: {total_files_deleted}")
115-
print(f"Total folders deleted: {total_folders_deleted}")
116-
else:
117-
for item in items_deleted:
118-
print(item)
119105

120106

121107
def copy_file(source_path, destination_path):
@@ -255,16 +241,6 @@ def get_loaded_templates(source_path, plain_source):
255241
return plain_source, liquid_loader.loaded_templates
256242

257243

258-
def copy_unchanged_files_from_previous_build(
259-
previous_build_folder, build_folder, existing_files, response_files, debug
260-
):
261-
for file_name in existing_files:
262-
if file_name not in response_files:
263-
if debug:
264-
print("Copying file: ", file_name)
265-
copy_file(os.path.join(previous_build_folder, file_name), os.path.join(build_folder, file_name))
266-
267-
268244
def update_build_folder_with_rendered_files(build_folder, existing_files, response_files):
269245
changed_files = set()
270246
changed_files.update(response_files.keys())

git_utils.py

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,61 @@
1+
import os
2+
from typing import Union
3+
14
from git import Repo
25

6+
import file_utils
7+
38
RENDERED_FRID_MESSAGE = "Changes related to Functional requirement ID (FRID): {}"
9+
RENDER_ID_MESSAGE = "Render ID: {}"
410
BASE_FOLDER_COMMIT_MESSAGE = "Initialize build with Base Folder content"
11+
REFACTORED_CODE_COMMIT_MESSAGE = "Refactored code after implementing {}"
12+
CONFORMANCE_TESTS_PASSED_COMMIT_MESSAGE = (
13+
"Fixed issues in the implementation code identified during conformance testing"
14+
)
15+
FUNCTIONAL_REQUIREMENT_FINISHED_COMMIT_MESSAGE = "Functional requirement ID (FRID): {} fully implemented"
516

617
# The commit hash of the empty tree
718
EMPTY_TREE_COMMIT_HASH = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
819

920

10-
def init_clean_repo(repo_path):
11-
"""Initializes a new git repository in the given path."""
12-
repo = Repo.init(repo_path)
21+
def init_git_repo(path_to_repo: Union[str, os.PathLike]) -> Repo:
22+
"""
23+
Initializes a new git repository in the given path.
24+
If folder does not exist, it creates it.
25+
If the folder already exists, it deletes the content of the folder.
26+
"""
27+
if os.path.isdir(path_to_repo):
28+
file_utils.delete_files_and_subfolders(path_to_repo)
29+
else:
30+
os.makedirs(path_to_repo)
31+
32+
repo = Repo.init(path_to_repo)
1333

1434
return repo
1535

1636

17-
def is_dirty(repo_path):
37+
def is_dirty(repo_path: Union[str, os.PathLike]) -> bool:
1838
"""Checks if the repository is dirty."""
1939
repo = Repo(repo_path)
2040
return repo.is_dirty(untracked_files=True)
2141

2242

23-
def add_all_files_and_commit(repo_path, commit_message, frid):
43+
def add_all_files_and_commit(
44+
repo_path: Union[str, os.PathLike], commit_message: str, frid: str = None, render_id: str = None
45+
) -> Repo:
2446
"""Adds all files to the git repository and commits them."""
2547
repo = Repo(repo_path)
2648
repo.git.add(".")
2749

28-
message = f"{commit_message}\n\n{RENDERED_FRID_MESSAGE.format(frid)}" if frid else commit_message
50+
message = f"{commit_message}"
51+
52+
if frid or render_id:
53+
message += "\n\n" + "-" * 80
54+
55+
if frid:
56+
message += f"\n\n{RENDERED_FRID_MESSAGE.format(frid)}"
57+
if render_id:
58+
message += f"\n\n{RENDER_ID_MESSAGE.format(render_id)}"
2959

3060
# Check if there are any changes to commit
3161
if not repo.is_dirty(untracked_files=True):
@@ -36,15 +66,15 @@ def add_all_files_and_commit(repo_path, commit_message, frid):
3666
return repo
3767

3868

39-
def revert_changes(repo_path):
69+
def revert_changes(repo_path: Union[str, os.PathLike]) -> Repo:
4070
"""Reverts all changes made since the last commit."""
4171
repo = Repo(repo_path)
4272
repo.git.reset("--hard")
4373
repo.git.clean("-xdf")
4474
return repo
4575

4676

47-
def revert_to_commit_with_frid(repo_path, frid):
77+
def revert_to_commit_with_frid(repo_path: Union[str, os.PathLike], frid: str) -> Repo:
4878
"""Finds commit with given frid mentioned in the commit message and reverts the branch to it."""
4979
repo = Repo(repo_path)
5080
commit = _get_commit_with_frid(repo, frid)
@@ -53,15 +83,16 @@ def revert_to_commit_with_frid(repo_path, frid):
5383
return repo
5484

5585

56-
def diff(repo_path, previous_frid=None):
86+
def diff(repo_path: Union[str, os.PathLike], previous_frid: str = None) -> dict:
5787
"""
5888
Get the git diff between the current code state and the previous frid using git's native diff command.
5989
If previous_frid is not provided, we try to find the commit related to the copy of the base folder.
6090
Removes the 'diff --git' and 'index' lines to get clean unified diff format.
6191
6292
6393
Args:
64-
repo_path (str): Path to the git repository
94+
repo_path (str | os.PathLike): Path to the git repository
95+
previous_frid (str): Functional requirement ID (FRID) of the previous commit
6596
6697
Returns:
6798
dict: Dictionary with file names as keys and their clean diff strings as values
@@ -134,14 +165,18 @@ def diff(repo_path, previous_frid=None):
134165
return diff_dict
135166

136167

137-
def _get_commit_with_frid(repo, frid):
168+
def _get_commit_with_frid(repo: Repo, frid: str) -> str:
138169
"""Finds commit with given frid mentioned in the commit message."""
139-
commit = repo.git.rev_list("main", "--grep", RENDERED_FRID_MESSAGE.format(frid), "-n", "1")
170+
current_branch = repo.active_branch.name
171+
commit = repo.git.rev_list(
172+
current_branch, "--grep", FUNCTIONAL_REQUIREMENT_FINISHED_COMMIT_MESSAGE.format(frid), "-n", "1"
173+
)
140174
if not commit:
141175
raise Exception(f"No commit with frid {frid} found.")
142176
return commit
143177

144178

145-
def _get_base_folder_commit(repo):
179+
def _get_base_folder_commit(repo: Repo) -> str:
146180
"""Finds commit related to copy of the base folder."""
147-
return repo.git.rev_list("main", "--grep", BASE_FOLDER_COMMIT_MESSAGE, "-n", "1")
181+
current_branch = repo.active_branch.name
182+
return repo.git.rev_list(current_branch, "--grep", BASE_FOLDER_COMMIT_MESSAGE, "-n", "1")

0 commit comments

Comments
 (0)