From 32cf994538c19f52713cb1eeaba4497dcf67ea55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jim=20Br=C3=A4nnlund?= Date: Tue, 24 Nov 2020 18:22:53 +0100 Subject: [PATCH] refactor: Add possibility to turn off truncation (#52) --- README.md | 22 +++++++++++----------- lib/success.js | 5 ++++- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 805268b..cadd964 100644 --- a/README.md +++ b/README.md @@ -80,17 +80,17 @@ Alternatively, you could pass the webhook as a configuration option. ### Options -| Option | Description | Default | -| ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- | -| `notifyOnSuccess` | Determines if a succesfull 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 | -| `onSuccessTemplate` | Provides a template for the slack message object on success when `notifyOnSuccess` is `true`. See [templating](#templating). | undefined | -| `onFailTemplate` | Provides a template for the slack message object on fail when `notifyOnFail` is `true`. See [templating](#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 is called. | SLACK_WEBHOOK | -| `slackWebhook` | Slack webhook created when adding app to workspace. | value of the environment variable matching `slackWebhookEnVar` | -| `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 maxLength is too high, messages can be dropped. [Read here](https://github.com/juliuscc/semantic-release-slack-bot/issues/26#issuecomment-569804359) for more information. | 2900 | +| Option | Description | Default | +| :--------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :------------------------------------------------------------- | +| `notifyOnSuccess` | Determines if a succesfull 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 | +| `onSuccessTemplate` | Provides a template for the slack message object on success when `notifyOnSuccess` is `true`. See [templating](#templating). | undefined | +| `onFailTemplate` | Provides a template for the slack message object on fail when `notifyOnFail` is `true`. See [templating](#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 is called. | SLACK_WEBHOOK | +| `slackWebhook` | Slack webhook created when adding app to workspace. | value of the environment variable matching `slackWebhookEnVar` | +| `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 maxLength is too high, messages can be dropped. [Read here](https://github.com/juliuscc/semantic-release-slack-bot/issues/26#issuecomment-569804359) for more information. Set to '0' to turn off truncation entirely. | 2900 | ### Templating diff --git a/lib/success.js b/lib/success.js index 967bcfd..09cab4c 100644 --- a/lib/success.js +++ b/lib/success.js @@ -15,6 +15,7 @@ module.exports = async (pluginConfig, context) => { options, env: { SEMANTIC_RELEASE_PACKAGE, npm_package_name } } = context + const { slackWebhookEnVar = 'SLACK_WEBHOOK', slackWebhook = process.env[slackWebhookEnVar], @@ -42,7 +43,9 @@ module.exports = async (pluginConfig, context) => { } // truncate long messages - releaseNotes = truncate(releaseNotes, unsafeMaxLength) + if (unsafeMaxLength > 0) { + releaseNotes = truncate(releaseNotes, unsafeMaxLength) + } let slackMessage = {} // Override default success message