cmds.projects.CmdListRepos: Try Forgejo users and orgs

A "username" in jw-pkg terms, as in $(CLONE_FROM_USER), is not
sufficient to identify a remote API URL on a Forgejo server, it can
denote both an organization and a user, so try organizations first,
then users, and stop on the first occasion found.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-01-28 12:03:52 +01:00
commit 26bfda109c

View file

@ -66,12 +66,17 @@ class CmdListRepos(Cmd): # export
assert username is not None
cmd_input = (f'-u {username}:{password}').encode('utf-8')
curl_args.extend(['-K-'])
curl_args.extend([
f'https://{url.hostname}/code/api/v1/orgs/{args.from_user}/repos'
])
repos = await run_curl(curl_args, cmd_input=cmd_input)
for repo in repos:
print(repo['name'])
for entities_dir in ['orgs', 'users']:
api_url = f'https://{url.hostname}/code/api/v1/{entities_dir}/{args.from_user}/repos'
try:
repos = await run_curl(curl_args + api_url, cmd_input=cmd_input)
for repo in repos:
print(repo['name'])
break
except:
pass
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]: