-
-
Notifications
You must be signed in to change notification settings - Fork 690
103 lines (90 loc) · 4.01 KB
/
notify-triager.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
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
name: Notify Triagers
on:
pull_request_target:
types: [opened, reopened, synchronize, edited, ready_for_review]
jobs:
Notify-triagers:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/[email protected]
with:
fetch-depth: 0
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.sha }}
- name: Get commit message
id: commit-message
run: |
# Extract the commit message
commit_message=$(git log --format=%B -n 1 ${{ github.event.pull_request.head.sha }})
commit_message=$(echo "$commit_message" | tr '\n' ' ')
commit_message=$(echo "$commit_message" | sed 's/[<>|]//g' | sed 's/[][]//g' | sed 's/(//g' | sed 's/)//g' | xargs)
echo "commit_message=$commit_message" >> $GITHUB_OUTPUT
- name: Check if last commit is a merge commit
id: check-merge-branch
run: |
if [[ "${{ steps.commit-message.outputs.commit_message }}" == *"Merge branch"* ]]; then
echo "Last commit is a merge commit"
echo "isMergeCommit=true" >> $GITHUB_OUTPUT
else
echo "Last commit message does not contain Merge branch"
echo "isMergeCommit=false" >> $GITHUB_OUTPUT
fi
- name: Count changed files
id: changed_files
run: |
# Get the list of files changed in the latest commit
changed_files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }})
# Initialize counters
md_count=0
non_md_count=0
# Count .md files
md_count=$(echo "$changed_files" | grep -c '\.md$' || true)
# Count non-.md files
non_md_count=$(echo "$changed_files" | grep -vc '\.md$' || true)
echo "md_count=$md_count" >> $GITHUB_OUTPUT
echo "non_md_count=$non_md_count" >> $GITHUB_OUTPUT
- name: Extract Doc Triage Maintainers
id: doc-triager
run: |
docTriagers=$(grep '^#' CODEOWNERS | tail -n 2 | head -n 1)
echo "docTriagers: $docTriagers"
prefix="#docTriagers: "
docTriagers=${docTriagers#$prefix}
echo "docTriagers=$docTriagers" >> $GITHUB_ENV
- name: Extract Code Triage Maintainers
id: code-triager
run: |
codeTriagers=$(grep '^#' CODEOWNERS | tail -n 1)
echo "codeTriagers: $codeTriagers"
prefix="#codeTriagers: "
codeTriagers=${codeTriagers#$prefix}
echo "codeTriagers=$codeTriagers" >> $GITHUB_ENV
- name: Add Reviewers for code files
if: ${{ steps.check-merge-branch.outputs.isMergeCommit == 'false' && steps.changed_files.outputs.non_md_count > 0 }}
run: |
IFS=' ' read -r -a codeTriagers <<< "${{ env.codeTriagers }}"
reviewers=$(printf ', "%s"' "${codeTriagers[@]}")
reviewers=[${reviewers:2}]
curl \
-X POST \
-H "Authorization: token ${{ secrets.GH_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/requested_reviewers \
-d "{
\"reviewers\": $reviewers
}"
- name: Add Reviewers for doc files
if: ${{ steps.check-merge-branch.outputs.isMergeCommit == 'false' && steps.changed_files.outputs.md_count > 0 }}
run: |
IFS=' ' read -r -a docTriagers <<< "${{ env.docTriagers }}"
reviewers=$(printf ', "%s"' "${docTriagers[@]}")
reviewers=[${reviewers:2}]
curl \
-X POST \
-H "Authorization: token ${{ secrets.GH_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/requested_reviewers \
-d "{
\"reviewers\": $reviewers
}"