1 | import request from 'request-promise-native';
|
2 | import { SLACK_HOOKS_URL } from "./utils";
|
3 | export const sendRepoSlackMessage = async (log, prefixes, options) => {
|
4 | if (typeof options.token !== 'string') {
|
5 | throw new Error('Slack token is required');
|
6 | }
|
7 |
|
8 | await request({
|
9 | uri: `${SLACK_HOOKS_URL}${options.token}`,
|
10 | method: 'POST',
|
11 | json: {
|
12 | channel: options.channel,
|
13 | username: options.username,
|
14 | link_names: '1',
|
15 | icon_emoji: options.iconEmoji,
|
16 | unfurl_media: false,
|
17 | attachments: [{
|
18 | color: options.colors[log.type],
|
19 | fields: [{
|
20 | title: `v${log.version}`,
|
21 | value: log.messages.map(message => `${prefixes.required[message.type].value} ${message.value}`).join('\n')
|
22 | }]
|
23 | }]
|
24 | }
|
25 | });
|
26 | }; |
\ | No newline at end of file |