refactor: move valueOrDefault to typeutils as exported DerefOrElse#2835
Open
github-actions[bot] wants to merge 2 commits intomainfrom
Open
refactor: move valueOrDefault to typeutils as exported DerefOrElse#2835github-actions[bot] wants to merge 2 commits intomainfrom
github-actions[bot] wants to merge 2 commits intomainfrom
Conversation
Extracts the private `valueOrDefault` helper from `alerting_rule.go` into `internal/utils/typeutils/ptr.go` as the exported `DerefOrElse` function, making it reusable across all packages. Updates the single call site in `alerting_rule.go` to use the new utility and adds unit tests. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
Author
|
✅ PR Changelog Check passed — |
tobio
approved these changes
May 10, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors a string-pointer dereference helper out of internal/clients/kibanaoapi/alerting_rule.go into the shared internal/utils/typeutils utilities, making it reusable and adding focused unit coverage.
Changes:
- Added
typeutils.DerefOrElse(*string, string) stringto centralize “nil-or-empty-string pointer → fallback” behavior. - Updated the alerting rule response conversion code to use
typeutils.DerefOrElseand removed the now-redundant private helper. - Added unit tests covering nil, empty, and non-empty pointer inputs.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| internal/utils/typeutils/ptr.go | Adds exported DerefOrElse helper for string pointer deref-with-fallback behavior. |
| internal/utils/typeutils/ptr_test.go | Adds unit tests validating DerefOrElse behavior for nil/empty/non-empty inputs. |
| internal/clients/kibanaoapi/alerting_rule.go | Replaces the local helper usage with typeutils.DerefOrElse and removes the private function. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
valueOrDefault(val *string, def string) stringhelper frominternal/clients/kibanaoapi/alerting_rule.gointointernal/utils/typeutils/ptr.goas the exportedDerefOrElsefunction.alerting_rule.goto usetypeutils.DerefOrElse, removing the now-redundant private definition.ptr_test.gocovering nil, empty-string, and non-empty-string inputs.DerefOrElseis the semantic inverse of the existingNonEmptyStringPtr: it dereferences a string pointer but treats an empty string as absent, returning the provided fallback. NeitherDeref(uses zero value) nor any other existing utility covers this case.Test plan
go build ./...passesgo vet ./internal/clients/kibanaoapi/... ./internal/utils/typeutils/...passesgo test ./internal/utils/typeutils/passes (including newTestDerefOrElsesubtests)go test ./internal/clients/kibanaoapi/passesmake buildpassesCloses #2834
🤖 Generated with [Claude Code]((claude.com/redacted)