Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a957401a59 | |||
| 9cc5db5d28 | |||
| 16da17e533 |
@@ -0,0 +1,28 @@
|
|||||||
|
name: Auto Label PR
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types: [opened, synchronize, reopened]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
add-automerge-label:
|
||||||
|
runs-on: [macos, host]
|
||||||
|
steps:
|
||||||
|
- name: Add 'automerge' label to PR
|
||||||
|
env:
|
||||||
|
CI_TOKEN: ${{ secrets.CI_TOKEN }}
|
||||||
|
GITEA_BASE_URL: https://gitea.jaybe.dev
|
||||||
|
PR_NUMBER: ${{ github.event.pull_request.number }}
|
||||||
|
REPO: ${{ github.repository }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
if [ -z "${CI_TOKEN:-}" ]; then
|
||||||
|
echo "CI_TOKEN not set; skipping labeling"; exit 0; fi
|
||||||
|
OWNER=$(echo "$REPO" | cut -d'/' -f1)
|
||||||
|
NAME=$(echo "$REPO" | cut -d'/' -f2)
|
||||||
|
echo "Labeling PR #$PR_NUMBER on $OWNER/$NAME with 'automerge'"
|
||||||
|
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 '["automerge"]' || true
|
||||||
+19
-2
@@ -56,10 +56,27 @@ jobs:
|
|||||||
echo "CI_TOKEN not set; skipping auto-merge"; exit 0; fi
|
echo "CI_TOKEN not set; skipping auto-merge"; 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 "Checking labels for PR #$PR_NUMBER on $OWNER/$NAME"
|
||||||
|
LABELS_JSON=$(curl -sS -X GET \
|
||||||
|
-H "Authorization: token ${CI_TOKEN}" \
|
||||||
|
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/issues/${PR_NUMBER}")
|
||||||
|
echo "labels payload (first 200 chars):"; echo "$LABELS_JSON" | cut -c1-200 || true
|
||||||
|
if ! echo "$LABELS_JSON" | grep -qi '"name":"automerge"'; then
|
||||||
|
echo "Label 'automerge' not present; skipping merge"; exit 0; fi
|
||||||
|
echo "Label 'automerge' present; proceeding to merge"
|
||||||
|
# ensure PR is open
|
||||||
|
PR_JSON=$(curl -sS -X GET \
|
||||||
|
-H "Authorization: token ${CI_TOKEN}" \
|
||||||
|
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/pulls/${PR_NUMBER}")
|
||||||
|
STATE=$(echo "$PR_JSON" | sed -n 's/.*"state":"\([^"]*\)".*/\1/p')
|
||||||
|
echo "PR state: ${STATE:-unknown}"
|
||||||
|
if [ "${STATE:-}" != "open" ]; then
|
||||||
|
echo "PR state is not open; skipping merge"; exit 0; fi
|
||||||
echo "Merging PR #$PR_NUMBER for $OWNER/$NAME"
|
echo "Merging PR #$PR_NUMBER for $OWNER/$NAME"
|
||||||
RESP=$(curl -sS -X POST \
|
HTTP_CODE=$(curl -sS -o /tmp/merge_resp.json -w "%{http_code}" -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}/pulls/${PR_NUMBER}/merge" \
|
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/pulls/${PR_NUMBER}/merge" \
|
||||||
-d '{"Do":"merge","MergeMessage":"auto-merge: CI green"}' || true)
|
-d '{"Do":"merge","MergeMessage":"auto-merge: CI green"}' || true)
|
||||||
echo "API response: $RESP"
|
echo "merge http: $HTTP_CODE"
|
||||||
|
echo "merge resp:"; cat /tmp/merge_resp.json || true
|
||||||
|
|||||||
Reference in New Issue
Block a user