Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cd8ae32203 | |||
| 7b36e14b65 | |||
| 3d2f1dc8d4 |
@@ -20,9 +20,25 @@ jobs:
|
|||||||
echo "CI_TOKEN not set; skipping labeling"; exit 0; fi
|
echo "CI_TOKEN not set; skipping labeling"; exit 0; fi
|
||||||
OWNER=$(echo "$REPO" | cut -d'/' -f1)
|
OWNER=$(echo "$REPO" | cut -d'/' -f1)
|
||||||
NAME=$(echo "$REPO" | cut -d'/' -f2)
|
NAME=$(echo "$REPO" | cut -d'/' -f2)
|
||||||
echo "Labeling PR #$PR_NUMBER on $OWNER/$NAME with 'automerge'"
|
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?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 \
|
||||||
|
-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 "Labeling PR #$PR_NUMBER with id $LID"
|
||||||
curl -sS -X POST \
|
curl -sS -X POST \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-H "Authorization: token ${CI_TOKEN}" \
|
-H "Authorization: token ${CI_TOKEN}" \
|
||||||
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/issues/${PR_NUMBER}/labels" \
|
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/issues/${PR_NUMBER}/labels" \
|
||||||
-d '["automerge"]' || true
|
-d '{"labels":['"${LID}"']}' || true
|
||||||
|
|||||||
@@ -55,12 +55,29 @@ jobs:
|
|||||||
done
|
done
|
||||||
|
|
||||||
if [ -n "${PR_NUMBER:-}" ]; then
|
if [ -n "${PR_NUMBER:-}" ]; then
|
||||||
echo "Adding 'automerge' label to PR #$PR_NUMBER"
|
echo "Resolving label id for 'automerge' in $OWNER/$NAME"
|
||||||
curl -sS -X POST \
|
curl -sS -o /tmp/labels.json -H "Authorization: token ${CI_TOKEN}" \
|
||||||
-H "Content-Type: application/json" \
|
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/labels"
|
||||||
-H "Authorization: token ${CI_TOKEN}" \
|
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}/issues/${PR_NUMBER}/labels" \
|
if [ -z "${LID:-}" ]; then
|
||||||
-d '["automerge"]' || true
|
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
|
||||||
|
if [ -n "${LID:-}" ]; then
|
||||||
|
echo "Adding 'automerge' (id=$LID) label to PR #$PR_NUMBER"
|
||||||
|
curl -sS -X POST \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "Authorization: token ${CI_TOKEN}" \
|
||||||
|
"${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"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "PR number could not be determined after retries; skipping label add"
|
echo "PR number could not be determined; skipping label add"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user