Skip to content

Commit

Permalink
feat: Add packageName as a config option (#34)
Browse files Browse the repository at this point in the history
* feat: add packageName as a config option

* Fix linting errors

* correct typo in verifyConditions error
  • Loading branch information
darkphnx authored Feb 7, 2020
1 parent 22d83db commit bf323ca
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions lib/fail.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
6 changes: 4 additions & 2 deletions lib/success.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
10 changes: 7 additions & 3 deletions lib/verifyConditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <semantic-release-script> 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 <semantic-release-script> to use npm package name or define packageName in the plugin config or \`SEMANTIC_RELEASE_PACKAGE\` in the environment`
)
}
}

0 comments on commit bf323ca

Please sign in to comment.