name: Notify Slack on Review Request
on:
pull_request:
types: [review_requested]
jobs:
notify:
runs-on: ubuntu-latest
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_IDS: ${{ secrets.SLACK_IDS }}
steps:
- name: Get PR Details
id: pr
uses: actions/github-script@v5
with:
script: |
const pr = context.payload.pull_request;
const slackIds = JSON.parse(process.env.SLACK_IDS);
const requested_reviewers = pr.requested_reviewers.map(reviewer => slackIds[reviewer.login]).filter(Boolean);
const reviewers_string = requested_reviewers.map(id => `<@${id}>`).join(', ');
return {
url: pr.html_url,
requested_reviewers: reviewers_string
};
- name: Send Message to Slack
uses: 8398a7/action-slack@v3
with:
status: custom
fields: repo,message,commit,author,action,eventName,ref,workflow,job,took
custom_payload: |
{
"text": "${{ steps.pr.outputs.requested_reviewers }} your review was requested for ${{ steps.pr.outputs.url }}"
}