fix(ci): replace inline python with curl+jq api fallback
This commit is contained in:
parent
9e55288f08
commit
c1b08bd194
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
|
|
@ -50,30 +50,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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue