fix(ci): replace inline python with curl+jq api fallback
This commit is contained in:
parent
630d15bcf7
commit
2f6792c25b
1 changed files with 5 additions and 24 deletions
29
.github/workflows/sync-to-gitea.yml
vendored
29
.github/workflows/sync-to-gitea.yml
vendored
|
|
@ -49,30 +49,11 @@ jobs:
|
||||||
if [ -z "$TARGET_URL" ]; then
|
if [ -z "$TARGET_URL" ]; then
|
||||||
echo "Owner guess failed; searching accessible repos via Gitea API"
|
echo "Owner guess failed; searching accessible repos via Gitea API"
|
||||||
API_URL="https://${GITEA_HOST}/api/v1/repos/search?q=${REPO_NAME}&limit=100"
|
API_URL="https://${GITEA_HOST}/api/v1/repos/search?q=${REPO_NAME}&limit=100"
|
||||||
TARGET_URL="$(python3 - <<'PY'
|
API_JSON="$(curl -fsS -H "Authorization: token ${GITEA_TOKEN}" "${API_URL}" || true)"
|
||||||
import json
|
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')"
|
||||||
import os
|
if [ -n "$TARGET_FULL_NAME" ]; then
|
||||||
import urllib.request
|
TARGET_URL="https://${GITEA_USERNAME}:${GITEA_TOKEN}@${GITEA_HOST}/${TARGET_FULL_NAME}.git"
|
||||||
|
fi
|
||||||
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
|
|
||||||
)"
|
|
||||||
if [ -n "$TARGET_URL" ]; then
|
if [ -n "$TARGET_URL" ]; then
|
||||||
echo "Resolved Gitea target via API"
|
echo "Resolved Gitea target via API"
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue