@@ -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
0 commit comments