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