fix(ci): correct yaml-safe gitea API fallback script
This commit is contained in:
parent
41091185ca
commit
c7c330ad8c
1 changed files with 15 additions and 12 deletions
27
.github/workflows/sync-to-gitea.yml
vendored
27
.github/workflows/sync-to-gitea.yml
vendored
|
|
@ -50,27 +50,30 @@ 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'
|
TARGET_URL="$(python3 - <<'PY'
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
|
||||||
api_url = os.environ["API_URL"]
|
req = urllib.request.Request(
|
||||||
token = os.environ["GITEA_TOKEN"]
|
os.environ["API_URL"],
|
||||||
repo_name = os.environ["REPO_NAME"]
|
headers={"Authorization": f"token {os.environ['GITEA_TOKEN']}"},
|
||||||
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:
|
with urllib.request.urlopen(req, timeout=20) as resp:
|
||||||
data = json.loads(resp.read().decode("utf-8"))
|
payload = json.loads(resp.read().decode("utf-8"))
|
||||||
|
|
||||||
for repo in data.get("data", []):
|
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", ""))
|
full_name = str(repo.get("full_name", ""))
|
||||||
if full_name.lower().endswith("/" + repo_name.lower()):
|
if full_name.lower().endswith("/" + repo_name):
|
||||||
print(f"https://{username}:{token}@{os.environ['GITEA_HOST']}/{full_name}.git")
|
print(f"https://{username}:{token}@{host}/{full_name}.git")
|
||||||
break
|
break
|
||||||
PY
|
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