fix(ci): resolve gitea sync target via API search fallback
This commit is contained in:
parent
4cd6eeba63
commit
f59681460b
1 changed files with 29 additions and 0 deletions
29
.github/workflows/sync-to-gitea.yml
vendored
29
.github/workflows/sync-to-gitea.yml
vendored
|
|
@ -46,6 +46,35 @@ jobs:
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
api_url = os.environ["API_URL"]
|
||||||
|
token = os.environ["GITEA_TOKEN"]
|
||||||
|
repo_name = os.environ["REPO_NAME"]
|
||||||
|
username = os.environ["GITEA_USERNAME"]
|
||||||
|
|
||||||
|
req = urllib.request.Request(api_url, headers={"Authorization": f"token {token}"})
|
||||||
|
with urllib.request.urlopen(req, timeout=20) as resp:
|
||||||
|
data = json.loads(resp.read().decode("utf-8"))
|
||||||
|
|
||||||
|
for repo in data.get("data", []):
|
||||||
|
full_name = str(repo.get("full_name", ""))
|
||||||
|
if full_name.lower().endswith("/" + repo_name.lower()):
|
||||||
|
print(f"https://{username}:{token}@{os.environ['GITEA_HOST']}/{full_name}.git")
|
||||||
|
break
|
||||||
|
PY
|
||||||
|
)
|
||||||
|
if [ -n "$TARGET_URL" ]; then
|
||||||
|
echo "Resolved Gitea target via API"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -z "$TARGET_URL" ]; then
|
if [ -z "$TARGET_URL" ]; then
|
||||||
echo "Could not access target repo on Gitea for owners: $CANDIDATE_OWNERS"
|
echo "Could not access target repo on Gitea for owners: $CANDIDATE_OWNERS"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue