@@ -3,45 +3,111 @@ name: Discord PR Review
33on :
44 pull_request_review :
55 types : [submitted]
6+ pull_request_review_comment :
7+ types : [created]
8+ issue_comment :
9+ types : [created]
610
711jobs :
812 notify_review :
9- if : ${{ github.actor != 'coderabbitai[bot]' && github.actor != 'coderabbitai' }}
13+ if : |
14+ github.actor != 'coderabbitai[bot]' &&
15+ github.actor != 'coderabbitai' &&
16+ (github.event_name != 'issue_comment' || github.event.issue.pull_request)
1017 runs-on : ubuntu-latest
1118
1219 steps :
13- - name : Send PR review to Discord
20+ - name : Send PR activity to Discord
1421 env :
1522 DISCORD_WEBHOOK_URL : ${{ secrets.DISCORD_WEBHOOK_URL }}
16-
17- PR_TITLE : ${{ github.event.pull_request.title }}
18- PR_URL : ${{ github.event.pull_request.html_url }}
19-
20- REVIEW_AUTHOR : ${{ github.event.review.user.login }}
21- REVIEW_BODY : ${{ github.event.review.body }}
22- REVIEW_URL : ${{ github.event.review.html_url }}
23- REVIEW_STATE : ${{ github.event.review.state }}
23+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
2424 run : |
2525 set -e
2626
27- AUTHOR="$REVIEW_AUTHOR"
28- BODY="$REVIEW_BODY"
29- LINK="$REVIEW_URL"
30- STATE="$REVIEW_STATE"
27+ EVENT_NAME="$GITHUB_EVENT_NAME"
28+ REPO=$(jq -r '.repository.full_name' "$GITHUB_EVENT_PATH")
29+
30+ PR_TITLE=""
31+ AUTHOR=""
32+ BODY=""
33+ STATE=""
34+
35+ if [ "$EVENT_NAME" = "pull_request_review" ]; then
36+ PR_TITLE=$(jq -r '.pull_request.title' "$GITHUB_EVENT_PATH")
37+ AUTHOR=$(jq -r '.review.user.login' "$GITHUB_EVENT_PATH")
38+ BODY=$(jq -r '.review.body // ""' "$GITHUB_EVENT_PATH")
39+ STATE=$(jq -r '.review.state' "$GITHUB_EVENT_PATH")
40+ PR_NUMBER=$(jq -r '.pull_request.number' "$GITHUB_EVENT_PATH")
41+ REVIEW_ID=$(jq -r '.review.id' "$GITHUB_EVENT_PATH")
42+
43+ # 리뷰 요약 본문이 비어있으면: 이 리뷰에 달린 인라인 코멘트들을 붙여서 "본문"을 채움
44+ COMMENTS_JSON=$(curl -sS -L \
45+ -H "Accept: application/vnd.github+json" \
46+ -H "Authorization: Bearer $GITHUB_TOKEN" \
47+ -H "X-GitHub-Api-Version: 2022-11-28" \
48+ "https://api.github.com/repos/$REPO/pulls/$PR_NUMBER/reviews/$REVIEW_ID/comments?per_page=100")
49+
50+ COMMENTS=$(echo "$COMMENTS_JSON" | jq -r '
51+ if type=="array" and length>0 then
52+ .[] | "- [\(.path)] \(.body | gsub("\r";""))"
53+ else
54+ ""
55+ end
56+ ')
57+
58+ if [ -z "$BODY" ] || [ "$BODY" = "null" ]; then
59+ BODY=""
60+ fi
61+
62+ if [ -n "$COMMENTS" ]; then
63+ if [ -n "$BODY" ]; then
64+ BODY="$BODY\n\n💬 인라인 코멘트:\n$COMMENTS"
65+ else
66+ BODY="💬 인라인 코멘트:\n$COMMENTS"
67+ fi
68+ fi
3169
32- # 링크가 비면 PR 링크로 fallback
33- if [ -z "$LINK" ]; then
34- LINK="$PR_URL"
70+ if [ -z "$BODY" ] || [ "$BODY" = "null" ]; then
71+ BODY="(본문 없음)"
72+ fi
73+
74+ TITLE="📝 PR 리뷰 (${STATE})"
75+
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 존재)
89+ PR_TITLE=$(jq -r '.issue.title' "$GITHUB_EVENT_PATH")
90+ AUTHOR=$(jq -r '.comment.user.login' "$GITHUB_EVENT_PATH")
91+ BODY=$(jq -r '.comment.body // ""' "$GITHUB_EVENT_PATH")
92+
93+ if [ -z "$BODY" ] || [ "$BODY" = "null" ]; then
94+ BODY="(본문 없음)"
95+ fi
96+
97+ TITLE="💬 PR 댓글"
98+ else
99+ exit 0
35100 fi
36101
37- # 상태 표시(approved/changes_requested/commented)
38- msg=$(printf "%s\n%s\n%s\n%s\n\n%s\n" \
39- "📝 PR 리뷰 (${STATE})" \
40- "- PR: ${PR_TITLE}" \
41- "- 작성자: ${AUTHOR}" \
42- "- 본문: ${BODY}" \
43- "🔗 ${LINK}"
102+ msg=$(printf "%s\n- PR: %s\n- 작성자: %s\n- 본문:\n%s\n" \
103+ "$TITLE" \
104+ "$PR_TITLE" \
105+ "$AUTHOR" \
106+ "$BODY"
44107 )
45108
109+ # Discord 2000자 제한 대비
110+ msg=$(echo "$msg" | head -c 1800)
111+
46112 payload=$(jq -n --arg content "$msg" '{content: $content}')
47113 curl -sS -X POST -H "Content-Type: application/json" -d "$payload" "$DISCORD_WEBHOOK_URL" > /dev/null
0 commit comments