-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
108 lines (101 loc) · 3.56 KB
/
action.yml
File metadata and controls
108 lines (101 loc) · 3.56 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
name: Satel PR slack notifier
description: Notify devs on slack about the comments on their PR
inputs:
SLACK_API_TOKEN:
description: Slack token with permission users:read.email
required: true
SLACK_WEBHOOK_URL:
description: Webhook for the slack app
required: true
runs:
using: "composite"
steps:
- name: Check event type and set variables
id: check_event_type
run: |
event_type="${{ github.event_name }}"
if [ "$event_type" == "issue_comment" ]; then
issue_number="${{ github.event.issue.number }}"
event_name='issues'
username="${{ github.event.issue.user.login }}"
else
issue_number="${{ github.event.pull_request.number }}"
event_name='pulls'
username="${{ github.event.pull_request.user.login }}"
fi
echo "issue_number=$issue_number" >> $GITHUB_ENV
echo "event_name=$event_name" >> $GITHUB_ENV
echo "username=$username" >> $GITHUB_ENV
shell: bash
- name: Check for comment author
id: check_comment_author
run: |
last_comment_author=$(gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${{ github.repository }}/${{ env.event_name }}/${{ env.issue_number }}/comments" --jq '.[-1].user.login')
echo "last_comment_author=$last_comment_author" >> $GITHUB_ENV
if [ "${{ env.username }}" != "$last_comment_author" ]; then
echo "slack_trigger=true" >> $GITHUB_ENV
fi
env:
GH_TOKEN: ${{ github.token }}
shell: bash
- name: Find slack user email
if: env.slack_trigger == 'true'
id: find_slack_user_email
run: |
# Define mapping for frontend devs
declare -A mapping=(
[ZoeElizabeth]=zoe@satel.ca
[shallow-and-limited]=alex@satel.ca
[CaseyQWood]=casey@satel.ca
)
github_username="${{ env.username }}"
echo "github_username" $github_username
slack_user_email=${mapping[$github_username]:-Unknown}
echo "slack_user_email" $slack_user_email
if [ "$slack_user_email" != "Unknown" ]; then
echo "slack_user_email_found=true" >> $GITHUB_ENV
echo "slack_user_email=$slack_user_email" >> $GITHUB_ENV
fi
shell: bash
- name: Find Slack user based on the emails
if: env.slack_user_email_found == 'true'
id: find_slack_user
uses: scribd/find-slack-user-action@v1.0.4
with:
slack-token: ${{ inputs.SLACK_API_TOKEN }}
email: ${{ env.slack_user_email }}
include-at-symbol: true
- name: Get PR comment URL
if: env.slack_user_email_found == 'true'
id: get_comment
run: |
last_comment_url=$(gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${{ github.repository }}/${{ env.event_name }}/${{ env.issue_number }}/comments" --jq '.[-1].html_url')
echo "last_comment_url=$last_comment_url" >> $GITHUB_ENV
env:
GH_TOKEN: ${{ github.token }}
shell: bash
- name: Slack notification
if: env.slack_user_email_found == 'true'
uses: 8398a7/action-slack@v3
with:
status: custom
custom_payload: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Hi ${{ steps.find_slack_user.outputs.username }}, there's a comment on your PR. Please review it. Here's the <${{ env.last_comment_url }}|link>"
}
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ inputs.SLACK_WEBHOOK_URL }}