Skip to content

chore(*): slack μ•Œλ¦Ό 연동 test #53

chore(*): slack μ•Œλ¦Ό 연동 test

chore(*): slack μ•Œλ¦Ό 연동 test #53

Workflow file for this run

name: Notify Slack on PR and Comment
on:
pull_request:
types: [opened, reopened, synchronize, review_requested]
issue_comment:
types: [created]
pull_request_review:
types: [submitted]
jobs:
notify:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Determine event type
id: determine_event
run: echo "event_type=${{ github.event_name }}" >> $GITHUB_ENV
- name: Cache Slack message timestamp
if: ${{ env.event_type == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'reopened' || github.event.action == 'synchronize') }}
id: cache_slack_ts
run: |
if [ -f slack_ts_${{ github.event.pull_request.number }}.txt ]; then
echo "slack_ts=$(cat slack_ts_${{ github.event.pull_request.number }}.txt)" >> $GITHUB_ENV
else
echo "slack_ts=" >> $GITHUB_ENV
fi
- name: Send notification for PR
if: ${{ env.event_type == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'reopened' || github.event.action == 'synchronize') }}
id: slack_pr
run: |
response=$(curl -X POST -H 'Content-type: application/json' --data '{
"text": "*πŸ§žβ€β™‚οΈ PR λ“œλ¦¬λŠ” μ§€λ‹ˆκ°€ μ™”μŠ΅λ‹ˆλ‹€~*\n*<'"${{ github.event.pull_request.html_url }}"'|[sambad#'"${{ github.event.pull_request.number }}"'] [${{ github.event.pull_request.title }}]>*\n${{ github.event.pull_request.user.login }}λ‹˜μ΄ μƒμ„±ν–ˆμ–΄μš”."
}' https://slack.com/api/chat.postMessage -H "Authorization: Bearer ${{ secrets.SLACK_BOT_ACCESS_TOKEN }}")
slack_ts=$(echo $response | jq -r '.ts')
echo "slack_ts=$slack_ts" >> $GITHUB_ENV
echo $slack_ts > slack_ts_${{ github.event.pull_request.number }}.txt
env:
SLACK_BOT_ACCESS_TOKEN: ${{ secrets.SLACK_BOT_ACCESS_TOKEN }}
- name: Send notification for review request
if: ${{ env.event_type == 'pull_request' && github.event.action == 'review_requested' }}
run: |
reviewer=${{ github.event.requested_reviewer.login }}
slack_username=$(cat .github/user-mapping.json | jq -r --arg reviewer "$reviewer" '.[$reviewer]')
if [ "$slack_username" != "null" ]; then
curl -X POST -H 'Content-type: application/json' --data '{
"text": "*πŸ”” 리뷰 μš”μ²­μ΄ λ„μ°©ν–ˆμŠ΅λ‹ˆλ‹€*: <@'$slack_username'>"
}' https://slack.com/api/chat.postMessage -H "Authorization: Bearer ${{ secrets.SLACK_BOT_ACCESS_TOKEN }}"
else
echo "Reviewer not found in mapping: $reviewer"
fi
env:
SLACK_BOT_ACCESS_TOKEN: ${{ secrets.SLACK_BOT_ACCESS_TOKEN }}
- name: Restore Slack message timestamp
id: restore_slack_ts
run: |
if [ -f slack_ts_${{ github.event.issue.number || github.event.pull_request.number }}.txt ]; then
cat slack_ts_${{ github.event.issue.number || github.event.pull_request.number }}.txt
echo "SLACK_MESSAGE_TS=$(cat slack_ts_${{ github.event.issue.number || github.event.pull_request.number }}.txt)" >> $GITHUB_ENV
else
echo "SLACK_MESSAGE_TS=" >> $GITHUB_ENV
fi
- name: Send notification for comment
if: ${{ env.event_type == 'issue_comment' && env.SLACK_MESSAGE_TS == '' }}
run: |
commenter=${{ github.event.comment.user.login }}
slack_username=$(cat .github/user-mapping.json | jq -r --arg commenter "$commenter" '.[$commenter]')
if [ "$slack_username" != "null" ]; then
response=$(curl -X POST -H 'Content-type: application/json' --data '{
"text": "<@'$slack_username'>λ‹˜μ΄ μ½”λ©˜νŠΈλ₯Ό λ‹¬μ•˜μŠ΅λ‹ˆλ‹€ πŸ’Œ:\n${{ github.event.comment.body }}"
}' https://slack.com/api/chat.postMessage -H "Authorization: Bearer ${{ secrets.SLACK_BOT_ACCESS_TOKEN }}")
slack_ts=$(echo $response | jq -r '.ts')
echo "slack_ts=$slack_ts" >> $GITHUB_ENV
echo $slack_ts > slack_ts_${{ github.event.issue.number || github.event.pull_request.number }}.txt
else
echo "Commenter not found in mapping: $commenter"
fi
env:
SLACK_BOT_ACCESS_TOKEN: ${{ secrets.SLACK_BOT_ACCESS_TOKEN }}
- name: Send notification for comment in thread
if: ${{ env.event_type == 'issue_comment' && env.SLACK_MESSAGE_TS != '' }}
run: |
commenter=${{ github.event.comment.user.login }}
slack_username=$(cat .github/user-mapping.json | jq -r --arg commenter "$commenter" '.[$commenter]')
if [ "$slack_username" != "null" ]; then
curl -X POST -H 'Content-type: application/json' --data '{
"text": "<@'$slack_username'>λ‹˜μ΄ μ½”λ©˜νŠΈλ₯Ό λ‹¬μ•˜μŠ΅λ‹ˆλ‹€ πŸ’Œ:\n${{ github.event.comment.body }}",
"thread_ts": "'${{ env.SLACK_MESSAGE_TS }}'"
}' https://slack.com/api/chat.postMessage -H "Authorization: Bearer ${{ secrets.SLACK_BOT_ACCESS_TOKEN }}"
else
echo "Commenter not found in mapping: $commenter"
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=$(cat .github/user-mapping.json | jq -r --arg reviewer "$reviewer" '.[$reviewer]')
if [ "$slack_username" != "null" ]; then
curl -X POST -H 'Content-type: application/json' --data '{
"text": "<@'$slack_username'>λ‹˜μ΄ PR을 μŠΉμΈν–ˆμŠ΅λ‹ˆλ‹€ πŸŽ‰",
"thread_ts": "'${{ env.SLACK_MESSAGE_TS }}'"
}' https://slack.com/api/chat.postMessage -H "Authorization: Bearer ${{ secrets.SLACK_BOT_ACCESS_TOKEN }}"
else
echo "Reviewer not found in mapping: $reviewer"
fi
env:
SLACK_BOT_ACCESS_TOKEN: ${{ secrets.SLACK_BOT_ACCESS_TOKEN }}