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 ingestion CLI #124

Merged
merged 1 commit into from
Nov 11, 2024
Merged

Fix ingestion CLI #124

merged 1 commit into from
Nov 11, 2024

Conversation

neilnaveen
Copy link
Member

@neilnaveen neilnaveen commented Nov 11, 2024

  • Refactored cmd/ingest, since commands did not match their functionality.

Summary by CodeRabbit

  • New Features

    • Updated command usage descriptions for OSV, SBOM, and Scorecard ingestion to enhance clarity.
    • Improved output messages to reflect successful ingestion of vulnerabilities, SBOMs, and scorecards.
  • Bug Fixes

    • Enhanced progress output formatting for better user feedback during ingestion processes.
  • Documentation

    • Revised short descriptions for commands to accurately represent their functionality.

- Refactored cmd/ingest, since commands did not match their
  functionality.

Signed-off-by: neilnaveen <[email protected]>
Copy link
Contributor

coderabbitai bot commented Nov 11, 2024

Walkthrough

The changes in this pull request involve updates to the osv.go, sbom.go, and scorecard.go files, primarily focusing on renaming variables and modifying output messages to improve clarity regarding the ingestion of vulnerability and scorecard data. The command usage descriptions have been revised to reflect these changes, emphasizing the transition from graphing to ingestion. The output formatting has been enhanced to provide clearer progress indications during the ingestion processes.

Changes

File Path Change Summary
cmd/ingest/osv/osv.go Renamed vulnsDir to vulnsPath, updated output messages from "graphed" to "ingested", modified command usage and short description.
cmd/ingest/sbom/sbom.go Updated output formatting for SBOM ingestion, changed command usage and short description for clarity.
cmd/ingest/scorecard/scorecard.go Renamed sbomPath to scorecardPath, updated output messages and command usage to reflect focus on scorecards.

Possibly related PRs

  • Cleaned up ingestion #117: The changes in this PR involve modifications to the SBOM ingestion process, specifically utilizing LoadDataFromPath, which aligns with the changes made in the main PR regarding the osv.go file where LoadDataFromPath is also called for loading vulnerability data.

Suggested reviewers

  • naveensrinivasan

Poem

In the code where rabbits play,
Ingestion leads the way!
From graphs to paths we hop,
Clarity at every stop.
With messages now bright and clear,
We celebrate our code, oh dear! 🐇✨


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.

Copy link

codecov bot commented Nov 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Outside diff range and nitpick comments (7)
cmd/ingest/sbom/sbom.go (4)

31-33: Consider improving terminal output handling robustness.

The current implementation has potential issues with terminal compatibility and width handling:

  1. Fixed 80-character clear might not work for all terminal widths
  2. No fallback for terminals that don't support ANSI escape codes
  3. Progress updates might cause issues in non-interactive terminals or logs

Consider using a terminal handling library like github.com/fatih/color or github.com/mattn/go-isatty to:

  • Detect terminal capabilities
  • Handle terminal width dynamically
  • Provide fallback for non-interactive terminals
+import (
+    "os"
+    "github.com/mattn/go-isatty"
+)

-fmt.Printf("\r\033[1;36m%-80s\033[0m", " ")
-fmt.Printf("\r\033[1;36mIngested %d/%d SBOMs\033[0m | \033[1;34m%s\033[0m", index+1, len(result), tools.TruncateString(data.Path, 50))
+if isatty.IsTerminal(os.Stdout.Fd()) {
+    fmt.Printf("\r\033[1;36mIngested %d/%d SBOMs\033[0m | \033[1;34m%s\033[0m", index+1, len(result), tools.TruncateString(data.Path, 50))
+} else {
+    fmt.Printf("Ingested %d/%d SBOMs: %s\n", index+1, len(result), data.Path)
+}

36-36: Improve consistency in success and error messages.

The success message uses plural form ("SBOMs") while error messages still use singular form ("SBOM"). Also, consider including the total count in the success message for better feedback.

-fmt.Println("\nSBOMs ingested successfully")
+fmt.Printf("\nSuccessfully ingested %d SBOMs\n", len(result))

And for consistency, update the error messages:

-return fmt.Errorf("failed to ingest SBOM: %w", err)
+return fmt.Errorf("failed to ingest SBOMs: %w", err)

