1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-11-07 22:53:16 +01:00

Change 'git-obs' to use owner/repo[#pull] arguments consistently

This commit is contained in:
2025-01-15 17:01:47 +01:00
parent 99dcb4e10a
commit e23c566b0d
11 changed files with 172 additions and 63 deletions

View File

@@ -1,3 +1,6 @@
import subprocess
import sys
import osc.commandline_git
@@ -13,8 +16,7 @@ class RepoCloneCommand(osc.commandline_git.GitObsCommand):
parent = "RepoCommand"
def init_arguments(self):
self.add_argument_owner()
self.add_argument_repo()
self.add_argument_owner_repo(nargs="+")
self.add_argument(
"-a",
@@ -45,15 +47,42 @@ class RepoCloneCommand(osc.commandline_git.GitObsCommand):
def run(self, args):
from osc import gitea_api
from osc.output import tty
self.print_gitea_settings()
gitea_api.Repo.clone(
self.gitea_conn,
args.owner,
args.repo,
directory=args.directory,
anonymous=args.anonymous,
add_remotes=True,
ssh_private_key_path=args.ssh_key or self.gitea_login.ssh_key,
ssh_strict_host_key_checking=not(args.no_ssh_strict_host_key_checking),
)
if len(args.owner_repo) > 1 and args.directory:
self.parser.error("The --directory option cannot be used with multiple repos")
num_entries = 0
failed_entries = []
for owner, repo in args.owner_repo:
print(f"Cloning git repo {owner}/{repo} ...", file=sys.stderr)
try:
gitea_api.Repo.clone(
self.gitea_conn,
owner,
repo,
directory=args.directory,
anonymous=args.anonymous,
add_remotes=True,
ssh_private_key_path=args.ssh_key or self.gitea_login.ssh_key,
ssh_strict_host_key_checking=not(args.no_ssh_strict_host_key_checking),
)
num_entries += 1
except gitea_api.GiteaException as e:
if e.status == 404:
print(f" * {tty.colorize('ERROR', 'red,bold')}: Repo doesn't exist: {owner}/{repo}", file=sys.stderr)
failed_entries.append(f"{owner}/{repo}")
continue
raise
except subprocess.CalledProcessError as e:
print(f" * {tty.colorize('ERROR', 'red,bold')}: git clone failed", file=sys.stderr)
failed_entries.append(f"{owner}/{repo}")
continue
print("", file=sys.stderr)
print(f"Total cloned repos: {num_entries}", file=sys.stderr)
if failed_entries:
print(f"{tty.colorize('ERROR', 'red,bold')}: Couldn't clone the following repos: {', '.join(failed_entries)}", file=sys.stderr)
sys.exit(1)