Skip to content

feat: implement exclude settings #136

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

Merged
merged 1 commit into from
Jul 14, 2025
Merged

Conversation

isasmendiagus
Copy link
Contributor

@isasmendiagus isasmendiagus commented Jul 14, 2025

Summary by CodeRabbit

  • New Features
    • Added support for specifying an "exclude" list of components in the Bill of Materials (BOM) for scans, allowing users to blacklist components during scanning.
  • Improvements
    • Enhanced handling of BOM settings to better differentiate between include and exclude lists for both legacy and new settings files.
    • Improved documentation for BOM-related methods.

@isasmendiagus isasmendiagus marked this pull request as ready for review July 14, 2025 15:07
Copy link

coderabbitai bot commented Jul 14, 2025

Walkthrough

The changes update the scan settings logic to support an "exclude" list of components in the Bill of Materials (BOM) for both legacy and new settings file types. New methods and logic branches are introduced to handle exclusion, and the scan type assignment is adjusted accordingly in both the CLI and settings handler.

Changes

File(s) Change Summary
src/scanoss/cli.py Modified scan function logic to stop setting scan type to 'identify' by default for new files.
src/scanoss/scanoss_settings.py Added get_bom_exclude() method, updated asset retrieval logic for 'exclude' lists and scan types, fixed docstring, and reordered return keys in get_sbom().

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant ScanossSettings

    User->>CLI: Run scan command (no --identify/--ignore)
    CLI->>ScanossSettings: Load JSON settings file
    alt New settings file
        alt 'include' list present
            ScanossSettings->>CLI: Set file_type='new', scan_type='identify', return include list
        else 'exclude' list present
            ScanossSettings->>CLI: Set file_type='new', scan_type='blacklist', return exclude list
        else
            ScanossSettings->>CLI: Set file_type='new', no scan_type
        end
    else Legacy settings file
        alt scan_type='identify'
            ScanossSettings->>CLI: Return combined include and replace lists
        else scan_type='blacklist'
            ScanossSettings->>CLI: Return exclude list
        end
    end
Loading

Poem

In the warren of code, a new path we pursue,
Exclude lists now honored, for scans old and new.
With settings more clever, our scans hop along,
Identifying or blacklisting, we’re never wrong.
🐇✨
—A rabbit, delighted by settings anew

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b7028be and 8afa005.

📒 Files selected for processing (2)
  • src/scanoss/cli.py (1 hunks)
  • src/scanoss/scanoss_settings.py (5 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/scanoss/cli.py (1)
src/scanoss/scanoss_settings.py (2)
  • load_json_file (103-138)
  • set_file_type (140-152)
src/scanoss/scanoss_settings.py (1)
src/scanoss/scanossbase.py (1)
  • print_debug (58-63)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (4)
src/scanoss/scanoss_settings.py (3)

175-175: Good catch on the typo correction!

The change from "Billing of Materials" to "Bill of Materials" is the correct terminology.


200-209: LGTM! The new method follows the established pattern.

The get_bom_exclude() method correctly mirrors the implementation pattern of existing methods like get_bom_include() and get_bom_remove().


250-259: Review scan_type determination for new settings_file_type

The automatic setting of scan_type is confined to src/scanoss/scanoss_settings.py and no other parts of the codebase (including the CLI) or any tests reference scan_type. Before merging, please:

  • Verify that the CLI logic which consumes the payload from scanoss_settings correctly handles the new "identify" and "blacklist" values when settings_file_type == 'new'.
  • Add or update tests to cover:
    • When only bom_include is provided → scan_type == 'identify'
    • When only bom_exclude is provided → scan_type == 'blacklist'
    • Behavior when both or neither lists are present
src/scanoss/cli.py (1)

1074-1075: Verify automatic scan type determination

The removal of the explicit

.set_scan_type('identify')

call at src/scanoss/cli.py:1074–1075 now delegates scan-type assignment to
ScanossSettings._get_sbom_assets(). That method only sets scan_type when either the include or exclude list is non-empty, so for a “new” settings file with neither list populated you’ll fall back to whatever default (or unset) state.

Please add or confirm tests for these scenarios:

  • “new” settings with only bom.include → expect scan_type = 'identify'
  • “new” settings with only bom.exclude → expect scan_type = 'blacklist'
  • “new” settings with neither list → verify default scan_type and asset payload (e.g. error, null assets, etc.)

Ensure the observed behavior matches requirements.

@@ -244,6 +266,14 @@ def _get_sbom_assets(self):
f'From Replace list: {[entry["purl"] for entry in replace_bom_entries]} \n'
)
return include_bom_entries + replace_bom_entries

