Coverage for src / eclipse / care / utils / git_provider.py: 74%
19 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-24 09:38 +0100
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-24 09:38 +0100
1# Copyright (c) 2026 The Eclipse Foundation
2#
3# This program and the accompanying materials are made available under the
4# terms of the Eclipse Public License 2.0 which is available at
5# http://www.eclipse.org/legal/epl-2.0.
6#
7# SPDX-License-Identifier: EPL-2.0
8#
9# Contributors:
10# asgomes - Initial implementation
12from abc import ABC, abstractmethod
13from pathlib import Path
14from typing import Optional, List, Any
17class GitProviderEMO(ABC):
18 """
19 Abstract Base Class for Git Provider (GitHub, GitLab, etc.)
20 This acts as a contract that all provider implementations must follow.
21 """
22 # Each provider uses its own cache for repos
23 repos: dict
25 def __init__(self, credentials: Optional[dict] = None, verbose: bool = False):
26 # The actual implementation of __init__ can stay in the child
27 # because authentication logic differs wildly between providers.
28 super().__init__()
30 @abstractmethod
31 def get_repo(self, repo: str) -> Any:
32 """Return the repository object, from cache or remote."""
33 pass
35 @abstractmethod
36 def get_content_root(self, repo: str) -> Optional[List[str]]:
37 """List files and directories at the root of the repository."""
38 pass
40 @abstractmethod
41 def get_content_recursive(self, repo: str, branch: Optional[str] = None) -> Optional[List[dict]]:
42 """List files and directories of the repository recursively."""
43 pass
45 @abstractmethod
46 def get_file(self, repo: str, tmpdir: str, fpath: str, branch: Optional[str] = None,
47 bytes_to_read: Optional[int] = 2048) -> Optional[Path]:
48 """Download a file from the repo and return its local Path."""
49 pass