-
Notifications
You must be signed in to change notification settings - Fork 0
73 lines (67 loc) ยท 2.9 KB
/
slack-notification.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
name: Slack Notification
on:
pull_request:
types: [opened, ready_for_review]
issue_comment:
types: [created, edited]
jobs:
send_slack_notification:
name: Send Slack Notification
runs-on: ubuntu-latest
steps:
- name: Send Slack Notification for PR creation
if: github.event_name == 'pull_request' && github.event.pull_request.draft == false
uses: 8398a7/action-slack@v3
with:
status: custom
fields: author,pullRequest
custom_payload: |
{
attachments: [{
color: '${{ job.status }}' === 'success' ? 'good' : '${{ job.status }}' === 'failure' ? 'danger' : 'warning',
text: `Actor: ${process.env.AS_AUTHOR}
PR: ${process.env.AS_PULL_REQUEST}`,
}]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
- name: Extract mentions from comment body
id: extract_mentions_comment
if: github.event_name == 'issue_comment'
run: |
mentions=$(echo "${{ github.event.comment.body }}" | grep -o '@[[:alnum:]_-]\+' | paste -sd ' ' -)
echo "::set-output name=mentions::$mentions"
- name: Map GitHub mentions to Slack user IDs
id: map_to_slack_ids
if: github.event_name == 'issue_comment'
run: |
declare -A slack_ids
slack_ids=(["@Doeunnkimm"]="U07600UQG3T" ["@semnil5202"]="U075KR29RGR" ["@Andrevile"]="U07545VMS21" ["@LeeJeongHooo"]="U075C1A16LT")
mentions="${{ steps.extract_mentions_comment.outputs.mentions }}"
slack_mentions=""
for mention in $mentions; do
if [[ -n "${slack_ids[$mention]}" ]]; then
slack_mentions="$slack_mentions <@${slack_ids[$mention]}>"
fi
done
echo "::set-output name=slack_mentions::$slack_mentions"
- name: Send Slack Notification for comment if team members mentioned
if: ${{ github.event_name == 'issue_comment' && steps.map_to_slack_ids.outputs.slack_mentions != '' }}
uses: 8398a7/action-slack@v3
with:
status: custom
fields: pullRequest
custom_payload: |
{
attachments: [{
color: '${{ job.status }}' === 'success' ? 'good' : '${{ job.status }}' === 'failure' ? 'danger' : 'warning',
text: `${process.env.AS_PULL_REQUEST}์์ ${{ steps.map_to_slack_ids.outputs.slack_mentions }} ๋์ ์ธ๊ธํ์ต๋๋ค.
๊ผญ ๋์ค์ ๋ค์ด๊ฐ์ ํ์ธํ๊ธฐ!
๋ฉ์์ง: ${{ github.event.comment.body }}`,
}]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
- name: Debug mentions
if: ${{ github.event_name == 'issue_comment' && steps.map_to_slack_ids.outputs.slack_mentions == '' }}
run: echo "No team members mentioned in the comment."