Refactor add_interactive.go into 6 domain-focused modules#12545
Merged
Refactor add_interactive.go into 6 domain-focused modules#12545
Conversation
- Split 1025-line file into 6 modules: - add_interactive_orchestrator.go (243 lines) - main orchestration - add_interactive_auth.go (180 lines) - authentication/validation - add_interactive_secrets.go (82 lines) - secret management - add_interactive_engine.go (253 lines) - AI engine selection - add_interactive_git.go (127 lines) - Git operations - add_interactive_workflow.go (193 lines) - workflow status - Add comprehensive tests for all modules - All modules under 300 lines - Build, tests, and linting pass Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
- Use _ = os.Setenv() to explicitly ignore errors - Reduces gosec warnings from 75 to 73 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor add_interactive.go into focused modules
Refactor add_interactive.go into 6 domain-focused modules
Jan 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Split 1025-line
add_interactive.gointo smaller, focused modules organized by functional domain. Each module under 300 lines.Module Structure
Test Coverage
Added unit tests for orchestration flow, secret management, and workflow status checking (321 lines total).
Changes
AddInteractiveConfigand main flow throughRunAddInteractive()Public API unchanged -
RunAddInteractive()signature and behavior identical.Original prompt
This section details on the original issue you should resolve
<issue_title>[file-diet] Refactor add_interactive.go into focused modules (1025 lines)</issue_title>
<issue_description>### Overview
The file
pkg/cli/add_interactive.gohas grown to 1025 lines, making it difficult to maintain and test. This task involves refactoring it into smaller, focused files with improved test coverage.Current State
pkg/cli/add_interactive.goFull File Analysis
Detailed Breakdown
The file contains 23 functions organized into these functional areas:
1. Repository & Authentication Checks (5 functions, ~170 lines)
checkGHAuthStatus()- Verify GitHub CLI authenticationcheckGitRepository()- Verify git repo and get org/repo infocheckRepoVisibility()- Check if repo is public/privatecheckActionsEnabled()- Verify GitHub Actions enabledcheckUserPermissions()- Check user has write access2. Secret Management (2 functions, ~80 lines)
checkExistingSecrets()- Fetch existing repository secretsaddRepositorySecret()- Add a new repository secret3. AI Engine Selection & API Key Collection (4 functions, ~240 lines)
selectAIEngineAndKey()- Prompt user to select engine and provide key (110 lines)collectAPIKey()- Collect API key for selected enginecollectCopilotPAT()- Special handling for Copilot PAT creation (60 lines)collectGenericAPIKey()- Generic API key collection (60 lines)4. Workflow Resolution & Display (3 functions, ~50 lines)
resolveWorkflows()- Resolve workflow specifications earlyshowWorkflowDescriptions()- Display workflow descriptionsdetermineFilesToAdd()- Determine which files will be added5. Change Application & Git Operations (4 functions, ~120 lines)
getSecretInfo()- Get secret name and value for engineconfirmChanges()- Ask user to confirm changesapplyChanges()- Create PR, merge it, and add secret (70 lines)updateLocalBranch()- Update local branch after merge (40 lines)6. Workflow Execution & Status (4 functions, ~160 lines)
checkStatusAndOfferRun()- Check workflow status and offer to run (135 lines)getWorkflowStatuses()- Helper to get workflow statuses (45 lines)mergePullRequest()- Merge a pull request (10 lines)showFinalInstructions()- Display final instructions (20 lines)7. Main Orchestration (1 function, ~95 lines)
RunAddInteractive()- Main entry point that coordinates all stepsComplexity Hotspots
selectAIEngineAndKey()(lines 372-478): 110 lines handling engine selection logic with multiple priority checks (workflow frontmatter, existing secrets, environment variables)checkStatusAndOfferRun()(lines 825-956): 135 lines managing workflow status polling, spinner UI, and conditional run triggeringcollectCopilotPAT()(lines 499-557): 60 lines with extensive GitHub PAT creation instructionsapplyChanges()(lines 701-769): 70 lines coordinating workflow addition, PR creation, and mergingCode Patterns
charmbracelet/huhlibrarygh) command execution viaworkflow.RunGH()AddInteractiveConfigstruct passed through methodsRefactoring Strategy
Proposed File Splits
Based on semantic analysis, split the file into the following modules:
add_interactive_orchestrator.goRunAddInteractive(),resolveWorkflows(),showWorkflowDescriptions(),determineFilesToAdd(),confirmChanges(),showFinalInstructions()add_interactive_auth.gocheckGHAuthStatus(),checkGitRepository(),checkRepoVisibility(),checkActionsEnabled(),checkUserPermissions()add_interactive_secrets.gocheckExistingSecrets(),addRepositorySecret(),getSecretInfo()add_interactive_engine.goselectAIEngineAndKey(),collectAPIKey(),collectCopilotPAT(),collectGenericAPIKey()add_interactive_git.goapplyChanges(),updateLocalBranch(),mergePullRequest()💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.