|
| 1 | +name: Notify (GitHub Events) |
| 2 | + |
| 3 | +permissions: |
| 4 | + issues: write |
| 5 | + pull-requests: write |
| 6 | + contents: read |
| 7 | + |
| 8 | +on: |
| 9 | + issues: |
| 10 | + types: [opened, edited, reopened, closed, assigned, labeled] |
| 11 | + pull_request: |
| 12 | + types: [opened, closed, reopened, ready_for_review, review_requested] |
| 13 | + pull_request_review: |
| 14 | + types: [submitted, edited, dismissed] |
| 15 | + issue_comment: |
| 16 | + types: [created, edited] |
| 17 | + pull_request_review_comment: |
| 18 | + types: [created, edited] |
| 19 | + |
| 20 | +jobs: |
| 21 | + notify: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + name: Send Notifications |
| 24 | + |
| 25 | + steps: |
| 26 | + - name: Determine Event Type |
| 27 | + id: event_info |
| 28 | + run: | |
| 29 | + EVENT="${{ github.event_name }}" |
| 30 | + ACTION="${{ github.event.action }}" |
| 31 | + REPO="${{ github.repository }}" |
| 32 | + ACTOR="${{ github.actor }}" |
| 33 | + REPO_URL="${{ github.server_url }}/${{ github.repository }}" |
| 34 | +
|
| 35 | + if [[ "$EVENT" == "issues" ]]; then |
| 36 | + TITLE="Issue $ACTION: ${{ github.event.issue.title }}" |
| 37 | + URL="${{ github.event.issue.html_url }}" |
| 38 | + NUMBER="${{ github.event.issue.number }}" |
| 39 | + USER="${{ github.event.issue.user.login }}" |
| 40 | + DESCRIPTION="Issue #$NUMBER by $USER" |
| 41 | + STATE="${{ github.event.issue.state }}" |
| 42 | + EMOJI="🐛" |
| 43 | +
|
| 44 | + elif [[ "$EVENT" == "pull_request" ]]; then |
| 45 | + NUMBER="${{ github.event.pull_request.number }}" |
| 46 | + USER="${{ github.event.pull_request.user.login }}" |
| 47 | + URL="${{ github.event.pull_request.html_url }}" |
| 48 | + STATE="${{ github.event.pull_request.state }}" |
| 49 | + SOURCE="${{ github.event.pull_request.head.ref }}" |
| 50 | + TARGET="${{ github.event.pull_request.base.ref }}" |
| 51 | +
|
| 52 | + if [[ "$ACTION" == "closed" && "${{ github.event.pull_request.merged }}" == "true" ]]; then |
| 53 | + TITLE="PR merged: ${{ github.event.pull_request.title }}" |
| 54 | + EMOJI="✅" |
| 55 | + STATE="merged" |
| 56 | + elif [[ "$ACTION" == "closed" ]]; then |
| 57 | + TITLE="PR closed: ${{ github.event.pull_request.title }}" |
| 58 | + EMOJI="❌" |
| 59 | + else |
| 60 | + TITLE="PR $ACTION: ${{ github.event.pull_request.title }}" |
| 61 | + EMOJI="🔀" |
| 62 | + fi |
| 63 | + DESCRIPTION="PR #$NUMBER by $USER: $SOURCE → $TARGET" |
| 64 | +
|
| 65 | + elif [[ "$EVENT" == "pull_request_review" ]]; then |
| 66 | + TITLE="PR Review: ${{ github.event.pull_request.title }}" |
| 67 | + URL="${{ github.event.review.html_url }}" |
| 68 | + NUMBER="${{ github.event.pull_request.number }}" |
| 69 | + USER="${{ github.event.review.user.login }}" |
| 70 | + REVIEW_STATE="${{ github.event.review.state }}" |
| 71 | + STATE="${{ github.event.review.state }}" |
| 72 | + SOURCE="${{ github.event.pull_request.head.ref }}" |
| 73 | + TARGET="${{ github.event.pull_request.base.ref }}" |
| 74 | + DESCRIPTION="Review by $USER on PR #$NUMBER" |
| 75 | + EMOJI="👀" |
| 76 | +
|
| 77 | + elif [[ "$EVENT" == "issue_comment" ]]; then |
| 78 | + NUMBER="${{ github.event.issue.number }}" |
| 79 | + USER="${{ github.event.comment.user.login }}" |
| 80 | + URL="${{ github.event.comment.html_url }}" |
| 81 | + STATE="commented" |
| 82 | +
|
| 83 | + if [[ "${{ github.event.issue.pull_request }}" != "" ]]; then |
| 84 | + TITLE="Comment on PR: ${{ github.event.issue.title }}" |
| 85 | + EMOJI="💬" |
| 86 | + else |
| 87 | + TITLE="Comment on Issue: ${{ github.event.issue.title }}" |
| 88 | + EMOJI="💬" |
| 89 | + fi |
| 90 | + DESCRIPTION="Comment by $USER on #$NUMBER" |
| 91 | +
|
| 92 | + elif [[ "$EVENT" == "pull_request_review_comment" ]]; then |
| 93 | + TITLE="Comment on PR: ${{ github.event.pull_request.title }}" |
| 94 | + URL="${{ github.event.comment.html_url }}" |
| 95 | + NUMBER="${{ github.event.pull_request.number }}" |
| 96 | + USER="${{ github.event.comment.user.login }}" |
| 97 | + STATE="commented" |
| 98 | + SOURCE="${{ github.event.pull_request.head.ref }}" |
| 99 | + TARGET="${{ github.event.pull_request.base.ref }}" |
| 100 | + DESCRIPTION="Review comment by $USER on PR #$NUMBER" |
| 101 | + EMOJI="💬" |
| 102 | + else |
| 103 | + TITLE="GitHub Event: $EVENT" |
| 104 | + URL="${{ github.event.repository.html_url }}" |
| 105 | + DESCRIPTION="Event triggered in $REPO" |
| 106 | + STATE="N/A" |
| 107 | + NUMBER="N/A" |
| 108 | + USER="$ACTOR" |
| 109 | + EMOJI="📢" |
| 110 | + fi |
| 111 | +
|
| 112 | + echo "title=$TITLE" >> $GITHUB_OUTPUT |
| 113 | + echo "url=$URL" >> $GITHUB_OUTPUT |
| 114 | + echo "description=$DESCRIPTION" >> $GITHUB_OUTPUT |
| 115 | + echo "emoji=$EMOJI" >> $GITHUB_OUTPUT |
| 116 | + echo "number=${NUMBER:-N/A}" >> $GITHUB_OUTPUT |
| 117 | + echo "user=${USER:-$ACTOR}" >> $GITHUB_OUTPUT |
| 118 | + echo "state=${STATE:-N/A}" >> $GITHUB_OUTPUT |
| 119 | + echo "source=${SOURCE:-N/A}" >> $GITHUB_OUTPUT |
| 120 | + echo "target=${TARGET:-N/A}" >> $GITHUB_OUTPUT |
| 121 | + echo "repo_url=$REPO_URL" >> $GITHUB_OUTPUT |
| 122 | +
|
| 123 | + - name: Google Chat Notification |
| 124 | + if: always() |
| 125 | + uses: Co-qn/google-chat-notification@releases/v1 |
| 126 | + with: |
| 127 | + name: ${{ steps.event_info.outputs.title }} |
| 128 | + url: ${{ secrets.GOOGLE_CHAT_WEBHOOK }} |
| 129 | + status: ${{ job.status }} |
| 130 | + |
| 131 | + - name: Slack Notification |
| 132 | + if: always() |
| 133 | + uses: slackapi/slack-github-action@v1.24.0 |
| 134 | + with: |
| 135 | + channel-id: ${{ secrets.SLACK_CHANNEL_ID }} |
| 136 | + payload: | |
| 137 | + { |
| 138 | + "text": "${{ steps.event_info.outputs.title }}", |
| 139 | + "blocks": [ |
| 140 | + { |
| 141 | + "type": "header", |
| 142 | + "text": { |
| 143 | + "type": "plain_text", |
| 144 | + "text": "${{ steps.event_info.outputs.emoji }} ${{ steps.event_info.outputs.title }}" |
| 145 | + } |
| 146 | + }, |
| 147 | + { |
| 148 | + "type": "section", |
| 149 | + "fields": [ |
| 150 | + { "type": "mrkdwn", "text": "*Repository:*\n<${{ steps.event_info.outputs.repo_url }}|${{ github.repository }}>" }, |
| 151 | + { "type": "mrkdwn", "text": "*Event:*\n${{ github.event_name }}" }, |
| 152 | + { "type": "mrkdwn", "text": "*Author:*\n${{ steps.event_info.outputs.user }}" }, |
| 153 | + { "type": "mrkdwn", "text": "*Action:*\n${{ github.event.action }}" }, |
| 154 | + { "type": "mrkdwn", "text": "*Number:*\n<${{ steps.event_info.outputs.url }}|#${{ steps.event_info.outputs.number }}>" }, |
| 155 | + { "type": "mrkdwn", "text": "*State:*\n${{ steps.event_info.outputs.state }}" } |
| 156 | + ] |
| 157 | + }, |
| 158 | + { |
| 159 | + "type": "section", |
| 160 | + "text": { "type": "mrkdwn", "text": "${{ steps.event_info.outputs.description }}" } |
| 161 | + }, |
| 162 | + { |
| 163 | + "type": "actions", |
| 164 | + "elements": [ |
| 165 | + { "type": "button", "text": { "type": "plain_text", "text": "View on GitHub" }, "url": "${{ steps.event_info.outputs.url }}", "style": "primary" }, |
| 166 | + { "type": "button", "text": { "type": "plain_text", "text": "View Repository" }, "url": "${{ steps.event_info.outputs.repo_url }}" } |
| 167 | + ] |
| 168 | + }, |
| 169 | + { |
| 170 | + "type": "context", |
| 171 | + "elements": [ |
| 172 | + { "type": "mrkdwn", "text": "Triggered by ${{ github.actor }} • ${{ github.event_name }} event" } |
| 173 | + ] |
| 174 | + } |
| 175 | + ] |
| 176 | + } |
| 177 | + env: |
| 178 | + SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} |
0 commit comments