Skip to content

[code-simplifier] Extract action mode helper to reduce code duplication#13982

Merged
pelikhan merged 1 commit intomainfrom
code-simplifier/extract-action-mode-helper-2026-02-05-0c2930ba485cc8a5
Feb 5, 2026
Merged

[code-simplifier] Extract action mode helper to reduce code duplication#13982
pelikhan merged 1 commit intomainfrom
code-simplifier/extract-action-mode-helper-2026-02-05-0c2930ba485cc8a5

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Feb 5, 2026

Code Simplification - 2026-02-05

This PR simplifies recently modified code to improve clarity, consistency, and maintainability while preserving all functionality.

Files Simplified

  • pkg/workflow/action_mode.go - Added GetActionModeFromWorkflowData() helper function
  • pkg/workflow/copilot_mcp.go - Simplified createRenderer closure to use helper
  • pkg/workflow/claude_mcp.go - Simplified createRenderer closure to use helper
  • pkg/workflow/codex_mcp.go - Simplified createRenderer closure to use helper
  • pkg/workflow/custom_engine.go - Simplified createRenderer closure to use helper

Improvements Made

  1. Reduced Duplication

    • Extracted repeated 4-line conditional pattern into single helper function
    • Eliminated duplicate code across all four engine MCP renderers
    • Reduced 16 lines of duplicate code to 8 lines (1 helper function + 4 single-line calls)
  2. Enhanced Clarity

    • Cleaner, more readable createRenderer closures
    • Single point of truth for action mode extraction logic
    • Explicit function name documents intent
  3. Applied Project Standards

    • Follows Go convention of extracting repeated patterns
    • Maintains explicit, readable code over compact code
    • Improves maintainability without sacrificing clarity

Changes Based On

Recent changes from:

Testing

The changes are purely structural and preserve exact functionality:

  • ✅ No functional changes - behavior is identical
  • ✅ Same action mode extraction logic, just refactored
  • ✅ All four engine renderers maintain original behavior
  • ✅ Helper function follows existing patterns in action_mode.go

Review Focus

Please verify:

  • Functionality is preserved (action mode extraction works identically)
  • Simplification improves code quality and maintainability
  • Helper function follows project conventions
  • No unintended side effects from the refactoring

Context: This simplification addresses code duplication introduced in PR #13974, which added ActionMode propagation to MCP renderers. All four engine files (Copilot, Claude, Codex, Custom) had identical 4-line blocks for extracting action mode from workflow data. This PR consolidates that logic into a single, reusable helper function.

Benefits:

  • Maintainability: Changes to action mode extraction logic now only need to be made in one place
  • Readability: Cleaner code with less visual clutter in each renderer
  • Consistency: Ensures all engines handle action mode extraction identically

Testing Strategy: Since this is a pure refactoring with no behavioral changes, the existing test suite validates correctness. The helper function uses the same logic (nil check with default to ActionModeDev) that was previously inline in each file.

AI generated by Code Simplifier

  • expires on Feb 6, 2026, 8:00 PM UTC

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.
@pelikhan pelikhan added the cookie Issue Monster Loves Cookies! label Feb 5, 2026
@pelikhan pelikhan marked this pull request as ready for review February 5, 2026 21:39
Copilot AI review requested due to automatic review settings February 5, 2026 21:39
@pelikhan pelikhan merged commit d929166 into main Feb 5, 2026
43 checks passed
@pelikhan pelikhan deleted the code-simplifier/extract-action-mode-helper-2026-02-05-0c2930ba485cc8a5 branch February 5, 2026 21:39
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR simplifies code by extracting a repeated 4-line pattern into a single helper function, improving maintainability while preserving all functionality. The refactoring addresses code duplication introduced in PR #13974, which added ActionMode propagation to MCP renderers.

Changes:

  • Added GetActionModeFromWorkflowData() helper function to centralize action mode extraction logic
  • Updated all four engine MCP renderers (Copilot, Claude, Codex, Custom) to use the new helper
  • Reduced 16 lines of duplicate code to 8 lines total (1 helper + 4 single-line calls)

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pkg/workflow/action_mode.go Added GetActionModeFromWorkflowData() helper function with nil-check and default to dev mode
pkg/workflow/copilot_mcp.go Simplified createRenderer closure to use helper function instead of inline nil-check
pkg/workflow/claude_mcp.go Simplified createRenderer closure to use helper function instead of inline nil-check
pkg/workflow/codex_mcp.go Simplified createRenderer closure to use helper function instead of inline nil-check
pkg/workflow/custom_engine.go Simplified createRenderer closure to use helper function instead of inline nil-check

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant