-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FIX] Notification 관련 CI workflow 에러 해결 #144
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
88c8649
feat : pr review 발생 notification ci 생성
kssumin 9d484a5
fix : secret json형식으로 변환
kssumin 9be83cb
fix : 해당하는 멤버를 태그하도록 변경
kssumin b5e575e
fix : 멤버를 직접 태그하도록 변경
kssumin 9de36ab
fix : json형식 파싱 에러 처리
kssumin 5b2c953
fix : json에서 멤버를 찾지 못 하는 오류 해결
kssumin 267ab3e
fix : json 파싱 방법 변경
kssumin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
name: PR Review Slack Notification | ||
on: | ||
pull_request_review: | ||
types: [submitted] | ||
jobs: | ||
notify_pr_author: | ||
runs-on: ubuntu-latest | ||
env: | ||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_PR_REVIEW_WEBHOOK_URL }} | ||
SLACK_IDS: ${{ secrets.SLACK_IDS }} | ||
steps: | ||
- name: PR 리뷰 시 Slack 알림 보내기 | ||
run: | | ||
set -e | ||
PR_TITLE="${{ github.event.pull_request.title }}" | ||
PR_URL="${{ github.event.pull_request.html_url }}" | ||
PR_AUTHOR="${{ github.event.pull_request.user.login }}" | ||
REVIEW_STATE="${{ github.event.review.state }}" | ||
REVIEWER="${{ github.event.review.user.login }}" | ||
|
||
# Parse SLACK_IDS as JSON | ||
SLACK_IDS_JSON=$(echo "$SLACK_IDS" | jq -r '.' 2>/dev/null || echo "{}") | ||
if [ "$SLACK_IDS_JSON" == "{}" ]; then | ||
echo "Warning: SLACK_IDS is not a valid JSON. Attempting to parse as a string." | ||
SLACK_IDS_JSON=$(echo "$SLACK_IDS" | sed 's/^"//; s/"$//' | jq -R 'split(",") | map(split(":")) | from_entries' 2>/dev/null || echo "{}") | ||
if [ "$SLACK_IDS_JSON" == "{}" ]; then | ||
echo "Error: Failed to parse SLACK_IDS as JSON or string. Please check the format." | ||
exit 1 | ||
fi | ||
fi | ||
|
||
get_slack_id() { | ||
local github_username="$1" | ||
echo "$SLACK_IDS_JSON" | jq -r --arg user "$github_username" '.[$user] // empty' | ||
} | ||
|
||
author_slack_id=$(get_slack_id "$PR_AUTHOR") | ||
reviewer_slack_id=$(get_slack_id "$REVIEWER") | ||
|
||
if [ -n "$author_slack_id" ]; then | ||
author_mention="<@$author_slack_id>" | ||
else | ||
author_mention="$PR_AUTHOR" | ||
echo "Warning: No Slack ID found for PR author $PR_AUTHOR" >&2 | ||
fi | ||
|
||
if [ -n "$reviewer_slack_id" ]; then | ||
reviewer_mention="<@$reviewer_slack_id>" | ||
else | ||
reviewer_mention="$REVIEWER" | ||
echo "Warning: No Slack ID found for reviewer $REVIEWER" >&2 | ||
fi | ||
|
||
case "$REVIEW_STATE" in | ||
"changes_requested") | ||
message="$author_mention님, $reviewer_mention님이 PR에 변경을 요청했습니다: <$PR_URL|$PR_TITLE>" | ||
;; | ||
"commented") | ||
message="$author_mention님, $reviewer_mention님이 PR에 댓글을 달았습니다: <$PR_URL|$PR_TITLE>" | ||
;; | ||
"approved") | ||
message="$author_mention님, 축하합니다! $reviewer_mention님이 PR을 승인했습니다: <$PR_URL|$PR_TITLE>" | ||
;; | ||
esac | ||
|
||
if [ -n "$message" ]; then | ||
response=$(curl -s -o /dev/null -w "%{http_code}" -X POST -H 'Content-type: application/json' \ | ||
--data "{\"text\":\"$message\"}" \ | ||
"$SLACK_WEBHOOK_URL") | ||
|
||
if [ "$response" = "200" ]; then | ||
echo "Successfully sent Slack notification" | ||
else | ||
echo "Error: Failed to send Slack notification. HTTP status code: $response" >&2 | ||
exit 1 | ||
fi | ||
else | ||
echo "No notification to send" | ||
fi |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
엄청난 양의 shell Script...대단해요!