Skip to content

Conversation

@Luap99
Copy link
Member

@Luap99 Luap99 commented Jul 30, 2025

Simplify the code a bit. Should not change the behavior.

Summary by Sourcery

Use strings.Cut to simplify parsing of filter strings across PrepareFilters, MatchLabelFilters, and MatchNegatedLabelFilters while preserving existing behavior.

Enhancements:

  • Replace strings.SplitN-based parsing with strings.Cut for key/value extraction in filter handling
  • Remove the redundant splitFilterValue helper function

Simplify the code a bit. Should not change the behavior.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
@sourcery-ai
Copy link

sourcery-ai bot commented Jul 30, 2025

Reviewer's Guide

The PR refactors filter parsing by replacing manual split logic and a custom helper with Go’s strings.Cut API, streamlining code in PrepareFilters, MatchLabelFilters, and MatchNegatedLabelFilters without altering behavior.

Class diagram for refactored filter parsing functions

classDiagram
    class filters {
        +PrepareFilters(r *http.Request) map[string][]string
        +MatchLabelFilters(filterValues []string, labels map[string]string) bool
        +MatchNegatedLabelFilters(filterValues []string, labels map[string]string) bool
        -splitFilterValue(filterValue string) (string, string)  %% removed
    }

    filters : -splitFilterValue removed
    filters : +PrepareFilters updated to use strings.Cut
    filters : +MatchLabelFilters updated to use strings.Cut
    filters : +MatchNegatedLabelFilters updated to use strings.Cut
Loading

File-Level Changes

Change Details Files
Use strings.Cut in PrepareFilters to parse key/value pairs
  • Replace strings.SplitN call with strings.Cut
  • Check found boolean instead of split length
  • Append value to filterMap based on key and val
pkg/filters/filters.go
Apply strings.Cut directly in label-matching functions
  • Remove splitFilterValue call in MatchLabelFilters and unpack Cut return
  • Remove splitFilterValue call in MatchNegatedLabelFilters and unpack Cut return
  • Ignore the boolean return when splitting filterValue
pkg/filters/filters.go
Remove the splitFilterValue helper function
  • Delete splitFilterValue definition and associated comments
pkg/filters/filters.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @Luap99 - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jul 30, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Luap99, sourcery-ai[bot]

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@mheon
Copy link
Member

mheon commented Jul 30, 2025

LGTM

Copy link
Contributor

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

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

/lgtm

split := strings.SplitN(filter, "=", 2)
if len(split) > 1 {
filterMap[split[0]] = append(filterMap[split[0]], split[1])
key, val, found := strings.Cut(filter, "=")
Copy link
Contributor

Choose a reason for hiding this comment

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

(FiltersFromRequest just created all of these using %s=%s. We could avoid the single-string form, and the if found condition, entirely, by parsing directly into a map, or at least an array of key-value pairs. And similarly for Podman’s pkg/util/filters.go.

… does this function, as opposed to podman/pkg/util.PrepareFilters, have any callers at all?)

Copy link
Member Author

Choose a reason for hiding this comment

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

there was a phase were people blindly moved code to c/common for various reasons and then never actually updated podman to use it and remove the podman code...

So yeah that does not surprise me at all and yeah you are right there seems be a lot of pointless conversation involved.

@openshift-ci openshift-ci bot added the lgtm label Aug 1, 2025
@openshift-merge-bot openshift-merge-bot bot merged commit 233060e into containers:main Aug 1, 2025
14 checks passed
@Luap99 Luap99 deleted the filter branch August 1, 2025 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants