|
| 1 | +name: PR Label Notify |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request_target: |
| 5 | + types: [labeled] |
| 6 | + repository_dispatch: |
| 7 | + types: [pr_notify] |
| 8 | + |
| 9 | +jobs: |
| 10 | + notify: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - name: Checkout code |
| 14 | + uses: actions/checkout@v4 |
| 15 | + |
| 16 | + - name: Send Discord notification for PR label |
| 17 | + if: github.event_name == 'pull_request' && github.event.label.name == 'need_review' |
| 18 | + env: |
| 19 | + DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }} |
| 20 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 21 | + PR_TITLE: ${{ github.event.pull_request.title }} |
| 22 | + PR_AUTHOR: ${{ github.event.pull_request.user.login }} |
| 23 | + PR_URL: ${{ github.event.pull_request.html_url }} |
| 24 | + REPO_NAME: ${{ github.repository }} |
| 25 | + run: | |
| 26 | + # Security: Only allow CODEOWNERS to trigger notifications |
| 27 | + ALLOWED_AUTHORS=("wibaek" "manNomi" "enunsnv" "khwww") |
| 28 | + if [[ ! " ${ALLOWED_AUTHORS[@]} " =~ " ${PR_AUTHOR} " ]]; then |
| 29 | + echo "⚠️ Skipping notification: PR author is not a CODEOWNER" |
| 30 | + exit 0 |
| 31 | + fi |
| 32 | +
|
| 33 | + TIMESTAMP=$(date -u +%Y-%m-%dT%H:%M:%SZ) |
| 34 | +
|
| 35 | + jq -n \ |
| 36 | + --arg username "프론트 PR 리뷰봇" \ |
| 37 | + --arg avatar_url "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png" \ |
| 38 | + --arg content "리뷰가 필요합니다! <@&1368737911301865503>" \ |
| 39 | + --arg pr_number "$PR_NUMBER" \ |
| 40 | + --arg pr_title "$PR_TITLE" \ |
| 41 | + --arg pr_author "$PR_AUTHOR" \ |
| 42 | + --arg pr_url "$PR_URL" \ |
| 43 | + --arg repo_name "$REPO_NAME" \ |
| 44 | + --arg timestamp "$TIMESTAMP" \ |
| 45 | + '{ |
| 46 | + username: $username, |
| 47 | + avatar_url: $avatar_url, |
| 48 | + content: $content, |
| 49 | + embeds: [{ |
| 50 | + title: ("PR #" + $pr_number + ": " + $pr_title), |
| 51 | + description: "리뷰 요청이 있습니다", |
| 52 | + url: $pr_url, |
| 53 | + color: 3447003, |
| 54 | + fields: [ |
| 55 | + { |
| 56 | + name: "작성자", |
| 57 | + value: $pr_author, |
| 58 | + inline: true |
| 59 | + }, |
| 60 | + { |
| 61 | + name: "저장소", |
| 62 | + value: $repo_name, |
| 63 | + inline: true |
| 64 | + } |
| 65 | + ], |
| 66 | + footer: { |
| 67 | + text: "GitHub Actions" |
| 68 | + }, |
| 69 | + timestamp: $timestamp |
| 70 | + }], |
| 71 | + allowed_mentions: { |
| 72 | + roles: ["1368737911301865503"] |
| 73 | + } |
| 74 | + }' | curl -X POST "$DISCORD_WEBHOOK_URL" \ |
| 75 | + -H "Content-Type: application/json" \ |
| 76 | + -d @- |
| 77 | +
|
| 78 | + - name: Send Discord notification for webhook |
| 79 | + if: github.event_name == 'repository_dispatch' |
| 80 | + env: |
| 81 | + DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }} |
| 82 | + CUSTOM_MESSAGE: ${{ github.event.client_payload.message }} |
| 83 | + run: | |
| 84 | + MESSAGE="${CUSTOM_MESSAGE:-리뷰가 필요합니다! <@&1368737911301865503>}" |
| 85 | +
|
| 86 | + jq -n \ |
| 87 | + --arg username "프론트 PR 리뷰봇" \ |
| 88 | + --arg avatar_url "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png" \ |
| 89 | + --arg content "$MESSAGE" \ |
| 90 | + '{ |
| 91 | + username: $username, |
| 92 | + avatar_url: $avatar_url, |
| 93 | + content: $content, |
| 94 | + allowed_mentions: { |
| 95 | + roles: ["1368737911301865503"] |
| 96 | + } |
| 97 | + }' | curl -X POST "$DISCORD_WEBHOOK_URL" \ |
| 98 | + -H "Content-Type: application/json" \ |
| 99 | + -d @- |
0 commit comments