1.1.0 • Published 2 years ago

semantic-release-discord-bot v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

semantic-release-discord-bot

semantic-release plugin to get release notifications on Discord from Discord.

npm license

StepDescription
successSend a Discord message to notify of a new release.
failSend a Discord message to notify of a failed release.

Install

Add the plugin to your npm-project:

$ npm install semantic-release-discord-bot -D

Usage

The plugin can be configured in the semantic-release configuration file:

{
    "plugins": [
        "@semantic-release/commit-analyzer",
        "@semantic-release/release-notes-generator",
        [
            "semantic-release-discord-bot",
            {
                "notifications": [
                    {
                        "branch": "release/*.x.x"
                    }
                ]
            }
        ]
    ]
}

Configuration

Environment variables

The DISCORD_WEBHOOK variable can be defined in the environment where you will run semantic release. Copy and past the Discord hook value to this variable.

Options

OptionDescriptionRequiredDefault
packageNameOverride or add package name instead of npm package namenoSEMANTIC_RELEASE_PACKAGE or npm package name
notifyOnSuccessDetermines if a successful release should trigger a telegram message to be sent. If false this plugin does nothing on success. Can be overwritten by the same property in notificationsnotrue
notifyOnFailDetermines if a failed release should trigger a telegram message to be sent. If false this plugin does nothing on fail. Can be overwritten by the same property in notificationsnofalse
successProvides a template for the telegram message on success when notifyOnSuccess is true.noDEFAULT SUCCESS MESSAGE
failProvides a template for the telegram message on fail when notifyOnFail is true.noDEFAULT FAIL MESSAGE
notificationsProvides a list of notification objects that can be flexibly configuredyes[]

Notification object

In the notification property, you can pass an object with the following values

OptionDescriptionRequiredDefault
notifyOnSuccessDetermines if a successful release should trigger a telegram message to be sent. If false this plugin does nothing on success. Can be overwritten by the same property in notificationsnotrue
notifyOnFailDetermines if a failed release should trigger a telegram message to be sent. If false this plugin does nothing on fail. Can be overwritten by the same property in notificationsnofalse
successProvides a template for the telegram message on success when notifyOnSuccess is true.noDEFAULT SUCCESS MESSAGE
failProvides a template for the telegram message on fail when notifyOnFail is true.noDEFAULT FAIL MESSAGE
branchDescribes a pattern for filtering a branch using a glob expression.noundefined

Template options

success and failure messages can be configured by passing an object with custom message, or a path to a template file.

Inline message

Here is a description of the object that can be passed to the success or fail property to describe the inline message

OptionDescriptionRequiredDefault
messageNotification messageyesundefined
formatMessage format, may have html or markdown valuesno'markdown'
customDataAn object with custom values that can be used for output in a messagenoundefined

Message template

If you need more functionality, you can pass a path to the template file that will be rendered using nunjucks, you will also have access to the context, and all a functionality that nunjucks provides.

Here is a description of the object with path that can be passed to the success or fail property

OptionDescriptionRequiredDefault
pathPath to a message templateyesundefined
customDataAn object with custom values that can be used for output in a messagenoundefined

Context

A special context is available for each message, which provides access to the properties described by you in customData property, as well as to the following values

OptionDescription
packageNameThe name of the current package
branchA branch object. You can find its description here
lastReleaseA lastRelease object. You can find its description here
nextReleaseA nextRelease object. You can find its description here
commitsA list of commits. You can find its description here
errorsA list of native Error objects, available only for fail messages

Examples

ATTENTION - NOT AVAILABLE NOW: Sending messages to specific chats

{
    "plugins": [
        "@semantic-release/commit-analyzer",
        "@semantic-release/release-notes-generator",
        [
            "semantic-release-telegram-bot",
            {
                "success": {
                    "message": "Here is the new release!"
                },
                "notifications": [
                    {
                        "chatIds": "PrivateChatId",
                        "notifyOnFail": true,
                        "notifyOnSuccess": false,
                        "fail": {
                            "message": "Oops!"
                        }
                    },
                    {
                        "chatIds": "PrivateChatId",
                        "branch": "rc/*"
                    },
                    {
                        "chatIds": "PublicChatId",
                        "branch": "release/*"
                    }
                ]
            }
        ]
    ]
}

In this example:

  • Failure messages from all branches will be sent to PrivateChatId chat, also the messages changed to Oops!
  • Success messages from rc branches will be sent to PrivateChatId chat
  • Only a success message from release branches will be sent to PublicChatId chat
  • All success messages changed to Here is the new release!

Custom inline template

Here is an example of the inline template, it uses template function from lodash to render your message.

{
    "plugins": [
        "@semantic-release/commit-analyzer",
        "@semantic-release/release-notes-generator",
        [
            "semantic-release-telegram-bot",
            {
                "success": {
                    "message": "Here is a new release of ${packageName} library and value ${myVariable} of my custom variable",
                    "customData": {
                        "myVariable": "myVariable"
                    }
                }
            }
        ]
    ]
}

Custom template

Be careful when describing your templates, you must support html or markdown telegram syntax.

Look at the nunjucks docs to see what functionality you can use

<!--custom-success-template.html-->

<b>A new version of {{packageName}} has been released!</b>

Custom change log:

{% for commit in commits %}
• ({{ commit.subject }}): {{ commit.message }}
{% endfor %}

And specify the path to the template

{
    "plugins": [
        "@semantic-release/commit-analyzer",
        "@semantic-release/release-notes-generator",
        [
            "semantic-release-telegram-bot",
            {
                "success": {
                    "path": "./path/to/custom-success-template.html"
                }
            }
        ]
    ]
}

MIT Licence