Skip to content

PR Comment Slack Notification #115

PR Comment Slack Notification

PR Comment Slack Notification #115

name: PR Comment Slack Notification
on:
pull_request_review:
types: [submitted]
jobs:
notify_pr_review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Map assignees & reviewers
id: map_ids
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const workers = JSON.parse(fs.readFileSync('.github/reviewers.json', 'utf8'));
const assignees = context.payload.pull_request.assignees || [];
const mappedAssignees = assignees.map(assignee => `<@${workers[assignee.login]}>`);
const reviewer = context.payload.review.user.login;
const mappedReviewer = `<@${workers[reviewer]}>`;
core.setOutput("assignees", mappedAssignees.join(", "));
core.setOutput("reviewer", mappedReviewer);
- name: Notify Slack
uses: slackapi/slack-github-action@v1.23.0
with:
channel-id: ${{ secrets.SLACK_CHANNEL_ID }}
payload: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "${{ github.event.review.state == 'approved' && '*✅ PR이 승인되었어요!*' || '*🚨 PR에 댓글이 달렸어요!*' }}\n> *제목:* ${{ github.event.pull_request.title }}\n> *담당자:* ${{ steps.map_ids.outputs.assignees }}\n> *리뷰어:* ${{ steps.map_ids.outputs.reviewer }}\n> *링크:* <${{ github.event.pull_request.html_url }}>"
}
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}