Skip to content

Commit

Permalink
chore: approve trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
Doeunnkimm committed Jun 25, 2024
1 parent 63d3880 commit ed26f75
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions .github/workflows/slack-notify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
types: [opened, reopened, synchronize, review_requested]
issue_comment:
types: [created]
pull_request_review:
types: [submitted]

jobs:
notify:
Expand Down Expand Up @@ -61,17 +63,17 @@ jobs:
SLACK_BOT_ACCESS_TOKEN: ${{ secrets.SLACK_BOT_ACCESS_TOKEN }}

- name: Restore Slack message timestamp
if: ${{ env.event_type == 'issue_comment' }}
if: ${{ env.event_type == 'issue_comment' || env.event_type == 'pull_request_review' }}
id: restore_ts
uses: actions/cache@v2
with:
path: slack_ts.txt
key: slack-ts-${{ github.event.issue.number }}
key: slack-ts-${{ github.event.issue.number || github.event.pull_request.number }}
restore-keys: |
slack-ts-
- name: Load Slack message timestamp
if: ${{ env.event_type == 'issue_comment' && steps.restore_ts.outputs.cache-hit == 'true' }}
if: ${{ (env.event_type == 'issue_comment' || env.event_type == 'pull_request_review') && steps.restore_ts.outputs.cache-hit == 'true' }}
run: echo "SLACK_MESSAGE_TS=$(cat slack_ts.txt)" >> $GITHUB_ENV

- name: Send notification for comment
Expand All @@ -89,3 +91,19 @@ jobs:
fi
env:
SLACK_BOT_ACCESS_TOKEN: ${{ secrets.SLACK_BOT_ACCESS_TOKEN }}

- name: Send notification for approval
if: ${{ env.event_type == 'pull_request_review' && github.event.review.state == 'approved' && env.SLACK_MESSAGE_TS != '' }}
run: |
reviewer=${{ github.event.review.user.login }}
slack_username=$(echo ${{ env.mapping }} | jq -r --arg reviewer "$reviewer" '.[$reviewer]')
if [ "$slack_username" != "null" ]; then
curl -X POST -H 'Content-type: application/json' --data '{
"text": "โœ… @'$slack_username'๋‹˜์ด ์Šน์ธํ•˜์…จ์–ด์š” ๐ŸŽ‰",
"thread_ts": "${{ env.SLACK_MESSAGE_TS }}"
}' ${{ secrets.SLACK_BOT_ACCESS_TOKEN }}
else
echo "Reviewer not found in mapping: $reviewer"
fi
env:
SLACK_BOT_ACCESS_TOKEN: ${{ secrets.SLACK_BOT_ACCESS_TOKEN }}

0 comments on commit ed26f75

Please sign in to comment.