From bf323caf287f32bd72cebae3f5d70937bc407133 Mon Sep 17 00:00:00 2001 From: Dan Wentworth Date: Fri, 7 Feb 2020 12:48:54 +0000 Subject: [PATCH] feat: Add packageName as a config option (#34) * feat: add packageName as a config option * Fix linting errors * correct typo in verifyConditions error --- README.md | 1 + lib/fail.js | 5 +++-- lib/success.js | 6 ++++-- lib/verifyConditions.js | 10 +++++++--- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 571d77b..18242cb 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,7 @@ Alternatively, you could pass the webhook as a configuration option. | `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 | +| `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 | ### Templating diff --git a/lib/fail.js b/lib/fail.js index 2a47928..82e8f29 100644 --- a/lib/fail.js +++ b/lib/fail.js @@ -9,9 +9,10 @@ module.exports = async (pluginConfig, context) => { errors, env: { SEMANTIC_RELEASE_PACKAGE, npm_package_name } } = context - const { slackWebhook = process.env.SLACK_WEBHOOK } = pluginConfig + const { slackWebhook = process.env.SLACK_WEBHOOK, packageName } = pluginConfig - const package_name = SEMANTIC_RELEASE_PACKAGE || npm_package_name + const package_name = + SEMANTIC_RELEASE_PACKAGE || packageName || npm_package_name if (!pluginConfig.notifyOnFail) { logger.log('Notifying on fail skipped') diff --git a/lib/success.js b/lib/success.js index 0c8d549..83fe1ea 100644 --- a/lib/success.js +++ b/lib/success.js @@ -17,10 +17,12 @@ module.exports = async (pluginConfig, context) => { } = context const { slackWebhook = process.env.SLACK_WEBHOOK, - unsafeMaxLength = MAX_LENGTH + unsafeMaxLength = MAX_LENGTH, + packageName } = pluginConfig - const package_name = SEMANTIC_RELEASE_PACKAGE || npm_package_name + const package_name = + SEMANTIC_RELEASE_PACKAGE || packageName || npm_package_name if (!pluginConfig.notifyOnSuccess) { logger.log('Notifying on success skipped') diff --git a/lib/verifyConditions.js b/lib/verifyConditions.js index 9b87aac..ac439da 100644 --- a/lib/verifyConditions.js +++ b/lib/verifyConditions.js @@ -13,14 +13,18 @@ module.exports = (pluginConfig, context) => { ) } - if (!context.env.npm_package_name && !context.env.SEMANTIC_RELEASE_PACKAGE) { + if ( + !context.env.npm_package_name && + !pluginConfig.packageName && + !context.env.SEMANTIC_RELEASE_PACKAGE + ) { logger.log( - 'npm package name and SEMANTIC_RELEASE_PACKAGE name are undefined' + 'npm package name, config packageName and SEMANTIC_RELEASE_PACKAGE name are undefined' ) throw new SemanticReleaseError( 'No name for the package defined.', 'ENOPACKAGENAME', - `A name for the package must be created. Run through npm (npm run to use npm package name or define \`SEMANTIC_RELEASE_PACKAGE\` in the environment` + `A name for the package must be created. Run through npm (npm run to use npm package name or define packageName in the plugin config or \`SEMANTIC_RELEASE_PACKAGE\` in the environment` ) } }