|
| 1 | +name: DingTalk Notify |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [master] |
| 6 | + tags: ['v*'] |
| 7 | + pull_request: |
| 8 | + types: [opened, closed, reopened] |
| 9 | + pull_request_review: |
| 10 | + types: [submitted] |
| 11 | + pull_request_review_comment: |
| 12 | + types: [created] |
| 13 | + issues: |
| 14 | + types: [opened, closed, reopened] |
| 15 | + issue_comment: |
| 16 | + types: [created] |
| 17 | + release: |
| 18 | + types: [published] |
| 19 | + workflow_run: |
| 20 | + workflows: ["Build and Release"] |
| 21 | + types: [completed] |
| 22 | + |
| 23 | +jobs: |
| 24 | + notify: |
| 25 | + runs-on: ubuntu-latest |
| 26 | + steps: |
| 27 | + - name: Send DingTalk notification |
| 28 | + env: |
| 29 | + EVENT_NAME: ${{ github.event_name }} |
| 30 | + REPO: ${{ github.repository }} |
| 31 | + ACTOR: ${{ github.actor }} |
| 32 | + REF_NAME: ${{ github.ref_name }} |
| 33 | + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
| 34 | + run: | |
| 35 | + case "$EVENT_NAME" in |
| 36 | + push) |
| 37 | + TITLE="📤 Push to $REF_NAME" |
| 38 | + TEXT="**操作人**: $ACTOR\n\n[查看详情]($RUN_URL)" |
| 39 | + ;; |
| 40 | + pull_request) |
| 41 | + ACTION="${{ github.event.action }}" |
| 42 | + PR_TITLE="${{ github.event.pull_request.title }}" |
| 43 | + PR_URL="${{ github.event.pull_request.html_url }}" |
| 44 | + TITLE="🔀 PR $ACTION: $PR_TITLE" |
| 45 | + TEXT="**操作人**: $ACTOR\n\n[查看 PR]($PR_URL)" |
| 46 | + ;; |
| 47 | + pull_request_review) |
| 48 | + PR_TITLE="${{ github.event.pull_request.title }}" |
| 49 | + PR_URL="${{ github.event.pull_request.html_url }}" |
| 50 | + STATE="${{ github.event.review.state }}" |
| 51 | + TITLE="👀 PR Review ($STATE)" |
| 52 | + TEXT="**PR**: $PR_TITLE\n\n**操作人**: $ACTOR\n\n[查看]($PR_URL)" |
| 53 | + ;; |
| 54 | + pull_request_review_comment) |
| 55 | + PR_TITLE="${{ github.event.pull_request.title }}" |
| 56 | + COMMENT_URL="${{ github.event.comment.html_url }}" |
| 57 | + TITLE="💬 PR Comment" |
| 58 | + TEXT="**PR**: $PR_TITLE\n\n**操作人**: $ACTOR\n\n[查看评论]($COMMENT_URL)" |
| 59 | + ;; |
| 60 | + issues) |
| 61 | + ACTION="${{ github.event.action }}" |
| 62 | + ISSUE_TITLE="${{ github.event.issue.title }}" |
| 63 | + ISSUE_URL="${{ github.event.issue.html_url }}" |
| 64 | + TITLE="📋 Issue $ACTION: $ISSUE_TITLE" |
| 65 | + TEXT="**操作人**: $ACTOR\n\n[查看 Issue]($ISSUE_URL)" |
| 66 | + ;; |
| 67 | + issue_comment) |
| 68 | + ISSUE_TITLE="${{ github.event.issue.title }}" |
| 69 | + COMMENT_URL="${{ github.event.comment.html_url }}" |
| 70 | + TITLE="💬 Issue Comment" |
| 71 | + TEXT="**Issue**: $ISSUE_TITLE\n\n**操作人**: $ACTOR\n\n[查看评论]($COMMENT_URL)" |
| 72 | + ;; |
| 73 | + release) |
| 74 | + TAG="${{ github.event.release.tag_name }}" |
| 75 | + RELEASE_URL="${{ github.event.release.html_url }}" |
| 76 | + TITLE="🚀 Release $TAG" |
| 77 | + TEXT="**操作人**: $ACTOR\n\n[查看 Release]($RELEASE_URL)" |
| 78 | + ;; |
| 79 | + workflow_run) |
| 80 | + STATUS="${{ github.event.workflow_run.conclusion }}" |
| 81 | + BRANCH="${{ github.event.workflow_run.head_branch }}" |
| 82 | + WF_URL="${{ github.event.workflow_run.html_url }}" |
| 83 | + if [ "$STATUS" = "success" ]; then |
| 84 | + TITLE="✅ Build Success" |
| 85 | + else |
| 86 | + TITLE="❌ Build Failed" |
| 87 | + fi |
| 88 | + TEXT="**分支**: $BRANCH\n\n**状态**: $STATUS\n\n[查看详情]($WF_URL)" |
| 89 | + ;; |
| 90 | + *) |
| 91 | + TITLE="🔔 $EVENT_NAME" |
| 92 | + TEXT="**操作人**: $ACTOR\n\n[查看详情]($RUN_URL)" |
| 93 | + ;; |
| 94 | + esac |
| 95 | +
|
| 96 | + curl -s -X POST "${{ secrets.DINGTALK_WEBHOOK }}" \ |
| 97 | + -H "Content-Type: application/json" \ |
| 98 | + -d "{ |
| 99 | + \"msgtype\": \"markdown\", |
| 100 | + \"markdown\": { |
| 101 | + \"title\": \"$TITLE\", |
| 102 | + \"text\": \"### $TITLE\n\n**仓库**: $REPO\n\n$TEXT\" |
| 103 | + } |
| 104 | + }" |
0 commit comments