fix(backend): prioritize git remote detection over env var for repo (#1555)
The GITHUB_REPO/GITLAB_PROJECT env vars were taking priority over auto-detection from the project's git remote, causing all projects to incorrectly use the hardcoded repo from .env in multi-project setups. Changed priority order: 1. Explicit --repo/--project CLI flag (highest) 2. Auto-detect from project's git remote/config (primary) 3. Environment variable (fallback only) Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -106,7 +106,12 @@ def get_config(args) -> GitHubRunnerConfig:
|
||||
|
||||
token = args.token or os.environ.get("GITHUB_TOKEN", "")
|
||||
bot_token = args.bot_token or os.environ.get("GITHUB_BOT_TOKEN")
|
||||
repo = args.repo or os.environ.get("GITHUB_REPO", "")
|
||||
|
||||
# Repo detection priority:
|
||||
# 1. Explicit --repo flag (highest priority)
|
||||
# 2. Auto-detect from project's git remote (primary for multi-project setups)
|
||||
# 3. GITHUB_REPO env var (fallback only)
|
||||
repo = args.repo # Only use explicit CLI flag initially
|
||||
|
||||
# Find gh CLI - use get_gh_executable for cross-platform support
|
||||
gh_path = get_gh_executable()
|
||||
@@ -131,8 +136,8 @@ def get_config(args) -> GitHubRunnerConfig:
|
||||
except FileNotFoundError:
|
||||
pass # gh not installed or not in PATH
|
||||
|
||||
# Auto-detect repo from project's git remote (takes priority over env var)
|
||||
if not repo and gh_path:
|
||||
# Try to detect from git remote
|
||||
try:
|
||||
result = subprocess.run(
|
||||
[
|
||||
@@ -155,6 +160,10 @@ def get_config(args) -> GitHubRunnerConfig:
|
||||
except FileNotFoundError:
|
||||
pass # gh not installed or not in PATH
|
||||
|
||||
# Fall back to environment variable only if auto-detection failed
|
||||
if not repo:
|
||||
repo = os.environ.get("GITHUB_REPO", "")
|
||||
|
||||
if not token:
|
||||
safe_print(
|
||||
"Error: No GitHub token found. Set GITHUB_TOKEN or run 'gh auth login'"
|
||||
|
||||
@@ -61,11 +61,16 @@ def print_progress(callback: ProgressCallback) -> None:
|
||||
def get_config(args) -> GitLabRunnerConfig:
|
||||
"""Build config from CLI args and environment."""
|
||||
token = args.token or os.environ.get("GITLAB_TOKEN", "")
|
||||
project = args.project or os.environ.get("GITLAB_PROJECT", "")
|
||||
instance_url = args.instance or os.environ.get(
|
||||
"GITLAB_INSTANCE_URL", "https://gitlab.com"
|
||||
)
|
||||
|
||||
# Project detection priority:
|
||||
# 1. Explicit --project flag (highest priority)
|
||||
# 2. Auto-detect from .auto-claude/gitlab/config.json (primary for multi-project setups)
|
||||
# 3. GITLAB_PROJECT env var (fallback only)
|
||||
project = args.project # Only use explicit CLI flag initially
|
||||
|
||||
if not token:
|
||||
# Try to get from glab CLI
|
||||
import subprocess
|
||||
@@ -86,8 +91,8 @@ def get_config(args) -> GitLabRunnerConfig:
|
||||
token = line.split("Token:")[-1].strip()
|
||||
break
|
||||
|
||||
# Auto-detect from project config (takes priority over env var)
|
||||
if not project:
|
||||
# Try to detect from .auto-claude/gitlab/config.json
|
||||
config_path = Path(args.project_dir) / ".auto-claude" / "gitlab" / "config.json"
|
||||
if config_path.exists():
|
||||
try:
|
||||
@@ -100,6 +105,10 @@ def get_config(args) -> GitLabRunnerConfig:
|
||||
except Exception as exc:
|
||||
print(f"Warning: Failed to read GitLab config: {exc}", file=sys.stderr)
|
||||
|
||||
# Fall back to environment variable only if auto-detection failed
|
||||
if not project:
|
||||
project = os.environ.get("GITLAB_PROJECT", "")
|
||||
|
||||
if not token:
|
||||
print(
|
||||
"Error: No GitLab token found. Set GITLAB_TOKEN or configure in project settings."
|
||||
|
||||
Reference in New Issue
Block a user