|
| 1 | +name: PR Automation |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, reopened] |
| 6 | + |
| 7 | +permissions: |
| 8 | + pull-requests: write |
| 9 | + contents: read |
| 10 | + |
| 11 | +jobs: |
| 12 | + pr-automation: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Checkout |
| 16 | + uses: actions/checkout@v4 |
| 17 | + |
| 18 | + - name: Get changed files |
| 19 | + id: changed-files |
| 20 | + run: | |
| 21 | + # Get list of changed files |
| 22 | + FILES=$(gh pr diff "$PR_NUMBER" --name-only) |
| 23 | + echo "files<<EOF" >> $GITHUB_OUTPUT |
| 24 | + echo "$FILES" >> $GITHUB_OUTPUT |
| 25 | + echo "EOF" >> $GITHUB_OUTPUT |
| 26 | + env: |
| 27 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 28 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 29 | + |
| 30 | + - name: Auto-label based on files |
| 31 | + run: | |
| 32 | + PR_NUMBER=${{ github.event.pull_request.number }} |
| 33 | + FILES="${{ steps.changed-files.outputs.files }}" |
| 34 | +
|
| 35 | + # Area labels based on file paths |
| 36 | + if echo "$FILES" | grep -q "^src/api/\|^api/"; then |
| 37 | + gh pr edit "$PR_NUMBER" --add-label "area:api" |
| 38 | + fi |
| 39 | +
|
| 40 | + if echo "$FILES" | grep -q "^src/frontend/\|^components/\|^ui/"; then |
| 41 | + gh pr edit "$PR_NUMBER" --add-label "area:frontend" |
| 42 | + fi |
| 43 | +
|
| 44 | + if echo "$FILES" | grep -q "^src/backend/\|^server/"; then |
| 45 | + gh pr edit "$PR_NUMBER" --add-label "area:backend" |
| 46 | + fi |
| 47 | +
|
| 48 | + if echo "$FILES" | grep -q "^docs/\|\.md$"; then |
| 49 | + gh pr edit "$PR_NUMBER" --add-label "area:docs" |
| 50 | + fi |
| 51 | +
|
| 52 | + if echo "$FILES" | grep -q "^tests/\|^test/"; then |
| 53 | + gh pr edit "$PR_NUMBER" --add-label "area:tests" |
| 54 | + fi |
| 55 | +
|
| 56 | + # Check for breaking changes in commits |
| 57 | + COMMITS=$(gh api repos/${{ github.repository }}/pulls/$PR_NUMBER/commits --jq '.[].commit.message' | grep -i "BREAKING CHANGE" || true) |
| 58 | + if [ -n "$COMMITS" ]; then |
| 59 | + gh pr edit "$PR_NUMBER" --add-label "type:breaking" |
| 60 | + fi |
| 61 | +
|
| 62 | + # Documentation only |
| 63 | + if echo "$FILES" | grep -v "^docs/\|\.md$" | grep -q .; then |
| 64 | + : |
| 65 | + else |
| 66 | + gh pr edit "$PR_NUMBER" --add-label "documentation" |
| 67 | + fi |
| 68 | + env: |
| 69 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 70 | + |
| 71 | + - name: Auto-assign reviewers based on files |
| 72 | + run: | |
| 73 | + PR_NUMBER=${{ github.event.pull_request.number }} |
| 74 | + FILES="${{ steps.changed-files.outputs.files }}" |
| 75 | +
|
| 76 | + # Assign reviewers based on code areas |
| 77 | + if echo "$FILES" | grep -q "^src/frontend/\|^components/\|^ui/"; then |
| 78 | + gh pr edit "$PR_NUMBER" --add-reviewer "frontend-team" || true |
| 79 | + fi |
| 80 | +
|
| 81 | + if echo "$FILES" | grep -q "^src/backend/\|^server/"; then |
| 82 | + gh pr edit "$PR_NUMBER" --add-reviewer "backend-team" || true |
| 83 | + fi |
| 84 | +
|
| 85 | + if echo "$FILES" | grep -q "^src/api/\|^api/"; then |
| 86 | + gh pr edit "$PR_NUMBER" --add-reviewer "api-team" || true |
| 87 | + fi |
| 88 | +
|
| 89 | + if echo "$FILES" | grep -q "^infra/\|^deploy/\|^\.github/"; then |
| 90 | + gh pr edit "$PR_NUMBER" --add-reviewer "devops-team" || true |
| 91 | + fi |
| 92 | + env: |
| 93 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 94 | + |
| 95 | + - name: Welcome first-time contributors |
| 96 | + run: | |
| 97 | + PR_NUMBER=${{ github.event.pull_request.number }} |
| 98 | + AUTHOR=${{ github.event.pull_request.user.login }} |
| 99 | +
|
| 100 | + # Check if this is the author's first PR |
| 101 | + PR_COUNT=$(gh pr list --author "$AUTHOR" --state all --limit 1 --json number --jq 'length') |
| 102 | +
|
| 103 | + if [ "$PR_COUNT" -eq 1 ]; then |
| 104 | + gh pr edit "$PR_NUMBER" --add-label "first-time-contributor" |
| 105 | +
|
| 106 | + gh pr comment "$PR_NUMBER" --body '## Welcome! 👋 |
| 107 | +
|
| 108 | + Thank you for your first contribution to this project! We appreciate you taking the time to improve our codebase. |
| 109 | +
|
| 110 | + ### Next Steps |
| 111 | + - A maintainer will review your PR shortly |
| 112 | + - Please check for any review comments and address them |
| 113 | + - Feel free to ask questions if anything is unclear |
| 114 | +
|
| 115 | + ### Contribution Guidelines |
| 116 | + - Ensure all tests pass |
| 117 | + - Update documentation if needed |
| 118 | + - Keep changes focused and atomic |
| 119 | +
|
| 120 | + Thanks again for contributing! 🎉' |
| 121 | + fi |
| 122 | + env: |
| 123 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments