-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlib.js
More file actions
38 lines (33 loc) · 1.2 KB
/
lib.js
File metadata and controls
38 lines (33 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const axios = require('axios')
// success, failure, or cancelled
const statusColor = (status) => ({
success: 'good',
failure: 'danger',
cancelled: 'warning',
}[status] || '#eee')
const send = (extra) => ({ title, link: title_link, status, slack_hook = process.env.SLACK_HOOK }) => {
const color = statusColor(status)
const attachment = {
mrkdwn_in: ['text'],
color,
title,
title_link,
fallback: title,
ts: Math.floor(Date.now() / 1000),
...extra,
}
return axios.post(slack_hook, { attachments: [attachment] })
.then(() => console.log('Notification sent to Slack'))
.catch(e => console.error((e.response || {}).data || e.toJSON()))
}
module.exports.send = send()
module.exports.deployment = (params) => {
const { success = true, status, stage = 'dev', project, commit } = params
const projLink = `https://github.com/${project}${commit ? `/commit/${commit}` : ''}`
const extra = { footer: `<${projLink}|${project}${commit ? `#${commit}` : ''}>` }
if (!status) {
extra.color = success ? 'good' : 'danger'
}
const title = `${project} (${stage}) deployment: ${status ? status : (success ? 'succeeded' : 'failed')}`
return send(extra)({ ...params, title })
}