Добавил clone приватных GitHub репозиториев

Этот коммит содержится в:
Виктор
2026-05-12 00:16:52 +09:00
родитель f6cfa3bd23
Коммит cbcded6469
+23 -1
Просмотреть файл
@@ -7,6 +7,8 @@ from dataclasses import dataclass, asdict
from pathlib import Path from pathlib import Path
from urllib.parse import urlparse from urllib.parse import urlparse
from backend.config_store import get_github_token, get_github_username
DATA_DIR = Path(os.getenv('DEVCONSOLE_DATA_DIR', '/var/lib/devconsole')) DATA_DIR = Path(os.getenv('DEVCONSOLE_DATA_DIR', '/var/lib/devconsole'))
PROJECTS_DIR = DATA_DIR / 'projects' PROJECTS_DIR = DATA_DIR / 'projects'
@@ -41,18 +43,38 @@ def _slug_from_repo_url(repo_url: str) -> str:
return slug or 'project' return slug or 'project'
def _build_authenticated_repo_url(repo_url: str) -> str:
username = get_github_username().strip()
token = (get_github_token() or '').strip()
if not username or not token:
return repo_url
if 'github.com' not in repo_url:
return repo_url
return repo_url.replace(
'https://',
f'https://{username}:{token}@',
1,
)
def clone_or_update_project(repo_url: str) -> Path: def clone_or_update_project(repo_url: str) -> Path:
PROJECTS_DIR.mkdir(parents=True, exist_ok=True) PROJECTS_DIR.mkdir(parents=True, exist_ok=True)
slug = _slug_from_repo_url(repo_url) slug = _slug_from_repo_url(repo_url)
workspace = PROJECTS_DIR / slug workspace = PROJECTS_DIR / slug
auth_repo_url = _build_authenticated_repo_url(repo_url)
if (workspace / '.git').exists(): if (workspace / '.git').exists():
subprocess.run(['git', '-C', str(workspace), 'fetch', '--all'], check=True) subprocess.run(['git', '-C', str(workspace), 'fetch', '--all'], check=True)
subprocess.run(['git', '-C', str(workspace), 'pull', '--ff-only'], check=False) subprocess.run(['git', '-C', str(workspace), 'pull', '--ff-only'], check=False)
else: else:
if workspace.exists(): if workspace.exists():
shutil.rmtree(workspace) shutil.rmtree(workspace)
subprocess.run(['git', 'clone', repo_url, str(workspace)], check=True) subprocess.run(['git', 'clone', auth_repo_url, str(workspace)], check=True)
return workspace return workspace