GithubHelp home page GithubHelp logo

juliuscc / semantic-release-slack-bot Goto Github PK

View Code? Open in Web Editor NEW
106.0 4.0 35.0 963 KB

📦 🚀 A slack bot for semantic-release notifying release statuses

License: MIT License

JavaScript 100.00%
semantic-release slack bot slack-bot release-notification release ci slack-notifications

semantic-release-slack-bot's Introduction

semantic-release-slack-bot

semantic-release plugin to get release notifications on slack from a slack bot

npm npm CircleCI branch license add to slack

Step Description
success Send a slack message to notify of a new release.
fail Send a slack message to notify of a failed release.

Install

Add the plugin to your npm-project:

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

Requirements

As per the new release of semantic-release library version 20, the library is requiring the use of Node v18, which we need to comply as well to use keep the repo updated with it's latest feature. More information can be found here.

Slack App/Webhook Usage

The corresponding slack app has to be installed in your slack workspace as well. Follow the instructions under configuration for more information.

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

{
  "plugins": [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    [
      "semantic-release-slack-bot",
      {
        "notifyOnSuccess": false,
        "notifyOnFail": false,
        "slackWebhook": "https://my-webhook.com",
        "branchesConfig": [
          {
            "pattern": "lts/*",
            "notifyOnFail": true
          },
          {
            "pattern": "master1",
            "notifyOnSuccess": true,
            "notifyOnFail": true
          }
        ]
      }
    ]
  ]
}

With this example:

  • Slack notification will always be sent using the "https://my-webhook.com" webhook url
  • Slack notifications are sent on a failure release from branches matching "lts/*"
  • Slack notifications are sent on a failure or successful release from branch "master"
  • Slack notifications are skipped on all other branches

Note

The official documentation says that a developer cannot override the default name, channel or icon that are associated with the webhook, but some users of this library reported that they were able to.

  • use slackName (or SLACK_NAME env var) for overriding slack app name
  • use slackIcon (or SLACK_ICON env var) for overriding slack app icon
  • use slackChannel (or SLACK_CHANNEL env var) for overriding slack channel

WARNING: This is not mentioned in the official documentation, so use at your own risk.

Slack Access Token/Channel Usage

This configuration can be used with a bot Slack Access token with minimum permissions of chat:write.

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

{
  "plugins": [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    [
      "semantic-release-slack-bot",
      {
        "notifyOnSuccess": false,
        "notifyOnFail": false,
        "slackToken": "token",
        "slackChannel": "#my-channel-name",
        "branchesConfig": [
          {
            "pattern": "lts/*",
            "notifyOnFail": true
          },
          {
            "pattern": "master1",
            "notifyOnSuccess": true,
            "notifyOnFail": true
          }
        ]
      }
    ]
  ]
}

With this example:

  • Slack notification will always be sent to the channel "#my-channel-name"
  • Slack notifications are sent on a failure release from branches matching "lts/*"
  • Slack notifications are sent on a failure or successful release from branch "master"
  • Slack notifications are skipped on all other branches

Screenshots

Screenshot of success Screenshot of fail

Configuration

Slack app installation

The plugin uses a slack webhook which you get by adding the slack app to your slack workspace. Register the app using the button below or this link.

Add to Slack

For the security concerned, feel free to create your own slack app and create a webhook or inspect the server code that does this creation for you at create-webhook.js. The only required permission for the webhook is to publish to a single channel.

Slack Webhook

Installing the app will yield you with a webhook that the app uses to publish updates to your selected channel. The Slack webhook authentication link is required and needs to be kept a secret. It should be defined in the environment variables.

Slack Access tokens

If you are creating your own slack app you can choose to use a bot access token and channel instead of the webhook with at least one of the following permission scopes.

  1. chat:write with this permission scope the app/bot must be added to any channels before it can post to them
  2. chat:write.public with this permission scope we can automatically post to any public channel for more information see here

Environment variables

Options can be defined in the environment where you will run semantic release. This can be done by exporting it in bash or in the user interface of your CI provider.

Alternatively, you can pass the webhook as a configuration option or use an Access Token.

Variable Description
SLACK_WEBHOOK Slack webhook created when adding app to workspace.
SLACK_TOKEN Slack bot Access token.
SLACK_CHANNEL Slack channel name or id to send notifications to.
SLACK_ICON Slack bot app icon.
SLACK_NAME Slack bot app name.
SEMANTIC_RELEASE_PACKAGE Override or add package name instead of npm package name

Options

