Skip to content

Fix RepoContext to work with non-GitHub repositories (VSCode issue #256753) #306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 18, 2025

Summary

Fixes #256753 by enhancing the RepoContext component to work with any Git repository, not just GitHub repositories. This enables CI/CD tools and other scenarios to get useful repository context regardless of the hosting provider.

Problem

Previously, the RepoContext component only worked with GitHub repositories. When users had repositories hosted on other platforms (Azure DevOps, GitLab, Bitbucket, etc.) or local repositories, the RepoContext would return empty and provide no useful repository information to the AI assistant.

// Before: Only worked with GitHub repos
const repoContext = activeRepository && getGitHubRepoInfoFromContext(activeRepository);
if (!repoContext || !activeRepository) {
    return; // No context provided for non-GitHub repos
}

Solution

Enhanced the RepoContext class to work with any Git repository by:

  1. Maintaining backward compatibility - GitHub repositories continue to work exactly as before
  2. Adding Azure DevOps support - Full integration with Azure DevOps repositories
  3. Adding generic Git support - Basic information extraction from any Git repository
  4. Graceful fallback - Provides basic Git context even when remote information is unavailable
// After: Works with all repository types
const githubRepoContext = getGitHubRepoInfoFromContext(activeRepository);
let repoInfo, remoteUrl;

if (githubRepoContext) {
    // GitHub repository - use existing logic
    repoInfo = { org: githubRepoContext.id.org, repo: githubRepoContext.id.repo, type: 'github' };
    remoteUrl = githubRepoContext.remoteUrl;
} else {
    // Try Azure DevOps and other supported providers
    const repoInfos = Array.from(getOrderedRepoInfosFromContext(activeRepository));
    if (repoInfos.length > 0 && repoInfos[0].repoId.type === 'ado') {
        repoInfo = { org: repoInfos[0].repoId.org, repo: repoInfos[0].repoId.repo, type: 'azure-devops' };
    } else {
        // Fallback: extract basic info from any Git repository
        const fetchUrl = activeRepository.remoteFetchUrls?.[0];
        if (fetchUrl) {
            const parsed = parseRemoteUrl(fetchUrl);
            const pathMatch = parsed?.path.match(/^\/?([^/]+)\/([^/]+?)(\/|\.git\/?)?$/i);
            if (pathMatch) {
                repoInfo = { org: pathMatch[1], repo: pathMatch[2], type: 'generic' };
            }
        }
    }
}

Enhanced Output

The RepoContext now provides repository information for different hosting providers:

GitHub Repositories (backward compatible)

Repository name: vscode-copilot-chat
Owner: microsoft  
Repository type: github
Current branch: main
Default branch: main
Remote URL: https://github.com/microsoft/vscode-copilot-chat.git

Azure DevOps Repositories

Repository name: myrepo
Owner: myorg
Repository type: azure-devops
Current branch: main
Remote URL: https://dev.azure.com/myorg/myproject/_git/myrepo

Generic Git Repositories (GitLab, Bitbucket, etc.)

Repository name: myrepo
Owner: myorg
Repository type: generic
Current branch: main
Remote URL: https://gitlab.com/myorg/myrepo.git

Local Repositories (no remote)

Current branch: main
Upstream branch: origin/main
Upstream remote: origin

Testing

Added comprehensive tests to ensure the enhancement works correctly:

  • Unit tests for core functionality with different repository types
  • Integration tests for real-world scenarios
  • Manual verification script that validates the logic works as expected

Verification results show all repository types work correctly:

  • ✅ GitHub repositories: Maintain backward compatibility
  • ✅ Azure DevOps repositories: Full support with org/repo/type detection
  • ✅ Generic Git repositories: Basic info extraction (GitLab, Bitbucket, etc.)
  • ✅ Local repositories: Graceful fallback with basic Git context

Benefits

  1. CI/CD Integration: CI/CD tools can now get repository context regardless of hosting provider
  2. Enterprise Support: Full support for Azure DevOps repositories commonly used in enterprises
  3. Open Source Flexibility: Works with GitLab, Bitbucket, and other Git hosting platforms
  4. Local Development: Provides useful context even for local repositories
  5. Backward Compatibility: No breaking changes for existing GitHub users

Files Changed

  • src/extension/prompts/node/agent/agentPrompt.tsx - Enhanced RepoContext class
  • test/unit/repoContext.test.ts - Unit tests for core functionality
  • test/prompts/repoContext.stest.ts - Integration tests
  • test/manual/ - Manual verification scripts and documentation
  • REPOCONTEXT_ENHANCEMENT.md - Comprehensive documentation

This enhancement makes Copilot Chat more useful and accessible to users working with diverse repository hosting solutions, addressing the core issue raised in VSCode #256753.

Created from VS Code via the GitHub Pull Request extension.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] Fix Implementation for VSCode Issue #256753 in Copilot Chat Fix RepoContext to work with non-GitHub repositories (VSCode issue #256753) Jul 18, 2025
@Copilot Copilot AI requested a review from digitarald July 18, 2025 18:46
Copilot finished work on behalf of digitarald July 18, 2025 18:46
@digitarald
Copy link
Contributor

Copilot analysis

Recommendation

PR #306 appears to be the more robust solution because:

  1. Consistency: Provides uniform output format across all repository types
  2. Comprehensive Testing: Extensive test coverage including manual verification
  3. Better Documentation: Includes detailed documentation and examples
  4. More Information: Provides additional context like repository type and remote URL
  5. Sophisticated Fallback: Better handling of edge cases with URL parsing

However, PR #307 might be preferred if:

  • You want a simpler, more focused change
  • The different output formats for different repository types are acceptable
  • You prefer minimal code changes

Both PRs solve the core issue effectively, but PR #306 provides a more enterprise-ready solution with better long-term maintainability.

@digitarald digitarald closed this Jul 18, 2025
@digitarald digitarald deleted the copilot/fix-51a988a4-b716-4d2c-83a7-128f08ce6f56 branch July 18, 2025 22:22
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