Skip to content

Commit

Permalink
fix(verify-conditions): Added check for non existant package name
Browse files Browse the repository at this point in the history
re #4
  • Loading branch information
hannesrabo committed Jun 17, 2019
1 parent 57bf855 commit dc5f1c1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ Installing the app will yield you with a webhook that the app uses to publish up

The `SLACK_WEBHOOK` variable has to be defined in the environment where you will be running semantic release. This can be done by exporting it in bash or in the user interface of you CI provider. Obtain this token by installing the slack app according to [slack app installation](#slack-app-installation).

| Variable | Description |
| --------------- | --------------------------------------------------- |
| `SLACK_WEBHOOK` | Slack webhook created when adding app to workspace. |
| Variable | Description |
| -------------------------- | -------------------------------------------------------- |
| `SLACK_WEBHOOK` | Slack webhook created when adding app to workspace. |
| `SEMANTIC_RELEASE_PACKAGE` | Override or add package name instead of npm package name |

### Options

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

module.exports = async (pluginConfig, context) => {
const { logger, nextRelease, options } = context
const { npm_package_name } = context.env

let package_name = context.env.SEMANTIC_RELEASE_PACKAGE
if (!package_name) package_name = context.env.npm_package_name

if (!pluginConfig.notifyOnSuccess) {
logger.log('Notifying on success skipped')
Expand All @@ -17,7 +19,7 @@ module.exports = async (pluginConfig, context) => {
type: 'section',
text: {
type: 'mrkdwn',
text: `A new version of \`${npm_package_name}\` has been released!\nCurrent version is *#${
text: `A new version of \`${package_name}\` has been released!\nCurrent version is *#${
nextRelease.version
}*`
}
Expand All @@ -36,7 +38,7 @@ module.exports = async (pluginConfig, context) => {

let slackMessage = {
blocks: messageBlocks,
text: `A new version of ${npm_package_name} has been released!`
text: `A new version of ${package_name} has been released!`
}

if (options.repositoryUrl.indexOf('[email protected]') !== -1) {
Expand Down
14 changes: 14 additions & 0 deletions lib/verifyConditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,18 @@ module.exports = (pluginConfig, context) => {
`A Slack Webhook must be created and set in the \`SLACK_WEBHOOK\` environment variable on your CI environment.\n\n\nPlease make sure to create a Slack Webhook and to set it in the \`SLACK_WEBHOOK\` environment variable on your CI environment.`
)
}

if (
!context.env.npm_package_name &&
!context.env.SEMANTIC_RELEASE_PACKAGE
) {
logger.log(
'npm package name 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`
)
}
}

0 comments on commit dc5f1c1

Please sign in to comment.