-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
61 lines (52 loc) · 1.72 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
const core = require('@actions/core');
const github = require('@actions/github');
const https = require('follow-redirects').https;
const fs = require('fs');
try {
let rawdata = fs.readFileSync('./postman-action-config.json');
const monitors = JSON.parse(rawdata);
monitors.forEach(m => {
var options = {
'method': 'POST',
'hostname': 'api.getpostman.com',
'path': `/monitors/${m.id}/run`,
'headers': {
'X-Api-Key': process.env.POSTMANAPIKEY
},
'maxRedirects': 20
};
var req = https.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", () => {
var body = Buffer.concat(chunks);
console.log(body.toString());
if (res.statusCode == 200) {
if (m.type === 'postman') {
if (JSON.parse(body.toString()).run.info.status == 'failed') {
core.setFailed(`1 or more Postman tests failed`);
console.log(body.toString());
}
} else if (m.type === 'ghostinspector') {
const stats = JSON.parse(body.toString()).run.stats;
if (stats.assertions.failed > 0) {
core.setFailed(`1 or more Ghost Inspector tests failed`);
console.log(stats);
}
}
} else {
core.setFailed(`Failed. Error code ${res.statusCode}`);
console.error(body.toString());
}
});
res.on("error", function (error) {
console.error(error);
});
});
req.end();
});
} catch (error) {
core.setFailed(error.message);
}