Skip to content

Workflow file for this run

name: Slack Notification on Pull Request
on:
pull_request:
types: [opened, synchronize]
push:
branches:
- master
- 1.*
- develop
- release*
- MOSIP*
jobs:
notify:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Get PR author
id: author
run: echo "author=${{ github.event.pull_request.user.login }}" >> $GITHUB_ENV
- name: Decode Slack Users Secret
id: slack_id
run: |
# Access the JSON string from the secret
SLACK_USERS_MAP="${{ secrets.SLACK_USERS_MAP }}"
# Extract GitHub username of the PR author
GITHUB_USER="${{ github.event.pull_request.user.login }}"
# Use jq to extract the Slack ID corresponding to the GitHub username
SLACK_USER_ID=$(echo "$SLACK_USERS_MAP" | jq -r --arg github_user "$GITHUB_USER" '.[$github_user]')
# Check if the Slack user ID was found
if [ -z "$SLACK_USER_ID" ] || [ "$SLACK_USER_ID" == "null" ]; then
echo "Slack user ID not found for GitHub user: $GITHUB_USER"
exit 1
fi
# Export the Slack user ID to the GitHub environment
echo "SLACK_USER_ID=$SLACK_USER_ID" >> $GITHUB_ENV
shell: bash
- name: Post to a Slack channel
id: slack
uses: slackapi/[email protected]
with:
channel-id: ${{ env.SLACK_USER_ID }}
slack-message: |
*GitHub Action Notification* :rocket:
*Repository*: ${{ github.repository }}
*Message*: ${{ github.event.head_commit.message || github.event.pull_request.title }}
*Commit*: ${{ github.sha }}
*Author*: ${{ github.event.pull_request.user.login }}
*Action*: ${{ github.event.action }}
*Event Name*: ${{ github.event_name }}
*Branch (ref)*: ${{ github.ref }}
*Workflow*: ${{ github.workflow }}
*PR/Commit URL*: ${{ github.event.pull_request.html_url || github.event.head_commit.url }}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}