Option Description Default
notifyOnSuccess Determines if a successful release should trigger a slack message to be sent. If false this plugin does nothing on success. false
notifyOnFail Determines if a failed release should trigger a slack message to be sent. If false this plugin does nothing on fail. false
onSuccessFunction Provides a function for the slack message object on success when notifyOnSuccess is true. See function. undefined
onFailFunction Provides a function for the slack message object on fail when notifyOnFail is true. See function. undefined
onSuccessTemplate Provides a template for the slack message object on success when notifyOnSuccess is true. See templating. undefined
onFailTemplate Provides a template for the slack message object on fail when notifyOnFail is true. See templating. undefined
markdownReleaseNotes Pass release notes through markdown to slack formatter before rendering. false
slackWebhookEnVar This decides what the environment variable for exporting the slack webhook value. SLACK_WEBHOOK
slackWebhook Slack webhook created when adding app to workspace. value of the environment variable matching slackWebhookEnVar
slackTokenEnVar This decides what the environment variable for exporting the slack token value. SLACK_TOKEN
slackToken Slack bot token. value of the environment variable matching slackTokenEnVar
slackChannelEnVar This decides what the environment variable for exporting the slack channel value. SLACK_CHANNEL
slackChannel Slack channel name or id to send notifications to. value of the environment variable matching slackChannelEnVar
slackIconEnVar This decides what the environment variable for specifying the slack app icon with slack emoji. ex. :smile: or smile (without semicolons) SLACK_ICON
slackIcon Slack app icon value of the environment variable matching slackIconEnVar
slackNameEnVar This decides what the environment variable for specifying the slack app name SLACK_NAME
slackName Slack app name value of the environment variable matching slackNameEnVar
packageName Override or add package name instead of npm package name SEMANTIC_RELEASE_PACKAGE or npm package name
unsafeMaxLength Maximum character length for the release notes before truncation. If unsafeMaxLength is too high, messages can be dropped. Read here for more information. Set to '0' to turn off truncation entirely. 2900
branchesConfig Allow to specify a custom configuration for branches which match a given pattern. For every branches matching a branch config, the config will be merged with the one put at the root. A key "pattern" used to filter the branch using glob expression must be contained in every branchesConfig. []

Function

If a function is provided with either the onSuccessFunction or onFailFunction options, it will be used for the respective slack message. The function should return an object that follows the Slack API message structure. The function is passed two objects, pluginConfig and context, the same objects that are passed to plugins.

Note: This only works with a configuration file that exports an object (see below for an example).

Example config (some parts omitted)
const slackifyMarkdown = require('slackify-markdown')
const { chunkifyString } = require('semantic-release-slack-bot/lib/chunkifier')

const onSuccessFunction = (pluginConfig, context) => {
  const releaseNotes = slackifyMarkdown(context.nextRelease.notes)
  const text = `Updates to ${pluginConfig.packageName} has been released to *Stage!*`
  const headerBlock = {
    type: 'section',
    text: {
      type: 'mrkdwn',
      text
    }
  }

  return {
    text,
    blocks: [
      headerBlock,
      ...chunkifyString(releaseNotes, 2900).map(chunk => {
        return {
          type: 'section',
          text: {
            type: 'mrkdwn',
            text: chunk
          }
        }
      })
    ]
  }
}

module.exports = {
  branches: ['master'],
  preset: 'eslint',
  plugins: [
    [
      'semantic-release-slack-bot',
      {
        notifyOnSuccess: true,
        onSuccessFunction,
        packageName: 'Testing Semantic Release'
      }
    ]
  ]
}

Templating

If a template is provided via either the onSuccessTemplate or onFailTemplate options, it will be used for the respective slack message. The template should be an object that follows the Slack API message structure. Strings within the template will have keywords replaced:

Keyword Description Example Template
$package_name The name of the package. semantic-release-test Both
$npm_package_version The version of the release. 1.0.93 onSuccessTemplate
$repo_path The repository path. juliuscc/semantic-release-test Both
$repo_url The repository URL. https://github.com/juliuscc/semantic-release-test Both
$release_notes The notes of the release. onSuccessTemplate

A sample configuration with template can look like this

"onSuccessTemplate": {
  "text": "A new version of $package_name with version $npm_package_version has been released at $repo_url!"
}

Helper functions

There are two helper functions exported by the chunkifier module.

chunkifyArray takes an array of strings and returns a new array based on maxLength and delimiter. delimiter is optional and defaults to newline.

chunkifyString takes a string and returns an array based on maxLength and delimiter. delimiter is optional and defaults to newline.

See respective implementation for more details.

semantic-release-slack-bot's People

Contributors

ahermant avatar alissonrs avatar andrewleedham avatar arnaudbesnier avatar beyondevil avatar darkphnx avatar dependabot[bot] avatar fmigot avatar fritiof avatar hannesrabo avatar juliuscc avatar killianhmyd avatar lfantone avatar mcfedr avatar nguyenj avatar saeger avatar simeonc avatar stephanbijzitter avatar thopaw avatar tripodsan avatar voltane avatar yoshitakahashi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

semantic-release-slack-bot's Issues

Question: support for Github releases?

Thanks for a cool sounding plugin for semantic-release! From the README I think the answer is sadly no, but does this repo support Github releases? We have a private Github repo, publishing release notes there, but no NPM package associated. We'd like to be able to post release notes in a slack channel. Can we accomplish that with this tool?

Slack channel from configs doesn't work when using token

Hi, thanks for putting together this plugin!

I am trying to use a Slack token for this passed through env vars while specifying the Slack channel through the configs. However this doesn't seem to work, I am seeing this error message:

A Slack Channel must be created and set in the SLACK_CHANNEL environment variable on your CI environment.
Please make sure to set a Slack Channel in the SLACK_CHANNEL environment variable on your CI environment. Alternatively, provide slackChannel as a configuration option.

This is the configuration of my plugin:

[
    "semantic-release-slack-bot",
    {
        "notifyOnSuccess": false,
        "notifyOnFail": false,
        "markdownReleaseNotes": true,
        "slackChannel": "#alerts",
        "branchesConfig": [
            {
                "pattern": "dev",
                "notifyOnSuccess": true,
                "onSuccessTemplate": {
                    "blocks": [
                        {
                            "type": "section",
                            "text": {
                                "type": "mrkdwn",
                                "text": "A new version has been released to *development*! :rocket:"
                            }
                        },
                        {
                            "type": "divider"
                        },
                        {
                            "type": "section",
                            "text": {
                                "type": "mrkdwn",
                                "text": "$release_notes"
                            }
                        }
                    ]
                }
            }
        ]
    }
]

I would expect the configuration to work when passing the Slack token as env var, is that not the case?

Slack Message Showing version as a channel (private channel)

Hello!

I loved this plugin for semantic-release, I was able to quickly get started.

Not sure if the issue below is related to this plugin or a problem with slack itself, but slack tries to generate a channel link in the version number since it contains a hashtag.

Would you have any ideas how I can prevent that from happening?

Thanks in advance!!!

image

Examples Request

Please provide usage examples for the options provided. Trying to integrate this into my build and adjust the slackWebhook env variable to what I have declared in my CI, but am uncertain as to the format it requires.

Support for [email protected]

At the moment the peerDependencies rule for the semantic-release package in package.json requires a version <18.0.0 is used. Does this library actually not work with [email protected] or is that rule just outdated? If it's the latter would you mind if I opened a PR to update the peerDependencies rule?

Thank you!

$repo_url not working

The plugin sends the message to slack literally as $repo_url instead of the actual repository url

package.json

{
    ...
  "repository": {
    "type": "git",
    "url": "<repoUrl>"
  },
  "config": {
    "commitizen": {
      "path": "./node_modules/cz-conventional-changelog"
    }
  },
  "release": {
    "plugins": [
      "@semantic-release/commit-analyzer",
      "@semantic-release/release-notes-generator",
      [
        "semantic-release-slack-bot",
        {
          "notifyOnSuccess": true,
          "notifyOnFail": false,
          "onSuccessTemplate": {
            "text": "A new version of $package_name with version $npm_package_version has been released at $repo_url ! \n $release_notes"
          },
          "markdownReleaseNotes": true
        }
      ],
      [
        "@semantic-release/npm",
        {
          "npmPublish": false
        }
      ],
      "@semantic-release/changelog",
      "@semantic-release/git"
    ]
  },
}

In the slack generated GitLab tag link is wrong!

In the slack GitLab tag link generation code below:
file: lib/success.js
code: /releases/tag/${gitTag}|${gitTag}> - line 105

link must be: ${repo.URL}/-/releases#${gitTag}|${gitTag} or ${repo.URL}/-/tags/${gitTag}|${gitTag}.
Link return 404 Not Found.
Screen Shot 2021-12-24 at 16 08 04
Thanks.

Release notes markdown format does not look compatible with Slack messages.

First of all, thanks for this nice little plugin 🙌🏼

Using the default configuration of the success template, I observe the that the changes displayed in the slack message is not well formatted. See the screenshot below:

Screenshot 2020-05-07 at 11 06 48

