Skip to content

Commit d929166

Browse files
github-actions[bot]Code Simplifier Agent
andauthored
refactor: extract action mode helper to reduce code duplication (#13982)
Extract repeated pattern of action mode extraction into a helper function GetActionModeFromWorkflowData() to improve code clarity and reduce duplication across all four engine MCP renderers (Copilot, Claude, Codex, Custom). Changes: - Add GetActionModeFromWorkflowData() helper to action_mode.go - Simplify createRenderer closures in all four engine files - Reduce 4-line conditional blocks to single function calls - Maintain identical functionality with cleaner code This simplification reduces 16 lines of duplicate code across 4 files while preserving exact behavior and improving maintainability. Co-authored-by: Code Simplifier Agent <copilot@github.com>
1 parent ada84f0 commit d929166

5 files changed

Lines changed: 12 additions & 20 deletions

File tree

pkg/workflow/action_mode.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,11 @@ func DetectActionMode(version string) ActionMode {
102102
actionModeLog.Printf("Detected dev mode (default): isRelease=%v, ref=%s", IsRelease(), githubRef)
103103
return ActionModeDev
104104
}
105+
106+
// GetActionModeFromWorkflowData extracts the ActionMode from WorkflowData, defaulting to dev mode if nil
107+
func GetActionModeFromWorkflowData(workflowData *WorkflowData) ActionMode {
108+
if workflowData != nil {
109+
return workflowData.ActionMode
110+
}
111+
return ActionModeDev
112+
}

pkg/workflow/claude_mcp.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,12 @@ func (e *ClaudeEngine) RenderMCPConfig(yaml *strings.Builder, tools map[string]a
1515
// Create unified renderer with Claude-specific options
1616
// Claude uses JSON format without Copilot-specific fields and multi-line args
1717
createRenderer := func(isLast bool) *MCPConfigRendererUnified {
18-
actionMode := ActionModeDev // Default to dev mode
19-
if workflowData != nil {
20-
actionMode = workflowData.ActionMode
21-
}
2218
return NewMCPConfigRenderer(MCPRendererOptions{
2319
IncludeCopilotFields: false, // Claude doesn't use "type" and "tools" fields
2420
InlineArgs: false, // Claude uses multi-line args format
2521
Format: "json",
2622
IsLast: isLast,
27-
ActionMode: actionMode,
23+
ActionMode: GetActionModeFromWorkflowData(workflowData),
2824
})
2925
}
3026

pkg/workflow/codex_mcp.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,12 @@ func (e *CodexEngine) RenderMCPConfig(yaml *strings.Builder, tools map[string]an
1818
// Create unified renderer with Codex-specific options
1919
// Codex uses TOML format without Copilot-specific fields and multi-line args
2020
createRenderer := func(isLast bool) *MCPConfigRendererUnified {
21-
actionMode := ActionModeDev // Default to dev mode
22-
if workflowData != nil {
23-
actionMode = workflowData.ActionMode
24-
}
2521
return NewMCPConfigRenderer(MCPRendererOptions{
2622
IncludeCopilotFields: false, // Codex doesn't use "type" and "tools" fields
2723
InlineArgs: false, // Codex uses multi-line args format
2824
Format: "toml",
2925
IsLast: isLast,
30-
ActionMode: actionMode,
26+
ActionMode: GetActionModeFromWorkflowData(workflowData),
3127
})
3228
}
3329

pkg/workflow/copilot_mcp.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,12 @@ func (e *CopilotEngine) RenderMCPConfig(yaml *strings.Builder, tools map[string]
1818
// Create unified renderer with Copilot-specific options
1919
// Copilot uses JSON format with type and tools fields, and inline args
2020
createRenderer := func(isLast bool) *MCPConfigRendererUnified {
21-
actionMode := ActionModeDev // Default to dev mode
22-
if workflowData != nil {
23-
actionMode = workflowData.ActionMode
24-
}
2521
return NewMCPConfigRenderer(MCPRendererOptions{
2622
IncludeCopilotFields: true, // Copilot uses "type" and "tools" fields
2723
InlineArgs: true, // Copilot uses inline args format
2824
Format: "json",
2925
IsLast: isLast,
30-
ActionMode: actionMode,
26+
ActionMode: GetActionModeFromWorkflowData(workflowData),
3127
})
3228
}
3329

pkg/workflow/custom_engine.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,16 +253,12 @@ func (e *CustomEngine) RenderMCPConfig(yaml *strings.Builder, tools map[string]a
253253
// Create unified renderer with Custom engine-specific options
254254
// Custom engine uses JSON format without Copilot-specific fields and multi-line args (like Claude)
255255
createRenderer := func(isLast bool) *MCPConfigRendererUnified {
256-
actionMode := ActionModeDev // Default to dev mode
257-
if workflowData != nil {
258-
actionMode = workflowData.ActionMode
259-
}
260256
return NewMCPConfigRenderer(MCPRendererOptions{
261257
IncludeCopilotFields: false, // Custom engine doesn't use "type" and "tools" fields
262258
InlineArgs: false, // Custom engine uses multi-line args format
263259
Format: "json",
264260
IsLast: isLast,
265-
ActionMode: actionMode,
261+
ActionMode: GetActionModeFromWorkflowData(workflowData),
266262
})
267263
}
268264

0 commit comments

Comments
 (0)