@@ -49,16 +49,20 @@ async def _snippet_comment(self, snippet: CodeSnippet, secrets: PipelineSensitiv
49
49
base_url = secrets .api_base ,
50
50
)
51
51
52
+ # Check if any of the snippet libraries is a bad package
52
53
storage_engine = StorageEngine ()
53
54
libobjects = await storage_engine .search_by_property ("name" , snippet .libraries )
54
55
logger .info (f"Found { len (libobjects )} libraries in the storage engine" )
55
56
56
- libraries_text = ""
57
+ # If no bad packages are found, just return empty comment
58
+ if len (libobjects ) == 0 :
59
+ return ""
60
+
61
+ # Otherwise, generate codegate warning message
57
62
warnings = []
58
63
59
- # Use snippet.libraries to generate a CSV list of libraries
60
- if snippet .libraries :
61
- libraries_text = ", " .join ([f"`{ lib } `" for lib in snippet .libraries ])
64
+ # Use libobjects to generate a CSV list of bad libraries
65
+ libobjects_text = ", " .join ([f"`{ lib .properties ["name" ]} `" for lib in libobjects ])
62
66
63
67
for lib in libobjects :
64
68
lib_name = lib .properties ["name" ]
@@ -70,12 +74,10 @@ async def _snippet_comment(self, snippet: CodeSnippet, secrets: PipelineSensitiv
70
74
f"- More information: [{ lib_url } ]({ lib_url } )\n "
71
75
)
72
76
73
- comment = ""
74
- if libraries_text != "" :
75
- comment += f"\n \n Codegate detected the following libraries: { libraries_text } \n "
76
-
77
- if warnings :
78
- comment += "\n ### 🚨 Warnings\n " + "\n " .join (warnings ) + "\n "
77
+ # Add a codegate warning for the bad packages found in the snippet
78
+ comment = f"\n \n Warning: CodeGate detected one or more potentially malicious or \
79
+ archived packages: { libobjects_text } \n "
80
+ comment += "\n ### 🚨 Warnings\n " + "\n " .join (warnings ) + "\n "
79
81
80
82
return comment
81
83
0 commit comments