Conversation
- Replace fileToProcess struct with []string queue in processIncludesWithWorkflowSpec - Extract splitImportPath helper using strings.Cut, eliminating 3 duplicate section-split blocks - Extract writeImportDirective helper, eliminating 2 duplicate directive-write blocks - Merge two adjacent if opts.Verbose blocks in addWorkflowWithTracking No behavioral changes; all tests pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors recently touched CLI logic to reduce duplication and simplify control flow without changing behavior, building on the fixes from PR #23817.
Changes:
- Simplified include-processing queue logic in
processIncludesWithWorkflowSpecby removing a single-field wrapper struct and using[]stringdirectly. - Extracted helpers in
imports.goto centralize repeated import-path splitting (splitImportPath) and directive emission (writeImportDirective). - Merged adjacent
opts.Verboseblocks inaddWorkflowWithTrackingto avoid redundant condition checks.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/cli/imports.go | Removes fileToProcess indirection and deduplicates section-splitting + directive-writing logic via new helpers. |
| pkg/cli/add_command.go | Consolidates verbose logging into a single block in addWorkflowWithTracking. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Code simplification of recently modified files from PR #23817 (fix: body-level
\{\\{\#import shared/X.md}}rewritten with wrong cross-repo path ingh aw add).Files Simplified
pkg/cli/imports.go— removedfileToProcesswrapper struct, extractedsplitImportPathandwriteImportDirectivehelperspkg/cli/add_command.go— merged two adjacentif opts.VerboseblocksImprovements Made
Reduced Complexity
fileToProcessstruct — the struct only held a singlepath stringfield; replaced with[]stringqueue directly, removing the indirection.Enhanced Clarity
splitImportPath(includePath string) (filePath, sectionName string)— the pattern of splitting an import path on#usingstrings.Contains+strings.SplitNappeared 3 times across two functions. Replaced all three with a single helper that usesstrings.Cut.writeImportDirective(w, workflowSpec, isOptional)— theif isOptional { ... } else { ... }directive-writing block appeared identically in bothprocessIncludesWithWorkflowSpecandprocessIncludesInContent. Now a single helper.if opts.Verboseblocks inaddWorkflowWithTracking— two consecutive verbose-guardedfmt.Fprintlncalls were separated by nothing, making them one logical block.Changes Based On
Recent changes from:
\{\\{\#import shared/X.md}}rewritten with wrong cross-repo path ingh aw addTesting
TestProcessIncludes*,TestIsLocalFile*,TestResolveImport*,TestProcessImports*)make build)make fmt)Review Focus
Please verify:
splitImportPathcorrectly replaces all three section-split patternswriteImportDirectiveproduces identical output to the inline blocks[]stringcorrectly (nofileToProcesswrapper needed)Automated by Code Simplifier Agent — analyzing code from the last 24 hours