chore(ci): auto-label robust ID resolution (pagination)
This commit is contained in:
@@ -22,8 +22,9 @@ jobs:
|
||||
NAME=$(echo "$REPO" | cut -d'/' -f2)
|
||||
echo "Resolving label id for 'automerge' in $OWNER/$NAME"
|
||||
curl -sS -o /tmp/labels.json -H "Authorization: token ${CI_TOKEN}" \
|
||||
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/labels"
|
||||
LID=$(awk 'BEGIN{RS="},"} /"name":"automerge"/ {if (match($0,/"id":([0-9]+)/,m)) {print m[1]; exit}}' /tmp/labels.json || true)
|
||||
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/labels?limit=1000" || 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
|
||||
echo "Label 'automerge' not found. Creating..."
|
||||
curl -sS -o /tmp/create_label.json -X POST \
|
||||
@@ -31,7 +32,7 @@ jobs:
|
||||
-H "Authorization: token ${CI_TOKEN}" \
|
||||
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/labels" \
|
||||
-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
|
||||
if [ -z "${LID:-}" ]; then
|
||||
echo "Failed to resolve or create label id; skipping"; exit 0; fi
|
||||
|
||||
Reference in New Issue
Block a user