Skip to content

feat: extend PURL identifier support for query string parameters #180

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
Dec 30, 2024

Conversation

naveensrinivasan
Copy link
Member

@naveensrinivasan naveensrinivasan commented Dec 26, 2024

This commit enhances the package URL (PURL) parsing capabilities to support query string parameters in identifiers. The changes include:

  • Updated the Ident lexer rule to accept additional characters (?=&+) commonly found in PURL query strings
  • Added test cases for PURLs containing qualifiers (e.g., ?type=jar)
  • Included a real-world example using Maven artifacts with query parameters
  • Improved test documentation and structure

The enhancement allows for proper handling of package URLs that include qualifiers, such as:
pkg:maven/org.apache.camel.quarkus/camel-quarkus-cassandraql-deployment@3.18.0-SNAPSHOT?type=jar

This change is particularly important for Maven artifacts and other package types commonly using query parameters in their identifiers.

#178

Summary by CodeRabbit

  • New Features

    • Expanded identifier parsing to include additional symbols (?, =, &, +).
    • NodeName field in queries is now optional.
  • Bug Fixes

    • Enhanced test coverage for queries with qualifiers in package URLs, including dependencies and dependents checks.
  • Tests

    • Added new test cases for handling queries with qualifiers and improved existing test cases for accuracy.

Copy link
Contributor

coderabbitai bot commented Dec 26, 2024

Walkthrough

The pull request introduces modifications to the pkg/graph/parser.go file, specifically updating the simpleLexer regular expression for the "Ident" rule to include additional symbols like ?, =, &, and +. The NodeName field in the Query struct is now marked as optional, allowing for potential nil values. In the corresponding test file pkg/graph/parser_test.go, new test cases are added to validate query parsing with qualifiers in package URLs (PURLs), enhancing test coverage for query-related functionality.

Changes

File Change Summary
pkg/graph/parser.go - Updated "Ident" rule regex to include ?, =, &, + symbols
- Made NodeName field optional in Query struct
pkg/graph/parser_test.go - Added new test cases for queries with PURL qualifiers
- Created mock node nodeCamel with query-string PURL
- Updated test cases to use dynamically generated node IDs

Sequence Diagram

sequenceDiagram
    participant Parser
    participant Lexer
    participant Query
    
    Parser->>Lexer: Parse input with extended Ident rule
    Lexer-->>Parser: Return tokens with new symbol support
    Parser->>Query: Create query with optional NodeName
    Query-->>Parser: Return query object
Loading

Possibly related PRs

Poem

🐰 In the realm of parsing delight,
Symbols dance with newfound might
Qualifiers bloom, NodeName takes flight
Flexible queries, a coder's bright
Lexer's magic, pure rabbit's insight! 🔍

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

This commit enhances the package URL (PURL) parsing capabilities to support
query string parameters in identifiers. The changes include:

- Updated the Ident lexer rule to accept additional characters (?=&+)
  commonly found in PURL query strings
- Added test cases for PURLs containing qualifiers (e.g., ?type=jar)
- Included a real-world example using Maven artifacts with query parameters
- Improved test documentation and structure

The enhancement allows for proper handling of package URLs that include
qualifiers, such as:
pkg:maven/org.apache.camel.quarkus/camel-quarkus-cassandraql-deployment@3.18.0-SNAPSHOT?type=jar

This change is particularly important for Maven artifacts and other package
types that commonly use query parameters in their identifiers.

#178

Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com>
@naveensrinivasan naveensrinivasan force-pushed the naveen/fix/special-character branch from 42ad018 to 1ace367 Compare December 26, 2024 02:37
Copy link

codecov bot commented Dec 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Files with missing lines Coverage Δ
pkg/graph/parser.go 65.69% <ø> (ø)

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: 0

🧹 Nitpick comments (1)
pkg/graph/parser.go (1)

39-40: Expand character set and consider using keyed struct fields
Allowing ?, =, &, and + in the Ident rule improves PURL query parameter parsing. As per the static analysis hint, you might consider using keyed struct fields in these literals to avoid accidental misordering in the future:

-{"Operator", `\b(?:and|or|xor)\b`},
-{"Ident", `[a-zA-Z][a-zA-Z0-9:/._@?=&+\-]*`},
+{Type: "Operator", Pattern: `\b(?:and|or|xor)\b`},
+{Type: "Ident", Pattern: `[a-zA-Z][a-zA-Z0-9:/._@?=&+\-]*`},
🧰 Tools
🪛 golangci-lint (1.62.2)

39-39: composites: github.com/alecthomas/participle/v2/lexer.SimpleRule struct literal uses unkeyed fields

(govet)


40-40: composites: github.com/alecthomas/participle/v2/lexer.SimpleRule struct literal uses unkeyed fields

(govet)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2a0949d and 1ace367.

📒 Files selected for processing (2)
  • pkg/graph/parser.go (1 hunks)
  • pkg/graph/parser_test.go (7 hunks)
🧰 Additional context used
🪛 golangci-lint (1.62.2)
pkg/graph/parser.go

39-39: composites: github.com/alecthomas/participle/v2/lexer.SimpleRule struct literal uses unkeyed fields

(govet)


40-40: composites: github.com/alecthomas/participle/v2/lexer.SimpleRule struct literal uses unkeyed fields

(govet)

🔇 Additional comments (11)
pkg/graph/parser_test.go (11)

9-10: Nice documentation update for qualifier coverage
These comments clearly explain the addition of tests involving query parameters, making it easier to understand the context and purpose of these tests.


32-36: Good introduction of a PURL with a query-string
Creating nodeCamel with ?type=jar helps demonstrate real-world use cases of qualifiers in PURLs.


38-39: Clearer explanation of dependency structure
Documenting the dependency chain helps readers quickly grasp the purpose of the subsequent test assertions.


53-57: Good test coverage for qualified PURLs
Making nodeCamel depend on node4 confirms that PURLs with query parameters can be processed in the same manner as regular PURLs.


74-74: No issues with test assertion
This verifies basic dependents functionality for node1, node2, and node3.


80-80: No issues with test assertion
Ensures the correct chain of dependencies for node1, including node3 and node4.


92-92: No issues with combined queries
Validates logical operators in queries involving multiple nodes and ensures correct result sets.


102-104: Solid test for default node name
This scenario checks fallback behavior when no node name is specified, improving coverage of edge cases.


108-114: Comprehensive test for dependencies with qualifiers
Verifies that queries with ?type=jar are accurately recognized and processed.


115-120: Dependents query for qualified PURL
Useful to confirm that qualifiers function correctly in both dependents and dependencies queries.


121-126: Proper handling of invalid qualified queries
Ensures erroneous queries with qualifiers are caught, maintaining robust validation.

Copy link
Member

@neilnaveen neilnaveen left a comment

Choose a reason for hiding this comment

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

LGTM

@naveensrinivasan naveensrinivasan merged commit b306298 into main Dec 30, 2024
14 of 16 checks passed
@naveensrinivasan naveensrinivasan deleted the naveen/fix/special-character branch December 30, 2024 17:03
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