Skip to content

Commit

Permalink
feat: add maxLength option (#27)
Browse files Browse the repository at this point in the history
* feat: add maxLength option

* refactor: prefix max length option with unsafe

* docs(readme): update max length option with unsafe

* docs(readme): revert indent

fixes: #26
  • Loading branch information
AndrewLeedham authored and juliuscc committed Jan 3, 2020
1 parent 8baf727 commit e4000b2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
39 changes: 20 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ The plugin can be configured in the [**semantic-release** configuration file](ht

```json
{
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"semantic-release-slack-bot",
{
"notifyOnSuccess": false,
"notifyOnFail": true
}
]
]
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"semantic-release-slack-bot",
{
"notifyOnSuccess": false,
"notifyOnFail": true
}
]
]
}
```

Expand Down Expand Up @@ -80,14 +80,15 @@ 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 |
| `slackWebhook` | Slack webhook created when adding app to workspace. | SLACK_WEBHOOK |
| 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 |
| `slackWebhook` | Slack webhook created when adding app to workspace. | SLACK_WEBHOOK |
| `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 |

### Templating

Expand Down
9 changes: 6 additions & 3 deletions lib/success.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const template = require('./template')
const truncate = require('./truncate')
const getRepoInfo = require('./getRepoInfo')

// Max lenght of message to the slack api is 3000 characters. Make sure we are below that.
// 2900 is the limit for a message block of type 'section'.
const MAX_LENGTH = 2900

module.exports = async (pluginConfig, context) => {
Expand All @@ -15,7 +15,10 @@ module.exports = async (pluginConfig, context) => {
options,
env: { SEMANTIC_RELEASE_PACKAGE, npm_package_name }
} = context
const { slackWebhook = process.env.SLACK_WEBHOOK } = pluginConfig
const {
slackWebhook = process.env.SLACK_WEBHOOK,
unsafeMaxLength = MAX_LENGTH
} = pluginConfig

const package_name = SEMANTIC_RELEASE_PACKAGE || npm_package_name

Expand All @@ -36,7 +39,7 @@ module.exports = async (pluginConfig, context) => {
}

// truncate long messages
releaseNotes = truncate(releaseNotes, MAX_LENGTH)
releaseNotes = truncate(releaseNotes, unsafeMaxLength)

let slackMessage = {}
// Override default success message
Expand Down

0 comments on commit e4000b2

Please sign in to comment.