chore(ci): auto-label robust ID resolution (pagination)
Auto PR / open-pr (push) Successful in 20s
Auto Label PR / add-automerge-label (pull_request) Successful in 8s
CI / test (pull_request) Successful in 1m4s

This commit is contained in:
2025-11-14 22:22:27 +09:00
parent 2e69714dba
commit 4b03a40363
+4 -3
View File
@@ -22,8 +22,9 @@ jobs:
NAME=$(echo "$REPO" | cut -d'/' -f2) NAME=$(echo "$REPO" | cut -d'/' -f2)
echo "Resolving label id for 'automerge' in $OWNER/$NAME" echo "Resolving label id for 'automerge' in $OWNER/$NAME"
curl -sS -o /tmp/labels.json -H "Authorization: token ${CI_TOKEN}" \ curl -sS -o /tmp/labels.json -H "Authorization: token ${CI_TOKEN}" \
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/labels" "${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/labels?limit=1000" || true
LID=$(awk 'BEGIN{RS="},"} /"name":"automerge"/ {if (match($0,/"id":([0-9]+)/,m)) {print m[1]; exit}}' /tmp/labels.json || true) # Robust parse without jq: find the id preceding name "automerge"
LID=$(tr '\n' ' ' < /tmp/labels.json | grep -o '"id":[0-9][0-9]*[^\}]*"name":"automerge"' | head -n1 | sed -E 's/.*"id":([0-9]+).*/\1/' || true)
if [ -z "${LID:-}" ]; then if [ -z "${LID:-}" ]; then
echo "Label 'automerge' not found. Creating..." echo "Label 'automerge' not found. Creating..."
curl -sS -o /tmp/create_label.json -X POST \ curl -sS -o /tmp/create_label.json -X POST \
@@ -31,7 +32,7 @@ jobs:
-H "Authorization: token ${CI_TOKEN}" \ -H "Authorization: token ${CI_TOKEN}" \
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/labels" \ "${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/labels" \
-d '{"name":"automerge","color":"#0ea5e9"}' -d '{"name":"automerge","color":"#0ea5e9"}'
LID=$(sed -n 's/.*"id":\([0-9]*\).*/\1/p' /tmp/create_label.json | head -n1 || true) LID=$(tr '\n' ' ' < /tmp/create_label.json | sed -E 's/.*"id":([0-9]+).*/\1/' | head -n1 || true)
fi fi
if [ -z "${LID:-}" ]; then if [ -z "${LID:-}" ]; then
echo "Failed to resolve or create label id; skipping"; exit 0; fi echo "Failed to resolve or create label id; skipping"; exit 0; fi