Skip to contentSkip to conversation

fetch2: add GitHub Codespaces support

PATCH New Oliver Kästner 1 participant 1 message Oct 12, 2024

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 fetch2: add GitHub Codespaces support

GitHub Codespaces allow users to use GitHub-hosted pre-configured Docker containers to work on GitHub repositories in VS Code within the browser or using a locally running instance of VS Code [1].

Users can define access permissions for Codespaces containers, allowing them to clone or work with other private repositories [2]. To do this, a git credential helper is injected into the container at /.codespaces/bin/gitcredential_github.sh, which contains the following lines:

    #!/bin/sh
    echo protocol=https
    echo host=github.com
    echo path=
    echo username=PersonalAccessToken
    echo password=$GITHUB_TOKEN

The GITHUB_TOKEN environment variable is automatically set when the Codespaces container is created. If authorized by the user, it has the specified permissions. It is thus required to be able to fetch private git repos from a Codespace container, so add it to FETCH_EXPORT_VARS to make it available for invocations of git.

[1] https://docs.github.com/en/codespaces/overview
[2] https://docs.github.com/en/codespaces/managing-your-codespaces/managing-repository-access-for-your-codespaces

---
Add some more details about Codespaces and its injected git credential helper.

 lib/bb/fetch2/__init__.py | 1 +
 1 file changed, 1 insertion(+)
lib/bb/fetch2/__init__.py +1 -0
index 33a8086f2..06687b018 100644
@@ -878,6 +878,7 @@ FETCH_EXPORT_VARS = ['HOME', 'PATH',
                      'AWS_SESSION_TOKEN',
                      'GIT_CACHE_PATH',
                      'REMOTE_CONTAINERS_IPC',
+                     'GITHUB_TOKEN',
                      'SSL_CERT_DIR']
 
 def get_fetcher_environment(d):
Signature · 1 line
2.43.0