Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can you provide an example for discord embeds with vars? #88

Open
gryphonDev1 opened this issue Oct 2, 2021 · 10 comments
Open

Can you provide an example for discord embeds with vars? #88

gryphonDev1 opened this issue Oct 2, 2021 · 10 comments

Comments

@gryphonDev1
Copy link

Basically an example with how you did the sample png you show would be great, thanks!

@delphiactual
Copy link

delphiactual commented Mar 5, 2022

      DISCORD_EMBEDS: '[{"title":"DIM - crowdin", "color": F37422, "url": "https://crowdin.com/project/destiny-item-manager","description": "${{ steps.i18n-diff.outputs.insertions }} translations have been added or changed on crowdin."  }]'

@rildomar
Copy link

Can someone help-me?
i cant send message with Embeds, becase i take this erro using this example:

      DISCORD_EMBEDS: '[{"title":"DIM - crowdin", "color": F37422, "url": "https://crowdin.com/project/destiny-item-manager","description": "${{ steps.i18n-diff.outputs.insertions }} translations have been added or changed on crowdin."  }]'

the documentations says:

DISCORD_EMBEDS (optional): This should be a valid JSON string of an array of Discord embed objects. See the documentation on Discord WebHook Embeds for more information. You can use set it to ${{ toJson(my_value) }} using toJson() if your input is an object value.

any example ?

@luisfun
Copy link

luisfun commented Aug 30, 2022

This code worked.

name: Discord notification

on:
  push:
    branches: [ master ]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - name: Discord notification
      env:
        DISCORD_WEBHOOK: ${{secrets.DISCORD_WEBHOOK}}
        DISCORD_EMBEDS: '[{ "title":"${{github.event.head_commit.message}}", "footer":{"text":"Pushed by ${{github.event.head_commit.author.name}}"} }]'
      uses: Ilshidur/action-discord@0.3.2

image

@NorkzYT
Copy link

NorkzYT commented Nov 21, 2022

@gryphonDev1

I just finished making an example that looks very nice. Hope you, and anyone else who uses this example enjoys!

name: Discord Notification

on:
  push:

jobs:
  Discord:
    runs-on: ubuntu-latest
    name: Discord Notifier
    #if: "contains(github.event.head_commit.message, '[skip ci]')"
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0  # OR "2" -> To retrieve the preceding commit.
      - name: Get changed files
        id: changed-files
        uses: tj-actions/changed-files@v34
        with:
          separator: "----------------------"
      - name: List all changed files
        run: |
          for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
            echo "$file was changed"
          done
      - uses: benjlevesque/short-sha@v2.1
        id: short-sha
        with:
          length: 7
      - run: echo $SHA
        env: 
          SHA: ${{ steps.short-sha.outputs.sha }}
      - run: echo $SHA
        env: 
          SHA: ${{ env.SHA }}
      - name: Discord notification
        env:
          DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
          DISCORD_AVATAR: 'https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png'
          DISCORD_EMBEDS: '[    { 
          "author": {  "icon_url": "https://avatars.githubusercontent.com/${{ github.actor }}", "name": "${{ github.actor }}", "url": "https://github.com/${{github.actor}}" },
          "url": "https://github.com/${{github.repository}}/commit/${{github.sha}}",
          "fields": [
          { "name": "Repository", "value": "[${{github.event.repository.name}}](${{github.event.repository.clone_url}})", "inline": true },
          { "name": "Branch", "value": "[${{github.ref_name}}](https://github.com/${{github.repository}}/tree/${{github.ref_name}})", "inline": true },
          { "name": "Event", "value": "${{github.event_name}}", "inline": true },
          { "name": "Job", "value": "${{github.job}}", "inline": true },
          { "name": "Commit Message", "value": "[${{ env.SHA }}](https://github.com/${{github.repository}}/commit/${{github.sha}}) - `${{github.event.head_commit.message}}`" },
          { "name": "Changed Files", "value": "${{ steps.changed-files.outputs.all_changed_files }}" },
          { "name": "Author", "value": "[${{github.event.head_commit.author.name}}](https://github.com/${{github.actor}})" }
          ],
          "color":1127128,
          "timestamp": "${{github.event.head_commit.timestamp}}",
          "footer":{"text": "${{github.event.head_commit.timestamp}}"}
          }    ]'
        uses: Ilshidur/action-discord@master
      - name: echo
        run: | 
          echo ${{github.event_name}}

# https://stackoverflow.com/a/68068674/19395252
# https://birdie0.github.io/discord-webhooks-guide/structure/embeds.html
# https://github.com/marketplace/actions/changed-files

Text under the following fields are hyperlinked.

Repository and Branch.

image

I have another workflow called, "github-variables.yml" to be able to get all of the Github Variables which contains the following contents.

name: Show GitHub context

on: [workflow_dispatch]

jobs:
  github:
    runs-on: ubuntu-latest
    steps:
      - name: Show GitHub context
        run: echo "$GITHUB_CONTEXT"
        env:
          GITHUB_CONTEXT: ${{ toJson(github) }}

The output of the aforementioned workflow starts like the following.

GITHUB_CONTEXT: {
    "token": "***",
    "job": "github",
    "ref": "refs/heads/xxx",
    "sha": "xxx",
    "repository": "xxx",
    "repository_owner": "xxx",
    "repository_owner_id": "xxx",
    "repositoryUrl": "xxx",
    "run_id": "xxx",
    "run_number": "xxx",
    "retention_days": "xxxx",
    "run_attempt": "xxx",
    "artifact_cache_size_limit": "xxx",
    "repository_visibility": "xxx",
    "repository_id": "xxx",
    "actor_id": "xxx",
    "actor": "xxx",
    "triggering_actor": "xxx",
    "workflow": "xxx",
    "head_ref": "",
    "base_ref": "",
    "event_name": "xxx",
    "event": {

@irostub
Copy link

irostub commented Jan 27, 2023

@NorkzYT thank you. It really saved me a lot of time.

@NorkzYT
Copy link

NorkzYT commented Jan 27, 2023

@irostub
No problem mate.

@adiatma85
Copy link

This should have been in the readme.md file

@adiatma85
Copy link

adiatma85 commented Jan 8, 2024

Just ignore the mention, I accidentally copy the whole url in my PR for reference in the future

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants
@rildomar @delphiactual @NorkzYT @adiatma85 @irostub @gryphonDev1 @luisfun and others