refactor: relocate misplaced functions to appropriate modules #12673
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.
Semantic function clustering analysis identified 4 functions in wrong files - workflow compilation logic in git utilities, user interaction in git operations, config validation in workflow validation, and action validators in build commands.
Relocations
Workflow post-processing (
git.go→compile_post_processing.go):ensureGitAttributes()- manages.gitattributesfor compiled.lock.ymlfilesstageGitAttributesIfChanged()- stages gitattributes after compilationUser interaction (
git.go→interactive.go):confirmPushOperation()- prompts user for push confirmation usinghuhlibraryConfig validation (
compile_validation.go→compile_config.go):validateCompileConfig()- validates CLI flags (--dependabot,--purge,--dir)Action validation (
actions_build_command.go→validators.go):validateActionYml()- validates GitHub action metadata structureChanges
Logging updated to match new module contexts. Unused imports removed.
Original prompt
This section details on the original issue you should resolve
<issue_title>[refactor] Semantic Function Clustering Analysis - Code Organization Recommendations</issue_title>
<issue_description>Semantic analysis of 490 Go source files in repository: githubnext/gh-aw
Executive Summary
A comprehensive semantic function clustering analysis has identified significant code organization patterns, outlier functions in wrong files, and duplicate implementations across the codebase. The analysis covered 490 non-test Go files across key packages, with deep focus on:
Key Findings:
Critical Issues Identified
1. Exact Duplicate Functions
Issue #1:
extractBaseRepo()- Identical Implementation in Two FilesDuplicate Locations:
pkg/workflow/action_resolver.go:93pkg/cli/update_actions.go:20Code Comparison:
Similarity: 100% identical logic, only comments differ
Recommendation:
pkg/repoutil/repoutil.go(which already has related utilities)ExtractBaseRepo(path string) stringrepoutil.ExtractBaseRepo()Estimated Impact: Reduced code duplication, single source of truth for repository path parsing
Issue #2:
ParseGitHubURL()- Similar Functions with Different ImplementationsDuplicate Locations:
pkg/repoutil/repoutil.go:28- Returns(owner, repo string, err error)pkg/parser/github_urls.go:56- Returns(*GitHubURLComponents, error)Implementations:
git@github.com:) and HTTPS formats, returns simple owner/repo tupleurl.Parse(), handles raw.githubusercontent.com, returns structuredGitHubURLComponentswith file paths, refs, etc.Analysis:
These functions have different purposes:
repoutil.ParseGitHubURL- Simple owner/repo extraction for git operationsparser.ParseGitHubURL- Comprehensive URL parsing with file paths, refs, and content typesRecommendation:
repoutil.ParseGitHubURL→repoutil.ParseGitRepoURL(emphasizes git repo focus)parser.ParseGitHubURLas-is (comprehensive parser)repoutilcallparserversion and extract owner/repo?Estimated Impact: Improved API clarity, reduced naming confusion
2. Outlier Functions (Functions in Wrong Files)
Priority 1: High-Impact Misplacements
Outlier #1: Git Attribute Configuration in Git Operations File
File:
pkg/cli/git.go:157Function:
ensureGitAttributes()Current Purpose: Configuring
.gitattributesfor compiled workflow filesIssue: This is compilation post-processing, not a core git operation
Used By:
compile_helpers.gocompile_orchestration.goadd_command.goWhy It's Misplaced:
The function sets up
.gitattributesto handle.mdand.ymlfiles in the.github/workflowsdirectory. This is a workflow compilation concern, not a generic git utility. The git.go file should contain reusable git operations (commits, branches, remotes), not workflow-specific configuration.Recommendation:
pkg/cli/compile_post_processing.go(or create it)configureWorkflowGitAttributes()for clarityEstimated Impact: Clearer separation of concerns, easier to find compilation-related setup
Outlier #2: User Interaction in Git Operations File
File:
pkg/cli/git.go:550Function:
confirmPushOperation()Issue: User interaction l...
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.