if self.settings_file_type == 'legacy' and self.scan_type == 'blacklist': # sbom-identify.json
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix incorrect comment.

The comment mentions "sbom-identify.json" but this code block handles the 'blacklist' scan type.

-    if self.settings_file_type == 'legacy' and self.scan_type == 'blacklist':            # sbom-identify.json
+    if self.settings_file_type == 'legacy' and self.scan_type == 'blacklist':            # sbom-exclude.json
📝 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
if self.settings_file_type == 'legacy' and self.scan_type == 'blacklist': # sbom-identify.json
if self.settings_file_type == 'legacy' and self.scan_type == 'blacklist': # sbom-exclude.json
🤖 Prompt for AI Agents
In src/scanoss/scanoss_settings.py at line 270, the comment incorrectly
references "sbom-identify.json" while the code handles the 'blacklist' scan
type. Update the comment to accurately describe the condition related to the
'blacklist' scan type instead of mentioning "sbom-identify.json".

Comment on lines +249 to +259

if self.settings_file_type == 'new':
if len(self.get_bom_include()):
self.scan_type = 'identify'
include_bom_entries = self._remove_duplicates(self.normalize_bom_entries(self.get_bom_include()))
return {"components": include_bom_entries}
elif len(self.get_bom_exclude()):
self.scan_type = 'blacklist'
exclude_bom_entries = self._remove_duplicates(self.normalize_bom_entries(self.get_bom_exclude()))
return {"components": exclude_bom_entries}

Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Refactor to avoid side effects in getter method.

The _get_sbom_assets() method is modifying self.scan_type as a side effect, which violates the single responsibility principle. Getter methods should retrieve data without modifying state.

Additionally, if both 'include' and 'exclude' lists are present, only the 'include' list is processed. Consider documenting this behavior or handling both lists appropriately.

Consider refactoring to separate concerns:

def _get_sbom_assets(self):
    """
    Get the SBOM assets
    Returns:
        List: List of SBOM assets
    """

    if self.settings_file_type == 'new':
        if len(self.get_bom_include()):
-            self.scan_type = 'identify'
            include_bom_entries = self._remove_duplicates(self.normalize_bom_entries(self.get_bom_include()))
            return {"components": include_bom_entries}
        elif len(self.get_bom_exclude()):
-            self.scan_type = 'blacklist'
            exclude_bom_entries = self._remove_duplicates(self.normalize_bom_entries(self.get_bom_exclude()))
            return {"components": exclude_bom_entries}

Move the scan type determination to a separate method or handle it where _get_sbom_assets() is called.

📝 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
if self.settings_file_type == 'new':
if len(self.get_bom_include()):
self.scan_type = 'identify'
include_bom_entries = self._remove_duplicates(self.normalize_bom_entries(self.get_bom_include()))
return {"components": include_bom_entries}
elif len(self.get_bom_exclude()):
self.scan_type = 'blacklist'
exclude_bom_entries = self._remove_duplicates(self.normalize_bom_entries(self.get_bom_exclude()))
return {"components": exclude_bom_entries}
def _get_sbom_assets(self):
"""
Get the SBOM assets
Returns:
List: List of SBOM assets
"""
if self.settings_file_type == 'new':
if len(self.get_bom_include()):
include_bom_entries = self._remove_duplicates(
self.normalize_bom_entries(self.get_bom_include())
)
return {"components": include_bom_entries}
elif len(self.get_bom_exclude()):
exclude_bom_entries = self._remove_duplicates(
self.normalize_bom_entries(self.get_bom_exclude())
)
return {"components": exclude_bom_entries}
# … existing logic for legacy settings_file_type …
🤖 Prompt for AI Agents
In src/scanoss/scanoss_settings.py around lines 249 to 259, the method
_get_sbom_assets() improperly modifies self.scan_type, causing side effects in a
getter. Refactor by removing the assignment to self.scan_type from this method
and instead determine and set scan_type in a separate method or at the call site
before invoking _get_sbom_assets(). Also, clarify or handle the case when both
include and exclude lists are present, either by documenting the current
behavior or adjusting logic to process both appropriately.

@agustingroh agustingroh merged commit fae200e into main Jul 14, 2025
4 checks passed
@agustingroh agustingroh deleted the feat/exclude-in-settings branch July 14, 2025 16:17
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.

3 participants