Skip to content
Closed
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
872e860
Create slackPing.yml
LURKS02 Nov 14, 2024
a2af11b
Update slackPing.yml
LURKS02 Nov 14, 2024
741eb4e
Update slackPing.yml
LURKS02 Nov 14, 2024
09877e6
Update slackPing.yml
LURKS02 Nov 14, 2024
d1d04a9
Update slackPing.yml
LURKS02 Nov 14, 2024
23185b9
Update slackPing.yml
LURKS02 Nov 14, 2024
97f4fc3
Update slackPing.yml
LURKS02 Nov 14, 2024
62a12f7
Update slackPing.yml
LURKS02 Nov 14, 2024
3081511
Update slackPing.yml
LURKS02 Nov 14, 2024
b96ff69
Update slackPing.yml
LURKS02 Nov 14, 2024
c20e60e
Update slackPing.yml
LURKS02 Nov 14, 2024
6d8c9a3
Update slackPing.yml
LURKS02 Nov 14, 2024
3665e08
Update slackPing.yml
LURKS02 Nov 14, 2024
282b33c
Update slackPing.yml
LURKS02 Nov 14, 2024
bcdc1dc
Update slackPing.yml
LURKS02 Nov 14, 2024
164bbb5
Update slackPing.yml
LURKS02 Nov 14, 2024
bd572e6
Update slackPing.yml
LURKS02 Nov 14, 2024
a61eb26
Update slackPing.yml
LURKS02 Nov 14, 2024
9fdf819
Update slackPing.yml
LURKS02 Nov 14, 2024
c779bc6
Update slackPing.yml
LURKS02 Nov 14, 2024
b2e7f4d
Update slackPing.yml
LURKS02 Nov 14, 2024
6f66550
Update slackPing.yml
LURKS02 Nov 14, 2024
176b7fd
Update slackPing.yml
LURKS02 Nov 14, 2024
265b811
Update slackPing.yml
LURKS02 Nov 14, 2024
3a99671
Update slackPing.yml
LURKS02 Nov 14, 2024
4833777
Update slackPing.yml
LURKS02 Nov 14, 2024
e455e11
Update slackPing.yml
LURKS02 Nov 15, 2024
c33bf14
Update slackPing.yml
LURKS02 Nov 15, 2024
5a5b853
Update slackPing.yml
LURKS02 Nov 15, 2024
805a783
Update slackPing.yml
LURKS02 Nov 15, 2024
da01e8b
Update slackPing.yml
LURKS02 Nov 15, 2024
2fdb981
Update slackPing.yml
LURKS02 Nov 15, 2024
70de965
Update slackPing.yml
LURKS02 Nov 15, 2024
09ad056
Update slackPing.yml
LURKS02 Nov 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions .github/workflows/slackPing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Slack Ping

on:
pull_request:
types:
- review_requested
- synchronize
pull_request_review:
types:
- submitted

jobs:
notify:
runs-on: ubuntu-latest
steps:
- name: Install jq
run: sudo apt-get update && sudo apt-get install -y jq

- name: Debug requested reviewers
run: echo '${{ toJson(github.event.pull_request.requested_reviewers) }}'

- name: PR message
env:
SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }}
run: |
declare -A USER_SLACK_IDS
USER_SLACK_IDS["LURKS02"]="${{ secrets.SLACK_LURKS02 }}"
USER_SLACK_IDS["051198Hz"]="${{ secrets.SLACK_051198HZ }}"
USER_SLACK_IDS["around-forest"]="${{ secrets.SLACK_AROUNDFOREST }}"
USER_SLACK_IDS["jungseokyoung-cloud"]="${{ secrets.SLACK_JUNGSEOKYOUNGCLOUD }}"

MESSAGE=""

if [[ "${{ github.event_name }}" == "pull_request" ]] && [[ "${{ github.event.action }}" == "review_requested" ]]; then
MESSAGE="리뷰 요청: 나를 리뷰어로 지정한 PR이 생성되었어요.\n :arrow_right: <${{ github.event.pull_request.html_url }}|PR 링크>"

for GITHUB_USER in $(echo '>>>${{ toJson(github.event.pull_request.requested_reviewers) }}' | jq -r '.[] | .login'); do
SLACK_USER_ID="${USER_SLACK_IDS[$GITHUB_USER]}"
if [[ -n "$SLACK_USER_ID" ]]; then
curl -X POST -H "Authorization: Bearer $SLACK_TOKEN" -H "Content-Type: application/json" \
-d "{\"channel\":\"$SLACK_USER_ID\", \"text\":\"$MESSAGE\"}" \
https://slack.com/api/chat.postMessage
else
echo "'$GITHUB_USER'에 해당하는 슬랙 ID를 찾지 못했습니다."
fi
done

elif [[ "${{ github.event_name }}" == "pull_request_review" ]] && [[ "${{ github.event.action }}" == "submitted" ]]; then
GITHUB_USER="${{ github.event.pull_request.user.login }}"
SLACK_USER_ID="${USER_SLACK_IDS[$GITHUB_USER]}"
REVIEW_STATE="${{ github.event.review.state }}"

if [[ "$REVIEW_STATE" == "approved" ]]; then
STATE_MESSAGE="리뷰 완료 :white_check_mark:: PR이 승인되었어요! :partying_face:"
elif [[ "$REVIEW_STATE" == "changes_requested" ]]; then
STATE_MESSAGE="리뷰 완료 :warning:: PR에 변경 요청이 있어요."
else
STATE_MESSAGE="리뷰 완료 :speech_balloon:: PR에 코멘트가 추가되었어요."
fi

MESSAGE="${STATE_MESSAGE}\n :arrow_right: <${{ github.event.pull_request.html_url }}|PR 링크>"

if [[ -n "$SLACK_USER_ID" ]]; then
curl -X POST -H "Authorization: Bearer $SLACK_TOKEN" -H "Content-Type: application/json" \
-d "{\"channel\":\"$SLACK_USER_ID\", \"text\":\"$MESSAGE\"}" \
https://slack.com/api/chat.postMessage
else
echo "'$GITHUB_USER'에 해당하는 슬랙 ID를 찾지 못했습니다."
fi

elif [[ "${{ github.event_name }}" == "pull_request" ]] && [[ "${{ github.event.action }}" == "synchronize" ]]; then
MESSAGE="커밋 추가: PR에 새로운 커밋이 추가되었어요. 리뷰 요청 사항이 반영되었는지 확인해보세요.\n :arrow_right: <${{ github.event.pull_request.html_url }}|PR 링크>"
for GITHUB_USER in $(echo '${{ toJson(github.event.pull_request.requested_reviewers) }}' | jq -r '.[] | .login'); do
SLACK_USER_ID="${USER_SLACK_IDS[$GITHUB_USER]}"
if [[ -n "$SLACK_USER_ID" ]]; then
curl -X POST -H "Authorization: Bearer $SLACK_TOKEN" -H "Content-Type: application/json" \
-d "{\"channel\":\"$SLACK_USER_ID\", \"text\":\"$MESSAGE\"}" \
https://slack.com/api/chat.postMessage
else
echo "'$GITHUB_USER'에 해당하는 슬랙 ID를 찾지 못했습니다."
fi
done
fi