|
| 1 | +name: Full Repository Activity Logger (Discord Embed) |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - '**' |
| 7 | + pull_request: |
| 8 | + types: [opened, closed, reopened, merged, synchronize] |
| 9 | + issues: |
| 10 | + types: [opened, edited, closed, reopened] |
| 11 | + issue_comment: |
| 12 | + types: [created, edited, deleted] |
| 13 | + release: |
| 14 | + types: [published, edited, prereleased, deleted] |
| 15 | + create: # новая ветка или тег |
| 16 | + delete: # удаление ветки или тега |
| 17 | + watch: # подписка / star |
| 18 | + workflow_run: |
| 19 | + types: [completed] |
| 20 | + |
| 21 | +jobs: |
| 22 | + log_to_discord: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + |
| 25 | + steps: |
| 26 | + - name: Checkout repository |
| 27 | + uses: actions/checkout@v3 |
| 28 | + |
| 29 | + - name: Prepare Discord Embed |
| 30 | + id: discord_embed |
| 31 | + run: | |
| 32 | + EVENT_TYPE="${{ github.event_name }}" |
| 33 | + REPO="${{ github.repository }}" |
| 34 | + USER="${{ github.actor }}" |
| 35 | + AVATAR="https://github.com/${USER}.png" |
| 36 | + |
| 37 | + # Ссылка на объект |
| 38 | + URL="" |
| 39 | + case "$EVENT_TYPE" in |
| 40 | + push) URL="${{ github.event.head_commit.url }}" ;; |
| 41 | + pull_request) URL="${{ github.event.pull_request.html_url }}" ;; |
| 42 | + issues) URL="${{ github.event.issue.html_url }}" ;; |
| 43 | + issue_comment) URL="${{ github.event.comment.html_url }}" ;; |
| 44 | + release) URL="${{ github.event.release.html_url }}" ;; |
| 45 | + create) URL="https://github.com/${REPO}/tree/${{ github.ref_name }}" ;; |
| 46 | + delete) URL="https://github.com/${REPO}/tree/${{ github.ref_name }}" ;; |
| 47 | + esac |
| 48 | +
|
| 49 | + # Цвет Embed для разных событий |
| 50 | + COLOR="3447003" |
| 51 | + case "$EVENT_TYPE" in |
| 52 | + push) COLOR="3066993" ;; |
| 53 | + pull_request) COLOR="15105570" ;; |
| 54 | + issues) COLOR="15844367" ;; |
| 55 | + issue_comment) COLOR="15844367" ;; |
| 56 | + release) COLOR="10181046" ;; |
| 57 | + create) COLOR="3066993" ;; |
| 58 | + delete) COLOR="15105570" ;; |
| 59 | + watch) COLOR="15844367" ;; |
| 60 | + workflow_run) COLOR="10181046" ;; |
| 61 | + esac |
| 62 | +
|
| 63 | + TITLE="[$EVENT_TYPE] в репозитории $REPO" |
| 64 | + DESCRIPTION="Пользователь: **$USER**" |
| 65 | + if [ -n "$URL" ]; then |
| 66 | + DESCRIPTION="$DESCRIPTION\nСсылка: $URL" |
| 67 | + fi |
| 68 | +
|
| 69 | + EMBED=$(jq -n \ |
| 70 | + --arg title "$TITLE" \ |
| 71 | + --arg description "$DESCRIPTION" \ |
| 72 | + --arg author_name "$USER" \ |
| 73 | + --arg author_icon "$AVATAR" \ |
| 74 | + --argjson color $COLOR \ |
| 75 | + '{embeds:[{title:$title, description:$description, color:$color, author:{name:$author_name, icon_url:$author_icon}}]}') |
| 76 | + |
| 77 | + echo "embed=$EMBED" >> $GITHUB_OUTPUT |
| 78 | +
|
| 79 | + - name: Send to Discord |
| 80 | + uses: Ilshidur/action-discord@v2 |
| 81 | + with: |
| 82 | + webhook: ${{ secrets.DISCORD_WEBHOOK }} |
| 83 | + message: "Новое событие в репозитории:" |
| 84 | + embed: ${{ steps.discord_embed.outputs.embed }} |
0 commit comments