Skip to content

chore(*): workflow slack notification 추가 #5

chore(*): workflow slack notification 추가

chore(*): workflow slack notification 추가 #5

name: Slack Notification
on:
pull_request:
types: [opened, synchronize]
issue_comment:
types: [created, edited]
jobs:
send_slack_notification:
name: Send Slack Notification
runs-on: ubuntu-latest
steps:
- name: fetch branch
id: fetch-branch
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
try {
const pr = await github.rest.pulls.get({
owner : context.repo.owner,
repo : context.repo.repo,
pull_number : context.issue.pull_number
})
return pr.data
} catch (err) {
core.setFailed('Fail')
}
- name: checkout
uses: actions/checkout@v3
with:
ref: ${{ fromJson(steps.fetch-branch.outputs.result).head.sha }}
fetch-depth: 0
- name: Send Slack Notification for PR creation
if: github.event_name == 'pull_request'
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
fields: commit,author,pullRequest
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: Filter mentions for team members
id: filter_mentions
if: github.event_name == 'issue_comment'
run: |
mentions="${{ steps.extract_mentions_comment.outputs.mentions }}"
team_members=(Doeunnkimm semnil5202 Andrevile LeeJeongHooo)
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: ${{ job.status }}
fields: commit,author,eventName,ref,workflow,job,took,pullRequest
mentions: ${{ steps.filter_mentions.outputs.filtered_mentions }}
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."