|
| 1 | +name: Discord Notifications |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + pull_request: |
| 7 | + branches: [main] |
| 8 | + types: [opened, reopened, synchronize, closed, ready_for_review, converted_to_draft, edited, labeled, unlabeled, assigned, unassigned, review_requested, review_request_removed] |
| 9 | + pull_request_review: |
| 10 | + types: [submitted, edited, dismissed] |
| 11 | + pull_request_review_comment: |
| 12 | + types: [created, edited, deleted] |
| 13 | + issues: |
| 14 | + types: [opened, reopened, closed, edited, labeled, unlabeled, assigned, unassigned, milestoned, demilestoned, transferred, pinned, unpinned, locked, unlocked, deleted] |
| 15 | + issue_comment: |
| 16 | + types: [created, edited, deleted] |
| 17 | + release: |
| 18 | + types: [published, unpublished, created, edited, deleted, prereleased, released] |
| 19 | + create: |
| 20 | + delete: |
| 21 | + fork: |
| 22 | + star: |
| 23 | + types: [created, deleted] |
| 24 | + watch: |
| 25 | + types: [started] |
| 26 | + discussion: |
| 27 | + types: [created, edited, deleted, pinned, unpinned, locked, unlocked, transferred, category_changed, answered, unanswered] |
| 28 | + discussion_comment: |
| 29 | + types: [created, edited, deleted] |
| 30 | + workflow_run: |
| 31 | + types: [completed, requested, in_progress] |
| 32 | + workflow_dispatch: |
| 33 | + repository_dispatch: |
| 34 | + public: |
| 35 | + member: |
| 36 | + types: [added, edited, removed] |
| 37 | + milestone: |
| 38 | + types: [created, closed, opened, edited, deleted] |
| 39 | + label: |
| 40 | + types: [created, edited, deleted] |
| 41 | + project: |
| 42 | + types: [created, closed, reopened, edited, deleted] |
| 43 | + project_card: |
| 44 | + types: [created, moved, converted, edited, deleted] |
| 45 | + project_column: |
| 46 | + types: [created, updated, moved, deleted] |
| 47 | + status: |
| 48 | + deployment: |
| 49 | + deployment_status: |
| 50 | + page_build: |
| 51 | + gollum: |
| 52 | + |
| 53 | +jobs: |
| 54 | + notify: |
| 55 | + runs-on: ubuntu-latest |
| 56 | + if: ${{ github.ref == 'refs/heads/main' || github.event_name != 'push' }} |
| 57 | + steps: |
| 58 | + - name: Send Discord notification |
| 59 | + env: |
| 60 | + DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }} |
| 61 | + EVENT_NAME: ${{ github.event_name }} |
| 62 | + ACTION: ${{ github.event.action }} |
| 63 | + REPO: ${{ github.repository }} |
| 64 | + ACTOR: ${{ github.actor }} |
| 65 | + REF: ${{ github.ref }} |
| 66 | + SHA: ${{ github.sha }} |
| 67 | + SERVER_URL: ${{ github.server_url }} |
| 68 | + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
| 69 | + run: | |
| 70 | + if [ "${GITHUB_REF}" != "refs/heads/main" ]; then |
| 71 | + exit 0 |
| 72 | + fi |
| 73 | +
|
| 74 | + URL="$SERVER_URL/$REPO" |
| 75 | + CONTENT="**$EVENT_NAME**" |
| 76 | + if [ -n "$ACTION" ] && [ "$ACTION" != "null" ]; then |
| 77 | + CONTENT="$CONTENT (\`$ACTION\`)" |
| 78 | + fi |
| 79 | + CONTENT="$CONTENT in **$REPO** von **$ACTOR**\nRef: \`$REF\`\n$URL\nRun: $RUN_URL" |
| 80 | +
|
| 81 | + if [ "$EVENT_NAME" = "push" ]; then |
| 82 | + SHORT_SHA=$(echo "$SHA" | cut -c1-7) |
| 83 | + CONTENT="$CONTENT\nCommit: \`$SHORT_SHA\`\n$URL/commit/$SHA" |
| 84 | + fi |
| 85 | +
|
| 86 | + if [ "$EVENT_NAME" = "pull_request" ]; then |
| 87 | + PR_URL="${{ github.event.pull_request.html_url }}" |
| 88 | + PR_TITLE="${{ github.event.pull_request.title }}" |
| 89 | + PR_NUM="${{ github.event.pull_request.number }}" |
| 90 | + CONTENT="$CONTENT\nPR #$PR_NUM: **$PR_TITLE**\n$PR_URL" |
| 91 | + fi |
| 92 | +
|
| 93 | + if [ "$EVENT_NAME" = "issues" ]; then |
| 94 | + ISSUE_URL="${{ github.event.issue.html_url }}" |
| 95 | + ISSUE_TITLE="${{ github.event.issue.title }}" |
| 96 | + ISSUE_NUM="${{ github.event.issue.number }}" |
| 97 | + CONTENT="$CONTENT\nIssue #$ISSUE_NUM: **$ISSUE_TITLE**\n$ISSUE_URL" |
| 98 | + fi |
| 99 | +
|
| 100 | + if [ "$EVENT_NAME" = "issue_comment" ]; then |
| 101 | + C_URL="${{ github.event.comment.html_url }}" |
| 102 | + ISSUE_NUM="${{ github.event.issue.number }}" |
| 103 | + CONTENT="$CONTENT\nComment on Issue #$ISSUE_NUM\n$C_URL" |
| 104 | + fi |
| 105 | +
|
| 106 | + if [ "$EVENT_NAME" = "pull_request_review" ]; then |
| 107 | + R_URL="${{ github.event.review.html_url }}" |
| 108 | + PR_NUM="${{ github.event.pull_request.number }}" |
| 109 | + STATE="${{ github.event.review.state }}" |
| 110 | + CONTENT="$CONTENT\nReview on PR #$PR_NUM: \`$STATE\`\n$R_URL" |
| 111 | + fi |
| 112 | +
|
| 113 | + if [ "$EVENT_NAME" = "pull_request_review_comment" ]; then |
| 114 | + RC_URL="${{ github.event.comment.html_url }}" |
| 115 | + PR_NUM="${{ github.event.pull_request.number }}" |
| 116 | + CONTENT="$CONTENT\nReview comment on PR #$PR_NUM\n$RC_URL" |
| 117 | + fi |
| 118 | +
|
| 119 | + if [ "$EVENT_NAME" = "release" ]; then |
| 120 | + REL_URL="${{ github.event.release.html_url }}" |
| 121 | + REL_NAME="${{ github.event.release.name }}" |
| 122 | + REL_TAG="${{ github.event.release.tag_name }}" |
| 123 | + CONTENT="$CONTENT\nRelease: **$REL_NAME** (\`$REL_TAG\`)\n$REL_URL" |
| 124 | + fi |
| 125 | +
|
| 126 | + if [ "$EVENT_NAME" = "discussion" ]; then |
| 127 | + D_URL="${{ github.event.discussion.html_url }}" |
| 128 | + D_TITLE="${{ github.event.discussion.title }}" |
| 129 | + CONTENT="$CONTENT\nDiscussion: **$D_TITLE**\n$D_URL" |
| 130 | + fi |
| 131 | +
|
| 132 | + if [ "$EVENT_NAME" = "discussion_comment" ]; then |
| 133 | + DC_URL="${{ github.event.comment.html_url }}" |
| 134 | + CONTENT="$CONTENT\nDiscussion comment\n$DC_URL" |
| 135 | + fi |
| 136 | +
|
| 137 | + if [ "$EVENT_NAME" = "workflow_run" ]; then |
| 138 | + WR_URL="${{ github.event.workflow_run.html_url }}" |
| 139 | + WR_NAME="${{ github.event.workflow_run.name }}" |
| 140 | + WR_CONC="${{ github.event.workflow_run.conclusion }}" |
| 141 | + CONTENT="$CONTENT\nWorkflow: **$WR_NAME**\nConclusion: \`$WR_CONC\`\n$WR_URL" |
| 142 | + fi |
| 143 | +
|
| 144 | + payload=$(jq -n --arg content "$CONTENT" '{content: $content}') |
| 145 | + curl -H "Content-Type: application/json" -d "$payload" "$DISCORD_WEBHOOK_URL" |
0 commit comments