Refactor Forgejo LFS batch response handling to use a temporary Python script for improved readability and maintainability
All checks were successful
Publish FaceAI Container / publish (push) Successful in 3m43s

This commit is contained in:
MaddoScientisto 2026-04-19 12:31:29 +02:00
commit 6f191de115

View file

@ -131,34 +131,39 @@ jobs:
fi fi
fi fi
python3 - "${TMP_DIR}/batch-response.json" "${TMP_DIR}/download-url.txt" "${TMP_DIR}/download-headers.txt" <<'PY' printf '%s\n' \
import json 'import json' \
import sys 'import sys' \
'' \
'response_path, url_path, headers_path = sys.argv[1:4]' \
'with open(response_path, "r", encoding="utf-8") as handle:' \
' data = json.load(handle)' \
'' \
'objects = data.get("objects") or []' \
'if not objects:' \
' raise SystemExit("Forgejo LFS batch response did not contain any objects")' \
'' \
'obj = objects[0]' \
'if "error" in obj:' \
' raise SystemExit("Forgejo LFS object error: {}".format(obj["error"]))' \
'' \
'download = ((obj.get("actions") or {}).get("download"))' \
'if not download or "href" not in download:' \
' raise SystemExit("Forgejo LFS batch response did not contain a download action")' \
'' \
'with open(url_path, "w", encoding="utf-8") as handle:' \
' handle.write(download["href"])' \
'' \
'headers = download.get("header") or {}' \
'with open(headers_path, "w", encoding="utf-8") as handle:' \
' for key, value in headers.items():' \
' handle.write("{}: {}\\n".format(key, value))' \
> "${TMP_DIR}/parse_lfs_batch.py"
response_path, url_path, headers_path = sys.argv[1:4] python3 "${TMP_DIR}/parse_lfs_batch.py" \
with open(response_path, 'r', encoding='utf-8') as handle: "${TMP_DIR}/batch-response.json" \
data = json.load(handle) "${TMP_DIR}/download-url.txt" \
"${TMP_DIR}/download-headers.txt"
objects = data.get('objects') or []
if not objects:
raise SystemExit('Forgejo LFS batch response did not contain any objects')
obj = objects[0]
if 'error' in obj:
raise SystemExit(f"Forgejo LFS object error: {obj['error']}")
download = ((obj.get('actions') or {}).get('download'))
if not download or 'href' not in download:
raise SystemExit('Forgejo LFS batch response did not contain a download action')
with open(url_path, 'w', encoding='utf-8') as handle:
handle.write(download['href'])
headers = download.get('header') or {}
with open(headers_path, 'w', encoding='utf-8') as handle:
for key, value in headers.items():
handle.write(f'{key}: {value}\n')
PY
DOWNLOAD_URL="$(cat "${TMP_DIR}/download-url.txt")" DOWNLOAD_URL="$(cat "${TMP_DIR}/download-url.txt")"
download_args=() download_args=()