mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
fix(backend/copilot): run gh auth setup-git once per sandbox session
Use grep to skip re-running if the credential helper is already configured in ~/.gitconfig — only pays the cost on first command. Agent can still call it manually if GH_TOKEN changes mid-session.
This commit is contained in:
@@ -70,6 +70,8 @@ _E2B_TOOL_NOTES = """
|
||||
- If the user has connected their GitHub account, both `gh` and `git` are
|
||||
pre-authenticated — use them directly without any manual login step.
|
||||
`git` HTTPS operations (clone, push, pull) work automatically.
|
||||
- If the token changes mid-session (e.g. user reconnects with a new token),
|
||||
run `gh auth setup-git` to re-register the credential helper.
|
||||
- If `gh` or `git` fails with an authentication error (e.g. "authentication
|
||||
required", "could not read Username", or exit code 128), call
|
||||
`connect_integration(provider="github")` to surface the GitHub credentials
|
||||
|
||||
@@ -151,12 +151,16 @@ class BashExecTool(BaseTool):
|
||||
integration_env = await get_integration_env_vars(user_id)
|
||||
envs.update(integration_env)
|
||||
|
||||
# When GH_TOKEN is available, lazily configure git to use the gh credential
|
||||
# helper so that git HTTPS operations (clone/push/pull) are authenticated.
|
||||
# gh auth setup-git is idempotent (writes ~/.gitconfig) — safe to run every
|
||||
# time; failure is non-fatal (best-effort, logged at debug level only).
|
||||
# When GH_TOKEN is available, configure git to use the gh credential helper
|
||||
# so that git HTTPS operations (clone/push/pull) are authenticated.
|
||||
# Only runs once per sandbox session (grep skips it if already configured).
|
||||
# The agent can also call `gh auth setup-git` manually at any time — useful
|
||||
# if GH_TOKEN changes mid-session (e.g. user reconnects with a new token).
|
||||
if envs.get("GH_TOKEN"):
|
||||
command = "gh auth setup-git 2>/dev/null || true; " + command
|
||||
command = (
|
||||
"grep -q 'helper.*gh' ~/.gitconfig 2>/dev/null"
|
||||
" || gh auth setup-git 2>/dev/null || true; " + command
|
||||
)
|
||||
|
||||
try:
|
||||
result = await sandbox.commands.run(
|
||||
|
||||
Reference in New Issue
Block a user