2929
3030from git import Repo
3131from git .diff import NULL_TREE
32- from scancode . api import get_file_info
32+ from typecode import get_type
3333
3434from scanpipe .pipes .symbols import TS_QUERIES
3535from scanpipe .pipes .symbols import SymbolExtractor
@@ -55,10 +55,7 @@ def normalize_text(content):
5555
5656
5757def detect_language_with_scancode (file_path , content ):
58- """
59- Detect the programming language of the text
60- content using get_file_info function
61- """
58+ """Detect the programming language of the text"""
6259 content = normalize_text (content )
6360
6461 if not content :
@@ -67,11 +64,11 @@ def detect_language_with_scancode(file_path, content):
6764 tmp_dir = tempfile .mkdtemp (prefix = "patch-lang-" )
6865
6966 try :
70- target = Path (tmp_dir ) / Path (file_path ).name
71- target .write_text (content , encoding = "utf-8" , errors = "replace" )
67+ location = Path (tmp_dir ) / Path (file_path ).name
68+ location .write_text (content , encoding = "utf-8" , errors = "replace" )
7269
73- info = get_file_info (location = str ( target )) or {}
74- return info .get ( " programming_language" ) or None
70+ info = get_type (location )
71+ return info .programming_language or None
7572
7673 finally :
7774 shutil .rmtree (tmp_dir , ignore_errors = True )
@@ -652,7 +649,7 @@ def get_vulnerabilities_patches(package_vulnerabilities, dependency_vulnerabilit
652649
653650
654651def collect_resource_index (candidate_resources ):
655- """Collect resources symbols for each resource exactly once. """
652+ """Collect resources symbols for each resource"""
656653 resource_indexes = {}
657654 for resource in candidate_resources :
658655 resource_language = resource .programming_language
@@ -674,8 +671,8 @@ def collect_resource_index(candidate_resources):
674671
675672def collect_patch_symbols (patches ):
676673 """
677- For each unique repo: clone it once, collect patch symbols for all
678- related commits, then remove the local clone before moving on
674+ For each unique repo clone it once,
675+ collect patch symbols for all related commits
679676 """
680677 patch_symbols = {}
681678 patches_by_repo = {}
@@ -704,7 +701,7 @@ def collect_patch_symbols(patches):
704701 return patch_symbols
705702
706703
707- def collect_and_match_resources (
704+ def match_patches_to_resources (
708705 patches , patch_symbols , candidate_resources , resource_indexes
709706):
710707 """Match resource symbols against patch symbols."""
@@ -760,18 +757,18 @@ def collect_and_match_resources(
760757
761758def generate_advisory_reachability_report (project , patches , candidate_resources ):
762759 """
763- Generate reachability report keyed by advisory_uid .
760+ Generate a reachability report summarizing status by advisory .
764761
765762 Each advisory contains its overall reachability status
766763 and the reachability results collected from all resources
767764 and associated patches.
768765
769766 The overall reachability status is determined using the following
770- priority order: REACHABLE > UNKNOWN > NOT_REACHABLE
767+ priority order: REACHABLE: "yes" > UNKNOWN: "unknown" > NOT_REACHABLE: "no"
771768
772769 This means that an advisory is considered reachable if it is reachable
773770 through at least one resource or patch. If no reachable result exists,
774- but at least one result is unknown , the advisory status is UNKNOWN.
771+ but at least one result is UNKNOWN , the advisory status is UNKNOWN.
775772 Otherwise, it is NOT_REACHABLE.
776773 """
777774 status_priority = {
0 commit comments