fix(*): slack notification 메시지 수정 #14
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: 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 | |
uses: 8398a7/action-slack@v3 | |
with: | |
status: custom | |
fields: author,pullRequest | |
custom_payload: | | |
{ | |
attachments: [{ | |
color: '${{ job.status }}' === 'success' ? 'good' : '${{ job.status }}' === 'failure' ? 'danger' : 'warning', | |
text: `Actor: ${process.env.AS_AUTHOR}\\n PR: ${process.env.AS_PULL_REQUEST}`, | |
}] | |
} | |
env: | |
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | |
- 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: Transform mentions to Slack format | |
id: transform_mentions | |
if: github.event_name == 'issue_comment' | |
run: | | |
mentions="${{ steps.extract_mentions_comment.outputs.mentions }}" | |
# Transform specific mentions to desired format | |
transformed_mentions=$(echo "$mentions" | sed -E 's/@Doeunnkimm/@Web_김도은/g; s/@semnil5202/@Web_이세민/g; s/@Andrevile/@Web_장종오/g; s/@LeeJeongHooo/@Web_이정호/g') | |
echo "::set-output name=transformed_mentions::$transformed_mentions" | |
- name: Filter mentions for team members | |
id: filter_mentions | |
if: github.event_name == 'issue_comment' | |
run: | | |
mentions="${{ steps.transform_mentions.outputs.transformed_mentions }}" | |
team_members=(@Web_김도은 @Web_이세민 @Web_장종오 @Web_이정호) | |
filtered_mentions="" | |
for mention in $mentions; do | |
if [[ " ${team_members[@]} " =~ " ${mention} " ]]; then | |
filtered_mentions="$filtered_mentions $mention" | |
fi | |
done | |
echo "::set-output name=filtered_mentions::${filtered_mentions}" | |
- name: Send Slack Notification for comment if team members mentioned | |
if: ${{ github.event_name == 'issue_comment' && steps.filter_mentions.outputs.filtered_mentions != '' }} | |
uses: 8398a7/action-slack@v3 | |
with: | |
status: custom | |
fields: pullRequest | |
custom_payload: | | |
{ | |
attachments: [{ | |
color: '${{ job.status }}' === 'success' ? 'good' : '${{ job.status }}' === 'failure' ? 'danger' : 'warning', | |
text: `${process.env.AS_PULL_REQUEST}에서 ${{ steps.filter_mentions.outputs.filtered_mentions }} 님을 언급했습니다.\\n꼭 나중에 들어가서 확인하기!\\n메시지: ${{ github.event.comment.body }}`, | |
}] | |
} | |
env: | |
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | |
- name: Debug mentions | |
if: ${{ github.event_name == 'issue_comment' && steps.filter_mentions.outputs.filtered_mentions == '' }} | |
run: echo "No team members mentioned in the comment." |