deploy-vir 0.2.6 → 0.2.7
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.
- package/dist/notifications/slack.js +16 -14
- package/package.json +1 -1
- package/src/notifications/slack.ts +17 -14
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addPrefix, capitalizeFirstLetter } from '@augment-vir/common';
|
|
1
|
+
import { addPrefix, capitalizeFirstLetter, log } from '@augment-vir/common';
|
|
2
2
|
import { joinUrlPaths } from 'url-vir';
|
|
3
3
|
function truncateString(value, truncateAt = 100) {
|
|
4
4
|
if (value.length > truncateAt) {
|
|
@@ -80,31 +80,33 @@ export async function sendNotificationToSlack({ branchConfig, deployResult: { de
|
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
async function sendSlackMessage(slackConfig, body) {
|
|
83
|
+
const messageBody = {
|
|
84
|
+
...body,
|
|
85
|
+
...(slackConfig.avatarEmoji
|
|
86
|
+
? {
|
|
87
|
+
icon_emoji: slackConfig.avatarEmoji,
|
|
88
|
+
}
|
|
89
|
+
: {}),
|
|
90
|
+
...(slackConfig.username
|
|
91
|
+
? {
|
|
92
|
+
username: slackConfig.username,
|
|
93
|
+
}
|
|
94
|
+
: {}),
|
|
95
|
+
};
|
|
83
96
|
try {
|
|
84
97
|
const response = await fetch(slackConfig.webhookUrl, {
|
|
85
98
|
method: 'POST',
|
|
86
99
|
headers: {
|
|
87
100
|
'Content-Type': 'application/json',
|
|
88
101
|
},
|
|
89
|
-
body: JSON.stringify(
|
|
90
|
-
...body,
|
|
91
|
-
...(slackConfig.avatarEmoji
|
|
92
|
-
? {
|
|
93
|
-
icon_emoji: slackConfig.avatarEmoji,
|
|
94
|
-
}
|
|
95
|
-
: {}),
|
|
96
|
-
...(slackConfig.username
|
|
97
|
-
? {
|
|
98
|
-
username: slackConfig.username,
|
|
99
|
-
}
|
|
100
|
-
: {}),
|
|
101
|
-
}),
|
|
102
|
+
body: JSON.stringify(messageBody),
|
|
102
103
|
});
|
|
103
104
|
if (!response.ok) {
|
|
104
105
|
throw new Error(`Failed to send Slack webhook: ${response.status}`);
|
|
105
106
|
}
|
|
106
107
|
}
|
|
107
108
|
catch (error) {
|
|
109
|
+
log.error(JSON.stringify(messageBody, null, 4));
|
|
108
110
|
console.error('Error sending Slack message:', error);
|
|
109
111
|
}
|
|
110
112
|
}
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {addPrefix, capitalizeFirstLetter} from '@augment-vir/common';
|
|
1
|
+
import {addPrefix, capitalizeFirstLetter, log} from '@augment-vir/common';
|
|
2
2
|
import {type ChatPostMessageArguments, type KnownBlock} from '@slack/web-api';
|
|
3
3
|
import {joinUrlPaths} from 'url-vir';
|
|
4
4
|
import {type SlackNotificationConfig} from '../config.js';
|
|
@@ -109,31 +109,34 @@ async function sendSlackMessage(
|
|
|
109
109
|
slackConfig: Readonly<Pick<SlackNotificationConfig, 'avatarEmoji' | 'webhookUrl' | 'username'>>,
|
|
110
110
|
body: Readonly<ChatPostMessageArguments>,
|
|
111
111
|
) {
|
|
112
|
+
const messageBody = {
|
|
113
|
+
...body,
|
|
114
|
+
...(slackConfig.avatarEmoji
|
|
115
|
+
? {
|
|
116
|
+
icon_emoji: slackConfig.avatarEmoji,
|
|
117
|
+
}
|
|
118
|
+
: {}),
|
|
119
|
+
...(slackConfig.username
|
|
120
|
+
? {
|
|
121
|
+
username: slackConfig.username,
|
|
122
|
+
}
|
|
123
|
+
: {}),
|
|
124
|
+
};
|
|
125
|
+
|
|
112
126
|
try {
|
|
113
127
|
const response = await fetch(slackConfig.webhookUrl, {
|
|
114
128
|
method: 'POST',
|
|
115
129
|
headers: {
|
|
116
130
|
'Content-Type': 'application/json',
|
|
117
131
|
},
|
|
118
|
-
body: JSON.stringify(
|
|
119
|
-
...body,
|
|
120
|
-
...(slackConfig.avatarEmoji
|
|
121
|
-
? {
|
|
122
|
-
icon_emoji: slackConfig.avatarEmoji,
|
|
123
|
-
}
|
|
124
|
-
: {}),
|
|
125
|
-
...(slackConfig.username
|
|
126
|
-
? {
|
|
127
|
-
username: slackConfig.username,
|
|
128
|
-
}
|
|
129
|
-
: {}),
|
|
130
|
-
}),
|
|
132
|
+
body: JSON.stringify(messageBody),
|
|
131
133
|
});
|
|
132
134
|
|
|
133
135
|
if (!response.ok) {
|
|
134
136
|
throw new Error(`Failed to send Slack webhook: ${response.status}`);
|
|
135
137
|
}
|
|
136
138
|
} catch (error) {
|
|
139
|
+
log.error(JSON.stringify(messageBody, null, 4));
|
|
137
140
|
console.error('Error sending Slack message:', error);
|
|
138
141
|
}
|
|
139
142
|
}
|