45-46: Enhance command documentation and remove trailing space.

The command description could be more specific, and adding examples would improve usability. Also, there's an unnecessary trailing space in the Short description.

-		Use:               "sbom [path to sbom file/dir]",
-		Short:             "Ingest an sbom into the graph ",
+		Use:               "sbom [path to sbom file/dir]",
+		Short:             "Ingest an SBOM into the graph",
+		Long:              "Ingest Software Bill of Materials (SBOM) data from a file or directory into the graph database",
+		Example: `
+  # Ingest a single SBOM file
+  minefield ingest sbom path/to/sbom.json
+
+  # Ingest all SBOMs from a directory
+  minefield ingest sbom path/to/sboms/`,

Line range hint 12-14: Consider renaming for architectural clarity.

Since the command description now mentions "graph" but the interface is named "Storage", consider aligning the naming for better architectural clarity.

type options struct {
-	storage graph.Storage
+	graph graph.Storage
}

This would make it clearer that we're working with a graph database implementation of the storage interface.

cmd/ingest/scorecard/scorecard.go (1)

Line range hint 56-58: Remove unused function printProgress

This function appears to be unused and still references "SBOMs" instead of "Scorecards".

The function should be removed as it's no longer used and contains outdated terminology.

cmd/ingest/osv/osv.go (2)

29-31: Consider handling non-ANSI terminals

While the ANSI color formatting improves readability, it might not work correctly in all terminal environments.

Consider detecting terminal capabilities or adding a flag to disable colors:

+func supportsANSI() bool {
+    term := os.Getenv("TERM")
+    return term != "dumb" && term != ""
+}

 func (o *options) Run(_ *cobra.Command, args []string) error {
+    useColors := supportsANSI()
     // ... existing code ...
-    fmt.Printf("\r\033[1;36m%-80s\033[0m", " ")
-    fmt.Printf("\r\033[K\033[1;36mIngested %d/%d vulnerabilities\033[0m | \033[1;34mCurrent: %s\033[0m",
+    if useColors {
+        fmt.Printf("\r\033[1;36m%-80s\033[0m", " ")
+        fmt.Printf("\r\033[K\033[1;36mIngested %d/%d vulnerabilities\033[0m | \033[1;34mCurrent: %s\033[0m",
+    } else {
+        fmt.Printf("\rIngested %d/%d vulnerabilities | Current: %s",
+    }

Line range hint 53-55: Remove unused printProgress function

The printProgress function appears to be unused and contains outdated terminology ("Graphed" instead of "Ingested").

-func printProgress(count int, path string) string {
-    return fmt.Sprintf("\033[1;36mGraphed %d vulnerabilities\033[0m | \033[1;34mCurrent: %s\033[0m", count, tools.TruncateString(path, 50))
-}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 70d07c2 and 8cbf8eb.

📒 Files selected for processing (3)
  • cmd/ingest/osv/osv.go (2 hunks)
  • cmd/ingest/sbom/sbom.go (2 hunks)
  • cmd/ingest/scorecard/scorecard.go (3 hunks)
🔇 Additional comments (4)
cmd/ingest/scorecard/scorecard.go (2)

30-32: LGTM! Clean progress indication implementation

The progress indication is well-implemented with:

  • Line clearing for smooth updates
  • Color coding for better readability
  • Path truncation to prevent overflow

35-35: LGTM! Clear success message

The success message correctly reflects the scorecard context.

cmd/ingest/osv/osv.go (2)

19-21: LGTM! Variable name improvement

The rename from vulnsDir to vulnsPath better reflects that the argument can be either a file or directory path.


33-33: LGTM! Clear success message

The success message clearly indicates the completion of the ingestion process.

cmd/ingest/scorecard/scorecard.go Show resolved Hide resolved
cmd/ingest/scorecard/scorecard.go Show resolved Hide resolved
cmd/ingest/scorecard/scorecard.go Show resolved Hide resolved
cmd/ingest/osv/osv.go Show resolved Hide resolved
@naveensrinivasan naveensrinivasan merged commit fd7c19e into main Nov 11, 2024
8 checks passed
@naveensrinivasan naveensrinivasan deleted the neil/fixcli branch November 11, 2024 16:54
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.

2 participants