Skip to content

[code-simplifier] refactor: simplify imports.go and add_command.go from PR #23817#23844

Merged
pelikhan merged 1 commit intomainfrom
simplify-imports-add-command-2026-04-01-42578a77ea02feae
Apr 1, 2026
Merged

[code-simplifier] refactor: simplify imports.go and add_command.go from PR #23817#23844
pelikhan merged 1 commit intomainfrom
simplify-imports-add-command-2026-04-01-42578a77ea02feae

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot commented Apr 1, 2026

Code simplification of recently modified files from PR #23817 (fix: body-level \{\\{\#import shared/X.md}} rewritten with wrong cross-repo path in gh aw add).

Files Simplified

  • pkg/cli/imports.go — removed fileToProcess wrapper struct, extracted splitImportPath and writeImportDirective helpers
  • pkg/cli/add_command.go — merged two adjacent if opts.Verbose blocks

Improvements Made

Reduced Complexity

  • Removed unnecessary fileToProcess struct — the struct only held a single path string field; replaced with []string queue directly, removing the indirection.

Enhanced Clarity

  • Extracted splitImportPath(includePath string) (filePath, sectionName string) — the pattern of splitting an import path on # using strings.Contains + strings.SplitN appeared 3 times across two functions. Replaced all three with a single helper that uses strings.Cut.
  • Extracted writeImportDirective(w, workflowSpec, isOptional) — the if isOptional { ... } else { ... } directive-writing block appeared identically in both processIncludesWithWorkflowSpec and processIncludesInContent. Now a single helper.
  • Merged adjacent if opts.Verbose blocks in addWorkflowWithTracking — two consecutive verbose-guarded fmt.Fprintln calls were separated by nothing, making them one logical block.

Changes Based On

Recent changes from:

Testing

  • ✅ All relevant tests pass (TestProcessIncludes*, TestIsLocalFile*, TestResolveImport*, TestProcessImports*)
  • ✅ Build succeeds (make build)
  • ✅ Code formatted (make fmt)
  • ✅ No functional changes — behavior is identical

Review Focus

Please verify:

  • splitImportPath correctly replaces all three section-split patterns
  • writeImportDirective produces identical output to the inline blocks
  • Queue now uses []string correctly (no fileToProcess wrapper needed)

Automated by Code Simplifier Agent — analyzing code from the last 24 hours

Generated by Code Simplifier ·

  • expires on Apr 2, 2026, 6:32 AM UTC

- 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>
@pelikhan pelikhan marked this pull request as ready for review April 1, 2026 11:21
Copilot AI review requested due to automatic review settings April 1, 2026 11:21
Copy link
Copy Markdown
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

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 processIncludesWithWorkflowSpec by removing a single-field wrapper struct and using []string directly.
  • Extracted helpers in imports.go to centralize repeated import-path splitting (splitImportPath) and directive emission (writeImportDirective).
  • Merged adjacent opts.Verbose blocks in addWorkflowWithTracking to 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.

@pelikhan pelikhan merged commit 6e097a6 into main Apr 1, 2026
11 checks passed
@pelikhan pelikhan deleted the simplify-imports-add-command-2026-04-01-42578a77ea02feae branch April 1, 2026 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants