-
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.
- Loading branch information
1 parent
ce4c896
commit d541e59
Showing
4 changed files
with
107 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const fetch = require('node-fetch') | ||
const SemanticReleaseError = require('@semantic-release/error') | ||
// require('dotenv').config() | ||
|
||
async function postMessage(message) { | ||
const slackHook = process.env.SLACK_WEBHOOK | ||
|
||
if (!slackHook) { | ||
throw new SemanticReleaseError( | ||
'Slack web-hook is not defined in environment. Define SLACK_WEBHOOK!' | ||
) | ||
} | ||
|
||
await fetch(slackHook, { | ||
method: 'post', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify(message) | ||
}) | ||
.then(res => res.text()) | ||
.then(text => { | ||
if (text != 'ok') { | ||
logger.log('Json message format invalid') | ||
throw new SemanticReleaseError( | ||
new Error().stdout, | ||
'INVALID SLACK COMMAND: ' + text | ||
) | ||
} | ||
}) | ||
.catch(e => { | ||
throw new SemanticReleaseError( | ||
e.stdout, | ||
'SLACK CONNECTION FAILED: ' | ||
) | ||
}) | ||
} | ||
|
||
module.exports = postMessage |
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 |
---|---|---|
@@ -1,8 +1,59 @@ | ||
module.exports = (pluginConfig, context) => { | ||
const postMessage = require('./postMessage') | ||
|
||
module.exports = async (pluginConfig, context) => { | ||
if (!pluginConfig.notifyOnSuccess) { | ||
return | ||
} | ||
|
||
const { logger, nextRelease } = context | ||
logger.log(context.nextRelease) | ||
const { nextRelease, options } = context | ||
|
||
let messageBlocks = [ | ||
{ | ||
type: 'section', | ||
text: { | ||
type: 'mrkdwn', | ||
text: `A new version has been released!\n Current version is *#${ | ||
nextRelease.version | ||
}*` | ||
} | ||
} | ||
] | ||
|
||
if (nextRelease.notes != '') { | ||
messageBlocks.push({ | ||
type: 'section', | ||
text: { | ||
type: 'mrkdwn', | ||
text: `*Notes*: ${nextRelease.notes}` | ||
} | ||
}) | ||
} | ||
|
||
if (options.repositoryUrl.indexOf('git@github.com') != -1) { | ||
const repoPath = options.repositoryUrl.split(':')[1].replace('.git', '') | ||
const repoURL = `https://github.com/${repoPath}` | ||
const gitTag = nextRelease.gitTag | ||
|
||
// const divider = { | ||
// type: 'divider' | ||
// } | ||
const metadata = { | ||
type: 'context', | ||
elements: [ | ||
{ | ||
type: 'mrkdwn', | ||
text: `*<${repoURL}|${repoPath}>:* <${repoURL}/releases/tag/${gitTag}|${gitTag}>` | ||
} | ||
] | ||
} | ||
|
||
messageBlocks.push(metadata) | ||
// messageBlocks.push(divider) | ||
} | ||
|
||
let slackMessage = { | ||
blocks: messageBlocks | ||
} | ||
|
||
await postMessage(slackMessage) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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