forked from qltysh-archive/javascript-test-reporter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp_client.js
More file actions
46 lines (37 loc) · 1.19 KB
/
http_client.js
File metadata and controls
46 lines (37 loc) · 1.19 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
39
40
41
42
43
44
45
46
var request = require("request");
var url = require("url");
var pjson = require('./package.json');
var host = process.env.CODECLIMATE_API_HOST || "https://codeclimate.com";
var options = {
url: host + "/test_reports",
method: "POST",
headers: {
"User-Agent": "Code Climate (JavaScript Test Reporter v" + pjson.version + ")",
"Content-Type": "application/json"
},
timeout: 5000
};
var proxy = process.env.HTTP_PROXY || false;
if (proxy) {
options.proxy = proxy;
}
var postJson = function(data) {
var parts = url.parse(options.url);
options.body = JSON.stringify(data);
console.log("Sending test coverage results to " + parts.host + " ...");
request(options, function(error, response, body) {
if (error) {
console.error("A problem occurred", error);
}
if (response) {
if (response.statusCode >= 200 && response.statusCode < 300) {
console.log("Test coverage data sent.");
} else if (response.statusCode === 401) {
console.log("An invalid CODECLIMATE_REPO_TOKEN repo token was specified.");
} else {
console.log("Status code: " + response.statusCode);
}
}
});
};
module.exports = { postJson: postJson };