Skip to content

Consolidate git repository helper functions into centralized utilities#6876

Merged
pelikhan merged 3 commits into
mainfrom
copilot/refactor-git-repo-function
Dec 18, 2025
Merged

Consolidate git repository helper functions into centralized utilities#6876
pelikhan merged 3 commits into
mainfrom
copilot/refactor-git-repo-function

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 18, 2025

Duplicate git repository information resolution logic was scattered across compile_orchestrator.go, devcontainer.go, and git.go, with each implementing its own URL parsing and git root finding.

Changes

Centralized helpers in git.go:

  • parseGitHubRepoSlugFromURL() - Parses GitHub URLs (HTTPS/SSH) to extract owner/repo
  • getRepositorySlugFromRemote() - Extracts slug from current directory's remote
  • getRepositorySlugFromRemoteForPath(path) - Extracts slug for specific file paths
  • findGitRootForPath(path) - Finds git root containing a file

Refactored consumers:

  • compile_orchestrator.go: Removed wrapper functions, all code now directly calls centralized helpers
  • compile_validation.go: Updated to use centralized helpers directly
  • compile_orchestrator_stability_test.go: Updated to use centralized helpers directly
  • devcontainer.go: Updated getCurrentRepoName() and getRepoOwner() to use centralized functions

Example:

Before:

// In compile_orchestrator.go
func getRepositorySlug() string {
    cmd := exec.Command("git", "config", "--get", "remote.origin.url")
    output, _ := cmd.Output()
    url := strings.TrimSpace(string(output))
    url = strings.TrimSuffix(url, ".git")
    if strings.HasPrefix(url, "https://github.com/") {
        return strings.TrimPrefix(url, "https://github.com/")
    }
    // ... duplicate logic
}

After:

// In git.go - single implementation
func parseGitHubRepoSlugFromURL(url string) string {
    url = strings.TrimSuffix(url, ".git")
    if strings.HasPrefix(url, "https://github.com/") {
        return strings.TrimPrefix(url, "https://github.com/")
    }
    // ... handles both HTTPS and SSH
}

// In compile_orchestrator.go - direct call
repoSlug := getRepositorySlugFromRemote()
Original prompt

Review the function to resolve git repository information and reuse or refactor helpers from compile_orchestrator.go ( see getRepositorySlug others)


✨ 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 self-assigned this Dec 18, 2025
- Move git repository URL parsing to centralized parseGitHubRepoSlugFromURL in git.go
- Add findGitRootForPath for finding git root from any file path
- Add getRepositorySlugFromRemote and getRepositorySlugFromRemoteForPath helpers
- Refactor compile_orchestrator.go to use centralized helpers
- Refactor devcontainer.go to use centralized helpers
- Add comprehensive unit tests for new helper functions
- Remove unused imports and deprecated wrapper functions

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor function to resolve git repository information Consolidate git repository helper functions into centralized utilities Dec 18, 2025
Copilot AI requested a review from pelikhan December 18, 2025 16:14
@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot remove wrappers

- Remove getRepositorySlug(), getRepositorySlugForPath(), getRepositoryRoot(), getRepositoryRootForPath() wrappers from compile_orchestrator.go
- Update all callers to use centralized functions directly:
  - getRepositorySlugFromRemote() instead of getRepositorySlug()
  - getRepositorySlugFromRemoteForPath() instead of getRepositorySlugForPath()
  - findGitRoot() instead of getRepositoryRoot()
  - findGitRootForPath() instead of getRepositoryRootForPath()
- Updated files: compile_orchestrator.go, compile_validation.go, compile_orchestrator_stability_test.go

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Dec 18, 2025

@copilot remove wrappers

Removed all wrapper functions. All callers now use the centralized helpers directly (fdb8f78).

@pelikhan pelikhan marked this pull request as ready for review December 18, 2025 16:37
@pelikhan pelikhan merged commit 3067bd8 into main Dec 18, 2025
107 of 108 checks passed
@pelikhan pelikhan deleted the copilot/refactor-git-repo-function branch December 18, 2025 16:38
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.

2 participants