-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
103 lines (89 loc) · 2.52 KB
/
index.js
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* This is the entry point for your Probot App.
* @param {import('probot').Application} app - Probot's Application class.
*/
const getConfig = require('./src/getConfig')
const slackNotify = require('./src/slackNotify')
const sendEmail = require('./src/sendMail')
const writeConfluence = require('./src/writeConfluence')
module.exports = app => {
app.log('Yay, the app was loaded!')
app.on('release.published', async context => {
app.log("Yayyy we released. Now let's do some stuff!")
const configPath = 'releaseBuddy.config.json'
const config = await getConfig(app.log, context, configPath)
const { release, repository } = context.payload
const releaseDetails = {
name: release.name,
body: release.body,
url: release.html_url,
version: release.tag_name,
}
if (!config) {
app.log(
`Error loading release notifier configuration details from ${configPath}. Double check that you have added the necessary settings.`
)
return
}
const { slackSettings, emailSettings, confluenceSettings, teamName } = config
const { name: repositoryName } = repository
if (slackSettings && slackSettings.enabled === true) {
app.log('Delivering Slack notifications.')
try {
const responseMsg = await slackNotify(
slackSettings,
repositoryName,
releaseDetails,
teamName
)
app.log('Slack notifications delivered.')
app.log(responseMsg)
} catch (error) {
app.log('Error delivering slack notification.')
app.log(error)
}
}
if (emailSettings && emailSettings.enabled === true) {
app.log('Delivering email notifications.')
try {
const mailResponse = await sendEmail(
emailSettings,
releaseDetails,
repositoryName,
teamName
)
app.log(mailResponse)
app.log('Email notifications delivered.')
} catch (error) {
app.log('Error sending email.')
app.log(error)
if (error.response.body.errors) {
app.log(error.response.body.errors)
} else {
app.log(error)
}
}
}
if (confluenceSettings && confluenceSettings.enabled === true) {
app.log('Writing confluence wiki pages.')
try {
const confluenceResponse = await writeConfluence(
confluenceSettings,
releaseDetails,
repositoryName,
teamName
)
app.log(confluenceResponse)
app.log('Confluence wiki written.')
} catch (error) {
app.log('Error writing confluence wiki.')
app.log(error)
if (error.response.body.errors) {
app.log(error.response.body.errors)
} else {
app.log(error)
}
}
}
})
}