Improve gitea-api config discovery and repo pagination
This commit is contained in:
@@ -9,10 +9,30 @@ import sys
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
|
||||
CONFIG_PATHS = [
|
||||
"/home/node/.openclaw/workspace/.clawdbot/credentials/gitea/config.json",
|
||||
os.path.expanduser("~/.clawdbot/credentials/gitea/config.json"),
|
||||
]
|
||||
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
||||
def candidate_config_paths():
|
||||
paths = []
|
||||
|
||||
current = SCRIPT_DIR
|
||||
while True:
|
||||
paths.append(os.path.join(current, ".clawdbot", "credentials", "gitea", "config.json"))
|
||||
parent = os.path.dirname(current)
|
||||
if parent == current:
|
||||
break
|
||||
current = parent
|
||||
|
||||
paths.extend([
|
||||
"/home/node/.openclaw/workspace/.clawdbot/credentials/gitea/config.json",
|
||||
os.path.expanduser("~/.clawdbot/credentials/gitea/config.json"),
|
||||
])
|
||||
|
||||
# Deduplicate while preserving order
|
||||
return list(dict.fromkeys(paths))
|
||||
|
||||
|
||||
CONFIG_PATHS = candidate_config_paths()
|
||||
|
||||
|
||||
def get_config():
|
||||
@@ -77,12 +97,33 @@ def api_request(endpoint, method="GET", payload=None):
|
||||
return None, None, str(e)
|
||||
|
||||
|
||||
def api_get_all_pages(endpoint, page_size=100):
|
||||
page = 1
|
||||
items = []
|
||||
|
||||
while True:
|
||||
sep = "&" if "?" in endpoint else "?"
|
||||
paged_endpoint = f"{endpoint}{sep}limit={page_size}&page={page}"
|
||||
data, status, err = api_request(paged_endpoint)
|
||||
if data is None:
|
||||
return None, status, err
|
||||
if not isinstance(data, list):
|
||||
return data, status, err
|
||||
|
||||
items.extend(data)
|
||||
if len(data) < page_size:
|
||||
break
|
||||
page += 1
|
||||
|
||||
return items, 200, None
|
||||
|
||||
|
||||
def print_api_error(action, status, err):
|
||||
print(f"❌ Failed to {action}. status={status} error={err}")
|
||||
|
||||
|
||||
def cmd_repos(_):
|
||||
repos, status, err = api_request("/user/repos")
|
||||
repos, status, err = api_get_all_pages("/user/repos")
|
||||
if repos is None:
|
||||
print_api_error("list repos", status, err)
|
||||
return 1
|
||||
|
||||
Reference in New Issue
Block a user