Skip to content

chore(*): PR ์ฝ”๋ฉ˜ํŠธ ์Šค๋ ˆ๋“œ ๊ธฐ๋Šฅ ์ถ”๊ฐ€ #28

chore(*): PR ์ฝ”๋ฉ˜ํŠธ ์Šค๋ ˆ๋“œ ๊ธฐ๋Šฅ ์ถ”๊ฐ€

chore(*): PR ์ฝ”๋ฉ˜ํŠธ ์Šค๋ ˆ๋“œ ๊ธฐ๋Šฅ ์ถ”๊ฐ€ #28

name: Slack Notification
on:
pull_request:
types: [opened, ready_for_review]
issue_comment:
types: [created, edited]
jobs:
send_slack_notification:
name: Send Slack Notification
runs-on: ubuntu-latest
steps:
- name: Send Slack Notification for PR creation
if: github.event_name == 'pull_request' && github.event.pull_request.draft == false
id: send_pr_notification
run: |
response=$(curl -X POST -H "Authorization: Bearer ${{ secrets.SLACK_BOT_TOKEN }}" -H "Content-type: application/json" \
--data '{
"channel": "C079A5A8BL0",
"text": "PR ์•Œ๋ฆผ",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*์ž‘์„ฑ์ž:* '${{ github.actor }}'
*PR ๋งํฌ:* '${{ github.event.pull_request.html_url }}'"
}
}
]
}' https://slack.com/api/chat.postMessage)
echo "$response" > output.json
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
- name: Extract mentions from comment body
id: extract_mentions_comment
if: github.event_name == 'issue_comment'
run: |
mentions=$(echo "${{ github.event.comment.body }}" | grep -o '@[[:alnum:]_-]\+' | paste -sd ' ' -)
echo "::set-output name=mentions::$mentions"
- name: Map GitHub mentions to Slack user IDs
id: map_to_slack_ids
if: github.event_name == 'issue_comment'
run: |
declare -A slack_ids
slack_ids=(["@Doeunnkimm"]="U07600UQG3T" ["@semnil5202"]="U075KR29RGR" ["@Andrevile"]="U07545VMS21" ["@LeeJeongHooo"]="U075C1A16LT")
mentions="${{ steps.extract_mentions_comment.outputs.mentions }}"
slack_mentions=""
for mention in $mentions; do
if [[ -n "${slack_ids[$mention]}" ]]; then
slack_mentions="$slack_mentions <@${slack_ids[$mention]}>"
fi
done
echo "::set-output name=slack_mentions::$slack_mentions"
- name: Send Slack Notification for comment if team members mentioned
if: github.event_name == 'issue_comment' && steps.map_to_slack_ids.outputs.slack_mentions != ''
run: |
ts=$(jq -r '.ts' output.json)
curl -X POST -H "Authorization: Bearer ${{ secrets.SLACK_BOT_TOKEN }}" -H "Content-type: application/json" \
--data '{
"channel": "C079A5A8BL0",
"thread_ts": "'"$ts"'",
"text": "'${{ steps.map_to_slack_ids.outputs.slack_mentions }}' ๋‹˜์„ ์–ธ๊ธ‰ํ–ˆ์Šต๋‹ˆ๋‹ค.
๊ผญ ๋‚˜์ค‘์— ํ™•์ธํ•ด์ฃผ์„ธ์š”!
๋ฉ”์‹œ์ง€: '${{ github.event.comment.body }}'"
}' https://slack.com/api/chat.postMessage
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
- name: Debug mentions
if: ${{ github.event_name == 'issue_comment' && steps.map_to_slack_ids.outputs.slack_mentions == '' }}
run: echo "No team members mentioned in the comment."