|
| 1 | +name: Discord PR Notifier |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, reopened, closed] |
| 6 | + |
| 7 | +jobs: |
| 8 | + notify: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + steps: |
| 11 | + - name: Send PR info to Discord |
| 12 | + env: |
| 13 | + DISCORD_WEBHOOK_URL_4: ${{ secrets.DISCORD_WEBHOOK_URL_4 }} |
| 14 | + run: | |
| 15 | + ACTION="${{ github.event.action }}" |
| 16 | + MERGED="${{ github.event.pull_request.merged }}" |
| 17 | +
|
| 18 | + # Ignore closed but not merged PRs |
| 19 | + if [ "$ACTION" = "closed" ] && [ "$MERGED" != "true" ]; then |
| 20 | + exit 0 |
| 21 | + fi |
| 22 | +
|
| 23 | + if [ "$ACTION" = "opened" ]; then |
| 24 | + TITLE="🆕 Pull Request Opened" |
| 25 | + COLOR=3447003 |
| 26 | + elif [ "$ACTION" = "reopened" ]; then |
| 27 | + TITLE="🔄 Pull Request Reopened" |
| 28 | + COLOR=16776960 |
| 29 | + else |
| 30 | + TITLE="✅ Pull Request Merged" |
| 31 | + COLOR=3066993 |
| 32 | + fi |
| 33 | +
|
| 34 | + curl -X POST "$DISCORD_WEBHOOK_URL_4" \ |
| 35 | + -H "Content-Type: application/json" \ |
| 36 | + -d @- << EOF |
| 37 | + { |
| 38 | + "username": "GitHub PR Bot", |
| 39 | + "avatar_url": "https://github.com/github.png", |
| 40 | + "embeds": [ |
| 41 | + { |
| 42 | + "title": "$TITLE", |
| 43 | + "url": "${{ github.event.pull_request.html_url }}", |
| 44 | + "description": "**${{ github.event.pull_request.title }}**", |
| 45 | + "color": $COLOR, |
| 46 | + "author": { |
| 47 | + "name": "${{ github.event.pull_request.user.login }}", |
| 48 | + "url": "${{ github.event.pull_request.user.html_url }}", |
| 49 | + "icon_url": "${{ github.event.pull_request.user.avatar_url }}" |
| 50 | + }, |
| 51 | + "fields": [ |
| 52 | + { |
| 53 | + "name": "Base → Head", |
| 54 | + "value": "${{ github.event.pull_request.base.ref }} → ${{ github.event.pull_request.head.ref }}", |
| 55 | + "inline": true |
| 56 | + }, |
| 57 | + { |
| 58 | + "name": "Repository", |
| 59 | + "value": "${{ github.repository }}", |
| 60 | + "inline": true |
| 61 | + } |
| 62 | + ], |
| 63 | + "footer": { |
| 64 | + "text": "JsWeb Framework • Pull Requests" |
| 65 | + } |
| 66 | + } |
| 67 | + ] |
| 68 | + } |
| 69 | + EOF |
0 commit comments