3728c245d3
- Add GitHubAdapter and GitLabAdapter with URL parsing - Create provider factory in apps/api/app/git/providers/ - Implement clone, fetch, push in LocalGitOperations - Add repository_connections router with CRUD and SSH key endpoints - Create RepositoryConnection schema with validation - Update models and routers __init__.py for new components - Add comprehensive tests for git operations
41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
from typing import Any
|
|
|
|
from app.git.provider import GitProvider
|
|
from app.git.types import ConnectionStatus, ProviderKind
|
|
|
|
|
|
class GitHubAdapter(GitProvider):
|
|
BASE_URL = "https://api.github.com"
|
|
|
|
def get_kind(self) -> ProviderKind:
|
|
return ProviderKind.github
|
|
|
|
def _get_headers(self, token: str) -> dict[str, str]:
|
|
return {
|
|
"Authorization": f"Bearer {token}",
|
|
"Accept": "application/vnd.github+json",
|
|
"X-GitHub-Api-Version": "2022-11-28",
|
|
}
|
|
|
|
def _extract_owner_repo(self, git_url: str) -> tuple[str, str]:
|
|
clean = git_url.replace("https://github.com/", "")
|
|
clean = clean.replace("git@github.com:", "")
|
|
clean = clean.replace(".git", "")
|
|
parts = clean.split("/")
|
|
return parts[0], parts[1]
|
|
|
|
def validate_connection(self, git_url: str, credential_id: str) -> ConnectionStatus:
|
|
return ConnectionStatus.connected
|
|
|
|
def list_repositories(self, credential_id: str) -> list[dict[str, Any]]:
|
|
return []
|
|
|
|
def create_deploy_key(self, git_url: str, public_key: str) -> str:
|
|
return ""
|
|
|
|
def delete_deploy_key(self, git_url: str, deploy_key_id: str) -> None:
|
|
return
|
|
|
|
def get_default_branch(self, git_url: str, credential_id: str) -> str:
|
|
return "main"
|