Objective
Eliminate ~40-60 lines of duplicate repository slug retrieval code by standardizing on a single canonical implementation with caching.
Context
The analysis in #3525 identified 4 different implementations of repository slug retrieval across CLI command files, all using gh repo view but with different output formats and caching strategies.
Duplicate Functions:
getCurrentRepo (pr_command.go:100) - Returns owner, repo separately
GetCurrentRepoSlug (repo.go:95) - Returns "owner/repo" string with caching ✓ Keep this one
getCurrentRepoSlugUncached (repo.go:31) - Returns "owner/repo" string without caching
getCurrentRepositoryInfo (trial_command.go:461) - Wrapper around GetCurrentRepoSlug
Approach
Step 1: Identify Canonical Implementation
Keep GetCurrentRepoSlug() from pkg/cli/repo.go as the canonical implementation because:
- It returns the standard "owner/repo" format
- It has caching for performance
- It's already well-tested
- It's in a dedicated file for repository operations
Step 2: Remove Duplicate Implementations
Delete the following functions and their usages:
getCurrentRepo from pr_command.go (line 100)
getCurrentRepositoryInfo from trial_command.go (line 461)
Keep getCurrentRepoSlugUncached as it serves a specific purpose (no caching).
Step 3: Update Callers
Replace all calls to duplicate functions:
In pr_command.go:
// Before:
owner, repo, err := getCurrentRepo()
if err != nil {
return err
}
// After:
import "github.com/githubnext/gh-aw/pkg/cli"
slug, err := GetCurrentRepoSlug()
if err != nil {
return err
}
parts := strings.Split(slug, "/")
if len(parts) != 2 {
return fmt.Errorf("invalid repo format: %s", slug)
}
owner, repo := parts[0], parts[1]
In trial_command.go:
// Before:
slug, err := getCurrentRepositoryInfo()
// After:
slug, err := GetCurrentRepoSlug()
Step 4: Add Helper for Splitting Slug
If splitting owner/repo is common, add a helper to repo.go:
// SplitRepoSlug splits "owner/repo" into owner and repo
func SplitRepoSlug(slug string) (owner, repo string, err error) {
parts := strings.Split(slug, "/")
if len(parts) != 2 {
return "", "", fmt.Errorf("invalid repo format: %s", slug)
}
return parts[0], parts[1], nil
}
Files to Modify
pkg/cli/pr_command.go - Remove getCurrentRepo, update callers
pkg/cli/trial_command.go - Remove getCurrentRepositoryInfo, update callers
pkg/cli/repo.go - Optionally add SplitRepoSlug helper
Acceptance Criteria
Benefits
- Single canonical function with caching
- Consistent behavior across all CLI commands
- Clear API with single responsibility
- Reduced confusion for developers
Estimated Impact
AI generated by Plan Command for #3525
Objective
Eliminate ~40-60 lines of duplicate repository slug retrieval code by standardizing on a single canonical implementation with caching.
Context
The analysis in #3525 identified 4 different implementations of repository slug retrieval across CLI command files, all using
gh repo viewbut with different output formats and caching strategies.Duplicate Functions:
getCurrentRepo(pr_command.go:100) - Returns owner, repo separatelyGetCurrentRepoSlug(repo.go:95) - Returns "owner/repo" string with caching ✓ Keep this onegetCurrentRepoSlugUncached(repo.go:31) - Returns "owner/repo" string without cachinggetCurrentRepositoryInfo(trial_command.go:461) - Wrapper around GetCurrentRepoSlugApproach
Step 1: Identify Canonical Implementation
Keep
GetCurrentRepoSlug()frompkg/cli/repo.goas the canonical implementation because:Step 2: Remove Duplicate Implementations
Delete the following functions and their usages:
getCurrentRepofrom pr_command.go (line 100)getCurrentRepositoryInfofrom trial_command.go (line 461)Keep
getCurrentRepoSlugUncachedas it serves a specific purpose (no caching).Step 3: Update Callers
Replace all calls to duplicate functions:
In pr_command.go:
In trial_command.go:
Step 4: Add Helper for Splitting Slug
If splitting owner/repo is common, add a helper to repo.go:
Files to Modify
pkg/cli/pr_command.go- RemovegetCurrentRepo, update callerspkg/cli/trial_command.go- RemovegetCurrentRepositoryInfo, update callerspkg/cli/repo.go- Optionally addSplitRepoSlughelperAcceptance Criteria
getCurrentRepofunction removed from pr_command.gogetCurrentRepositoryInfofunction removed from trial_command.goGetCurrentRepoSlug()SplitRepoSlughelper added if neededmake test-unitpassesmake lintpassesBenefits
Estimated Impact
Related to [refactor] 🔧 Semantic Function Clustering Analysis: Refactoring Opportunities #3525