forked from mosip/data-archive
-
Notifications
You must be signed in to change notification settings - Fork 4
56 lines (50 loc) · 1.9 KB
/
push-trigger.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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: |
# Decode the JSON string from the secret
SLACK_USERS_MAP="${{ secrets.SLACK_USERS_MAP }}"
# Use jq to extract the Slack ID corresponding to the GitHub username
SLACK_USER_ID=$(echo "$SLACK_USERS_MAP" | jq -r --arg github_user "${{ env.author }}" '.[$github_user]')
if [ -z "$SLACK_USER_ID" ] || [ "$SLACK_USER_ID" == "null" ]; then
echo "Slack user ID not found for GitHub user: ${{ env.author }}"
exit 1
fi
echo "SLACK_USER_ID=$SLACK_USER_ID" >> $GITHUB_ENV
- 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 }}