Skip to content

[refactor] Reinvented semver helpers reuse pkg/semverutilΒ #42151

Description

@github-actions

πŸ”§ Semantic Function Clustering Analysis

Analysis of repository: github/gh-aw β€” 2026-06-29

Executive Summary

Analyzed ~920 non-test Go files. The codebase already maintains dedicated *util packages (stringutil, sliceutil, setutil, semverutil, repoutil, jsonutil, fileutil, gitutil, ...) and is generally well-organized. The strongest actionable findings are a small cluster of semver helpers reinvented in feature files that the existing pkg/semverutil already provides, plus a few generic helpers misplaced in domain files.

The dominant noise source (wasm vs. native pairs in *_wasm.go) is intentional build-tag stubbing β€” not duplication. Likewise audit_math_helpers.go is already a consolidated helper file. Those are excluded.

Verified findings (high confidence)

Function File Duplicates Fix
ensureSemverPrefix pkg/cli/compile_update_check.go:323 semverutil.EnsureVPrefix (identical) delete, call util
semverMajorMinorParts pkg/cli/compile_update_check.go:301 semverutil.ParseVersion (.Major/.Minor) reuse parser
isMorePreciseVersion pkg/workflow/action_cache.go:722 semver-precision logic; near semverutil.IsPreciseVersion move to semverutil
Side-by-side
// pkg/cli/compile_update_check.go
func ensureSemverPrefix(version string) string {
    if strings.HasPrefix(version, "v") { return version }
    return "v" + version
}
// pkg/semverutil/semverutil.go  -> EnsureVPrefix(v string) string  (same behavior)

Priority 1: Consolidate semver helpers

Move pkg/workflow/action_cache.go:isMorePreciseVersion into pkg/semverutil, and replace ensureSemverPrefix / semverMajorMinorParts in compile_update_check.go with semverutil.EnsureVPrefix / semverutil.ParseVersion. Single source of truth for version logic. Est. 1–2h.

Priority 2: Centralize stray helpers

Generic comparison/string helpers (truncateSHAForLog already wraps stringutil.Truncate βœ“) and containsAny (pkg/cli/audit_agentic_analysis.go:497) overlap sliceutil. Audit per call-site; remove thin wrappers. Est. 2–3h.

Implementation checklist

  • Move semver helpers into pkg/semverutil, update call sites
  • Run go build ./... + tests
  • Review thin slice/string wrappers for removal

Metadata

  • Files analyzed: ~920 (pkg/, non-test, non-testdata) Β· Method: parallel symbol scan + manual verification of each finding
  • Excluded: *_wasm.go build-tag stub pairs (intentional), already-consolidated helper files

Generated by πŸ”§ Semantic Function Refactoring Β· 221.4 AIC Β· βŒ– 14.1 AIC Β· ⊞ 9.2K Β· β—·

  • expires on Jun 30, 2026, 4:14 PM UTC-08:00

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions