feat!: token support for cloning

This commit is contained in:
2026-06-27 22:57:58 +03:00
parent 28f1fda048
commit 206a8730a8
11 changed files with 336 additions and 45 deletions
+14 -4
View File
@@ -3,7 +3,7 @@ import sys
from os import makedirs
from src.config import Config, read_toml_config
from src.git import git_clone, git_pull
from src.git import git_clone, git_pull, http_git_env, ssh_git_env
from src.gitea_api import GiteaApi
from src.models import GiteaRepository
from src.repository_name import get_repository_name, is_valid_repository_names
@@ -12,15 +12,25 @@ BASE_PATH = "out"
FORMAT = "{owner}/{name}"
def get_fetch_params(config: Config, repo: GiteaRepository):
if config.fetch.ssh_key_path:
return repo.ssh_url, ssh_git_env(config.fetch.ssh_key_path)
return repo.clone_url, http_git_env(
user=config.fetch.user,
token=config.fetch.token,
)
def process_repo(config: Config, repo: GiteaRepository):
path = get_repository_name(name_format=config.repository_format, r=repo)
out_path = os.path.join(config.out_dir, path)
repository_url, git_env = get_fetch_params(config=config, repo=repo)
makedirs(out_path, exist_ok=True)
if os.path.exists(os.path.join(out_path, ".git")):
git_pull(out_path, ssh_key="fake")
git_pull(out_path, env=git_env)
return
print(f"New repository: {path}")
git_clone(ssh_url=repo.ssh_url, repository=out_path, ssh_key="fake")
git_clone(repository_url=repository_url, repository=out_path, env=git_env)
def main():
@@ -35,7 +45,7 @@ def main():
api = GiteaApi(
endpoint=config.endpoint,
token=config.token,
api_token=config.api_token,
)
repos = api.get_repositories()
print(f"total {len(repos)} repositories")