My guess is that Slack does not support standard markdown (according to this
documentation: https://www.markdownguide.org/tools/slack/).

If I am not wrong a about the issue, as I imagine that Slack won't change its markdown support, it would be great to have an automated translation from standard markdown to Slack markdown.
I would display a nice changelog content in Slack.

As a workaround, I'll use a custom success template to hide those changes in the message.

JSON message format invalid

Was hit by this today:

[12:30:22 PM] [semantic-release] [semantic-release-slack-bot] › ℹ  JSON message format invalid
[12:30:22 PM] [semantic-release] › ✖  Failed step "success" of plugin "semantic-release-slack-bot"
[12:30:22 PM] [semantic-release] › ℹ  Start step "fail" of plugin "@semantic-release/github"
[12:30:24 PM] [semantic-release] [@semantic-release/github] › ℹ  Created issue #118: https://github.com/proxyco/aux-api/issues/118.
[12:30:24 PM] [semantic-release] › ✔  Completed step "fail" of plugin "@semantic-release/github"
[12:30:24 PM] [semantic-release] › ℹ  Start step "fail" of plugin "semantic-release-slack-bot"
[12:30:24 PM] [semantic-release] [semantic-release-slack-bot] › ℹ  Notifying on fail skipped
[12:30:24 PM] [semantic-release] › ✔  Completed step "fail" of plugin "semantic-release-slack-bot"
[12:30:24 PM] [semantic-release] › ✖  SLACK CONNECTION FAILED:  
{ AggregateError: 
    SemanticReleaseError
        at fetch.then.then.catch.e (/usr/local/lib/node_modules/semantic-release-slack-bot/lib/postMessage.js:23:10)
    at /usr/local/lib/node_modules/semantic-release/lib/plugins/pipeline.js:54:11
    at process._tickCallback (internal/process/next_tick.js:68:7) name: 'AggregateError' }Exited with code 1

Config:

{
    "branch": "master",
    "preset": "eslint",
    "plugins": [
        "@semantic-release/commit-analyzer",
        "@semantic-release/release-notes-generator",
        "@semantic-release/changelog",
        "@semantic-release/git",
        "@semantic-release/github",
        [
            "semantic-release-slack-bot",
            {
                "notifyOnSuccess": true,
                "markdownReleaseNotes": true
            }
        ]
    ]
}

Only thing I can think of is that something in the release notes needed to be escaped. Problem is, the release notes was huge.

Also, looking here I'm expecting to see what was the cause of the malformed JSON, but it seems that maybe the catch-clause swallowed that? 🤔

I saw the other issue (#4) on the same topic, and afaict I'm running the latest version (v1.3.0). I installed it using npm install -g semantic-release-slack-bot (it's installed in a docker image that we use in our build pipeline, hence the global install).

Yep, truncate code is definitely there:

/usr/local/lib/node_modules/semantic-release-slack-bot/lib # cat success.js | grep truncate
			// truncate long messages
/usr/local/lib/node_modules/semantic-release-slack-bot/lib #

Where did you find the 3000 limit? All I could find was this.

There's also the "How to escape characters" here (maybe slackify-markdown deals with that?).

ENOPACKAGENAME No name for the package defined.

NPM v6.14.4
Node v14.4.x

   "@semantic-release/changelog": "^5.0.1",
    "@semantic-release/commit-analyzer": "^8.0.1",
    "@semantic-release/git": "^9.0.0",
    "@semantic-release/npm": "^7.0.9",
    "@semantic-release/release-notes-generator": "^9.0.1",
    "semantic-release-slack-bot": "^1.7.0",

I get this error and there is a package name in my repo (@react/common-components):

A name for the package must be created. Run through npm (npm run <semantic-release-script> to use npm package name or define packageName in the plugin config or SEMANTIC_RELEASE_PACKAGE in the environment

AggregateError:
  SemanticReleaseError: No name for the package defined.
  at module.exports (/Users/dasboot/projects/react-common/node_modules/semantic-release-slack-bot/lib/verifyConditions.js:27:11)
at validator (/Users/dasboot/projects/react-common/node_modules/semantic-release/lib/plugins/normalize.js:34:30)
at /Users/dasboot/projects/react-common/node_modules/semantic-release/lib/plugins/pipeline.js:37:40
at next (/Users/dasboot/projects/react-common/node_modules/p-reduce/index.js:17:9)
at /Users/dasboot/projects/react-common/node_modules/semantic-release/lib/plugins/pipeline.js:54:11
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async Object.pluginsConf.<computed> [as verifyConditions] (/Users/dasboot/projects/react-common/node_modules/semantic-release/lib/plugins/index.js:80:11)
  at async run (/Users/dasboot/projects/react-common/node_modules/semantic-release/index.js:95:3)
  at async module.exports (/Users/dasboot/projects/react-common/node_modules/semantic-release/index.js:260:22)
  at async module.exports (/Users/dasboot/projects/react-common/node_modules/semantic-release/cli.js:55:5)% 

Here is the release.config.js file:

/* eslint-disable */
module.exports = {
  branches: ['master', 'next'],
  plugins: [
    '@semantic-release/commit-analyzer',
    '@semantic-release/release-notes-generator',
    '@semantic-release/changelog',
    '@semantic-release/npm',
    [
      '@semantic-release/git',
      {
        assets: ['dist/**/*.{js,css}', 'docs', 'package.json'],
        message: 'chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}',
      },
    ],
    [
      'semantic-release-slack-bot',
      {
        notifyOnSuccess: true,
        notifyOnFail: true,
      },
    ],
  ],
}

It will begin working when adding packageName: require('./package.json').name to the plugin config args/opts.

Any thoughts?

Cleanup release template

We're using this package with much joy and adds real value for our team. Thanks!

We'd like to simplify the posted Slack message to keep noise as low as possible. I tried to use the onSuccessTemplate but that one seems to be missing all required variables.

We currently have this:
Schermafbeelding 2020-04-22 om 12 17 03

Can we adjust it to:

Version 5.8.4 for ho-nl/project-reachdigital.nl has been released!

Fixes
• ​metarobots:​ metaRobots is now required in GraphCMS (fb64921)

  • Date is redundant as it will send it to Slack immediately after the release has been made.
  • The diff link can be found very easily via the release link, so can that can be omitted
  • Attachment shows duplicate information already available above.

  • It would be nice if we could render the homepage url that is entered in the package.json

[Feature] Customise slack message

It would be nice if the message sent to slack was configurable.

For example:

{
  "plugins": [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    [
      "semantic-release-slack-bot",
      {
        "notifyOnSuccess": true,
        "notifyOnFail": false,
        "onSuccess": {
          "text": "**$npm_package_name $npm_package_version** was published to npm successfully",
          "attachments": {
            "text": "Check it out",
            "color": "good",
            "emoji": ":rocket:",
            "attachment_type": "default",
            "actions": [
              {
                "text": "View on npm",
                "url": "https://www.npmjs.com/package/$npm_package_name",
                "type": "button",
                "style": "primary"
              },
              {
                "text": "View on github",
                "url": "https://github.com/$npm_user_name/$npm_package_name",
                "type": "button",
                "style": "primary"
              }
            ]
          }
        }
      }
    ]
  ]
}

Verify env-conditions

The plugin should verify the conditions in the verifyConditions step. It should check that there is a SLACK_WEBHOOK

Why `$package_name` is not define automatically?

Hello 👋

I'm a little bit confused with the indication in the documentation and the reality.

Here's the description of packageName.

Option Description Default
packageName Override or add package name instead of npm package name SEMANTIC_RELEASE_PACKAGE or npm package name

In my case, I want the default behavior. For some reason, I get an error yelling at me:
A name for the package must be created. Run through npm (npm run <semantic-release-script> to use npm package name or define packageName in the plugin config or SEMANTIC_RELEASE_PACKAGE in the environment

https://github.com/juliuscc/semantic-release-slack-bot/blob/214aef05f05a6f79e6c437245bb592b83d3f8844/lib/verifyConditions.js#L34C3-L47C4

So I am confused, I just want the default package name without any override.

(We use the plugin within a mono repo setup with multi-semantic-release, could this lead to a different behavior?)

Don't send notification if pre-release ?

Is it currently possible to disable notifications if it's a pre-release, or specify another channel/webhook for pre-release ?

Couldn't find anything in the documentation

Provide slack webhook through config, rather than environment

We already have a slack webhook in our environment variables, but it is not the one we want this bot to use. Currently that means I have to do SLACK_WEBHOOK=... yarn semantic-release, which is a bit "meh".

Being able to pass the webhook through the configuration object would be nice in this case.

SLACK CONNECTION FAILED Only absolute URLs are supported

Using Node 18 we get an error message from fetch "Only absolute URLs are supported"

Drop the version back to Node 16 to resolve the problem.

Output

[4:59:55 AM] [semantic-release] › ✖ SLACK CONNECTION FAILED Only absolute URLs are supported

  | AggregateError:
  | SemanticReleaseError: Only absolute URLs are supported
  | at module.exports (/workdir/node_modules/semantic-release-slack-bot/lib/postMessage.js:49:11)
  | at async module.exports (/workdir/node_modules/semantic-release-slack-bot/lib/success.js:123:3)
  | at /workdir/node_modules/semantic-release/lib/plugins/pipeline.js:54:11
  | at async pluginsConf. [as success] (/workdir/node_modules/semantic-release/lib/plugins/index.js:80:11)
  | at async run (/workdir/node_modules/semantic-release/index.js:209:3)
  | at async module.exports (/workdir/node_modules/semantic-release/index.js:269:22)
  | error Command failed with exit code 1.
  | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
  | error Command failed.
  | Exit code: 1
  | Command: /usr/local/bin/node
  | Arguments: /opt/yarn-v1.22.19/lib/cli.js run semantic-release --debug
  | Directory: /workdir/apps/cron-coin-gecko
  | Output:
  |  
  | info Visit https://yarnpkg.com/en/docs/cli/workspaces for documentation about this command.
  | 🚨 Error: The command exited with status 1

wrong tag URL at the bottom of the message

Hello 👋
First off, I love your slack bot! ❤️

I found that the default message (no custom templating) sends this "/releases/tag/" url at the bottom of the success message

}/releases/tag/${gitTag}|${gitTag}>`

the url with gitlab.com looks something like this https://gitlab.com/myorg/myrepo/releases/tag/v1.5.0 which gives me http 404.

the correct URLs I can visit are https://gitlab.com/myorg/myrepo/-/releases/v1.5.0 and https://gitlab.com/myorg/myrepo/-/tags/v1.5.0.

I'm not sure if this is some kind of change in Gitlab URL paths or not.

Thanks!

Is this log line intentional?

logger.log(slackMessage)

Seems a bit out of place in the console...

[1:11:05 PM] [semantic-release] › ✔  Completed step "success" of plugin "@semantic-release/github"
[1:11:05 PM] [semantic-release] › ℹ  Start step "success" of plugin "semantic-release-slack-bot"
[1:11:05 PM] [semantic-release] [semantic-release-slack-bot] › ℹ  Sending slack notification on success
[1:11:05 PM] [semantic-release] [semantic-release-slack-bot] › ℹ  {
  blocks: [
    { type: 'section', text: [Object] },
    { type: 'section', text: [Object] }
  ],
  text: 'A new version of foo has been released!',
  attachments: [ { color: '#2cbe4e', blocks: [Array] } ]
}
[1:11:05 PM] [semantic-release] › ✔  Completed step "success" of plugin "semantic-release-slack-bot"
[1:11:05 PM] [semantic-release] › ✔  Published release 1.0.0 on default channel

ssh repository field with no protocol causes ERR_INVALID_URL

If the repository field is in the following format:

// package.json
{
  // ...
  "repository": "[email protected]:hello/world.git"
  // ...
}

it causes an ERR_INVALID_URL error, since new URL('[email protected]/hello/world.git') is expecting a protocol. So new URL('ssh://[email protected]/hello/world.git') would work.

Think there just needs to be a check for this case in getRepoInfo. Since, this format is one of the possible variants in https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes

slack bot should extend the accepted semantic release version to 21.0

when I build my project with the latest semantic-release, I get:

npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/semantic-release
npm ERR!   dev semantic-release@"21.0.0" from the root project
npm ERR!   peer semantic-release@">=18.0.0" from @semantic-release/[email protected]
npm ERR!   node_modules/@semantic-release/changelog
npm ERR!     dev @semantic-release/changelog@"6.0.3" from the root project
npm ERR!   6 more (@semantic-release/commit-analyzer, ...)

see https://github.com/semantic-release/semantic-release/releases/tag/v21.0.0

JSON message format invalid

When I want to use this plugin I get the following error during the execution of the plugin with debug flag:


[17:28:51] [semantic-release] › ✔  Completed step "publish" of plugin "@semantic-release/gitlab"
[17:28:51] [semantic-release] › ℹ  Start step "success" of plugin "semantic-release-slack-bot"
[17:28:51] [semantic-release] [semantic-release-slack-bot] › ℹ  Sending slack notification on success
[17:28:52] [semantic-release] [semantic-release-slack-bot] › ℹ  JSON message format invalid
[17:28:52] [semantic-release] › ✖  Failed step "success" of plugin "semantic-release-slack-bot"
[17:28:52] [semantic-release] › ℹ  Start step "fail" of plugin "semantic-release-slack-bot"
[17:28:52] [semantic-release] [semantic-release-slack-bot] › ℹ  Sending slack notification on fail
[17:28:52] [semantic-release] › ✔  Completed step "fail" of plugin "semantic-release-slack-bot"
[17:28:52] [semantic-release] › ✖  SLACK CONNECTION FAILED:  
{ AggregateError: 
    SemanticReleaseError
        at fetch.then.then.catch.e (/home/thopaw/git/freeyou/api-paymentmethod/node_modules/semantic-release-slack-bot/lib/postMessage.js:25:10)
        at <anonymous>
    at /home/thopaw/git/freeyou/api-paymentmethod/node_modules/semantic-release/lib/plugins/pipeline.js:54:11
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7) name: 'AggregateError' }

Also the emssage of the failure in slack does not contain the name of the project:

An error occurred while trying to publish the new version of undefined!

On a different project with exactly the same config it is working.
Can it be a problem of the length of the slack message?
This is the first run of semantic release and the release-notes are longer then the release-notes on the other project.

The project contains a releaserc.yml.

branch: master
plugins:
  - '@semantic-release/commit-analyzer'
  - '@semantic-release/release-notes-generator'
  - '@semantic-release/gitlab'
  - - semantic-release-slack-bot
    - notifyOnSuccess: true
      notifyOnFail: true

and these versions are defined within the package.json:

"devDependencies": {
    "@semantic-release/changelog": "^3.0.4",
    "@semantic-release/gitlab": "^3.1.5",
    "semantic-release": "^15.13.16",
    "semantic-release-slack-bot": "^1.0.4",
....

Is SLACK_ICON and SLACK_NAME working?

Hi,

I can't figure it out how the slack bot handle this vars? It's not showing on the posted message.
I use the slack app provided in the readme.

Thanks

TypeError: Cannot read properties of undefined (reading 'name')

Getting the following error using this library:

[4:36:20 PM] [semantic-release] › ✘  An error occurred while running semantic-release: TypeError: Cannot read properties of undefined (reading 'name')
    at module.exports (/builds/<snip>/<snip>/<snip>/node_modules/semantic-release-slack-bot/lib/getConfigToUse.js:5:15)
    at module.exports (/builds/<snip>/<snip>/<snip>/node_modules/semantic-release-slack-bot/lib/fail.js:15:23)
    at validator (file:///builds/<snip>/<snip>/<snip>/node_modules/semantic-release/lib/plugins/normalize.js:36:30)
    at file:///builds/<snip>/<snip>/<snip>/node_modules/semantic-release/lib/plugins/pipeline.js:37:40
    at next (file:///builds/<snip>/<snip>/<snip>/node_modules/semantic-release/node_modules/p-reduce/index.js:16:10)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  pluginName: 'semantic-release-slack-bot'
}

My current config:

        ["semantic-release-slack-bot", {
            markdownReleaseNotes: true,
            notifyOnSuccess: false,
            notifyOnFail: false,
            packageName: PROJECT_NAME,
            slackName: SLACK_APP_NAME,
            slackIcon: SLACK_APP_ICON,
            slackWebhook: "https://hooks.slack.com/services/<snip>/<snip>/<snip>",
            branchesConfig: [{
                pattern: "feat/test",
                notifyOnSuccess: true,
                notifyOnFail: true
            }]
        }]

I'm initiating semantic release using npx semantic-release.

Any ideas? I've tried with slackName/slackIcon and without, same outcome.

Slack Webhook doesn't respect proxy environment variables

We are running semantic-release on a private gitlab instance on our network, and all connections outside the network go through a corporate proxy. When we run with the webhook, we get the following error:

10:20:37 PM] [semantic-release] › ✘  SLACK CONNECTION FAILED request to [MASKED] failed, reason: read ECONNRESET
AggregateError: 
    SemanticReleaseError: request to [MASKED] failed, reason: read ECONNRESET
        at module.exports (/opt/app/node_modules/semantic-release-slack-bot/lib/postMessage.js:49:11)
        at async module.exports (/opt/app/node_modules/semantic-release-slack-bot/lib/success.js:119:3)
        at async validator (file:///opt/app/node_modules/semantic-release/lib/plugins/normalize.js:36:24)
        at async file:///opt/app/node_modules/semantic-release/lib/plugins/pipeline.js:37:34
        at async Promise.all (index 0)
        at async next (file:///opt/app/node_modules/p-reduce/index.js:15:44)
    at file:///opt/app/node_modules/semantic-release/lib/plugins/pipeline.js:54:11
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async pluginsConfigAccumulator.<computed> [as success] (file:///opt/app/node_modules/semantic-release/lib/plugins/index.js:87:11)
    at async run (file:///opt/app/node_modules/semantic-release/index.js:215:3)
    at async Module.default (file:///opt/app/node_modules/semantic-release/index.js:275:22)
    at async default (file:///opt/app/node_modules/semantic-release/cli.js:55:5) {
  errors: [
    SemanticReleaseError: request to [MASKED] failed, reason: read ECONNRESET
        at module.exports (/opt/app/node_modules/semantic-release-slack-bot/lib/postMessage.js:49:11)
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
        at async module.exports (/opt/app/node_modules/semantic-release-slack-bot/lib/success.js:119:3)
        at async validator (file:///opt/app/node_modules/semantic-release/lib/plugins/normalize.js:36:24)
        at async file:///opt/app/node_modules/semantic-release/lib/plugins/pipeline.js:37:34
        at async Promise.all (index 0)
        at async next (file:///opt/app/node_modules/p-reduce/index.js:15:44) {
      code: 'SLACK CONNECTION FAILED',
      details: undefined,
      semanticRelease: true,
      pluginName: 'semantic-release-slack-bot'
    }
  ]

Most applications in our pipelines respect the https_proxy and no_proxy environment variables, but looking through the code and the use of node-fetch, there doesn't seem to be any checks to see if a proxy is configured. The result is that we cannot make the webhook call out to Slack.

I'm not a nodejs developer (or a developer at all in any real sense), but it seems as though Node is working to get proxies working with native fetch, but until then, people have implemented workarounds.

Ideally, the application should look for a https_proxy environment variable, and if it is set, to use that proxy to make the webhook call to Slack. We also use a no_proxy variable to identify internal hosts that should not use that proxy, but I do not that functionality is necessary since the webhook will always be a proxied call.

semantic-release v17 support

I tried upgrading to semantic release v17 today and got this:

npm WARN [email protected] requires a peer of semantic-release@>=11.0.0 <16.0.0 but none is installed. You must install peer dependencies yourself.

Is there anything stopping us from supporting v17?

If yes, what? Maybe I can fix it.

If no, I can create a PR to bump the peerDependencies key.

Bump dependencies versions

Hi,
There are 3 PRs created for updating the dependencies.
We are now seeing a High severity issue when installing.

Screenshot_20210511_101556

can we please bump the version of slackify-markdown to latest 4.1.0 ? That should fix the issue.

Only the first occurence of a variable is properly set in a string of a custom template

Here is our global semantic release configuration:

module.exports = {
  plugins: [
    '@semantic-release/commit-analyzer',
    '@semantic-release/release-notes-generator',
    '@semantic-release/changelog',
    '@semantic-release/npm',
    '@semantic-release/git',
    '@semantic-release/github',
    [
      'semantic-release-slack-bot',
      {
        markdownReleaseNotes: true,
        notifyOnSuccess: true,
        notifyOnFail: false,
        onSuccessTemplate: {
          text: "📦 $package_name@$npm_package_version has been released!",
          blocks: [{
            type: 'section',
            text: {
              type: 'mrkdwn',
              text: '*New `$package_name` package released!*'
            }
          }, {
            type: 'context',
            elements: [{
              type: 'mrkdwn',
              text: "📦  *Version:* <$repo_url/releases/tag/v$npm_package_version|$npm_package_version>"
            }]
          }, {
            type: 'divider',
          }, {
            type: 'section',
            text: {
              type: 'mrkdwn',
              text: '$release_notes'
            }
          }],
        },
        packageName: 'forest-express',
      }
    ],
  ],
}

As you can see we have a string
"📦 *Version:* <$repo_url/releases/tag/v$npm_package_version|$npm_package_version>"
that uses $npm_package_version twice.

The link generated is good, but not the displayed text for the link:
Screenshot 2020-05-07 at 12 06 33

I think the replace function below, replaces only the first occurence:
https://github.com/juliuscc/semantic-release-slack-bot/blob/master/lib/template.js#L7

Error after installation with micromark package

On a project running nuxt 3 and @nuxt/content 2 (which use micromark too) everything is fine until I install this package. Then I got an error

 ERROR  [worker reload] [worker init] The requested module 'file:///path-to-project/node_modules/micromark/index.js' does not provide an export named 'postprocess'

  import { postprocess, preprocess } from 'node_modules/micromark/index.js';
  ^^^^^^^^^^^
  SyntaxError: The requested module 'node_modules/micromark/index.js' does not provide an export named 'postprocess'
  at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
  at async ModuleJob.run (node:internal/modules/esm/module_job:190:5)

Is it possible to update the package to the latest version?

Thanks 🙏

SEMANTIC_RELEASE_PACKAGE is always needed

It seems you always need to provide env variable of SEMANTIC_RELEASE_PACKAGE or npm_package_name needed. I assumed it will pick it up automatically form package.json.
Am I missing anything here?

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.