Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cd8ae32203 | |||
| 7b36e14b65 | |||
| 3d2f1dc8d4 | |||
| a957401a59 | |||
| 9cc5db5d28 | |||
| 16da17e533 | |||
| 8205215c17 | |||
| 36514286aa | |||
| cc271abedb | |||
| 8297002dc5 | |||
| 25ed57da53 | |||
| 90e410f49e | |||
| 14a3d32480 | |||
| 19b8becc30 |
@@ -0,0 +1,44 @@
|
|||||||
|
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 "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 \
|
||||||
|
-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
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
name: Auto PR
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- 'feat/**'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
open-pr:
|
||||||
|
runs-on: [macos, host]
|
||||||
|
steps:
|
||||||
|
- name: Create Pull Request via Gitea API
|
||||||
|
env:
|
||||||
|
CI_TOKEN: ${{ secrets.CI_TOKEN }}
|
||||||
|
GITEA_BASE_URL: https://gitea.jaybe.dev
|
||||||
|
REPO: ${{ github.repository }}
|
||||||
|
HEAD_BRANCH: ${{ github.ref_name }}
|
||||||
|
BASE_BRANCH: main
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
if [ -z "${CI_TOKEN:-}" ]; then
|
||||||
|
echo "GITEA_TOKEN not set; skipping auto-pr"; exit 0; fi
|
||||||
|
OWNER=$(echo "$REPO" | cut -d'/' -f1)
|
||||||
|
NAME=$(echo "$REPO" | cut -d'/' -f2)
|
||||||
|
TITLE="auto: PR for $HEAD_BRANCH"
|
||||||
|
BODY="Automated PR created on push to $HEAD_BRANCH"
|
||||||
|
echo "Creating PR $HEAD_BRANCH -> $BASE_BRANCH for $OWNER/$NAME"
|
||||||
|
HTTP_CODE=$(curl -sS -o /tmp/pr_resp.json -w "%{http_code}" -X POST \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "Authorization: token ${CI_TOKEN}" \
|
||||||
|
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/pulls" \
|
||||||
|
-d "{\"head\":\"${HEAD_BRANCH}\",\"base\":\"${BASE_BRANCH}\",\"title\":\"${TITLE}\",\"body\":\"${BODY}\"}") || true
|
||||||
|
echo "API status: $HTTP_CODE"
|
||||||
|
if [ "$HTTP_CODE" = "201" ]; then
|
||||||
|
echo "PR created"; cat /tmp/pr_resp.json
|
||||||
|
PR_NUMBER=$(cat /tmp/pr_resp.json | sed -n 's/.*"number":\([0-9]*\).*/\1/p' | head -n1)
|
||||||
|
else
|
||||||
|
echo "PR not created (possibly exists). Response:"; cat /tmp/pr_resp.json || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Retry to resolve PR number by listing open PRs and matching head/base
|
||||||
|
i=0
|
||||||
|
while [ -z "${PR_NUMBER:-}" ] && [ $i -lt 10 ]; do
|
||||||
|
i=$((i+1))
|
||||||
|
echo "[retry $i] Resolving PR number for $HEAD_BRANCH -> $BASE_BRANCH"
|
||||||
|
curl -sS -o /tmp/pr_list.json -H "Authorization: token ${CI_TOKEN}" \
|
||||||
|
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/pulls?state=open" || true
|
||||||
|
# Extract PR number matching head.ref==HEAD_BRANCH and base.ref==BASE_BRANCH
|
||||||
|
PR_NUMBER=$(awk -v hb="$HEAD_BRANCH" -v bb="$BASE_BRANCH" 'BEGIN{RS="},"; pr=""} {
|
||||||
|
if($0 ~ /\"head\":\{[^}]*\"ref\":\"" hb "\"/ && $0 ~ /\"base\":\{[^}]*\"ref\":\"" bb "\"/){
|
||||||
|
if (match($0, /\"number\":([0-9]+)/, m)) { print m[1]; exit }
|
||||||
|
}
|
||||||
|
}' /tmp/pr_list.json)
|
||||||
|
if [ -z "${PR_NUMBER:-}" ]; then sleep 2; fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -n "${PR_NUMBER:-}" ]; then
|
||||||
|
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)
|
||||||
|
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
|
||||||
|
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
|
||||||
|
echo "PR number could not be determined; skipping label add"
|
||||||
|
fi
|
||||||
@@ -42,3 +42,41 @@ jobs:
|
|||||||
path: playwright-report
|
path: playwright-report
|
||||||
if-no-files-found: ignore
|
if-no-files-found: ignore
|
||||||
retention-days: 3
|
retention-days: 3
|
||||||
|
|
||||||
|
- name: Auto-merge PR on green
|
||||||
|
if: ${{ github.event_name == 'pull_request' }}
|
||||||
|
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 auto-merge"; exit 0; fi
|
||||||
|
OWNER=$(echo "$REPO" | cut -d'/' -f1)
|
||||||
|
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"
|
||||||
|
HTTP_CODE=$(curl -sS -o /tmp/merge_resp.json -w "%{http_code}" -X POST \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "Authorization: token ${CI_TOKEN}" \
|
||||||
|
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/pulls/${PR_NUMBER}/merge" \
|
||||||
|
-d '{"Do":"merge","MergeMessage":"auto-merge: CI green"}' || true)
|
||||||
|
echo "merge http: $HTTP_CODE"
|
||||||
|
echo "merge resp:"; cat /tmp/merge_resp.json || true
|
||||||
|
|||||||
Reference in New Issue
Block a user