Skip to content

[task] Refactor script loading to use registry pattern #4671

Description

@github-actions

Objective

Reduce 90% boilerplate in script loading by implementing a registry-based loader pattern, reducing ~400 lines of repetitive code.

Context

Part of issue #4640 - Priority 5 (Quick Win)

pkg/workflow/scripts.go contains ~600 lines of boilerplate for 26 embedded scripts. Each script follows identical lazy-loading pattern with //go:embed, sync.Once, and bundling fallback logic.

Approach

  1. Create pkg/workflow/script_registry.go:

    • Define ScriptLoader struct with: source, bundled, once, bundler function
    • Implement ScriptRegistry with registration and retrieval methods
    • Provide lazy bundling with fallback on error
  2. Simplify pkg/workflow/scripts.go:

    • Keep 26 //go:embed directives (unavoidable)
    • Replace 78 variable declarations with registry initialization
    • Replace 26 getter functions with simple one-line registry lookups
    • Use init() function for registration
  3. Pattern transformation:

    • Before: 4 declarations per script (source var, cached var, sync.Once, getter func)
    • After: 1 embed declaration + 1 registration line + 1 getter line

Files to Modify

  • Create: pkg/workflow/script_registry.go (new registry pattern)
  • Update: pkg/workflow/scripts.go (use registry for all 26 scripts)

Acceptance Criteria

  • ScriptRegistry implementation created with lazy loading
  • All 26 scripts migrated to use registry pattern
  • ~400 lines of boilerplate reduced
  • Bundling behavior preserved (fallback on error)
  • All existing tests pass (make test)
  • Successful compilation (make build)
  • Scripts load correctly in workflows
    Related to [refactor] 🔧 Semantic Function Clustering Analysis - November 2025 #4640

AI generated by Plan Command for #4640

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions