From 6c1f0f4c95f5a3b29b1a1c4f3197e69b2dd953ad Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Thu, 26 Feb 2026 19:40:17 +0100 Subject: [PATCH] jw-pkg.py: CmdListRepos: Take base-url argument seriously base-url is not used as a prefix in its entirety, but massaged in a janware-specific way. Still is, but at least this commit is a step towards being more generic. Signed-off-by: Jan Lindemann --- .../jw/pkg/cmds/projects/CmdListRepos.py | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/python/jw/pkg/cmds/projects/CmdListRepos.py b/src/python/jw/pkg/cmds/projects/CmdListRepos.py index 8b36d515..ec9d3ece 100644 --- a/src/python/jw/pkg/cmds/projects/CmdListRepos.py +++ b/src/python/jw/pkg/cmds/projects/CmdListRepos.py @@ -4,6 +4,7 @@ import re, os from argparse import Namespace, ArgumentParser from ...lib.util import get_username, get_password, run_curl +from ...lib.log import * from ..Cmd import Cmd from ..CmdProjects import CmdProjects @@ -14,8 +15,7 @@ class CmdListRepos(Cmd): # export def add_arguments(self, parser: ArgumentParser) -> None: super().add_arguments(parser) - parser.add_argument('base_url', help='Base URL of all Git repositories') - parser.add_argument('--name-only', help='Only list names of repos, not URLs') + parser.add_argument('base_url', help='Base URL of all Git repositories without user part') parser.add_argument('--username', help='Username for SSH or HTTP authentication, don\'t specify for unauthenticated', default=None) parser.add_argument('--askpass', help='Program to echo password for SSH or HTTP authentication, don\'t specify for unauthenticated', default=None) parser.add_argument('--from-user', help='List from-user\'s projects', default='janware') @@ -46,9 +46,9 @@ class CmdListRepos(Cmd): # export cmd_input = None if re.match(r'https://github.com', args.base_url): curl_args = [ - '-f', - '-H', 'Accept: application/vnd.github+json', - '-H', 'X-GitHub-Api-Version: 2022-11-28', + '-f', + '-H', 'Accept: application/vnd.github+json', + '-H', 'X-GitHub-Api-Version: 2022-11-28', ] if password is not None: assert username is not None @@ -60,23 +60,24 @@ class CmdListRepos(Cmd): # export print(repo['name']) return if re.match(r'https://', args.base_url): - # assume Forgejo Backend + # assume Forgejo / Gitea Backend curl_args = ['-f'] if password is not None: assert username is not None cmd_input = (f'-u {username}:{password}').encode('utf-8') curl_args.extend(['-K-']) for entities_dir in ['orgs', 'users']: - api_url = f'https://{url.hostname}/code/api/v1/{entities_dir}/{args.from_user}/repos' + api_url = f'{args.base_url}/api/v1/{entities_dir}/{args.from_user}/repos' try: - repos = await run_curl(curl_args + api_url, cmd_input=cmd_input) + repos = await run_curl(curl_args + [api_url], cmd_input=cmd_input) for repo in repos: print(repo['name']) break - except: + except Exception as e: + log(DEBUG, f'No data from {api_url} ({str(e)})') pass - else: - raise RuntimeError(f'Failed to fetch repository list from assumed Forgejo instance at {args.base_url}') + else: + raise RuntimeError(f'Failed to fetch repository list from assumed Forgejo instance at {args.base_url}') return if os.path.isdir(args.base_url): for subdir in ["." , args.from_user]: