From 98cac96c1cd3da5e3fa78ad6e516de9483af45d0 Mon Sep 17 00:00:00 2001 From: Doeunnkimm Date: Sat, 29 Jun 2024 03:12:58 +0900 Subject: [PATCH] fix: pr-slack-noti --- .github/workflows/pr-slack-noti.yml | 39 ++++++++++ .github/workflows/reviewers.yml | 13 ++++ .github/workflows/slack-notify.yml | 109 ---------------------------- 3 files changed, 52 insertions(+), 109 deletions(-) create mode 100644 .github/workflows/pr-slack-noti.yml create mode 100644 .github/workflows/reviewers.yml delete mode 100644 .github/workflows/slack-notify.yml diff --git a/.github/workflows/pr-slack-noti.yml b/.github/workflows/pr-slack-noti.yml new file mode 100644 index 00000000..94e7f6cd --- /dev/null +++ b/.github/workflows/pr-slack-noti.yml @@ -0,0 +1,39 @@ +name: PR Slack Notification + +on: + pull_request: + types: [review_requested] + issue_comment: + types: [created] + +jobs: + notify: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: '20' + + - name: Install pnpm + run: npm install -g pnpm + + - name: Install dependencies + run: pnpm install + + - name: Build + run: pnpm build + + - name: Notify Slack + uses: ./ + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + slack_token: ${{ secrets.SLACK_BOT_ACCESS_TOKEN }} + slack_channel: C079A5A8BL0 + slack_workspace: 'DEPROMEET 15th' + reviewers_file: .github/workflows/reviewers.yml + slack_merge_emoji_name: check diff --git a/.github/workflows/reviewers.yml b/.github/workflows/reviewers.yml new file mode 100644 index 00000000..f9290381 --- /dev/null +++ b/.github/workflows/reviewers.yml @@ -0,0 +1,13 @@ +reviewers: + - githubName: Doeunnkimm + slackId: U07600UQG3T + name: WEB_김도은 + - githubName: semnil5202 + slackId: U075KR29RGR + name: Web_이세민 + - githubName: LeeJeongHooo + slackId: U075C1A16LT + name: Web_이정호 + - githubName: Andrevile + slackId: U07545VMS21 + name: Web_장종오 diff --git a/.github/workflows/slack-notify.yml b/.github/workflows/slack-notify.yml deleted file mode 100644 index 562563cb..00000000 --- a/.github/workflows/slack-notify.yml +++ /dev/null @@ -1,109 +0,0 @@ -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: Read user mapping - id: read_mapping - run: | - mapping=$(cat .github/user-mapping.json) - echo "mapping=$mapping" >> $GITHUB_ENV - - - name: Cache Slack message timestamp - if: ${{ env.event_type == 'pull_request' }} - uses: actions/cache@v2 - with: - path: slack_ts.txt - key: slack-ts-${{ github.event.pull_request.number }} - - - 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[sambad#${{ github.event.pull_request.number }}] [${{ github.event.pull_request.title }}](${{ github.event.pull_request.html_url }})\n${{ github.event.pull_request.user.login }}님이 생성했어요." - }' ${{ secrets.SLACK_BOT_ACCESS_TOKEN }}) - echo "slack_ts=$(echo $response | jq -r '.ts')" >> $GITHUB_ENV - echo $slack_ts > slack_ts.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=$(echo ${{ env.mapping }} | jq -r --arg reviewer "$reviewer" '.[$reviewer]') - if [ "$slack_username" != "null" ]; then - response=$(curl -X POST -H 'Content-type: application/json' --data '{ - "text": "🔔 리뷰 요청이 도착했습니다: @'$slack_username'" - }' ${{ secrets.SLACK_BOT_ACCESS_TOKEN }}) - echo "slack_ts=$(echo $response | jq -r '.ts')" >> $GITHUB_ENV - echo $slack_ts > slack_ts.txt - else - echo "Reviewer not found in mapping: $reviewer" - fi - env: - SLACK_BOT_ACCESS_TOKEN: ${{ secrets.SLACK_BOT_ACCESS_TOKEN }} - - - name: Restore Slack message timestamp - 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 || github.event.pull_request.number }} - restore-keys: | - slack-ts- - - - name: Load Slack message timestamp - 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 - if: ${{ env.event_type == 'issue_comment' && env.SLACK_MESSAGE_TS != '' }} - run: | - commenter=${{ github.event.comment.user.login }} - slack_username=$(echo ${{ env.mapping }} | 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 }}" - }' ${{ 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=$(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 }}