Skip to content

refactor: consolidate duplicated helpers into internal/util#92

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
feat/shared-util-helpers
Open

refactor: consolidate duplicated helpers into internal/util#92
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
feat/shared-util-helpers

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Summary

Several tiny helper functions were copy-pasted verbatim across packages. This adds a single generic internal/util package and replaces all the duplicates with it, removing the local copies.

New package internal/util:

func Ptr[T any](v T) *T                       // was boolPtr in 2 packages
func Deref[T any](p *T, fallback T) T          // was boolOrDefault
func OrDefault[T comparable](value, fallback T) T // was valueOrDefault (x3) + intOrDefault
func FirstNonEmpty(vals ...string) string      // was firstNonEmpty (x2) + firstNonEmptyString

Call sites updated:

  • boolPtrutil.Ptr in config/convert.go, service/store/sqlite_store.go
  • valueOrDefault/intOrDefaultutil.OrDefault, boolOrDefaultutil.Deref in config/config.go + config/config_loader.go, and valueOrDefault in extension/codex/catalog.go
  • firstNonEmpty/firstNonEmptyStringutil.FirstNonEmpty in protocol/openai/adapter.go, extension/deepseek_v4/{deepseek_v4,state}.go, service/server/adapter_dispatch.go
  • Removed a dead valueOrDefault (no callers) in service/provider/manager.go

util has no imports, so no import cycles are introduced. Behavior is identical — OrDefault uses the zero value (""/0) as the "empty" sentinel, matching the previous per-type helpers.

Testing

  • go build ./..., go vet ./... clean
  • go test ./... passes (all packages), including new internal/util unit tests

Link to Devin session: https://app.devin.ai/sessions/2d5f007ca93b447f9171f0bb1fbf757a
Requested by: @ZhiYi-R

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@ZhiYi-R ZhiYi-R self-assigned this Jul 11, 2026
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

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