Skip to content

refactor: move valueOrDefault to typeutils as exported DerefOrElse#2835

Open
github-actions[bot] wants to merge 2 commits intomainfrom
code-factory/issue-2834-9358294b6c9d3f32
Open

refactor: move valueOrDefault to typeutils as exported DerefOrElse#2835
github-actions[bot] wants to merge 2 commits intomainfrom
code-factory/issue-2834-9358294b6c9d3f32

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot commented May 9, 2026

Summary

  • Extracts the private valueOrDefault(val *string, def string) string helper from internal/clients/kibanaoapi/alerting_rule.go into internal/utils/typeutils/ptr.go as the exported DerefOrElse function.
  • Updates the single call site in alerting_rule.go to use typeutils.DerefOrElse, removing the now-redundant private definition.
  • Adds three unit tests in ptr_test.go covering nil, empty-string, and non-empty-string inputs.

DerefOrElse is the semantic inverse of the existing NonEmptyStringPtr: it dereferences a string pointer but treats an empty string as absent, returning the provided fallback. Neither Deref (uses zero value) nor any other existing utility covers this case.

Test plan

  • go build ./... passes
  • go vet ./internal/clients/kibanaoapi/... ./internal/utils/typeutils/... passes
  • go test ./internal/utils/typeutils/ passes (including new TestDerefOrElse subtests)
  • go test ./internal/clients/kibanaoapi/ passes
  • make build passes

Closes #2834

🤖 Generated with [Claude Code]((claude.com/redacted)

Generated by Code Factory Issue Intake · ● 195.9K ·

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>
@github-actions
Copy link
Copy Markdown
Contributor Author

github-actions Bot commented May 9, 2026

PR Changelog Check passedno-changelog label is set.

@tobio tobio marked this pull request as ready for review May 10, 2026 01:58
Copilot AI review requested due to automatic review settings May 10, 2026 01:58
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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) string to centralize “nil-or-empty-string pointer → fallback” behavior.
  • Updated the alerting rule response conversion code to use typeutils.DerefOrElse and 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.

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.

[semantic-refactor] valueOrDefault string utility is misplaced inside alerting_rule.go instead of typeutils

2 participants