Refactor update_command.go: Split 1,331-line file into 8 focused modules#6897
Merged
Refactor update_command.go: Split 1,331-line file into 8 focused modules#6897
Conversation
Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor large Go file pkg/cli/update_command.go
Refactor update_command.go: Split 1,331-line file into 8 focused modules
Dec 18, 2025
Contributor
|
@copilot format and lint |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Contributor
Author
Done. Code formatted and linter warnings fixed in commit 70f34c5.
Fixed 7 unused function warnings in |
This was referenced Dec 19, 2025
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.
Refactoring Complete: update_command.go Split Successfully
Original State
update_command.go- 1,331 linesupdate_command_test.go- 900 linesRefactored State
Successfully split into 8 focused files:
update_command.go- 122 lines (91% reduction!)NewUpdateCommand()UpdateWorkflowsWithExtensionCheck()update_workflows.go- 453 linesUpdateWorkflows()- Main workflow update logicfindWorkflowsWithSource()- Workflow discoveryupdateWorkflow()- Individual workflow updatesresolveLatestRef()- Ref resolution (branches/tags)resolveLatestRelease()- Semantic version resolutionupdate_actions.go- 374 linesUpdateActions()- GitHub Actions version updatesgetLatestActionRelease()- GitHub API integrationgetLatestActionReleaseViaGit()- Fallback via gitgetActionSHAForTag()- SHA resolutionmarshalActionsLockSorted()- JSON serializationupdate_merge.go- 226 linesMergeWorkflowContent()- 3-way merge via git merge-filenormalizeWhitespace()- Content normalizationhasLocalModifications()- Local change detectionupdate_git.go- 95 lineshasGitChanges()- Change detectionrunGitCommand()- Git command wrappercreateUpdatePR()- PR creationupdate_extension_check.go- 51 linescheckExtensionUpdate()- Extension update checkingupdate_display.go- 33 linesshowUpdateSummary()- Display utilitiesupdate_types.go- 26 linesValidation Results ✅
make test-unit)make build)make fmt)make lint)Benefits Achieved
create_*.gostyle)Pattern Followed
This refactoring follows the same pattern used successfully in:
safe_outputs_*.gofiles inpkg/workflow/create_*.gofiles inpkg/cli/Additional Changes
download_workflow.goby addingnolint:unuseddirectives for fallback functions that may be used when GitHub API is unavailableOriginal prompt
This section details on the original issue you should resolve
<issue_title>[file-diet] Refactor Large Go File: pkg/cli/update_command.go</issue_title>
<issue_description>The file
pkg/cli/update_command.gohas grown to 1,331 lines, making it difficult to maintain and test effectively. This task involves refactoring it into smaller, focused files with improved test coverage.Current State
pkg/cli/update_command.goCodebase Health Context
Current file size landscape:
pkg/cli/update_command.go(1,331 lines)pkg/parser/frontmatter.go(1,294 lines)pkg/workflow/copilot_engine.go(1,168 lines)Refactoring Strategy
Based on semantic analysis, the file has clear functional boundaries that can be split into focused modules:
Proposed File Splits
1.
update_command.go(Command Setup)NewUpdateCommand(), flag definitions, command configurationNewUpdateCommand()2.
update_workflows.go(Workflow Update Logic)UpdateWorkflows()findWorkflowsWithSource()updateWorkflow()resolveLatestRef()resolveLatestRelease()hasLocalModifications()UpdateWorkflows(),UpdateWorkflowsWithExtensionCheck()3.
update_merge.go(Merge Operations)MergeWorkflowContent()normalizeWhitespace()MergeWorkflowContent()4.
update_actions.go(GitHub Actions Updates)UpdateActions()getLatestActionRelease()getLatestActionReleaseViaGit()getActionSHAForTag()marshalActionsLockSorted()actionsLockEntry,actionsLockFileUpdateActions()5.
update_git.go(Git Operations)hasGitChanges()runGitCommand()createUpdatePR()6.
update_extension_check.go(Extension Version Check)checkExtensionUpdate()Shared Types
Keep shared types in a common location:
update_types.go:workflowWithSource,updateFailureUtility Functions
update_display.go:showUpdateSummary()(formatting and display)Test Coverage Plan
Expand tests for each new file to achieve >80% coverage:
1.
update_command_test.go2.
update_workflows_test.go3.
update_merge_test.go4.
update_actions_test.go5.
update_git_test.goImplementation Guidelines
NewUpdateCommand()must remain exportedUpdateWorkflows()must remain exportedUpdateActions()must remain exportedMergeWorkflowContent()must remain exported (used by other packages)make test-unitp...💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.