reg-notify-slack-plugin
Advanced tools
Comparing version 0.0.15 to 0.0.17
@@ -6,3 +6,3 @@ "use strict"; | ||
const reqParam = { | ||
uri: opt.webhookUrl, | ||
url: opt.webhookUrl, | ||
method: "POST", | ||
@@ -16,5 +16,4 @@ json: true, | ||
}; | ||
// FIXME | ||
return rp(reqParam); | ||
} | ||
exports.sendWebHook = sendWebHook; |
@@ -8,2 +8,3 @@ import { PluginCreateOptions, PluginLogger, NotifierPlugin, NotifyParams } from "reg-suit-interface"; | ||
_webhookUrl: string; | ||
_noEmmit: boolean; | ||
init(config: PluginCreateOptions<SlackNotiferPluginOptions>): void; | ||
@@ -10,0 +11,0 @@ notify(params: NotifyParams): Promise<any>; |
@@ -8,5 +8,10 @@ "use strict"; | ||
this._webhookUrl = config.options.webhookUrl; | ||
this._noEmmit = config.noEmit; | ||
} | ||
notify(params) { | ||
const body = this.createBody(params); | ||
this._logger.info(`Send to slack ${this._logger.colors.green(this._webhookUrl)}.`); | ||
this._logger.verbose("body to send to slack", body); | ||
if (this._noEmmit) | ||
return Promise.resolve(); | ||
return send_web_hook_1.sendWebHook({ | ||
@@ -13,0 +18,0 @@ body, |
import { PluginCreateOptions, PluginPreparer } from "reg-suit-interface"; | ||
import { SlackNotiferPluginOptions } from "./slack-notifier-plugin"; | ||
export interface QuestionResult { | ||
webhookUrl: string; | ||
webhookUrl?: string; | ||
sendTestMessage: boolean; | ||
@@ -17,4 +17,7 @@ } | ||
default: boolean; | ||
when: ({webhookUrl}: { | ||
webhookUrl?: string | undefined; | ||
}) => boolean; | ||
})[]; | ||
prepare(opt: PluginCreateOptions<QuestionResult>): Promise<SlackNotiferPluginOptions>; | ||
} |
@@ -17,2 +17,3 @@ "use strict"; | ||
default: true, | ||
when: ({ webhookUrl }) => !!webhookUrl, | ||
}, | ||
@@ -23,7 +24,14 @@ ]; | ||
const logger = opt.logger; | ||
const { webhookUrl } = opt.options; | ||
if (opt.options.sendTestMessage) { | ||
const { webhookUrl, sendTestMessage } = opt.options; | ||
if (!webhookUrl || !webhookUrl.length) { | ||
logger.warn(logger.colors.magenta("webhookUrl") + " is required parameter, edit this params later."); | ||
return Promise.resolve({ webhookUrl: "your_incoming_webhook_url" }); | ||
} | ||
if (sendTestMessage) { | ||
return send_web_hook_1.sendWebHook({ webhookUrl, body: "test message" }).then(() => { | ||
logger.info("Send test message successfully."); | ||
return { webhookUrl }; | ||
}).catch(reason => { | ||
logger.error(logger.colors.red(reason.message)); | ||
return Promise.reject(reason.error); | ||
}); | ||
@@ -30,0 +38,0 @@ } |
{ | ||
"name": "reg-notify-slack-plugin", | ||
"version": "0.0.15", | ||
"version": "0.0.17", | ||
"description": "Notify reg-suit result to Slack channel.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
6380
155