Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6ff27295e6 | |||
| 8d5501d927 | |||
| 7110db8a4a | |||
| 32a760dd9a |
@@ -20,22 +20,15 @@ jobs:
|
||||
echo "CI_TOKEN not set; skipping labeling"; exit 0; fi
|
||||
OWNER=$(echo "$REPO" | cut -d'/' -f1)
|
||||
NAME=$(echo "$REPO" | cut -d'/' -f2)
|
||||
echo "Resolving label id for 'automerge' in $OWNER/$NAME"
|
||||
echo "Resolving existing label id for 'automerge' in $OWNER/$NAME (no creation)"
|
||||
curl -sS -o /tmp/labels.json -H "Authorization: token ${CI_TOKEN}" \
|
||||
"${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)
|
||||
# Extract all ids whose name == automerge, prefer the smallest id (oldest)
|
||||
LID=$(tr '\n' ' ' < /tmp/labels.json | \
|
||||
grep -o '"id":[0-9][0-9]*[^\}]*"name":"automerge"' | \
|
||||
sed -E 's/.*"id":([0-9]+).*/\1/' | sort -n | head -n1 || true)
|
||||
if [ -z "${LID:-}" ]; then
|
||||
echo "Label 'automerge' not found. Creating..."
|
||||
curl -sS -o /tmp/create_label.json -X POST \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: token ${CI_TOKEN}" \
|
||||
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/labels" \
|
||||
-d '{"name":"automerge","color":"#0ea5e9"}'
|
||||
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
|
||||
echo "No existing 'automerge' label found; skipping labeling"; exit 0; fi
|
||||
echo "Labeling PR #$PR_NUMBER with id $LID"
|
||||
curl -sS -X POST \
|
||||
-H "Content-Type: application/json" \
|
||||
|
||||
@@ -55,19 +55,12 @@ jobs:
|
||||
done
|
||||
|
||||
if [ -n "${PR_NUMBER:-}" ]; then
|
||||
echo "Resolving label id for 'automerge' in $OWNER/$NAME"
|
||||
echo "Resolving existing label id for 'automerge' (no creation)"
|
||||
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)
|
||||
if [ -z "${LID:-}" ]; then
|
||||
echo "Label 'automerge' not found. Creating..."
|
||||
curl -sS -o /tmp/create_label.json -X POST \
|
||||
-H "Content-Type: application/json" \
|
||||
-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)
|
||||
fi
|
||||
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/labels?limit=1000" || true
|
||||
LID=$(tr '\n' ' ' < /tmp/labels.json | \
|
||||
grep -o '"id":[0-9][0-9]*[^\}]*"name":"automerge"' | \
|
||||
sed -E 's/.*"id":([0-9]+).*/\1/' | sort -n | head -n1 || true)
|
||||
if [ -n "${LID:-}" ]; then
|
||||
echo "Adding 'automerge' (id=$LID) label to PR #$PR_NUMBER"
|
||||
curl -sS -X POST \
|
||||
@@ -76,7 +69,7 @@ jobs:
|
||||
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/issues/${PR_NUMBER}/labels" \
|
||||
-d '{"labels":['"${LID}"']}' || true
|
||||
else
|
||||
echo "Failed to resolve label id; skipping label add"
|
||||
echo "No existing 'automerge' label found; skipping label add"
|
||||
fi
|
||||
else
|
||||
echo "PR number could not be determined; skipping label add"
|
||||
|
||||
Reference in New Issue
Block a user