-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequest.js
44 lines (38 loc) · 1.3 KB
/
request.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
const request = require('request');
const options = {
url: 'https://codecov.io/api/gh/codecov/TypeScript-Standard',
headers: {
token: process.env.API_KEY,
},
};
const callback = (error, response, body) => {
if (!error && response.statusCode == 200) {
console.log("Pinging Codecov's API..");
const info = JSON.parse(body);
commit_data = info['commits'][0];
coverage_percentage = commit_data['totals']['c'];
// Coverage percentage should be CORRECT_COVERAGE environment variable on Travis || 77.77778
if (coverage_percentage == process.env.CORRECT_COVERAGE) {
console.log(
"Success! Codecov's API returned the correct coverage percentage, " +
process.env.CORRECT_COVERAGE,
);
return process.exit(0);
}
} else {
console.log(
'Whoops, something is wrong D: Codecov did not return the correct coverage percentage. Coverage percentage should be ' +
process.env.CORRECT_COVERAGE +
' but Codecov returned ' +
coverage_percentage,
);
return process.exit(1);
}
};
const napTime = milliseconds => {
console.log('Waiting 60 seconds for report to upload before pinging API...');
return new Promise(resolve => setTimeout(resolve, milliseconds));
};
napTime(60000).then(() => {
request(options, callback);
});