Files

189 lines
8.4 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: ⚡ Senpai YOLO — Jules Auto-Accept & Conflict Resolver
on:
pull_request_target:
types: [opened, synchronize, reopened, ready_for_review]
jobs:
auto-merge:
name: 🤖 Jules PR Otomatik Kabul
# Jules'dan gelen tüm PR'ları (ve diğerlerini) yakala
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
issues: write
steps:
- name: 🔑 Jules Token ile Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: 📦 Araçları Kur
run: |
sudo apt-get update -qq
sudo apt-get install -y jq
- name: 🔍 PR Bilgilerini Al
id: pr-info
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
run: |
PR_DATA=$(gh pr view "$PR_NUMBER" --repo "$REPO" \
--json mergeable,isDraft,mergeStateStatus,author,title 2>/dev/null || echo '{}')
MERGEABLE=$(echo "$PR_DATA" | jq -r '.mergeable // "UNKNOWN"')
IS_DRAFT=$(echo "$PR_DATA" | jq -r '.isDraft // false')
STATE=$(echo "$PR_DATA" | jq -r '.mergeStateStatus // "UNKNOWN"')
AUTHOR=$(echo "$PR_DATA" | jq -r '.author.login // "unknown"')
echo "mergeable=$MERGEABLE" >> $GITHUB_OUTPUT
echo "is_draft=$IS_DRAFT" >> $GITHUB_OUTPUT
echo "state=$STATE" >> $GITHUB_OUTPUT
echo "author=$AUTHOR" >> $GITHUB_OUTPUT
echo "PR #$PR_NUMBER — mergeable=$MERGEABLE state=$STATE draft=$IS_DRAFT author=$AUTHOR"
# UNKNOWN ise 10 sn bekle, tekrar dene
if [ "$MERGEABLE" = "UNKNOWN" ]; then
sleep 10
PR_DATA2=$(gh pr view "$PR_NUMBER" --repo "$REPO" \
--json mergeable,mergeStateStatus 2>/dev/null || echo '{}')
MERGEABLE=$(echo "$PR_DATA2" | jq -r '.mergeable // "UNKNOWN"')
STATE=$(echo "$PR_DATA2" | jq -r '.mergeStateStatus // "UNKNOWN"')
echo "mergeable=$MERGEABLE" >> $GITHUB_OUTPUT
echo "state=$STATE" >> $GITHUB_OUTPUT
echo "Yeniden kontrol: mergeable=$MERGEABLE state=$STATE"
fi
- name: 📝 Draft'tan Çıkar
if: steps.pr-info.outputs.is_draft == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
run: |
echo "PR draft modunda, ready for review yapılıyor..."
gh pr ready "$PR_NUMBER" --repo "$REPO"
sleep 3
- name: ✅ Temiz Merge
if: steps.pr-info.outputs.mergeable == 'MERGEABLE'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
run: |
echo "Conflict yok — doğrudan approve + squash merge yapılıyor."
gh pr review "$PR_NUMBER" --repo "$REPO" --approve \
--body "🤖 Senpai onayladı! Çakışma yok, merge ediliyor. 🚀"
sleep 2
gh pr merge "$PR_NUMBER" --repo "$REPO" --squash --delete-branch
echo "✅ Merge tamamlandı."
- name: 🔧 Akıllı Conflict Çözümü
if: steps.pr-info.outputs.mergeable == 'CONFLICTING' || steps.pr-info.outputs.state == 'DIRTY'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
JULES_TOKEN: ${{ env.JULES_API_KEY }}
PR_NUMBER: ${{ github.event.pull_request.number }}
HEAD_REF: ${{ github.event.pull_request.head.ref }}
BASE_REF: ${{ github.event.pull_request.base.ref }}
REPO: ${{ github.repository }}
run: |
echo "Conflict tespit edildi — akıllı çözüm başlıyor..."
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "Senpai-YoloBot"
git remote set-url origin "https://x-access-token:${JULES_TOKEN}@github.com/${REPO}.git"
git fetch origin --prune
git fetch origin "$BASE_REF" 2>/dev/null || true
git fetch origin "$HEAD_REF" 2>/dev/null || \
git fetch origin "refs/pull/${PR_NUMBER}/head:refs/remotes/origin/pr/${PR_NUMBER}"
git checkout -B "$HEAD_REF" "origin/$HEAD_REF" 2>/dev/null || \
git checkout -B "$HEAD_REF" "refs/remotes/origin/pr/${PR_NUMBER}"
# main'i merge et (conflict'leri manuel çözeceğiz)
git merge "origin/$BASE_REF" --no-edit 2>&1 || true
CONFLICTS=$(git diff --name-only --diff-filter=U 2>/dev/null || echo "")
echo "Conflict'li dosyalar: $CONFLICTS"
if [ -n "$CONFLICTS" ]; then
while IFS= read -r file; do
[ -z "$file" ] && continue
if [[ "$file" == .jules/* ]]; then
# Jules dokümantasyon dosyaları → main'deki versiyonu koru
echo " [theirs] $file (.jules doc)"
git checkout --theirs -- "$file"
elif [[ "$file" == "core/storage.py" ]] || \
[[ "$file" == "apps/watchparty/views.py" ]]; then
# Bu dosyalar main'de zaten daha iyi versiyona sahip
echo " [theirs] $file (main versiyonu korunuyor)"
git checkout --theirs -- "$file"
else
# Tüm diğer kod dosyaları → PR'ın yeni kodunu koru
echo " [ours] $file (PR kodu korunuyor)"
git checkout --ours -- "$file"
fi
git add -- "$file"
done <<< "$CONFLICTS"
git commit --no-edit -m "🤖 Senpai: Resolve conflicts for PR #${PR_NUMBER} [skip ci]"
fi
git push --force-with-lease origin "HEAD:$HEAD_REF" || \
git push --force origin "HEAD:$HEAD_REF"
echo "Push tamamlandı. Merge bekleniyor..."
sleep 15
NEW_MERGEABLE=$(gh pr view "$PR_NUMBER" --repo "$REPO" \
--json mergeable -q '.mergeable // "UNKNOWN"' 2>/dev/null)
echo "Merge durumu: $NEW_MERGEABLE"
if [ "$NEW_MERGEABLE" = "MERGEABLE" ]; then
gh pr review "$PR_NUMBER" --repo "$REPO" --approve \
--body "🤖 Senpai çakışmayı çözdü! \`.jules/*.md\` → main korundu, kod değişiklikleri uygulandı. 🚀"
sleep 3
gh pr merge "$PR_NUMBER" --repo "$REPO" --squash --delete-branch
echo "✅ Conflict çözüldü ve merge edildi."
else
echo "Hâlâ merge edilemiyor, 20 sn daha bekleniyor..."
sleep 20
FINAL=$(gh pr view "$PR_NUMBER" --repo "$REPO" \
--json mergeable -q '.mergeable // "UNKNOWN"' 2>/dev/null)
if [ "$FINAL" = "MERGEABLE" ]; then
gh pr review "$PR_NUMBER" --repo "$REPO" --approve \
--body "🤖 Senpai geç onayladı — merge ediliyor! 🚀"
sleep 2
gh pr merge "$PR_NUMBER" --repo "$REPO" --squash --delete-branch
echo "✅ Gecikmeli merge tamamlandı."
else
gh pr comment "$PR_NUMBER" --repo "$REPO" \
--body "🚫 Otomatik çözüm başarısız. Durum: \`$FINAL\`. Manuel inceleme gerekli [@barkeser2002](https://github.com/barkeser2002)." || true
echo "❌ Manuel müdahale gerekiyor."
fi
fi
- name: ⏳ Bilinmeyen Durum — Bekle ve Dene
if: steps.pr-info.outputs.mergeable == 'UNKNOWN' && steps.pr-info.outputs.state != 'DIRTY'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
run: |
echo "Durum belirsiz, 30 sn bekleniyor..."
sleep 30
RETRY=$(gh pr view "$PR_NUMBER" --repo "$REPO" \
--json mergeable -q '.mergeable // "UNKNOWN"' 2>/dev/null)
echo "Yeniden kontrol: $RETRY"
if [ "$RETRY" = "MERGEABLE" ]; then
gh pr review "$PR_NUMBER" --repo "$REPO" --approve \
--body "🤖 Senpai bekleyip onayladı — merge! 🚀"
sleep 2
gh pr merge "$PR_NUMBER" --repo "$REPO" --squash --delete-branch
echo "✅ Beklemeli merge tamamlandı."
else
echo "ℹ️ PR hâlâ hazır değil ($RETRY). Sonraki tetiklemede tekrar denenecek."
fi