common: add WithOptions helper and embeddable mixin#1307
common: add WithOptions helper and embeddable mixin#1307klaskosk merged 1 commit intorh-ecosystem-edge:mainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdded a generic functional-options mechanism: new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@pkg/internal/common/common.go`:
- Around line 624-629: The code overwrites builder with the option result before
checking err, which will panic if option returns (nil, err); change the call to
use a temporary (e.g., newBuilder, err := option(builder)), check if err != nil
first, and if so call builder.SetError(err) only after guarding builder != nil
(or handle nil appropriately), then only assign builder = newBuilder when err ==
nil; keep references to the existing variables/methods: builder, option(...),
and builder.SetError.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: ff2f580e-7dae-4e92-94f2-3622a347398e
📒 Files selected for processing (5)
pkg/internal/common/common.gopkg/internal/common/common_test.gopkg/internal/common/embeddable_withoptions.gopkg/internal/common/testhelper/utils.gopkg/internal/common/testhelper/withoptionshelper.go
73d934c to
e1a5718
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pkg/internal/common/testhelper/withoptionshelper.go (1)
120-129: Optional: remove duplicated annotation retrieval in assertions.Small readability improvement: fetch annotations once before branching.
♻️ Proposed cleanup
- if result.GetError() == nil { - annotations := result.GetDefinition().GetAnnotations() + annotations := result.GetDefinition().GetAnnotations() + if result.GetError() == nil { require.NotNil(t, annotations) assert.Equal(t, testAnnotationValue, annotations[testAnnotationKey]) - } else { - annotations := result.GetDefinition().GetAnnotations() - if annotations != nil { - _, exists := annotations[testAnnotationKey] - assert.False(t, exists, "annotation should not be set when option fails") - } + } else if annotations != nil { + _, exists := annotations[testAnnotationKey] + assert.False(t, exists, "annotation should not be set when option fails") }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/internal/common/testhelper/withoptionshelper.go` around lines 120 - 129, The code duplicates fetching annotations from result.GetDefinition().GetAnnotations() in both branches; refactor the test in withoptionshelper.go to call annotations := result.GetDefinition().GetAnnotations() once before the if result.GetError() == nil check, then use annotations in the success branch to assert annotations[testAnnotationKey] equals testAnnotationValue and in the error branch to check annotations != nil and that testAnnotationKey does not exist; keep references to result.GetError(), result.GetDefinition().GetAnnotations(), testAnnotationKey, and testAnnotationValue to locate and update the assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@pkg/internal/common/testhelper/withoptionshelper.go`:
- Around line 120-129: The code duplicates fetching annotations from
result.GetDefinition().GetAnnotations() in both branches; refactor the test in
withoptionshelper.go to call annotations :=
result.GetDefinition().GetAnnotations() once before the if result.GetError() ==
nil check, then use annotations in the success branch to assert
annotations[testAnnotationKey] equals testAnnotationValue and in the error
branch to check annotations != nil and that testAnnotationKey does not exist;
keep references to result.GetError(), result.GetDefinition().GetAnnotations(),
testAnnotationKey, and testAnnotationValue to locate and update the assertions.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 62dd6763-b96d-4976-9113-d9bd16edc949
📒 Files selected for processing (5)
pkg/internal/common/common.gopkg/internal/common/common_test.gopkg/internal/common/embeddable_withoptions.gopkg/internal/common/testhelper/utils.gopkg/internal/common/testhelper/withoptionshelper.go
🚧 Files skipped from review as they are similar to previous changes (2)
- pkg/internal/common/common.go
- pkg/internal/common/embeddable_withoptions.go
e1a5718 to
bd07b90
Compare
Introduce generic WithOptions for functional options on builders, EmbeddableWithOptions mixin, and testhelper coverage with pluggable WithOptionsFunc for builder methods and common.WithOptions. Made-with: Cursor
bd07b90 to
32f48fa
Compare
Introduce generic WithOptions for functional options on builders, EmbeddableWithOptions mixin, and testhelper coverage with pluggable WithOptionsFunc for builder methods and common.WithOptions.
Made-with: Cursor
Summary by CodeRabbit
New Features
Tests