From 6daf288c01e9f29043cc67ac005227aef4dbb93b Mon Sep 17 00:00:00 2001 From: bn46 <147074924+bn46@users.noreply.github.com> Date: Wed, 9 Oct 2024 15:12:03 +0530 Subject: [PATCH] Update push-trigger.yml Signed-off-by: bn46 <147074924+bn46@users.noreply.github.com> --- .github/workflows/push-trigger.yml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/push-trigger.yml b/.github/workflows/push-trigger.yml index f44d67dc..ee1494de 100644 --- a/.github/workflows/push-trigger.yml +++ b/.github/workflows/push-trigger.yml @@ -26,16 +26,26 @@ jobs: - name: Decode Slack Users Secret id: slack_id run: | - # Decode the JSON string from the secret + # 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 "${{ env.author }}" '.[$github_user]') + 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: ${{ env.author }}" + 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/slack-github-action@v1.27.0