Skip to content

Commit 18e6017

Browse files
authored
♻️ Refactor: Refactor Slack notification payload handling
1 parent c45f0b1 commit 18e6017

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

.github/workflows/slack-pr-notify-ci.yml

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,24 @@ jobs:
2727
SLACK_MENTION="<@U0AL88TS412>"
2828
;;
2929
*)
30-
SLACK_MENTION="@$REQUESTED_REVIEWER"
30+
echo "Slack user mapping not found for: $REQUESTED_REVIEWER" >&2
31+
exit 1
3132
;;
3233
esac
3334
34-
curl -H "Content-Type: application/json" \
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" \
3545
-X POST \
36-
-d "{\"text\": \"$SLACK_MENTION 리뷰 요청이 왔어요! 👀\", \"attachments\": [{\"title\": \"#$PR_NUMBER $PR_TITLE\", \"title_link\": \"$PR_URL\", \"color\": \"#58B9FF\"}]}" \
37-
$SLACK_WEBHOOK
46+
-d "$PAYLOAD" \
47+
"$SLACK_WEBHOOK"
3848
3949
review-completed-notify:
4050
if: |
@@ -62,7 +72,8 @@ jobs:
6272
AUTHOR_MENTION="<@U0AL88TS412>"
6373
;;
6474
*)
65-
AUTHOR_MENTION="@$AUTHOR"
75+
echo "Slack user mapping not found for: $AUTHOR" >&2
76+
exit 1
6677
;;
6778
esac
6879
@@ -77,7 +88,17 @@ jobs:
7788
;;
7889
esac
7990
80-
curl -H "Content-Type: application/json" \
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" \
81102
-X POST \
82-
-d "{\"text\": \"$AUTHOR_MENTION $MESSAGE\", \"attachments\": [{\"title\": \"#$PR_NUMBER $PR_TITLE\", \"title_link\": \"$PR_URL\", \"color\": \"$COLOR\"}]}" \
83-
$SLACK_WEBHOOK
103+
-d "$PAYLOAD" \
104+
"$SLACK_WEBHOOK"

0 commit comments

Comments
 (0)