From cbcded64690c68afc153dfb200ddda0e789196d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B8=D0=BA=D1=82=D0=BE=D1=80?= <78488229+viktor138irk@users.noreply.github.com> Date: Tue, 12 May 2026 00:16:52 +0900 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20cl?= =?UTF-8?q?one=20=D0=BF=D1=80=D0=B8=D0=B2=D0=B0=D1=82=D0=BD=D1=8B=D1=85=20?= =?UTF-8?q?GitHub=20=D1=80=D0=B5=D0=BF=D0=BE=D0=B7=D0=B8=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D0=B5=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/project_analyzer.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/backend/project_analyzer.py b/backend/project_analyzer.py index dde4b7d..f34869e 100644 --- a/backend/project_analyzer.py +++ b/backend/project_analyzer.py @@ -7,6 +7,8 @@ from dataclasses import dataclass, asdict from pathlib import Path 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')) PROJECTS_DIR = DATA_DIR / 'projects' @@ -41,18 +43,38 @@ def _slug_from_repo_url(repo_url: str) -> str: 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: PROJECTS_DIR.mkdir(parents=True, exist_ok=True) slug = _slug_from_repo_url(repo_url) workspace = PROJECTS_DIR / slug + auth_repo_url = _build_authenticated_repo_url(repo_url) + if (workspace / '.git').exists(): subprocess.run(['git', '-C', str(workspace), 'fetch', '--all'], check=True) subprocess.run(['git', '-C', str(workspace), 'pull', '--ff-only'], check=False) else: if workspace.exists(): 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