Skip to content

Commit 05ce7d7

Browse files
authored
Merge pull request #133 from YAPP-Github/feat/#132-pr-slack-notify-ci
Discord PR 알림을 Slack으로 교체
2 parents a8ecc22 + 18e6017 commit 05ce7d7

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
name: Slack PR Notifications
2+
3+
on:
4+
pull_request:
5+
types: [review_requested]
6+
pull_request_review:
7+
types: [submitted]
8+
9+
jobs:
10+
review-request-notify:
11+
if: github.event.action == 'review_requested'
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Send Review Request Notification
15+
env:
16+
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
17+
REQUESTED_REVIEWER: ${{ github.event.requested_reviewer.login }}
18+
PR_TITLE: ${{ github.event.pull_request.title }}
19+
PR_URL: ${{ github.event.pull_request.html_url }}
20+
PR_NUMBER: ${{ github.event.pull_request.number }}
21+
run: |
22+
case "$REQUESTED_REVIEWER" in
23+
"chanho0908"|"JoungPeto0908")
24+
SLACK_MENTION="<@U0AKQT3ATF1>"
25+
;;
26+
"dogmania")
27+
SLACK_MENTION="<@U0AL88TS412>"
28+
;;
29+
*)
30+
echo "Slack user mapping not found for: $REQUESTED_REVIEWER" >&2
31+
exit 1
32+
;;
33+
esac
34+
35+
PAYLOAD=$(jq -n \
36+
--arg text "$SLACK_MENTION 리뷰 요청이 왔어요! 👀" \
37+
--arg title "#$PR_NUMBER $PR_TITLE" \
38+
--arg url "$PR_URL" \
39+
'{text: $text, attachments: [{title: $title, title_link: $url, color: "#58B9FF"}]}')
40+
41+
curl --fail-with-body \
42+
--max-time 10 \
43+
--retry 2 \
44+
-H "Content-Type: application/json" \
45+
-X POST \
46+
-d "$PAYLOAD" \
47+
"$SLACK_WEBHOOK"
48+
49+
review-completed-notify:
50+
if: |
51+
github.event_name == 'pull_request_review' &&
52+
github.event.review.user.type != 'Bot' &&
53+
github.event.review.user.login != github.event.pull_request.user.login &&
54+
github.event.review.state != 'commented'
55+
runs-on: ubuntu-latest
56+
steps:
57+
- name: Send Review Completed Notification
58+
env:
59+
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
60+
REVIEWER: ${{ github.event.review.user.login }}
61+
PR_TITLE: ${{ github.event.pull_request.title }}
62+
PR_URL: ${{ github.event.pull_request.html_url }}
63+
AUTHOR: ${{ github.event.pull_request.user.login }}
64+
PR_NUMBER: ${{ github.event.pull_request.number }}
65+
REVIEW_STATE: ${{ github.event.review.state }}
66+
run: |
67+
case "$AUTHOR" in
68+
"chanho0908"|"JoungPeto0908")
69+
AUTHOR_MENTION="<@U0AKQT3ATF1>"
70+
;;
71+
"dogmania")
72+
AUTHOR_MENTION="<@U0AL88TS412>"
73+
;;
74+
*)
75+
echo "Slack user mapping not found for: $AUTHOR" >&2
76+
exit 1
77+
;;
78+
esac
79+
80+
case "$REVIEW_STATE" in
81+
"changes_requested")
82+
MESSAGE="수정 요청이 있습니다 🔧"
83+
COLOR="#E01E5A"
84+
;;
85+
*)
86+
MESSAGE="리뷰가 완료되었습니다 📝"
87+
COLOR="#58B9FF"
88+
;;
89+
esac
90+
91+
PAYLOAD=$(jq -n \
92+
--arg text "$AUTHOR_MENTION $MESSAGE" \
93+
--arg title "#$PR_NUMBER $PR_TITLE" \
94+
--arg url "$PR_URL" \
95+
--arg color "$COLOR" \
96+
'{text: $text, attachments: [{title: $title, title_link: $url, color: $color}]}')
97+
98+
curl --fail-with-body \
99+
--max-time 10 \
100+
--retry 2 \
101+
-H "Content-Type: application/json" \
102+
-X POST \
103+
-d "$PAYLOAD" \
104+
"$SLACK_WEBHOOK"

0 commit comments

Comments
 (0)