Skip to content

Commit df2e214

Browse files
committed
pr review
1 parent 39f18ee commit df2e214

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

.github/workflows/pr_review.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: PR Notifications
2+
3+
on:
4+
pull_request_target:
5+
branches: [main]
6+
types: [opened, synchronize, edited, reopened, ready_for_review]
7+
8+
permissions:
9+
contents: read
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
notify:
17+
runs-on: ubuntu-latest
18+
if: github.event.pull_request.draft != true
19+
steps:
20+
- shell: bash
21+
run: |
22+
BRANCH_URL="${{ github.event.pull_request.head.repo.html_url }}/tree/${{ github.event.pull_request.head.ref }}"
23+
24+
MM_USERS_JSON='${{ secrets.MM_USERS }}'
25+
PR_AUTHOR="${{ github.event.pull_request.user.login }}"
26+
PR_AUTHOR_MM=$(echo "$MM_USERS_JSON" | jq -r --arg author "$PR_AUTHOR" '.[$author]')
27+
28+
readarray -t USERS_ARRAY < <(echo "$MM_USERS_JSON" | jq -r --arg exclude "$PR_AUTHOR_MM" '.[] | select(. != $exclude and . != null and . != "")')
29+
30+
if [ ${#USERS_ARRAY[@]} -gt 0 ]; then
31+
RANDOM_REVIEWER=${USERS_ARRAY[$RANDOM % ${#USERS_ARRAY[@]}]}
32+
else
33+
RANDOM_REVIEWER="${{ secrets.DEFAULT_REVIEWER }}"
34+
fi
35+
36+
echo "::add-mask::$PR_AUTHOR_MM"
37+
echo "::add-mask::$USERS_ARRAY"
38+
echo "::add-mask::$MM_USERS_JSON"
39+
echo "::add-mask::$RANDOM_REVIEWER"
40+
41+
MESSAGE="MR [!${{ github.event.pull_request.number }}](${{ github.event.pull_request.html_url }})"
42+
MESSAGE+=" от [${{ github.event.pull_request.user.login }} ${USER_NAME}]"
43+
MESSAGE+="(${{ github.event.pull_request.user.html_url }})"
44+
MESSAGE+="(ветка: [${{ github.event.pull_request.head.ref }}](${BRANCH_URL})) готов на ревью.\n"
45+
MESSAGE+="Выбран ревьюер: @${RANDOM_REVIEWER}."
46+
47+
curl -X POST \
48+
-H "Content-Type: application/json" \
49+
-d "{\"text\": \"$MESSAGE\"}" \
50+
"${{ secrets.BUILD_CHAT_WEBHOOK }}"

0 commit comments

Comments
 (0)