Skip to content

Commit

Permalink
CERT-7403 Fix file matching (#15)
Browse files Browse the repository at this point in the history
* CERT-7403 Fix file matching

* Auto change version.

* Small improvment

* Auto change version.

---------

Co-authored-by: nivcertora <nivcertora@users.noreply.github.com>
  • Loading branch information
nivcertora and nivcertora authored Nov 4, 2024
1 parent c55862e commit e4809d0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
22 changes: 20 additions & 2 deletions Quorum/checks/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,28 @@ 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 = []
source_str = current_source_path.as_posix()
for local_file in local_files:

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
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20241104.114056.551107
20241104.123243.886578

0 comments on commit e4809d0

Please sign in to comment.