mirror of
ssh://git.janware.com/janware/proj/jw-pkg
synced 2026-04-25 09:35:54 +02:00
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 <jan@janware.com>
This commit is contained in:
parent
b81406e11a
commit
6c1f0f4c95
1 changed files with 12 additions and 11 deletions
|
|
@ -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]:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue