-
Notifications
You must be signed in to change notification settings - Fork 20
51 lines (43 loc) · 2.16 KB
/
notification-code-review-completed.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
name: Code review completed
on:
pull_request_review:
types: [ submitted ]
jobs:
notify:
if: github.event.review.state == 'approved'
runs-on: ubuntu-latest
env:
TITLE: ${{ github.event.pull_request.title || 'Title pr' }}
URL: ${{ github.event.pull_request.html_url || 'https://github.com/salute-developers/plasma/pulls' }}
AUTHOR: ${{ github.event.pull_request.user.login || 'Yakutoc' }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Count approvals and author for pr
id: state
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = '.github/teammates.json';
const teammates = JSON.parse(fs.readFileSync(path, 'utf8'));
const teammatesGH = Object.keys(teammates);
const { data: reviews } = await github.rest.pulls.listReviews({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
});
const approvals = reviews
.filter(({ user: { login } }) => teammatesGH.includes(login))
.filter(({ state }) => state === 'APPROVED')
.length;
return { approved: approvals >= 2, author: teammates["${{ env.AUTHOR }}"] };
- name: Send notification
if: ${{ fromJSON(steps.state.outputs.result).approved }}
uses: mattermost/action-mattermost-notify@master
with:
MATTERMOST_WEBHOOK_URL: ${{ secrets.WEBHOOKS_NOTIFICATIONS_MM }}
TEXT: |
Code review пройдено ✅
**PR**: [${{ env.TITLE }}](${{ env.URL }})
**Автор**: @${{ fromJSON(steps.state.outputs.result).author }}