Skip to content

Commit

Permalink
CERT-7403 Fix file matching
Browse files Browse the repository at this point in the history
  • Loading branch information
nivcertora committed Nov 4, 2024
1 parent c55862e commit 52644e0
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions Quorum/checks/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,27 @@ def __find_most_common_path(self, source_path: Path, repo: Path) -> Optional[Pat
Optional[Path]: The most common file path if found, otherwise None.
"""
for i in range(len(source_path.parts)):
# Create a path suffix starting from the i-th part
current_source_path = Path(*source_path.parts[i:])

# Search for matching files in the repository
local_files = list(repo.rglob(str(current_source_path)))
if len(local_files) == 1:
return local_files[0]

if local_files:
# Compute similarity ratios between source_path and each local_file
similarities = []
for local_file in local_files:
source_str = source_path.as_posix()
local_str = local_file.as_posix()
ratio = difflib.SequenceMatcher(None, source_str, local_str).ratio()
similarities.append((local_file, ratio))

# Find the local_file with the highest similarity ratio
most_similar_file, _ = max(similarities, key=lambda x: x[1])

return most_similar_file

# Return None if no matching files are found
return None

def find_diffs(self) -> list[SourceCode]:
Expand Down

0 comments on commit 52644e0

Please sign in to comment.