-
Notifications
You must be signed in to change notification settings - Fork 0
109 lines (97 loc) Β· 4.8 KB
/
slack-notify.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
104
105
106
107
108
109
name: Notify Slack on PR and Comment
on:
pull_request:
types: [opened, reopened, synchronize, review_requested]
issue_comment:
types: [created]
pull_request_review:
types: [submitted]
jobs:
notify:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Determine event type
id: determine_event
run: echo "event_type=${{ github.event_name }}" >> $GITHUB_ENV
- name: Read user mapping
id: read_mapping
run: |
mapping=$(cat .github/user-mapping.json)
echo "mapping=$mapping" >> $GITHUB_ENV
- name: Cache Slack message timestamp
if: ${{ env.event_type == 'pull_request' }}
uses: actions/cache@v2
with:
path: slack_ts.txt
key: slack-ts-${{ github.event.pull_request.number }}
- name: Send notification for PR
if: ${{ env.event_type == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'reopened' || github.event.action == 'synchronize') }}
id: slack_pr
run: |
response=$(curl -X POST -H 'Content-type: application/json' --data '{
"text": "π§ββοΈ PR λ리λ μ§λκ° μμ΅λλ€\n[sambad#${{ github.event.pull_request.number }}] [${{ github.event.pull_request.title }}](${{ github.event.pull_request.html_url }})\n${{ github.event.pull_request.user.login }}λμ΄ μμ±νμ΄μ."
}' ${{ secrets.SLACK_BOT_ACCESS_TOKEN }})
echo "slack_ts=$(echo $response | jq -r '.ts')" >> $GITHUB_ENV
echo $slack_ts > slack_ts.txt
env:
SLACK_BOT_ACCESS_TOKEN: ${{ secrets.SLACK_BOT_ACCESS_TOKEN }}
- name: Send notification for review request
if: ${{ env.event_type == 'pull_request' && github.event.action == 'review_requested' }}
run: |
reviewer=${{ github.event.requested_reviewer.login }}
slack_username=$(echo ${{ env.mapping }} | jq -r --arg reviewer "$reviewer" '.[$reviewer]')
if [ "$slack_username" != "null" ]; then
response=$(curl -X POST -H 'Content-type: application/json' --data '{
"text": "π 리뷰 μμ²μ΄ λμ°©νμ΅λλ€: @'$slack_username'"
}' ${{ secrets.SLACK_BOT_ACCESS_TOKEN }})
echo "slack_ts=$(echo $response | jq -r '.ts')" >> $GITHUB_ENV
echo $slack_ts > slack_ts.txt
else
echo "Reviewer not found in mapping: $reviewer"
fi
env:
SLACK_BOT_ACCESS_TOKEN: ${{ secrets.SLACK_BOT_ACCESS_TOKEN }}
- name: Restore Slack message timestamp
if: ${{ env.event_type == 'issue_comment' || env.event_type == 'pull_request_review' }}
id: restore_ts
uses: actions/cache@v2
with:
path: slack_ts.txt
key: slack-ts-${{ github.event.issue.number || github.event.pull_request.number }}
restore-keys: |
slack-ts-
- name: Load Slack message timestamp
if: ${{ (env.event_type == 'issue_comment' || env.event_type == 'pull_request_review') && steps.restore_ts.outputs.cache-hit == 'true' }}
run: echo "SLACK_MESSAGE_TS=$(cat slack_ts.txt)" >> $GITHUB_ENV
- name: Send notification for comment
if: ${{ env.event_type == 'issue_comment' && env.SLACK_MESSAGE_TS != '' }}
run: |
commenter=${{ github.event.comment.user.login }}
slack_username=$(echo ${{ env.mapping }} | jq -r --arg commenter "$commenter" '.[$commenter]')
if [ "$slack_username" != "null" ]; then
curl -X POST -H 'Content-type: application/json' --data '{
"text": "@'$slack_username'λμ΄ μ½λ©νΈλ₯Ό λ¬μμ΅λλ€:\n${{ github.event.comment.body }}",
"thread_ts": "${{ env.SLACK_MESSAGE_TS }}"
}' ${{ secrets.SLACK_BOT_ACCESS_TOKEN }}
else
echo "Commenter not found in mapping: $commenter"
fi
env:
SLACK_BOT_ACCESS_TOKEN: ${{ secrets.SLACK_BOT_ACCESS_TOKEN }}
- name: Send notification for approval
if: ${{ env.event_type == 'pull_request_review' && github.event.review.state == 'approved' && env.SLACK_MESSAGE_TS != '' }}
run: |
reviewer=${{ github.event.review.user.login }}
slack_username=$(echo ${{ env.mapping }} | jq -r --arg reviewer "$reviewer" '.[$reviewer]')
if [ "$slack_username" != "null" ]; then
curl -X POST -H 'Content-type: application/json' --data '{
"text": "β
@'$slack_username'λμ΄ μΉμΈνμ
¨μ΄μ π",
"thread_ts": "${{ env.SLACK_MESSAGE_TS }}"
}' ${{ secrets.SLACK_BOT_ACCESS_TOKEN }}
else
echo "Reviewer not found in mapping: $reviewer"
fi
env:
SLACK_BOT_ACCESS_TOKEN: ${{ secrets.SLACK_BOT_ACCESS_TOKEN }}