-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allows a custom environment variable name for Slack webhook (#36)
This is particularly useful when using CircleCI and their `context` system. In our organisation, the context has a default SLACK_WEBHOOK value but we need to override it for some repositories (but still use the context). Since in CircleCI the context override custom environment variables we need this parameter to use another variable.
- Loading branch information
1 parent
87ab8bb
commit a8bec27
Showing
4 changed files
with
82 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const SemanticReleaseError = require('@semantic-release/error') | ||
const assert = require('assert') | ||
|
||
const verifyConditions = require('../lib/verifyConditions') | ||
|
||
describe('test verifyConditions', () => { | ||
beforeEach(() => { | ||
delete process.env.SLACK_WEBHOOK | ||
}) | ||
|
||
describe('test slack webhooks options', () => { | ||
const fakeContext = { logger: { log: () => undefined }, env: {} } | ||
const defaultPluginConfig = { packageName: 'test' } | ||
const getMissingWebhookError = slackWebhookEnVar => { | ||
return `A Slack Webhook must be created and set in the \`${slackWebhookEnVar}\` environment variable on your CI environment.\n\n\nPlease make sure to create a Slack Webhook and to set it in the \`${slackWebhookEnVar}\` environment variable on your CI environment. Alternatively, provide \`slackWebhook\` as a configuration option.` | ||
} | ||
|
||
it('should throw if neither slackWebhook and environment variable SLACK_WEBHOOK are set', () => { | ||
assert.throws( | ||
() => verifyConditions(defaultPluginConfig, fakeContext), | ||
new SemanticReleaseError( | ||
'No Slack web-hook defined.', | ||
'ENOSLACKHOOK', | ||
getMissingWebhookError('SLACK_WEBHOOK') | ||
) | ||
) | ||
}) | ||
|
||
it('should throw if slackWebhook is not set and slackWebhookEnVar give an empty environment variable', () => { | ||
assert.throws( | ||
() => | ||
verifyConditions( | ||
{ ...defaultPluginConfig, slackWebhookEnVar: 'CUSTOM_WEBHOOK' }, | ||
fakeContext | ||
), | ||
new SemanticReleaseError( | ||
'No Slack web-hook defined.', | ||
'ENOSLACKHOOK', | ||
getMissingWebhookError('CUSTOM_WEBHOOK') | ||
) | ||
) | ||
}) | ||
|
||
it('should not throw if slackWebhook is provided', () => { | ||
verifyConditions( | ||
{ ...defaultPluginConfig, slackWebhook: 'MY SLACK WEBHOOK' }, | ||
fakeContext | ||
) | ||
}) | ||
|
||
it('should not throw if SLACK_WEBHOOK is set', () => { | ||
process.env.SLACK_WEBHOOK = 'MY SLACK WEBHOOK' | ||
verifyConditions(defaultPluginConfig, fakeContext) | ||
}) | ||
|
||
it('should not throw if slackWebhookEnVar give an environment variable', () => { | ||
process.env.CUSTOM_WEBHOOK = 'MY SLACK WEBHOOK' | ||
verifyConditions( | ||
{ ...defaultPluginConfig, slackWebhookEnVar: 'CUSTOM_WEBHOOK' }, | ||
fakeContext | ||
) | ||
}) | ||
}) | ||
}) |