1616from vulnerabilities .pipelines import VulnerableCodePipeline
1717
1818
19- def extract_commit_id (url ):
20- """
21- Extract a commit ID from a URL, if available.
22- Supports different URL structures for commit references.
23-
24- >>> extract_commit_id("https://github.com/hedgedoc/hedgedoc/commit/c1789474020a6d668d616464cb2da5e90e123f65")
25- 'c1789474020a6d668d616464cb2da5e90e123f65'
26- """
27- if "/commit/" in url :
28- parts = url .split ("/" )
29- if len (parts ) > 1 and parts [- 2 ] == "commit" :
30- return parts [- 1 ]
31- return None
32-
33-
3419def is_reference_already_processed (reference_url , commit_id ):
3520 """
3621 Check if a reference and commit ID pair already exists in a CodeFix entry.
@@ -62,15 +47,14 @@ def collect_and_store_fix_commits(self):
6247 for reference in progress .iter (references .paginated (per_page = 500 )):
6348 for vulnerability in reference .vulnerabilities .all ():
6449 vcs_url = normalize_vcs_url (reference .url )
65- commit_id = extract_commit_id (reference .url )
6650
67- if not commit_id or not vcs_url :
51+ if not vcs_url :
6852 continue
6953
7054 # Skip if already processed
71- if is_reference_already_processed (reference .url , commit_id ):
55+ if is_reference_already_processed (reference .url , vcs_url ):
7256 self .log (
73- f"Skipping already processed reference: { reference .url } with commit { commit_id } "
57+ f"Skipping already processed reference: { reference .url } with VCS URL { vcs_url } "
7458 )
7559 continue
7660 purl = url2purl (vcs_url )
@@ -81,7 +65,7 @@ def collect_and_store_fix_commits(self):
8165 codefix = self .create_codefix_entry (
8266 vulnerability = vulnerability ,
8367 package = package ,
84- commit_id = commit_id ,
68+ vcs_url = vcs_url ,
8569 reference = reference .url ,
8670 )
8771 if codefix :
@@ -100,15 +84,15 @@ def get_or_create_package(self, purl):
10084 self .log (f"Error creating package from purl { purl } : { e } " )
10185 return None
10286
103- def create_codefix_entry (self , vulnerability , package , commit_id , reference ):
87+ def create_codefix_entry (self , vulnerability , package , vcs_url , reference ):
10488 """
10589 Create a CodeFix entry associated with the given vulnerability and package.
10690 """
10791 try :
10892 codefix , created = CodeFix .objects .get_or_create (
10993 base_version = package ,
11094 defaults = {
111- "commits" : [commit_id ],
95+ "commits" : [vcs_url ],
11296 "references" : [reference ],
11397 },
11498 )
0 commit comments