diff --git a/.github/workflows/common-slack-notify-opened.yml b/.github/workflows/common-slack-notify-opened.yml index 85f9178f..0994d2f5 100644 --- a/.github/workflows/common-slack-notify-opened.yml +++ b/.github/workflows/common-slack-notify-opened.yml @@ -2,9 +2,9 @@ name: Slack Notification (Opened/Ready) on: pull_request: - types: [opened, ready_for_review] + types: [ opened, ready_for_review ] -permissions: {} +permissions: { } concurrency: group: pr-${{ github.event.pull_request.number }}-slack-opened-ready @@ -28,6 +28,8 @@ jobs: PR_AUTHOR: ${{ github.event.pull_request.user.login }} REVIEWERS_JSON: ${{ toJson(github.event.pull_request.requested_reviewers) }} run: | + REPO_NAME="${GITHUB_REPOSITORY#*/}" + declare -A GITHUB_TO_SLACK GITHUB_TO_SLACK["soeun2537"]="U09A0LM0CRW" GITHUB_TO_SLACK["taek2222"]="U099ARRH3D3" @@ -56,7 +58,20 @@ jobs: echo "리뷰어가 없으므로 알림 생략" exit 0 fi - - curl -X POST -H 'Content-type: application/json' \ - --data "{\"text\": \"🔥 *리뷰 요청 알림*\n*PR 제목:* ${PR_TITLE} (#${PR_NUMBER})\n*작성자:* ${SLACK_AUTHOR_MENTION}\n*리뷰어:* ${REVIEWER_MENTIONS}\n*링크:* ${PR_URL}\"}" \ - $SLACK_WEBHOOK_URL + + PAYLOAD=$(jq -n \ + --arg repo "$REPO_NAME" \ + --arg title "$PR_TITLE" \ + --arg number "$PR_NUMBER" \ + --arg author "$SLACK_AUTHOR_MENTION" \ + --arg reviewers "$REVIEWER_MENTIONS" \ + --arg url "$PR_URL" \ + '{ + text: "🔥 (\($repo)) 리뷰 요청 알림", + blocks: [ + {type: "header", text: {type: "plain_text", text: "🔥 (\($repo)) 리뷰 요청 알림", emoji: true}}, + {type: "section", text: {type: "mrkdwn", text: "*PR 제목:* \($title) (#\($number))\n*작성자:* \($author)\n*리뷰어:* \($reviewers)\n*링크:* \($url)"}} + ] + }') + + curl -X POST -H 'Content-type: application/json' --data "$PAYLOAD" $SLACK_WEBHOOK_URL diff --git a/.github/workflows/common-slack-notify-rerequested.yml b/.github/workflows/common-slack-notify-rerequested.yml index dcf76883..4b58c605 100644 --- a/.github/workflows/common-slack-notify-rerequested.yml +++ b/.github/workflows/common-slack-notify-rerequested.yml @@ -2,7 +2,7 @@ name: Slack Notification (Review Requested) on: pull_request: - types: [review_requested] + types: [ review_requested ] permissions: contents: read @@ -32,6 +32,8 @@ jobs: PR_REVIEWER: ${{ github.event.requested_reviewer.login }} REPOSITORY: ${{ github.repository }} run: | + REPO_NAME="${GITHUB_REPOSITORY#*/}" + declare -A GITHUB_TO_SLACK GITHUB_TO_SLACK["soeun2537"]="U09A0LM0CRW" GITHUB_TO_SLACK["taek2222"]="U099ARRH3D3" @@ -59,7 +61,7 @@ jobs: echo "매핑 없는 사용자(${PR_REVIEWER})는 생략" exit 0 fi - + if [[ -n "${GITHUB_TO_SLACK[$PR_AUTHOR]}" ]]; then SLACK_AUTHOR_MENTION="<@${GITHUB_TO_SLACK[$PR_AUTHOR]}>" else @@ -67,7 +69,20 @@ jobs: fi SLACK_REVIEWER_MENTION="<@$slack_id>" - - curl -X POST -H 'Content-type: application/json' \ - --data "{\"text\": \"🏸 *재리뷰 요청 알림*\n*PR 제목:* ${PR_TITLE} (#${PR_NUMBER})\n*작성자:* ${SLACK_AUTHOR_MENTION}\n*리뷰어:* ${SLACK_REVIEWER_MENTION}\n*링크:* ${PR_URL}\"}" \ - $SLACK_WEBHOOK_URL + + PAYLOAD=$(jq -n \ + --arg repo "$REPO_NAME" \ + --arg title "$PR_TITLE" \ + --arg number "$PR_NUMBER" \ + --arg author "$SLACK_AUTHOR_MENTION" \ + --arg reviewer "$SLACK_REVIEWER_MENTION" \ + --arg url "$PR_URL" \ + '{ + text: "🏸 (\($repo)) 재리뷰 요청 알림", + blocks: [ + {type: "header", text: {type: "plain_text", text: "🏸 (\($repo)) 재리뷰 요청 알림", emoji: true}}, + {type: "section", text: {type: "mrkdwn", text: "*PR 제목:* \($title) (#\($number))\n*작성자:* \($author)\n*리뷰어:* \($reviewer)\n*링크:* \($url)"}} + ] + }') + + curl -X POST -H 'Content-type: application/json' --data "$PAYLOAD" $SLACK_WEBHOOK_URL diff --git a/.github/workflows/common-slack-notify-submitted.yml b/.github/workflows/common-slack-notify-submitted.yml index 8e86657a..0f817889 100644 --- a/.github/workflows/common-slack-notify-submitted.yml +++ b/.github/workflows/common-slack-notify-submitted.yml @@ -2,9 +2,9 @@ name: Slack Notification (Submitted) on: pull_request_review: - types: [submitted] + types: [ submitted ] -permissions: {} +permissions: { } concurrency: group: pr-${{ github.event.pull_request.number }}-slack-submitted @@ -15,6 +15,9 @@ jobs: notify: runs-on: ubuntu-latest steps: + - name: Install jq + run: sudo apt-get update && sudo apt-get install -y jq + - name: Notify Review Submitted env: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} @@ -29,6 +32,8 @@ jobs: echo "단순 코멘트 리뷰는 알림 생략" exit 0 fi + + REPO_NAME="${GITHUB_REPOSITORY#*/}" declare -A GITHUB_TO_SLACK GITHUB_TO_SLACK["soeun2537"]="U09A0LM0CRW" @@ -54,7 +59,21 @@ jobs: approved) ICON="✅" ;; changes_requested) ICON="🔴" ;; esac - - curl -X POST -H 'Content-type: application/json' \ - --data "{\"text\": \"${ICON} *리뷰 완료 알림*\n*PR 제목:* ${PR_TITLE} (#${PR_NUMBER})\n*작성자:* ${SLACK_AUTHOR_MENTION}\n*상태:* ${REVIEW_STATE}\n*링크:* ${PR_URL}\"}" \ - $SLACK_WEBHOOK_URL + + PAYLOAD=$(jq -n \ + --arg icon "$ICON" \ + --arg repo "$REPO_NAME" \ + --arg title "$PR_TITLE" \ + --arg number "$PR_NUMBER" \ + --arg author "$SLACK_AUTHOR_MENTION" \ + --arg state "$REVIEW_STATE" \ + --arg url "$PR_URL" \ + '{ + text: "\($icon) (\($repo)) 리뷰 완료 알림", + blocks: [ + {type: "header", text: {type: "plain_text", text: "\($icon) (\($repo)) 리뷰 완료 알림", emoji: true}}, + {type: "section", text: {type: "mrkdwn", text: "*PR 제목:* \($title) (#\($number))\n*작성자:* \($author)\n*상태:* \($state)\n*링크:* \($url)"}} + ] + }') + + curl -X POST -H 'Content-type: application/json' --data "$PAYLOAD" $SLACK_WEBHOOK_URL