Skip to content

Commit

Permalink
Fix _get_license_matches_grouped and improve testing #569
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Druez <[email protected]>
  • Loading branch information
tdruez committed May 15, 2023
1 parent a41a389 commit 0edc4c2
Show file tree
Hide file tree
Showing 5 changed files with 433 additions and 34 deletions.
41 changes: 21 additions & 20 deletions scanpipe/pipes/scancode.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,25 +547,25 @@ def _get_license_matches_grouped(project):
for resource in resources_with_license:
file_cache = []

# TODO:
for match in resource.license_detections[0].get("matches", []):
license_expression = match.get("license_expression")
matched_text = match.get("matched_text")

# Do not include duplicated matched_text for a given license_expression
# within the same file
cache_key = ":".join([license_expression, resource.path, matched_text])
cache_key = hashlib.md5(cache_key.encode()).hexdigest()
if cache_key in file_cache:
continue
file_cache.append(cache_key)

license_matches[license_expression].append(
{
"path": resource.path,
"matched_text": matched_text,
}
)
for detection_data in resource.license_detections:
for match in detection_data.get("matches", []):
license_expression = match.get("license_expression")
matched_text = match.get("matched_text")

# Do not include duplicated matched_text for a given license_expression
# within the same file
cache_key = ":".join([license_expression, resource.path, matched_text])
cache_key = hashlib.md5(cache_key.encode()).hexdigest()
if cache_key in file_cache:
continue
file_cache.append(cache_key)

license_matches[license_expression].append(
{
"path": resource.path,
"matched_text": matched_text,
}
)

return dict(license_matches)

Expand All @@ -584,7 +584,8 @@ def make_results_summary(project, scan_results_location):

summary = scan_data.get("summary")

# Inject the generated `license_matches` in the summary
# Inject the generated `license_matches` in the summary from the project
# codebase resources.
summary["license_matches"] = _get_license_matches_grouped(project)

# Inject the `key_files` and their file content in the summary
Expand Down
Loading

0 comments on commit 0edc4c2

Please sign in to comment.