Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 30, 2026

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.gocompile_post_processing.go):

  • ensureGitAttributes() - manages .gitattributes for compiled .lock.yml files
  • stageGitAttributesIfChanged() - stages gitattributes after compilation

User interaction (git.gointeractive.go):

  • confirmPushOperation() - prompts user for push confirmation using huh library

Config validation (compile_validation.gocompile_config.go):

  • validateCompileConfig() - validates CLI flags (--dependabot, --purge, --dir)

Action validation (actions_build_command.govalidators.go):

  • validateActionYml() - validates GitHub action metadata structure

Changes

// Before: git.go contained workflow compilation concerns
func ensureGitAttributes() error {
    gitLog.Print("Ensuring .gitattributes is updated")
    // ... workflow-specific .lock.yml configuration
}

// After: compile_post_processing.go owns compilation artifacts
func ensureGitAttributes() error {
    compilePostProcessingLog.Print("Ensuring .gitattributes is updated")
    // ... same logic, correct location and logger
}

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:

  • pkg/workflow (250 files) - Workflow compilation and processing
  • pkg/cli (163 files) - Command-line interface
  • pkg/parser (30 files) - Parsing utilities
  • pkg/campaign (14 files) - Campaign orchestration

Key Findings:

  • 60-70% well-organized - Many files follow single-responsibility principles
  • ⚠️ ~25% mixed concerns - Files mixing 2-3 different responsibilities
  • ~10% major issues - Files with significant organizational problems
  • 🔄 2 exact duplicates found - Functions with identical implementations
  • 📦 Multiple scattered utilities - Helper functions spread across files

Critical Issues Identified

1. Exact Duplicate Functions

Issue #1: extractBaseRepo() - Identical Implementation in Two Files

Duplicate Locations:

  • pkg/workflow/action_resolver.go:93
  • pkg/cli/update_actions.go:20

Code Comparison:

// pkg/workflow/action_resolver.go:93
func extractBaseRepo(repo string) string {
    parts := strings.Split(repo, "/")
    if len(parts) >= 2 {
        // Take first two parts (owner/repo)
        return parts[0] + "/" + parts[1]
    }
    return repo
}

// pkg/cli/update_actions.go:20
func extractBaseRepo(actionPath string) string {
    parts := strings.Split(actionPath, "/")
    if len(parts) >= 2 {
        // Return owner/repo (first two segments)
        return parts[0] + "/" + parts[1]
    }
    // If less than 2 parts, return as-is (shouldn't happen in practice)
    return actionPath
}

Similarity: 100% identical logic, only comments differ

Recommendation:

  • Consolidate into pkg/repoutil/repoutil.go (which already has related utilities)
  • Export as ExtractBaseRepo(path string) string
  • Update both callers to use repoutil.ExtractBaseRepo()

Estimated Impact: Reduced code duplication, single source of truth for repository path parsing


Issue #2: ParseGitHubURL() - Similar Functions with Different Implementations

Duplicate Locations:

  • pkg/repoutil/repoutil.go:28 - Returns (owner, repo string, err error)
  • pkg/parser/github_urls.go:56 - Returns (*GitHubURLComponents, error)

Implementations:

  • repoutil version: Handles SSH (git@github.com:) and HTTPS formats, returns simple owner/repo tuple
  • parser version: Uses url.Parse(), handles raw.githubusercontent.com, returns structured GitHubURLComponents with file paths, refs, etc.

Analysis:
These functions have different purposes:

  • repoutil.ParseGitHubURL - Simple owner/repo extraction for git operations
  • parser.ParseGitHubURL - Comprehensive URL parsing with file paths, refs, and content types

Recommendation:

  • Rename for clarity:
    • repoutil.ParseGitHubURLrepoutil.ParseGitRepoURL (emphasizes git repo focus)
    • Keep parser.ParseGitHubURL as-is (comprehensive parser)
  • Add cross-reference comments explaining the distinction
  • Consider consolidation: Could repoutil call parser version 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:157
Function: ensureGitAttributes()
Current Purpose: Configuring .gitattributes for compiled workflow files
Issue: This is compilation post-processing, not a core git operation

Used By:

  • compile_helpers.go
  • compile_orchestration.go
  • add_command.go

Why It's Misplaced:
The function sets up .gitattributes to handle .md and .yml files in the .github/workflows directory. 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:

  • Move to pkg/cli/compile_post_processing.go (or create it)
  • Rename to configureWorkflowGitAttributes() for clarity
  • Keep git.go focused on reusable git operations

Estimated Impact: Clearer separation of concerns, easier to find compilation-related setup


Outlier #2: User Interaction in Git Operations File

File: pkg/cli/git.go:550
Function: 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.

Copilot AI and others added 6 commits January 30, 2026 04:38
Move ensureGitAttributes() and stageGitAttributesIfChanged() from git.go to
compile_post_processing.go. These functions are specific to workflow compilation
post-processing, not general git operations.

- Moved ensureGitAttributes() to compile_post_processing.go
- Moved stageGitAttributesIfChanged() to compile_post_processing.go
- Updated logging to use compilePostProcessingLog instead of gitLog
- Added os/exec and strings imports to compile_post_processing.go
- All tests passing

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Move confirmPushOperation() from git.go to interactive.go. This function is
user interaction logic, not a core git operation.

- Moved confirmPushOperation() to interactive.go
- Updated logging to use interactiveLog instead of gitLog
- Removed unused huh import from git.go
- All tests passing

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Move validateCompileConfig() from compile_validation.go to compile_config.go.
This function validates CLI configuration flags, not workflow content, so it
belongs with the CompileConfig struct definition.

- Moved validateCompileConfig() to compile_config.go
- Updated logging to use compileConfigLog instead of compileValidationLog
- Added fmt and path/filepath imports to compile_config.go
- All tests passing

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Move validateActionYml() from actions_build_command.go to validators.go.
This is a reusable validation function that should be centralized with other
validators for better discoverability.

- Moved validateActionYml() to validators.go
- Added fmt, os, and path/filepath imports to validators.go
- Simplified function documentation
- All tests passing

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Apply go fmt formatting to files after refactoring. Removes trailing blank
lines and extra whitespace per project standards.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Remove orphaned function comment for confirmPushOperation that was moved to
interactive.go. This comment was inadvertently left behind during refactoring.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor code organization based on semantic analysis refactor: relocate misplaced functions to appropriate modules Jan 30, 2026
Copilot AI requested a review from pelikhan January 30, 2026 04:50
@pelikhan pelikhan marked this pull request as ready for review January 30, 2026 05:48
@pelikhan pelikhan closed this Jan 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[refactor] Semantic Function Clustering Analysis - Code Organization Recommendations

2 participants