-
Notifications
You must be signed in to change notification settings - Fork 45
Closed
Description
Objective
Create a reusable helper function for parsing version values to reduce code duplication and ensure consistent type handling across the codebase.
Context
The same type coercion logic (string/int/float → string) is duplicated across three locations. Creating a shared helper promotes DRY principles and makes future maintenance easier.
Proposed Implementation
Add to pkg/workflow/config_helpers.go:
// parseVersionValue converts version values of various types to strings.
// Supports string, int, int64, uint64, and float64 types.
// Returns empty string for unsupported types.
func parseVersionValue(version any) string {
switch v := version.(type) {
case string:
return v
case int, int64, uint64:
return fmt.Sprintf("%d", v)
case float64:
return fmt.Sprintf("%g", v)
default:
return ""
}
}Refactor Usage Sites
Update the three fixed locations to use the helper:
1. engine.go:
if version, hasVersion := engineObj["version"]; hasVersion {
config.Version = parseVersionValue(version)
}2. mcp.go (GitHub MCP, line 372):
if version, exists := toolConfig["version"]; exists {
if versionStr := parseVersionValue(version); versionStr != "" {
dockerImage := "ghcr.io/github/github-mcp-server:" + versionStr
}
}3. mcp.go (Playwright, line 447):
if version, exists := toolConfig["version"]; exists {
if versionStr := parseVersionValue(version); versionStr != "" {
// Version handling logic
}
}Files to Modify
- Update:
pkg/workflow/config_helpers.go(add helper function) - Update:
pkg/workflow/config_helpers_test.go(add tests) - Update:
pkg/workflow/engine.go(refactor to use helper) - Update:
pkg/parser/mcp.go(refactor two locations to use helper)
Acceptance Criteria
- Helper function is added to
config_helpers.go - Helper function has unit tests
- All three version field locations use the helper
- Existing tests continue to pass
- Code duplication is eliminated
Estimated Effort
~20 minutes implementation
Dependencies
Should be completed after sub-issues #1, #2, and #3 are fixed.
Related to #8221
AI generated by Plan Command for discussion #8218
Reactions are currently unavailable