Skip to content

Commit 2392f10

Browse files
author
Tjaz Erzen
committed
Handle filtering by FRID
1 parent c64f1a5 commit 2392f10

3 files changed

Lines changed: 70 additions & 9 deletions

File tree

git_utils.py

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,49 @@ def _get_commit(repo: Repo, frid: Optional[str]) -> str:
264264
return initial_commit
265265

266266

267-
def _get_commit_with_frid(repo: Repo, frid: str) -> str:
268-
"""Finds commit with given frid mentioned in the commit message."""
269-
return _get_commit_with_message(repo, FUNCTIONAL_REQUIREMENT_FINISHED_COMMIT_MESSAGE.format(frid))
267+
def _get_commit_with_frid(
268+
repo: Repo, frid: str, module_name: Optional[str] = None
269+
) -> str:
270+
"""
271+
Finds commit with given frid mentioned in the commit message.
272+
273+
Args:
274+
repo (Repo): Git repository object
275+
frid (str): Functional requirement ID
276+
module_name (Optional[str]): Module name to filter by. If provided, only returns
277+
commits that have both the FRID and module name.
278+
279+
Returns:
280+
str: Commit SHA if found, empty string otherwise
281+
"""
282+
commit_message_pattern = FUNCTIONAL_REQUIREMENT_FINISHED_COMMIT_MESSAGE.format(frid)
283+
284+
# If no module name filtering is needed, use the original logic
285+
if not module_name:
286+
return _get_commit_with_message(repo, commit_message_pattern)
287+
288+
# Use multiple grep patterns with --all-match for AND condition
289+
escaped_frid_message = commit_message_pattern.replace("[", "\\[").replace(
290+
"]", "\\]"
291+
)
292+
module_name_pattern = MODULE_NAME_MESSAGE.format(module_name)
293+
escaped_module_message = module_name_pattern.replace("[", "\\[").replace("]", "\\]")
294+
295+
return repo.git.rev_list(
296+
repo.active_branch.name,
297+
"--grep",
298+
escaped_frid_message,
299+
"--grep",
300+
escaped_module_message,
301+
"--all-match",
302+
"-n",
303+
"1",
304+
)
270305

271306

272-
def has_commit_for_frid(repo_path: Union[str, os.PathLike], frid: str) -> bool:
307+
def has_commit_for_frid(
308+
repo_path: Union[str, os.PathLike], frid: str, module_name: Optional[str] = None
309+
) -> bool:
273310
"""
274311
Check if a commit exists for the given FRID in the repository.
275312
@@ -281,7 +318,7 @@ def has_commit_for_frid(repo_path: Union[str, os.PathLike], frid: str) -> bool:
281318
bool: True if the commit exists, False otherwise
282319
"""
283320
repo = Repo(repo_path)
284-
commit_with_frid = _get_commit_with_frid(repo, frid)
321+
commit_with_frid = _get_commit_with_frid(repo, frid, module_name)
285322
if not commit_with_frid:
286323
return False
287324
return True

module_renderer.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,29 @@ def _validate_previous_frid_commits_exist(
7373

7474
# Check if commits exist for all previous FRIDs
7575
build_folder_path = os.path.join(self.args.build_folder, module_name)
76-
conformance_tests_path = os.path.join(self.args.conformance_tests_folder, module_name)
76+
conformance_tests_path = os.path.join(
77+
self.args.conformance_tests_folder, module_name
78+
)
79+
80+
if not os.path.exists(build_folder_path):
81+
raise MissingPreviousFridCommitsError(
82+
f"Cannot render from FRID {first_render_frid}: "
83+
f"Folder {build_folder_path} for module {module_name} does not exist. "
84+
f"Please render all previous FRIDs for module {module_name} first."
85+
)
86+
87+
if not os.path.exists(conformance_tests_path):
88+
raise MissingPreviousFridCommitsError(
89+
f"Cannot render from FRID {first_render_frid}: "
90+
f"Folder {conformance_tests_path} for module {module_name} does not exist. "
91+
f"Please render all previous FRIDs for module {module_name} first."
92+
)
7793

7894
for prev_frid in previous_frids:
7995
# Check in build folder
80-
if not git_utils.has_commit_for_frid(build_folder_path, prev_frid):
96+
if not git_utils.has_commit_for_frid(
97+
build_folder_path, prev_frid, module_name
98+
):
8199
raise MissingPreviousFridCommitsError(
82100
f"Cannot render from FRID {first_render_frid}: "
83101
f"Missing commit for previous FRID {prev_frid} in {build_folder_path}. "
@@ -86,7 +104,9 @@ def _validate_previous_frid_commits_exist(
86104

87105
# Check in conformance tests folder (only if conformance tests are enabled)
88106
if self.args.render_conformance_tests:
89-
if not git_utils.has_commit_for_frid(conformance_tests_path, prev_frid):
107+
if not git_utils.has_commit_for_frid(
108+
conformance_tests_path, prev_frid, module_name
109+
):
90110
raise MissingPreviousFridCommitsError(
91111
f"Cannot render from FRID {first_render_frid}: "
92112
f"Missing commit for previous FRID {prev_frid} in {conformance_tests_path}. "

plain2code.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import plain_file
1414
import plain_spec
1515
from event_bus import EventBus
16-
from module_renderer import ModuleRenderer
16+
from module_renderer import MissingPreviousFridCommitsError, ModuleRenderer
1717
from plain2code_arguments import parse_arguments
1818
from plain2code_console import console
1919
from plain2code_exceptions import PlainSyntaxError
@@ -272,6 +272,10 @@ def main(): # noqa: C901
272272
console.error(f"Error rendering plain code: {str(e)}\n")
273273
console.debug(f"Render ID: {run_state.render_id}")
274274
dump_crash_logs(args)
275+
except MissingPreviousFridCommitsError as e:
276+
console.error(f"Error rendering plain code: {str(e)}\n")
277+
console.debug(f"Render ID: {run_state.render_id}")
278+
dump_crash_logs(args)
275279
except Exception as e:
276280
console.error(f"Error rendering plain code: {str(e)}\n")
277281
console.debug(f"Render ID: {run_state.render_id}")

0 commit comments

Comments
 (0)