deploy-notify-slack 0.3.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +37 -4
  2. package/notify.js +10 -1
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -4,15 +4,16 @@
4
4
  - use Slack incoming webhooks API to send a message
5
5
  - can attach version description Markdown files
6
6
 
7
- ### ENV Variables
7
+ ### Use default message template
8
+ You can use default message template with the following env variables:
8
9
 
9
- #### Required
10
+ #### Required env variables
10
11
 
11
12
  - SLACK_WEBHOOK_URL - you should generate webhook url for your target channel, see: https://api.slack.com/messaging/webhooks
12
13
  - STAGE - name of an application stage you're deploying, usually: dev, staging, prod..
13
14
  - VERSION - deployed version
14
15
 
15
- #### Optional
16
+ #### Optional env variables
16
17
 
17
18
  - TITLE - ('Deployment' by default) notification title
18
19
  - CHANGELOG_PATH - path of your deployed version details file (`changelog` by default as well as we assume that the package installed locally, so this option is required if the package installed globally)
@@ -25,7 +26,7 @@
25
26
 
26
27
  - FAILS_IF_NOT_SENT - (false by default) Should exit with not 0 error code if message was not sent successfully.
27
28
 
28
- ### How it works
29
+ #### How it works
29
30
 
30
31
  - Generate Slack webhook URL https://api.slack.com/messaging/webhooks
31
32
 
@@ -124,3 +125,35 @@ definitions:
124
125
  POSTGRES_USER: api
125
126
  POSTGRES_PASSWORD: example
126
127
  ```
128
+
129
+ ### Use custom message template
130
+
131
+ You can specify your own message template instead of default one.
132
+ It's useful if you want to add some additional information to the message.
133
+
134
+ Try to use [Slack message builder](https://api.slack.com/tools/block-kit-builder) to create your own message template.
135
+
136
+ Then you should load your template from file and pass it to the script as env variable `CUSTOM_MESSAGE`:
137
+
138
+ For example you saved your message template to `message.json` file:
139
+ ```json
140
+ {
141
+ "blocks": [
142
+ {
143
+ "type": "header",
144
+ "text": {
145
+ "type": "plain_text",
146
+ "text": ":flying_saucer: New API deploy of stage *DEV*",
147
+ "emoji": true
148
+ }
149
+ }
150
+ ]
151
+ }
152
+ ```
153
+
154
+ Then you can run the script with the following command:
155
+ ```shell
156
+ npm i --location=global deploy-notify-slack@latest
157
+ CUSTOM_MESSAGE=$(cat message.json)
158
+ SLACK_WEBHOOK_URL=${SLACK_WEBHOOK_URL} CUSTOM_MESSAGE=$CUSTOM_MESSAGE node /usr/local/lib/node_modules/deploy-notify-slack/notify.js
159
+ ```
package/notify.js CHANGED
@@ -6,6 +6,7 @@ const slackWebHookURL = process.env.SLACK_WEBHOOK_URL;
6
6
  const stage = process.env.STAGE;
7
7
  const version = process.env.VERSION;
8
8
  const title = process.env.TITLE || 'Deployment';
9
+ const customMessage = process.env.CUSTOM_MESSAGE;
9
10
  const changelogPath = process.env.CHANGELOG_PATH || path.join(__dirname, '../../changelog');
10
11
  const failsIfNotSent = process.env.FAILS_IF_NOT_SENT !== undefined
11
12
  ? stringToBool(process.env.FAILS_IF_NOT_SENT, false)
@@ -26,6 +27,11 @@ function getChangelog() {
26
27
  }
27
28
 
28
29
  function notificationBody() {
30
+ if (customMessage) {
31
+ return {
32
+ "attachments": [ JSON.parse(customMessage) ]
33
+ }
34
+ }
29
35
  let blocks = [
30
36
  {
31
37
  "type": "section",
@@ -144,6 +150,10 @@ function stringToBool(str, defaultValue = false){
144
150
 
145
151
  function validate() {
146
152
  let success = true;
153
+ if (customMessage) {
154
+ console.log('Custom message', customMessage);
155
+ return true;
156
+ }
147
157
  if (!slackWebHookURL) {
148
158
  console.error('Please fill in slack Webhook URL as SLACK_WEBHOOK_URL env');
149
159
  success = false;
@@ -167,7 +177,6 @@ function validate() {
167
177
  if (!validate()) {
168
178
  process.exit(3);
169
179
  }
170
-
171
180
  console.log('Sending slack message');
172
181
  try {
173
182
  const slackResponse = await sendSlackMessage(slackWebHookURL, notificationBody());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deploy-notify-slack",
3
- "version": "0.3.2",
3
+ "version": "0.4.0",
4
4
  "description": "Send Slack notification about deploy with version comments",
5
5
  "main": "notify.js",
6
6
  "scripts": {