Code Monkey home page Code Monkey logo

discord-commits's Introduction

Discord Action Commits

Notify Discord with all commits present in a payload. Customize layout by customizing templates.

Example Appearance:

Use markdown in your commit messages for nice formatting. As an example, here is a link to commit in picture. https://github.com/Sniddl/discord-commits/commit/1e5aedd3f8bae8bb8272289cea173f2258e519e8

Imgur


Example Usage

- name: Discord Commits
        uses: Sniddl/[email protected]
        with:
          webhook: ${{ secrets.DISCORD_WEBHOOK }}
          template: 'avatar-with-link'
          include-extras: true

Variables inside templates

Global Variable Description
github Access all data provided by GitHub such as payloads and commits. For example, the repository name. {{ github.context.payload.repository.name }}
env Access all environment variables. For example, an environment variable called my_data. {{ env.my_data }}
commit Access the data for the current commit. This will apply to ALL commits in the push event. If you do not want multiple commits see other options. Here's an example for commit data {{ commit.author.name }}

Required options

Option Description
webhook The url for a Discord webhook. Store this as a secret otherwise you may receive unwanted spam in your discord.

Essential options

Option Description
template The name of a premade template located into the discord-commits/templates folder.
message The text message that appears on Discord. This would be the equivalent of typing a message.
embed The template for each embed item. An embed item is shown for every commit message in the push event. There may be multiple commits per push. This can be prevented by enabling last-commit-only

Other options

Option Description
include-extras Boolean - Include extra embeds from templates such as a link to the payload difference.
last-commit-only Boolean - Only include the last commit.

Predefined templates

Here are the defaults for each template. If you want to modify the values, you need to turn the JSON into a string so it can be passed from the action environment to the script. See main.yml for a commented out example.

plain

Returns a message and no embeds

{
    embed: false,
}

plain-author

Returns embeds containing a title and description. Includes the author's name.

{
  embed: {
    title: "{{ commit.title }}",
    description: "{{ commit.description }}",
    author: {
      name: "{{ commit.author.name }}"
    }
  }
}

simple-link

Returns embeds containing a title and description. The title links to the commit url

{
  embed: {
    title: "{{ commit.title }}",
    description: "{{ commit.description }}",
    url: "{{ commit.url }}"
  }
}

author-with-link

Returns embeds containing a title and description. The title links to the commit url. Includes the author's name

embed: {
  title: "{{ commit.title }}",
  description: "{{ commit.description }}",
  url: "{{ commit.url }}",
  author: {
    name: "{{ commit.author.name }}"
  }
}

avatar-with-link

Returns embeds containing a title and description. The title links to the commit url. Includes author's name and GitHub avatar.

embed: {
  title: "{{ commit.title }}",
  description: "{{ commit.description }}",
  url: "{{ commit.url }}",
  author: {
    name: "{{ commit.author.name }}",
    icon_url: "https://github.com/{{ commit.author.username }}.png"
  }
}

Testing / Contributing.

We suggest everyone uses a tool like https://github.com/nektos/act to test GitHub actions locally. This is the tool I use so the directory structure will reflect that. If the following command does not pass, I will not accept your PR.

  1. install act see https://github.com/nektos/act for instructions.
  2. cp .env.example .env paste discord commit url into .env
  3. make sure the following command passes.
act -W tests/workflows -e tests/push.json

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.