Skip to content

LCORE-2631: Vulnerability report script: Dependabot data processing part#1961

Merged
tisnik merged 1 commit into
lightspeed-core:mainfrom
tisnik:lcore-2631-vulnerability-report-script-processing-part
Jun 22, 2026
Merged

LCORE-2631: Vulnerability report script: Dependabot data processing part#1961
tisnik merged 1 commit into
lightspeed-core:mainfrom
tisnik:lcore-2631-vulnerability-report-script-processing-part

Conversation

@tisnik

@tisnik tisnik commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Description

LCORE-2631: Vulnerability report script: Dependabot data processing part

Type of change

  • Refactor
  • New feature
  • Bug fix
  • CVE fix
  • Optimization
  • Documentation Update
  • Configuration Update
  • Bump-up service version
  • Bump-up dependent library
  • Bump-up library or tool used for development (does not change the final image)
  • CI configuration change
  • Konflux configuration change
  • Unit tests improvement
  • Integration tests improvement
  • End to end tests improvement
  • Benchmarks improvement
  • Helper scripts

Tools used to create PR

  • Assisted-by: N/A
  • Generated by: N/A

Related Tickets & Documents

  • Related Issue #LCORE-2631

Summary by CodeRabbit

  • New Features
    • Enhanced vulnerability report CLI with improved documentation and expanded configuration options for report generation, graph generation, and data comparison workflows.
    • Added comprehensive processing capabilities for Dependabot alert data with improved extraction, querying, and analysis functions.
    • New utility functions for analyzing vulnerability metrics including CVE status tracking and severity-based classification counting.

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

scripts/vulnerability_report.py gains expanded CLI documentation, two type aliases (DependabotAlert, DependabotAlerts), updated argument parser option defaults and nargs behavior, a set of new helper functions for loading and querying Dependabot alert JSON (including CVE/severity counts), a stub process_dependabot_file(), and a main() that routes through these new functions.

Changes

Dependabot Alert Helpers and CLI Wiring

Layer / File(s) Summary
Module docs, type aliases, argument parser updates
scripts/vulnerability_report.py
Expands module docstring with usage/options block. Adds DependabotAlert and DependabotAlerts type aliases. Updates --generate-graphs, --generate-page, and --comparison argument definitions (changed defaults; --comparison now uses nargs='+'). Adds dependabot_file_name(), load_dependabot_file(), has_attribute_with_value(), has_deep_attribute_with_value(), count_attribute_with_value(), count_deep_attribute_with_value(), opened_cves(), fixed_cves(), with_severity(), and a stub process_dependabot_file() returning {}.
main() wiring
scripts/vulnerability_report.py
main() derives the Dependabot alerts filename via dependabot_file_name(args) and calls process_dependabot_file(dependabot_file, prefix), replacing the prior debug print of parsed args.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • lightspeed-core/lightspeed-stack#1959: Introduced the initial skeleton of scripts/vulnerability_report.py; this PR builds directly on that skeleton by adding the Dependabot helper functions and wiring main() to use them.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main change: adding Dependabot data processing functionality to the vulnerability report script.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/vulnerability_report.py`:
- Around line 175-177: The function process_dependabot_file() is currently a
stub that returns an empty dictionary, and main() ignores its result, breaking
the report generation flow. Implement process_dependabot_file() to read the
Dependabot alerts file specified by the dependabot_file parameter and return a
dictionary containing the processed alert statistics. Then update main() to
capture the dictionary returned from process_dependabot_file() and incorporate
that data into the report generation logic so the vulnerability report contains
actual data.
- Around line 118-133: The helper functions has_attribute_with_value and
has_deep_attribute_with_value directly access nested dictionary keys without
validation, which causes KeyError or TypeError exceptions if the JSON is
malformed. Add JSON schema validation in the load_dependabot_file function to
validate the Dependabot alert structure when the file is loaded, ensuring only
properly formatted data is returned and preventing runtime crashes when the
helper functions access attributes on malformed items.
- Around line 100-108: The --comparison argument is parsed but never utilized in
the main() function, breaking the advertised CLI contract. In the main()
function, add a conditional check to determine if comparison mode is enabled by
verifying if the comparison argument contains values. When comparison mode is
active, implement logic to process multiple JSON files provided in the
comparison argument instead of only processing organization__repository.json.
Ensure the current single-file processing remains the default behavior when the
comparison argument is not provided. This will make the parser argument
definition match the actual execution flow.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: e0b596a7-65c2-4873-a0e3-683aa4977bc2

📥 Commits

Reviewing files that changed from the base of the PR and between ee37367 and e183249.

📒 Files selected for processing (1)
  • scripts/vulnerability_report.py
📜 Review details
⏰ Context from checks skipped due to timeout. (16)
  • GitHub Check: integration_tests (3.12)
  • GitHub Check: integration_tests (3.13)
  • GitHub Check: Pylinter
  • GitHub Check: spectral
  • GitHub Check: build-pr
  • GitHub Check: unit_tests (3.13)
  • GitHub Check: unit_tests (3.12)
  • GitHub Check: E2E: library mode / ci / group 1
  • GitHub Check: E2E: server mode / ci / group 1
  • GitHub Check: E2E: server mode / ci / group 2
  • GitHub Check: E2E: library mode / ci / group 3
  • GitHub Check: E2E: library mode / ci / group 2
  • GitHub Check: E2E: server mode / ci / group 3
  • GitHub Check: E2E Tests for Lightspeed Evaluation job
  • GitHub Check: Konflux kflux-prd-rh02 / lightspeed-stack-0-6-on-pull-request
  • GitHub Check: Konflux kflux-prd-rh02 / lightspeed-stack-on-pull-request
