forked from lf-edge/eve
-
Notifications
You must be signed in to change notification settings - Fork 0
54 lines (51 loc) · 2.21 KB
/
request_codeowners_review.yml
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
---
name: Request Code Owners Review
on:
pull_request:
types: ["opened", "synchronize"]
jobs:
auto_request_review:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: ${{ github.event.pull_request.commits + 1 }}
- name: Auto request review
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
reviewers=""
# Get changed files in this pull request
echo "Checking base: ${{ github.event.pull_request.base.sha }}"
echo "Checking head: ${{ github.event.pull_request.head.sha }}"
for changed_file in $(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }}); do
echo "Checking $changed_file"
while read -r line; do
# Get pattern of the files owned
pattern=$(echo "$line" | awk '{print $1}')
# Remove leading / from pattern and changed_file for comparison
pattern="${pattern#/}"
# Get owners of the files owned
owners=$(echo "$line" | awk '{$1=""; print $0}' | xargs)
# Remove leading / from changed_file for comparison
changed_file="${changed_file#/}"
if [[ "$changed_file" == $pattern* ]]; then
# Add owners to reviewers
echo "Found owners for $changed_file: $owners"
reviewers="$reviewers $owners"
fi
done < .github/CODEOWNERS
done
# Remove duplicates
reviewers=$(echo "$reviewers" | xargs -n1 | sort -u | xargs)
if [ -n "$reviewers" ]; then
# Remove @ from reviewers (it stays in the beginning of the username)
reviewers_cleaned=${reviewers//@/}
# Convert reviewers to comma separated list
reviewers_comma_separated=$(echo "$reviewers_cleaned" | tr ' ' ',')
echo "Requesting review from: $reviewers_comma_separated"
gh pr edit ${{ github.event.pull_request.number }} --add-reviewer $reviewers_comma_separated
else
echo "No reviewers found for the changed files."
fi