Comment · PR merge conflict help #15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: 🤖 PR Automation | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| schedule: | |
| - cron: '0 * * * *' # Run every hour to catch any missed PRs | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| issues: write | |
| jobs: | |
| process-pr: | |
| runs-on: ubuntu-latest | |
| if: github.repository == 'fineanmol/Hacktoberfest2025' | |
| steps: | |
| - name: 🔄 Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: 📋 Get PR information | |
| id: pr-info | |
| run: | | |
| # For pull_request events, use the event PR number | |
| if [ "${{ github.event_name }}" = "pull_request" ]; then | |
| pr_number="${{ github.event.pull_request.number }}" | |
| gh pr view $pr_number --json number,title,author,mergeable,files > pr.json | |
| else | |
| # For scheduled/manual runs, process all open PRs | |
| gh pr list --state open --json number,title,author,mergeable,files --limit 100 > prs.json | |
| fi | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: 🔍 Process PRs | |
| run: | | |
| # If we have a single PR (from event), wrap it in an array | |
| if [ -f pr.json ]; then | |
| jq -s '.' pr.json > prs.json | |
| fi | |
| cat prs.json | jq -r '.[] | @base64' | while IFS= read -r pr_data; do | |
| if [ -z "$pr_data" ]; then | |
| continue | |
| fi | |
| pr=$(echo "$pr_data" | base64 --decode) | |
| pr_number=$(echo "$pr" | jq -r '.number') | |
| pr_title=$(echo "$pr" | jq -r '.title') | |
| pr_author=$(echo "$pr" | jq -r '.author.login') | |
| pr_mergeable=$(echo "$pr" | jq -r '.mergeable') | |
| echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" | |
| echo "🔄 Processing PR #$pr_number by @$pr_author" | |
| echo "📝 Title: $pr_title" | |
| echo "🔀 Mergeable: $pr_mergeable" | |
| # Get files changed in this PR | |
| files_changed=$(echo "$pr" | jq -r '.files[].path') | |
| # Check if only contributors file is modified | |
| contributors_only=false | |
| other_files_count=0 | |
| contributors_modified=false | |
| while IFS= read -r file; do | |
| if [ -n "$file" ]; then | |
| if [ "$file" = "contributors/contributorsList.js" ]; then | |
| contributors_modified=true | |
| else | |
| other_files_count=$((other_files_count + 1)) | |
| fi | |
| fi | |
| done <<< "$files_changed" | |
| if [ "$contributors_modified" = "true" ] && [ "$other_files_count" = "0" ]; then | |
| contributors_only=true | |
| fi | |
| echo "📁 Files changed: $(echo "$files_changed" | wc -l)" | |
| echo "👥 Contributors file: $contributors_modified" | |
| echo "📄 Other files: $other_files_count" | |
| echo "🎯 Contributors only: $contributors_only" | |
| # Decision logic: SINGLE SOURCE OF TRUTH | |
| if [ "$contributors_only" = "true" ]; then | |
| echo "" | |
| echo "🎉 CLOSING contributor-only PR #$pr_number" | |
| gh pr close "$pr_number" --comment "🎉 Thank you for your contribution to Hacktoberfest 2025! Your changes have been noted. ✅ You're officially part of Hacktoberfest 2025! This PR was automatically closed because it only modifies the contributors list. We're managing contributor additions through automated merges to avoid conflicts. Thank you @$pr_author for participating in open source! 🚀 #Hacktoberfest #OpenSource" || echo "Failed to close PR #$pr_number" | |
| elif [ "$pr_mergeable" = "MERGEABLE" ]; then | |
| echo "" | |
| echo "✅ AUTO-MERGING valuable PR #$pr_number" | |
| if gh pr merge "$pr_number" --merge --delete-branch; then | |
| echo "✅ Successfully merged PR #$pr_number" | |
| gh pr comment "$pr_number" --body "🎉 Automatically Merged! Thank you @$pr_author for your valuable contribution! ✅ No conflicts detected. 🚀 Your changes are now live! #Hacktoberfest #OpenSource" || echo "Comment failed but PR merged" | |
| else | |
| echo "❌ Failed to merge PR #$pr_number" | |
| fi | |
| elif [ "$pr_mergeable" = "CONFLICTING" ]; then | |
| echo "" | |
| echo "⚠️ PR #$pr_number has CONFLICTS" | |
| gh pr comment "$pr_number" --body "🔧 Merge Conflicts Detected - This PR has merge conflicts that need manual resolution. To fix: 1. Pull latest changes from master 2. Resolve conflicts in your local branch 3. Push updated branch. The PR will auto-merge once conflicts are resolved. Thank you! 🚀" || echo "Failed to comment on PR #$pr_number" | |
| else | |
| echo "" | |
| echo "👀 PR #$pr_number needs MANUAL REVIEW (status: $pr_mergeable)" | |
| gh pr comment "$pr_number" --body "👀 Manual Review Required - This PR is being reviewed manually to ensure quality and compatibility. A maintainer will review this soon. Thank you for your patience! 🚀" || echo "Failed to comment on PR #$pr_number" | |
| fi | |
| echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" | |
| echo "" | |
| sleep 2 # Rate limiting to avoid API throttling | |
| done | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: 📊 Summary | |
| run: | | |
| echo "✅ PR automation workflow completed!" | |
| contributor_count=$(grep -c "id:" contributors/contributorsList.js || echo "unknown") | |
| echo "📊 Total contributors in list: $contributor_count" | |