Skip to content

Commit

Permalink
fix: Truncate release notes on "onSuccessTemplate" (#23)
Browse files Browse the repository at this point in the history
Fixes: #21
  • Loading branch information
BeyondEvil authored and hannesrabo committed Nov 14, 2019
1 parent cff4304 commit ad3b0af
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
28 changes: 13 additions & 15 deletions lib/success.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,25 @@ module.exports = async (pluginConfig, context) => {

logger.log('Sending slack notification on success')

let slackMessage = {}

const repoPath =
options.repositoryUrl.indexOf('git@github.com') !== -1
? options.repositoryUrl.split(':')[1].replace('.git', '')
: undefined
const repoURL = repoPath && `https://github.com/${repoPath}`

// Override default success message
if (pluginConfig.onSuccessTemplate) {
let releaseNotes = nextRelease.notes

if (pluginConfig.markdownReleaseNotes) {
// Creating slack format from the markdown notes.
let releaseNotes = nextRelease.notes
if (pluginConfig.markdownReleaseNotes)
releaseNotes = slackifyMarkdown(releaseNotes)
releaseNotes = slackifyMarkdown(releaseNotes)
}

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

let slackMessage = {}
// Override default success message
if (pluginConfig.onSuccessTemplate) {
slackMessage = template(pluginConfig.onSuccessTemplate, {
package_name,
npm_package_version: nextRelease.version,
Expand All @@ -60,18 +64,12 @@ module.exports = async (pluginConfig, context) => {
}
]

if (nextRelease.notes !== '') {
// truncate long messages
let messageText = truncate(nextRelease.notes, MAX_LENGTH)

if (pluginConfig.markdownReleaseNotes)
messageText = slackifyMarkdown(messageText)

if (releaseNotes !== '') {
messageBlocks.push({
type: 'section',
text: {
type: 'mrkdwn',
text: `${messageText}`
text: `${releaseNotes}`
}
})
}
Expand Down
6 changes: 6 additions & 0 deletions test/test_truncate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ const assert = require('assert')
const truncate = require('../lib/truncate')

describe('test truncate', () => {
it('should not fail with empty message', () => {
const expected = ''
const actual = truncate(expected, expected.length)
assert.equal(expected, actual)
})

it('should not truncate when length <= maxLength', () => {
const expected = 'hello world'
const actual = truncate(expected, expected.length)
Expand Down

0 comments on commit ad3b0af

Please sign in to comment.