Files
xiaoxia-saas/scripts/auto_merge_prs.sh
T
CI Bot d6a30bd4eb
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Has been cancelled
CI/CD Pipeline / Frontend Lint (pull_request) Has been cancelled
feat: add auto-merge scripts and CI failure notification
- Auto merge script for PRs targeting develop/main
- CI failure check script
- Gitea Actions workflow for scheduled auto-merge
- Cron jobs for periodic execution
2026-06-27 00:42:05 +08:00

44 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
# 自动合并通过 CI 检查的 PR
# 用法: ./scripts/auto_merge_prs.sh [target_branch]
GITEA_API="https://git.xiaoxiajianji.com/api/v1"
TOKEN="1f8058d097e3942a9ed31c44382baf7f08311272"
REPO="xiaoxia/xiaoxia-saas"
TARGET_BRANCH="${1:-develop}"
echo "=== Checking open PRs targeting $TARGET_BRANCH ==="
# 获取所有 open PR
PRS=$(curl -s -H "Authorization: token $TOKEN" \
"$GITEA_API/repos/$REPO/pulls?state=open&labels=0" | python3 -c "
import json, sys
data = json.load(sys.stdin)
for pr in data:
if pr.get('base', {}).get('ref') == '$TARGET_BRANCH':
if pr.get('mergeable', False):
print(f\"{pr['number']}|{pr['title']}|{pr.get('mergeable', 'unknown')}\")
")
if [ -z "$PRS" ]; then
echo "No mergeable PRs found for $TARGET_BRANCH"
exit 0
fi
echo "$PRS" | while IFS='|' read -r number title mergeable; do
echo "Merging PR #$number: $title"
RESULT=$(curl -s -X POST \
-H "Authorization: token $TOKEN" \
-H "Content-Type: application/json" \
"$GITEA_API/repos/$REPO/pulls/$number/merge" \
-d '{\"merge_method\": \"merge\"}')
if echo "$RESULT" | python3 -c "import json,sys; d=json.load(sys.stdin); sys.exit(0 if 'id' in d else 1)"; then
echo " ✅ PR #$number merged successfully"
else
echo " ❌ PR #$number failed: $RESULT"
fi
done
echo "=== Done ==="