|
| 1 | +name: Discord Commit Notification |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - '**' |
| 7 | + |
| 8 | +jobs: |
| 9 | + notify: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + |
| 12 | + steps: |
| 13 | + - name: Send Discord notification |
| 14 | + env: |
| 15 | + DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} |
| 16 | + COMMIT_MESSAGE: ${{ github.event.head_commit.message }} |
| 17 | + AUTHOR: ${{ github.event.head_commit.author.name }} |
| 18 | + run: | |
| 19 | + COMMIT_SHA="${{ github.sha }}" |
| 20 | + SHORT_SHA="${COMMIT_SHA:0:7}" |
| 21 | + BRANCH="${{ github.ref_name }}" |
| 22 | + REPO="${{ github.repository }}" |
| 23 | + COMMIT_URL="https://github.com/${REPO}/commit/${COMMIT_SHA}" |
| 24 | +
|
| 25 | + PAYLOAD=$(jq -n \ |
| 26 | + --arg title "New Commit in \`${REPO}\`" \ |
| 27 | + --arg url "$COMMIT_URL" \ |
| 28 | + --arg author "$AUTHOR" \ |
| 29 | + --arg branch "\`${BRANCH}\`" \ |
| 30 | + --arg commit "[\`${SHORT_SHA}\`](${COMMIT_URL})" \ |
| 31 | + --arg message "$COMMIT_MESSAGE" \ |
| 32 | + '{ |
| 33 | + embeds: [{ |
| 34 | + title: $title, |
| 35 | + url: $url, |
| 36 | + color: 5814783, |
| 37 | + fields: [ |
| 38 | + {name: "Author", value: $author, inline: true}, |
| 39 | + {name: "Branch", value: $branch, inline: true}, |
| 40 | + {name: "Commit", value: $commit, inline: true}, |
| 41 | + {name: "Message", value: $message} |
| 42 | + ] |
| 43 | + }] |
| 44 | + }') |
| 45 | +
|
| 46 | + curl -sf -X POST "$DISCORD_WEBHOOK" \ |
| 47 | + -H "Content-Type: application/json" \ |
| 48 | + -d "$PAYLOAD" |
0 commit comments