🔇 Additional comments (1)
scripts/vulnerability_report.py (1)

39-40: PEP 695 type alias syntax is compatible with declared Python version.

The repository declares requires-python = ">=3.12,<3.14" in pyproject.toml, confirming Python 3.12+ is the minimum supported version. The type DependabotAlert = ... syntax at lines 39–40 aligns with this requirement.

Comment on lines 100 to 108
parser.add_argument(
"-c",
"--comparison",
default=False,
help="Compare two repositories and generate comparison report. "
"Need to be used with --data1 and --data2 options",
required=False,
nargs="+",
default=[],
help="Compare two or more repositories and generate comparison report. "
"Multiple JSON files with Dependabot alerts needs to be provided",
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

--comparison is documented/parsed but never used in execution flow.

The parser advertises comparison mode, but main() always processes only organization__repository.json. This is a contract break for the CLI option.

Also applies to: 199-201

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/vulnerability_report.py` around lines 100 - 108, The --comparison
argument is parsed but never utilized in the main() function, breaking the
advertised CLI contract. In the main() function, add a conditional check to
determine if comparison mode is enabled by verifying if the comparison argument
contains values. When comparison mode is active, implement logic to process
multiple JSON files provided in the comparison argument instead of only
processing organization__repository.json. Ensure the current single-file
processing remains the default behavior when the comparison argument is not
provided. This will make the parser argument definition match the actual
execution flow.

Comment on lines +118 to +133
def load_dependabot_file(filename: str) -> Any:
"""Load JSON file containing Dependabot alerts."""
with open(filename, "r") as fin:
return json.load(fin)


def has_attribute_with_value(item: DependabotAlert, attribute: str, value: str) -> bool:
"""Check if dictionary has attribute with given value."""
return bool(item[attribute] == value)


def has_deep_attribute_with_value(
item: DependabotAlert, selector: str, attribute: str, value: str
) -> bool:
"""Check if dictionary has deep attribute with given value."""
return bool(item[selector][attribute] == value)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Validate Dependabot JSON schema at load time to prevent runtime crashes.

Helpers assume keys always exist (item[attribute], item[selector][attribute]). A single malformed alert will raise KeyError/TypeError and stop report generation.

Proposed fix
 def load_dependabot_file(filename: str) -> Any:
     """Load JSON file containing Dependabot alerts."""
-    with open(filename, "r") as fin:
-        return json.load(fin)
+    with open(filename, "r", encoding="utf-8") as fin:
+        data = json.load(fin)
+    if not isinstance(data, list):
+        raise ValueError("Dependabot alerts file must contain a JSON array")
+    for idx, item in enumerate(data):
+        if not isinstance(item, dict):
+            raise ValueError(f"Alert at index {idx} must be an object")
+        if "state" not in item:
+            raise ValueError(f"Alert at index {idx} is missing 'state'")
+        sa = item.get("security_advisory")
+        if not isinstance(sa, dict) or "severity" not in sa:
+            raise ValueError(
+                f"Alert at index {idx} is missing 'security_advisory.severity'"
+            )
+    return data

Also applies to: 136-155

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/vulnerability_report.py` around lines 118 - 133, The helper functions
has_attribute_with_value and has_deep_attribute_with_value directly access
nested dictionary keys without validation, which causes KeyError or TypeError
exceptions if the JSON is malformed. Add JSON schema validation in the
load_dependabot_file function to validate the Dependabot alert structure when
the file is loaded, ensuring only properly formatted data is returned and
preventing runtime crashes when the helper functions access attributes on
malformed items.

Comment on lines +175 to +177
def process_dependabot_file(dependabot_file: str, prefix: str) -> dict[str, Any]:
"""Read Dependabot alerts and prepare statistic info."""
return {}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

main() currently performs no effective processing.

process_dependabot_file() is a stub returning {}, and main() ignores its result. The CLI succeeds without producing report data, which breaks the processing flow.

Proposed fix
 def process_dependabot_file(dependabot_file: str, prefix: str) -> dict[str, Any]:
     """Read Dependabot alerts and prepare statistic info."""
-    return {}
+    source_data: DependabotAlerts = load_dependabot_file(dependabot_file)
+    return {
+        "prefix": prefix,
+        "opened_cves": opened_cves(source_data),
+        "fixed_cves": fixed_cves(source_data),
+        "critical": with_severity("critical", source_data),
+        "high": with_severity("high", source_data),
+        "medium": with_severity("medium", source_data),
+        "low": with_severity("low", source_data),
+    }

@@
-    process_dependabot_file(dependabot_file, prefix)
+    report = process_dependabot_file(dependabot_file, prefix)
+    print(json.dumps(report))
     return 0

Also applies to: 199-201

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/vulnerability_report.py` around lines 175 - 177, The function
process_dependabot_file() is currently a stub that returns an empty dictionary,
and main() ignores its result, breaking the report generation flow. Implement
process_dependabot_file() to read the Dependabot alerts file specified by the
dependabot_file parameter and return a dictionary containing the processed alert
statistics. Then update main() to capture the dictionary returned from
process_dependabot_file() and incorporate that data into the report generation
logic so the vulnerability report contains actual data.

@tisnik tisnik merged commit da4b945 into lightspeed-core:main Jun 22, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant