문의하기 api 적용 #359
Workflow file for this run
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
name: PR Slack Notification | |
on: | |
pull_request: | |
types: [opened, reopened] | |
jobs: | |
notify_reviewers: | |
runs-on: ubuntu-latest | |
steps: | |
- name: 변수 추출 | |
run: | | |
SLACK_WEBHOOK_URL=${{ secrets.SLACK_PR_CREATE_WEBHOOK_URL }} | |
SLACK_IDS=${{ secrets.SLACK_IDS }} | |
echo "SLACK_WEBHOOK_URL=$SLACK_WEBHOOK_URL" >> $GITHUB_ENV | |
echo "SLACK_IDS=$SLACK_IDS" >> $GITHUB_ENV | |
- name: PR 생성 시 reviewer들에게 Slack 알람 보내기 | |
run: | | |
PR_TITLE="${{ github.event.pull_request.title }}" | |
PR_URL="${{ github.event.pull_request.html_url }}" | |
REVIEWERS='${{ toJson(github.event.pull_request.requested_reviewers.*.login) }}' | |
LABELS='${{ toJson(github.event.pull_request.labels.*.name) }}' | |
echo "REVIEWERS: $REVIEWERS" | |
echo "LABELS: $LABELS" | |
parse_slack_ids() { | |
echo "$SLACK_IDS" | jq -r 'to_entries | map("\(.key):\(.value)") | .[]' | |
} | |
reviewers=$(echo "$REVIEWERS" | jq -r '.[]') | |
mentions="" | |
for reviewer in $reviewers; do | |
slack_id=$(parse_slack_ids | grep "^$reviewer:" | cut -d':' -f2) | |
if [ -n "$slack_id" ]; then | |
mentions="$mentions <@$slack_id>" | |
else | |
mentions="$mentions $reviewer" | |
fi | |
done | |
echo "Mentions: $mentions" | |
if [ ! -z "$mentions" ]; then | |
message="$mentions 님, 새로운 PR이 생성되었습니다: <$PR_URL|$PR_TITLE>" | |
if echo "$LABELS" | jq -e 'contains(["zap"])' > /dev/null; then | |
message=":rotating_light: 긴급 PR입니다. 빠른 리뷰 부탁드립니다!:rotating_light:\n$message" | |
fi | |
curl -X POST -H 'Content-type: application/json' \ | |
--data "{\"text\":\"$message\"}" \ | |
"$SLACK_WEBHOOK_URL" | |
echo "Sent message: $message" | |
else | |
echo "No reviewers to notify" | |
fi |