77# See https://aboutcode.org for more information about nexB OSS projects.
88#
99
10- from vulnerabilities .models import PackageCommitPatch , Patch
10+ from vulnerabilities .models import PackageCommitPatch
11+ from vulnerabilities .models import Patch
1112from vulnerabilities .pipelines import VulnerableCodePipeline
1213from vulnerabilities .utils import fetch_response
14+ from vulnerabilities .utils import generate_patch_url
1315
1416
1517class FetchPatchURLImproverPipeline (VulnerableCodePipeline ):
@@ -20,9 +22,7 @@ class FetchPatchURLImproverPipeline(VulnerableCodePipeline):
2022
2123 @classmethod
2224 def steps (cls ):
23- return (
24- cls .collect_patch_text ,
25- )
25+ return (cls .collect_patch_text ,)
2626
2727 def fetch_patch_content (self , url ):
2828 """
@@ -42,8 +42,8 @@ def fetch_patch_content(self, url):
4242
4343 def advisories_count (self ) -> int :
4444 return (
45- PackageCommitPatch .objects .filter (patch_text__isnull = True ).count () +
46- Patch .objects .filter (patch_text__isnull = True ).count ()
45+ PackageCommitPatch .objects .filter (patch_text__isnull = True ).count ()
46+ + Patch .objects .filter (patch_text__isnull = True ).count ()
4747 )
4848
4949 def collect_patch_text (self ):
@@ -62,22 +62,3 @@ def collect_patch_text(self):
6262
6363 patch .patch_text = content
6464 patch .save ()
65-
66- def generate_patch_url (vcs_url , commit_hash ):
67- """
68- Generate patch URL from VCS URL and commit hash.
69- """
70- if not vcs_url or not commit_hash :
71- return None
72-
73- vcs_url = vcs_url .rstrip ("/" )
74-
75- if vcs_url .startswith ("https://github.com" ):
76- return f"{ vcs_url } /commit/{ commit_hash } .patch"
77- elif vcs_url .startswith ("https://gitlab.com" ):
78- return f"{ vcs_url } /-/commit/{ commit_hash } .patch"
79- elif vcs_url .startswith ("https://bitbucket.org" ):
80- return f"{ vcs_url } /-/commit/{ commit_hash } /raw"
81- elif vcs_url .startswith ("https://git.kernel.org" ):
82- return f"{ vcs_url } .git/patch/?id={ commit_hash } "
83- return
0 commit comments