Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/clarify-vulnerabilities-found/ #608

Merged
merged 1 commit into from
Oct 16, 2024

Conversation

SafetyQuincyF
Copy link
Contributor

@SafetyQuincyF SafetyQuincyF commented Oct 10, 2024

Fixed the issue where the vulnerabilities
found were not being displayed correctly.
New Format:
image

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced a comprehensive summary of vulnerabilities in the scan reports, including total issues, ignored issues, and unique vulnerabilities.
    • Enhanced output structure for clarity, detailing vulnerabilities, suggested fixes, and their impacts.
  • Bug Fixes

    • Improved accuracy and detail in vulnerability reporting by refining handling logic.
  • Tests

    • Updated the test suite to validate the new summary outputs related to security scans.
    • Enhanced tests for the debug flag functionality in the CLI, including new scenarios.

Copy link

coderabbitai bot commented Oct 10, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The changes in this pull request involve significant updates to the safety/scan/command.py, safety/scan/render.py, and tests/scan/test_render.py files, focusing on enhancing the scanning process and report generation. The print_brief function has been removed and replaced with a new print_summary function that consolidates vulnerability reporting. A new helper function, get_vulnerability_summary, has been introduced to compute and summarize vulnerability data. The overall output structure has been refined for clarity and detail, improving how vulnerabilities and their statuses are reported.

Changes

File Path Change Summary
safety/scan/command.py - Removed print_brief and print_ignore_details functions.
- Added print_summary for consolidated reporting.
- Introduced get_vulnerability_summary for computing vulnerability totals.
- Updated process_report to include summary information.
safety/scan/render.py - Removed print_brief function.
- Added print_summary with enhanced parameters for detailed reporting.
tests/scan/test_render.py - Removed test_print_ignore_details method.
- Added test_print_summary to test the new print_summary function.
- Updated import statements to reflect new functionality.
tests/test_cli.py - Updated test_debug_flag method with type hints and improved assertions.
- Added test_debug_flag_with_value_1 and test_debug_flag_with_value_true methods for additional testing of debug flag functionality.

Possibly related PRs

  • chore/added check arg depreciation warning #607: The changes in this PR involve modifications to the CLI commands, but they do not directly relate to the enhancements made in the reporting functionality of the scanning process in the main PR.

Suggested reviewers

  • dylanpulver

Poem

In the land of code, where bunnies hop,
A summary shines, making issues stop.
With vulnerabilities tallied, clear and bright,
Our scans now sing, bringing bugs to light.
So let's celebrate, with a joyful cheer,
For clarity gained, and no more fear! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@SafetyQuincyF SafetyQuincyF added the bug Indicates a problem that needs to be resolved. label Oct 10, 2024
@SafetyQuincyF SafetyQuincyF self-assigned this Oct 10, 2024
coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

@SafetyQuincyF SafetyQuincyF force-pushed the fix/clearify-vulnerabilities-found branch 2 times, most recently from a1ce6cf to b6222d6 Compare October 11, 2024 00:06
coderabbitai[bot]

This comment was marked as resolved.

@SafetyQuincyF SafetyQuincyF force-pushed the fix/clearify-vulnerabilities-found branch 2 times, most recently from 0024b04 to 8370e17 Compare October 11, 2024 01:22
coderabbitai[bot]

This comment was marked as resolved.

@SafetyQuincyF SafetyQuincyF force-pushed the fix/clearify-vulnerabilities-found branch 4 times, most recently from 392c07d to 85fe87d Compare October 11, 2024 02:00
coderabbitai[bot]

This comment was marked as resolved.

@SafetyQuincyF SafetyQuincyF force-pushed the fix/clearify-vulnerabilities-found branch from c5f5d53 to 7d48881 Compare October 11, 2024 07:21
coderabbitai[bot]

This comment was marked as resolved.

@SafetyQuincyF SafetyQuincyF force-pushed the fix/clearify-vulnerabilities-found branch 7 times, most recently from f8ae84a to d8f5078 Compare October 11, 2024 18:58
coderabbitai[bot]

This comment was marked as resolved.

@SafetyQuincyF SafetyQuincyF force-pushed the fix/clearify-vulnerabilities-found branch from 3c1887e to d9b62c0 Compare October 14, 2024 00:04
coderabbitai[bot]

This comment was marked as resolved.

@SafetyQuincyF SafetyQuincyF force-pushed the fix/clearify-vulnerabilities-found branch from 576731f to bd1d198 Compare October 14, 2024 00:25
@SafetyQuincyF SafetyQuincyF force-pushed the fix/clearify-vulnerabilities-found branch 4 times, most recently from e83a1bd to 8eac6b2 Compare October 14, 2024 00:57
Copy link
Contributor

@dylanpulver dylanpulver left a comment

Choose a reason for hiding this comment

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

Looks good! Just one function to see if we can optimize on!

@@ -789,3 +790,33 @@ def system_scan(ctx: typer.Context,
console.print(Padding(detail, (0, 0, 0, 1)), emoji=True, overflow="crop")

process_report(ctx.obj, console, report, **{**ctx.params})

def get_vulnerability_summary(report: Dict[str, Any]) -> Tuple[int, int]:
Copy link
Contributor

Choose a reason for hiding this comment

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

If we can reduce the nesting it may help with efficiency.
Here is something to try to check if it produces the same:

def get_vulnerability_summary(report: Dict[str, Any]) -> Tuple[int, int]:
    """
    Summarize vulnerabilities from the given report.

    Args:
        report (ReportModel): The report containing vulnerability data.
    
    Returns:
        Tuple[int, int]: A tuple containing:
            - Total number of issues (including duplicates)
            - Total number of ignored issues
    """
    total_issues = 0
    ignored_issues = 0

    for project in report.scan_results.projects:
        for file in project.files:
            for dependency in file.results.dependencies:
                for specification in dependency.specifications:
                    known_vulnerabilities = specification.vulnerabilities.known_vulnerabilities
                    total_issues += len(known_vulnerabilities)
                    ignored_issues += sum(1 for v in known_vulnerabilities if v.ignored)

    return total_issues, ignored_issues

Fixed the issue where the vulnerabilities
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates a problem that needs to be resolved.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants