-
Notifications
You must be signed in to change notification settings - Fork 2
/
webhook.ts
88 lines (83 loc) · 2.39 KB
/
webhook.ts
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
import { readFileSync,existsSync } from 'fs';
webhook();
function webhook() {
console.log('SENDING WEBHOOK')
const fetch = require('node-fetch');
const webhookURL = process.env.GOOGLE_CHAT_WEBHOOK;
const resultLogFilePath ='./logs/results.log'
const resultErrorFilePath ='./logs/resultsErrors.log'
let logFile = '';
let errorLogFile = '';
if(existsSync(resultLogFilePath)){
logFile = readFileSync('./logs/results.log', 'utf-8');
errorLogFile = readFileSync('./logs/resultsErrors.log', 'utf-8');
}else{
logFile = '<br>'+'<b>Test Result: <font color="#ff0000">FAILED</font></b>' +
'<br>'+'Error Info: '+ 'Failed to start test due to whitelist script error.'
errorLogFile = '';
}
if (errorLogFile != ''){
errorLogFile = 'Failed Scenarios: <br>' +errorLogFile;
}
const data = JSON.stringify({
"cardsV2": [
{
"cardId": "unique-card-id",
"card": {
"header": {
"title": "Jobs Automated Health Check",
"subtitle": "Staging",
"imageUrl":
"https://developers.google.com/chat/images/quickstart-app-avatar.png",
"imageType": "CIRCLE",
"imageAltText": "Autobots transform"
},
"sections": [
{
"header": "Test Result",
"widgets": [
{
"decoratedText": {
"text": logFile
}
},
{
"decoratedText": {
"text": errorLogFile
}
},
{
"buttonList": {
"buttons": [
{
"text": "Open Github Actions",
"onClick": {
"openLink": {
"url": "https://github.com/cloudstaff-apps/jobs-automation-test/actions"
}
}
}
]
}
}
]
}
]
}
}
]
})
let resp;
fetch(webhookURL, {
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=UTF-8',
},
body: data,
}).then((response) => {
resp = response;
console.log(response);
console.log('WEBHOOK SENT')
});
return resp;
}