Skip to content

LCORE-2631: Better docstrings#1986

Merged
tisnik merged 1 commit into
lightspeed-core:mainfrom
tisnik:lcore-2631-docstrings
Jun 24, 2026
Merged

LCORE-2631: Better docstrings#1986
tisnik merged 1 commit into
lightspeed-core:mainfrom
tisnik:lcore-2631-docstrings

Conversation

@tisnik

@tisnik tisnik commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Description

LCORE-2631: Better docstrings

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

Tools used to create PR

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

Related Tickets & Documents

  • Related Issue #LCORE-2631

Summary by CodeRabbit

  • Bug Fixes

    • Improved validation when reading vulnerability report data, so malformed input is handled more reliably.
    • Updated summary statistics handling to better avoid errors when no fixed alerts are present.
    • Adjusted command-line behavior so report output now includes both the computed results and the selected prefix information.
  • Refactor

    • Streamlined the report script’s command-line setup and clarified function documentation and typing.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

scripts/vulnerability_report.py is refactored to use a cli_parser local variable in create_argument_parser(), adds required=True for --organization/--repository, introduces UTF-8 loading with structural JSON validation in load_dependabot_file(), expands docstrings across all helpers, inverts the division-by-zero guard in fill_in_days_statistic(), removes prefix from process_dependabot_file(), and updates main() accordingly.

Changes

Vulnerability Report Script Refactor

Layer / File(s) Summary
CLI argument parser construction
scripts/vulnerability_report.py
create_argument_parser() uses a local cli_parser variable, marks --organization and --repository as required=True, wires retrieve/graph/page/comparison options, and returns cli_parser. load_dependabot_file() opens files with UTF-8 encoding and validates that JSON is a list of dicts each containing state and security_advisory.severity. dependabot_file_name(args) helper is introduced.
Attribute matching and aggregation helper docstrings
scripts/vulnerability_report.py
Docstrings for has_attribute_with_value, has_deep_attribute_with_value, count_attribute_with_value, count_deep_attribute_with_value, fixed_cves, with_severity, filter_by, fill_in_state, fill_in_severity, and fill_in_severities_set are expanded; no logic changes.
Statistics generation, signature change, and main() wiring
scripts/vulnerability_report.py
fill_in_days_statistic() builds a typed days_stat dict with an inverted guard: average/median are computed via sum(days)/len(days) and median(days) under if not days, and set to 0 in the else branch. process_dependabot_file() drops the prefix parameter. main() calls process_dependabot_file(dependabot_file) without prefix and prints both stat and prefix.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • lightspeed-core/lightspeed-stack#1959: Introduced scripts/vulnerability_report.py with the original create_argument_parser() and process_dependabot_file(dependabot_file, prefix) signature that this PR directly extends and refactors.
  • lightspeed-core/lightspeed-stack#1961: Earlier work on the same file's Dependabot processing helpers and the process_dependabot_file signature change from two parameters to one.
  • lightspeed-core/lightspeed-stack#1973: Overlaps directly on fill_in_days_statistic logic and the stat generation path inside scripts/vulnerability_report.py.
🚥 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 is relevant to a real part of the changeset, since the PR does improve docstrings, even though it omits the broader refactor work.
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.

@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: 1

🤖 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 328-334: The guard in vulnerability_report.py is inverted in the
days statistics block, so the empty-input case still divides by zero and the
non-empty case returns zeros. Fix the logic around the days_stat assignment so
the sum/len and median calculations in the relevant branch run only when days
has values, and the fallback zero values are used only when days is empty. Use
the days_stat handling near the existing median(days) call to locate and correct
the branch condition.
🪄 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: 944f01d6-9968-475d-82cd-589b2bd75afa

📥 Commits

Reviewing files that changed from the base of the PR and between c9871df and 72acc17.

📒 Files selected for processing (1)
  • scripts/vulnerability_report.py
📜 Review details
⏰ Context from checks skipped due to timeout. (15)
  • GitHub Check: build-pr
  • GitHub Check: integration_tests (3.13)
  • GitHub Check: integration_tests (3.12)
  • GitHub Check: Pylinter
  • GitHub Check: unit_tests (3.13)
  • GitHub Check: unit_tests (3.12)
  • GitHub Check: E2E: library mode / ci / group 3
  • GitHub Check: E2E: server mode / ci / group 2
  • GitHub Check: E2E Tests for Lightspeed Evaluation job
  • GitHub Check: E2E: server mode / ci / group 3
  • GitHub Check: E2E: library mode / ci / group 1
  • GitHub Check: E2E: library mode / ci / group 2
  • GitHub Check: E2E: server mode / ci / group 1
  • 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 context used
🪛 ast-grep (0.44.0)
scripts/vulnerability_report.py

[warning] 140-140: File path is request-/variable-derived; validate and normalize to prevent path traversal.
Context: open(filename, "r", encoding="utf-8")
Note: [CWE-22] Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').

(open-filename-from-request)

Comment on lines +328 to +334
# avoid division by zero
if not days:
days_stat["avg"] = sum(days) / len(days)
days_stat["median"] = median(days)
else:
days_stat["avg"] = 0
days_stat["median"] = 0

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.

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Inverted division-by-zero guard breaks both branches.

The condition is reversed. When days is empty, if not days: is true and sum(days) / len(days) evaluates 0 / 0, raising ZeroDivisionError — the exact case the comment says it avoids. When days is non-empty, the else branch forces avg/median to 0, discarding the real values. So this function crashes on empty input and returns incorrect statistics for every non-empty input.

🐛 Proposed fix
     # avoid division by zero
-    if not days:
+    if days:
         days_stat["avg"] = sum(days) / len(days)
         days_stat["median"] = median(days)
     else:
         days_stat["avg"] = 0
         days_stat["median"] = 0
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# avoid division by zero
if not days:
days_stat["avg"] = sum(days) / len(days)
days_stat["median"] = median(days)
else:
days_stat["avg"] = 0
days_stat["median"] = 0
# avoid division by zero
if days:
days_stat["avg"] = sum(days) / len(days)
days_stat["median"] = median(days)
else:
days_stat["avg"] = 0
days_stat["median"] = 0
🤖 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 328 - 334, The guard in
vulnerability_report.py is inverted in the days statistics block, so the
empty-input case still divides by zero and the non-empty case returns zeros. Fix
the logic around the days_stat assignment so the sum/len and median calculations
in the relevant branch run only when days has values, and the fallback zero
values are used only when days is empty. Use the days_stat handling near the
existing median(days) call to locate and correct the branch condition.

@tisnik tisnik merged commit 5ca7a52 into lightspeed-core:main Jun 24, 2026
34 of 35 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Jun 26, 2026
16 tasks
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