@@ -259,12 +259,49 @@ def _get_commit(repo: Repo, frid: Optional[str]) -> str:
259259 return initial_commit
260260
261261
262- def _get_commit_with_frid (repo : Repo , frid : str ) -> str :
263- """Finds commit with given frid mentioned in the commit message."""
264- return _get_commit_with_message (repo , FUNCTIONAL_REQUIREMENT_FINISHED_COMMIT_MESSAGE .format (frid ))
262+ def _get_commit_with_frid (
263+ repo : Repo , frid : str , module_name : Optional [str ] = None
264+ ) -> str :
265+ """
266+ Finds commit with given frid mentioned in the commit message.
267+
268+ Args:
269+ repo (Repo): Git repository object
270+ frid (str): Functional requirement ID
271+ module_name (Optional[str]): Module name to filter by. If provided, only returns
272+ commits that have both the FRID and module name.
273+
274+ Returns:
275+ str: Commit SHA if found, empty string otherwise
276+ """
277+ commit_message_pattern = FUNCTIONAL_REQUIREMENT_FINISHED_COMMIT_MESSAGE .format (frid )
278+
279+ # If no module name filtering is needed, use the original logic
280+ if not module_name :
281+ return _get_commit_with_message (repo , commit_message_pattern )
282+
283+ # Use multiple grep patterns with --all-match for AND condition
284+ escaped_frid_message = commit_message_pattern .replace ("[" , "\\ [" ).replace (
285+ "]" , "\\ ]"
286+ )
287+ module_name_pattern = MODULE_NAME_MESSAGE .format (module_name )
288+ escaped_module_message = module_name_pattern .replace ("[" , "\\ [" ).replace ("]" , "\\ ]" )
289+
290+ return repo .git .rev_list (
291+ repo .active_branch .name ,
292+ "--grep" ,
293+ escaped_frid_message ,
294+ "--grep" ,
295+ escaped_module_message ,
296+ "--all-match" ,
297+ "-n" ,
298+ "1" ,
299+ )
265300
266301
267- def has_commit_for_frid (repo_path : Union [str , os .PathLike ], frid : str ) -> bool :
302+ def has_commit_for_frid (
303+ repo_path : Union [str , os .PathLike ], frid : str , module_name : Optional [str ] = None
304+ ) -> bool :
268305 """
269306 Check if a commit exists for the given FRID in the repository.
270307
@@ -276,7 +313,7 @@ def has_commit_for_frid(repo_path: Union[str, os.PathLike], frid: str) -> bool:
276313 bool: True if the commit exists, False otherwise
277314 """
278315 repo = Repo (repo_path )
279- commit_with_frid = _get_commit_with_frid (repo , frid )
316+ commit_with_frid = _get_commit_with_frid (repo , frid , module_name )
280317 if not commit_with_frid :
281318 return False
282319 return True
0 commit comments