-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscord-notification.js
49 lines (43 loc) · 1.65 KB
/
discord-notification.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
require('dotenv').config();
const DiscordNotification = require('@penseapp/discord-notification');
const discordNotification = new DiscordNotification.DiscordNotification('Performance-JMeter-Example', process.env.DISCORD_WEBHOOK);
function getCurrentTimestamp() {
const options = {
timeZone: 'Asia/Jakarta',
day: 'numeric',
month: 'short',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
};
const formatter = new Intl.DateTimeFormat('en-ID', options);
const formattedTimestamp = formatter.format(new Date());
return formattedTimestamp;
}
function test(state) {
if (state == 'start') {
discordNotification
.infoMessage()
.addTitle('Testing Start')
.addDescription(`from ${process.env.REPOSITORY_URL}`)
.addField({name: 'Branch', value: process.env.BRANCH, inline: false }) //breakline
.addField({name: 'Build URL', value: process.env.BUILD_URL, inline: false })
.addField({name: 'Build Number', value: `performance.v.1.${process.env.BUILD}` })
.addFooter(`Test start on ${getCurrentTimestamp()}`)
.sendMessage();
} else if (state == 'stop') {
discordNotification
.infoMessage()
.addTitle('Testing Complete')
.addDescription(`from ${process.env.REPOSITORY_URL}`)
.addField({name: 'Branch', value: process.env.BRANCH, inline: false }) //breakline
.addField({name: 'Build URL', value: process.env.BUILD_URL, inline: false })
.addField({name: 'Build Number', value: `performance.v.1.${process.env.BUILD}` })
.addFooter(`Test is completed on ${getCurrentTimestamp()}`)
.sendMessage();
} else {
// eslint-disable-next-line no-console
console.error('Invalid Parameter');
}
}
module.exports = { test };