Skip to content

Commit ce2e7eb

Browse files
authored
Refactor Discord notification workflow for reviews
1 parent c6d81ad commit ce2e7eb

1 file changed

Lines changed: 12 additions & 29 deletions

File tree

.github/workflows/discord_notify.yml

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ name: Discord PR Review
33
on:
44
pull_request_review:
55
types: [submitted]
6-
pull_request_review_comment:
7-
types: [created]
86
issue_comment:
97
types: [created]
108

119
jobs:
12-
notify_review:
10+
notify:
1311
if: |
1412
github.actor != 'coderabbitai[bot]' &&
1513
github.actor != 'coderabbitai' &&
@@ -24,23 +22,24 @@ jobs:
2422
run: |
2523
set -e
2624
27-
EVENT_NAME="$GITHUB_EVENT_NAME"
25+
EVENT="$GITHUB_EVENT_NAME"
2826
REPO=$(jq -r '.repository.full_name' "$GITHUB_EVENT_PATH")
2927
3028
PR_TITLE=""
3129
AUTHOR=""
3230
BODY=""
33-
STATE=""
31+
TITLE=""
3432
35-
if [ "$EVENT_NAME" = "pull_request_review" ]; then
33+
if [ "$EVENT" = "pull_request_review" ]; then
3634
PR_TITLE=$(jq -r '.pull_request.title' "$GITHUB_EVENT_PATH")
3735
AUTHOR=$(jq -r '.review.user.login' "$GITHUB_EVENT_PATH")
38-
BODY=$(jq -r '.review.body // ""' "$GITHUB_EVENT_PATH")
3936
STATE=$(jq -r '.review.state' "$GITHUB_EVENT_PATH")
37+
REVIEW_BODY=$(jq -r '.review.body // ""' "$GITHUB_EVENT_PATH")
38+
4039
PR_NUMBER=$(jq -r '.pull_request.number' "$GITHUB_EVENT_PATH")
4140
REVIEW_ID=$(jq -r '.review.id' "$GITHUB_EVENT_PATH")
4241
43-
# 리뷰 요약 본문이 비어있으면: 이 리뷰에 달린 인라인 코멘트들을 붙여서 "본문"을 채움
42+
# 이 리뷰에 포함된 인라인 코멘트들을 가져와서 본문에 합치기
4443
COMMENTS_JSON=$(curl -sS -L \
4544
-H "Accept: application/vnd.github+json" \
4645
-H "Authorization: Bearer $GITHUB_TOKEN" \
@@ -55,10 +54,7 @@ jobs:
5554
end
5655
')
5756
58-
if [ -z "$BODY" ] || [ "$BODY" = "null" ]; then
59-
BODY=""
60-
fi
61-
57+
BODY="$REVIEW_BODY"
6258
if [ -n "$COMMENTS" ]; then
6359
if [ -n "$BODY" ]; then
6460
BODY="$BODY\n\n💬 인라인 코멘트:\n$COMMENTS"
@@ -73,19 +69,8 @@ jobs:
7369
7470
TITLE="📝 PR 리뷰 (${STATE})"
7571
76-
elif [ "$EVENT_NAME" = "pull_request_review_comment" ]; then
77-
PR_TITLE=$(jq -r '.pull_request.title' "$GITHUB_EVENT_PATH")
78-
AUTHOR=$(jq -r '.comment.user.login' "$GITHUB_EVENT_PATH")
79-
BODY=$(jq -r '.comment.body // ""' "$GITHUB_EVENT_PATH")
80-
81-
if [ -z "$BODY" ] || [ "$BODY" = "null" ]; then
82-
BODY="(본문 없음)"
83-
fi
84-
85-
TITLE="💬 PR 인라인 코멘트"
86-
87-
elif [ "$EVENT_NAME" = "issue_comment" ]; then
88-
# PR Conversation 댓글(= issue_comment but issue.pull_request 존재)
72+
elif [ "$EVENT" = "issue_comment" ]; then
73+
# PR Conversation 댓글 (issue_comment지만 PR만 필터링됨)
8974
PR_TITLE=$(jq -r '.issue.title' "$GITHUB_EVENT_PATH")
9075
AUTHOR=$(jq -r '.comment.user.login' "$GITHUB_EVENT_PATH")
9176
BODY=$(jq -r '.comment.body // ""' "$GITHUB_EVENT_PATH")
@@ -95,15 +80,13 @@ jobs:
9580
fi
9681
9782
TITLE="💬 PR 댓글"
83+
9884
else
9985
exit 0
10086
fi
10187
10288
msg=$(printf "%s\n- PR: %s\n- 작성자: %s\n- 본문:\n%s\n" \
103-
"$TITLE" \
104-
"$PR_TITLE" \
105-
"$AUTHOR" \
106-
"$BODY"
89+
"$TITLE" "$PR_TITLE" "$AUTHOR" "$BODY"
10790
)
10891
10992
# Discord 2000자 제한 대비

0 commit comments

Comments
 (0)