Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit d390bda

Browse files
committed
Generate snippet message only in case of bad packages are found
1 parent be2356a commit d390bda

File tree

1 file changed

+12
-10
lines changed
  • src/codegate/pipeline/extract_snippets

1 file changed

+12
-10
lines changed

src/codegate/pipeline/extract_snippets/output.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,20 @@ async def _snippet_comment(self, snippet: CodeSnippet, secrets: PipelineSensitiv
4949
base_url=secrets.api_base,
5050
)
5151

52+
# Check if any of the snippet libraries is a bad package
5253
storage_engine = StorageEngine()
5354
libobjects = await storage_engine.search_by_property("name", snippet.libraries)
5455
logger.info(f"Found {len(libobjects)} libraries in the storage engine")
5556

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
5762
warnings = []
5863

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])
6266

6367
for lib in libobjects:
6468
lib_name = lib.properties["name"]
@@ -70,12 +74,10 @@ async def _snippet_comment(self, snippet: CodeSnippet, secrets: PipelineSensitiv
7074
f"- More information: [{lib_url}]({lib_url})\n"
7175
)
7276

73-
comment = ""
74-
if libraries_text != "":
75-
comment += f"\n\nCodegate 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\nWarning: CodeGate detected one or more potentially malicious or \
79+
archived packages: {libobjects_text}\n"
80+
comment += "\n### 🚨 Warnings\n" + "\n".join(warnings) + "\n"
7981

8082
return comment
8183

0 commit comments

Comments
 (0)