This GitHub Action sends a message via Slack workflows to a channel. It tags the owner of a Pull Request (PR), informing them that their PR has received the minimum number of approvals required for merging.
Screenshot
You can use this action after any other action. However, it also makes sense as a standalone workflow that runs independently. :)
- Create a
.github/workflows/slack-notify.yml
file in your GitHub repo. - Add the following code to the
slack-notify.yml
file.
name: 2 PR Approval Slack Notification
on:
pull_request_review:
types:
- submitted
jobs:
check-for-PR-approval-and-send-slack-notification:
runs-on: ubuntu-latest
steps:
- name: Get Code
uses: actions/checkout@v3
- name: Check for 2 approvals
id: approval-check
uses: 1904labs/slack-pr-approval-notification@main
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
user-mapping: '{"githubUser1":"U123456789","githubUser2":"U987654321"}'
approval-count: 2
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
-
Create a Slack workflow with a webhook as the trigger.
-
Name your Slack variables as follows:
Variable Type branch-name string approvals string pr-url string pr-owner string slack-user Slack user ID approval-count string -
Finalize your workflow configuration by designating the channel for receiving notifications. This process will generate a webhook URL.
-
-
Subsequently, establish the
SLACK_WEBHOOK_URL
by creating a secret within your GitHub Action's settings.
By default, this action takes 4 required inputs:
Input | Purpose |
---|---|
GITHUB_TOKEN | Allows access to your code to check PR approvals. GitHub automatically generates this token, all you have to do is use ${{ secrets.GITHUB_TOKEN }} |
user-mapping | A stringified JSON object with a user's GitHub handle as the key, and the same user's Slack ID as the value. Check out how to find a Slack user ID here. Example: '{"bob": "U123131312", "sarah": "U4392948393}' |
approval-count | The number of approvals required on a PR to send a notification to Slack |
SLACK_WEBHOOK_URL | The webhook URL generated by a Slack workflow |
Below is a an example screenshot showing how to setup the Slack workflow's text to use the GitHub action
MIT © 2023 1904labs