fix(ci): replace inline python with curl+jq api fallback

This commit is contained in:
Tracewebstudio Dev 2026-04-30 20:02:08 +02:00
parent 630d15bcf7
commit 2f6792c25b

View file

@ -49,30 +49,11 @@ jobs:
if [ -z "$TARGET_URL" ]; then
echo "Owner guess failed; searching accessible repos via Gitea API"
API_URL="https://${GITEA_HOST}/api/v1/repos/search?q=${REPO_NAME}&limit=100"
TARGET_URL="$(python3 - <<'PY'
import json
import os
import urllib.request
req = urllib.request.Request(
os.environ["API_URL"],
headers={"Authorization": f"token {os.environ['GITEA_TOKEN']}"},
)
with urllib.request.urlopen(req, timeout=20) as resp:
payload = json.loads(resp.read().decode("utf-8"))
repo_name = os.environ["REPO_NAME"].lower()
username = os.environ["GITEA_USERNAME"]
host = os.environ["GITEA_HOST"]
token = os.environ["GITEA_TOKEN"]
for repo in payload.get("data", []):
full_name = str(repo.get("full_name", ""))
if full_name.lower().endswith("/" + repo_name):
print(f"https://{username}:{token}@{host}/{full_name}.git")
break
PY
)"
API_JSON="$(curl -fsS -H "Authorization: token ${GITEA_TOKEN}" "${API_URL}" || true)"
TARGET_FULL_NAME="$(printf '%s' "$API_JSON" | jq -r --arg repo "$REPO_NAME" '[.data[]?.full_name | select((ascii_downcase | endswith("/" + ($repo | ascii_downcase))))][0] // empty')"
if [ -n "$TARGET_FULL_NAME" ]; then
TARGET_URL="https://${GITEA_USERNAME}:${GITEA_TOKEN}@${GITEA_HOST}/${TARGET_FULL_NAME}.git"
fi
if [ -n "$TARGET_URL" ]; then
echo "Resolved Gitea target via API"
fi