-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
61 lines (54 loc) · 1.75 KB
/
build.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
59
60
61
const axios = require('axios');
const console = require('better-console');
const ora = require('ora');
let previousLog = '';
let spinner;
exports.viewBuildInfo = function(url) {
const buildApi = `${url}api/json`;
axios.get(buildApi).then(function(response) {
const causeAction = response.data.actions.find(function(action) {
return action._class === 'hudson.model.CauseAction';
});
const user = causeAction.causes[0];
const buildData = response.data.actions.find(function(action) {
return action._class === 'hudson.plugins.git.util.BuildData';
});
if (!buildData) {
if (!spinner) {
spinner = ora('Waiting...').start();
spinner.color = 'yellow';
}
return exports.viewBuildInfo(url);
}
if (spinner) {
spinner.color = 'green';
spinner.stopAndPersist();
spinner.clear();
spinner.succeed('Started');
spinner = null;
}
const { lastBuiltRevision, remoteUrls } = buildData;
const buildingInfo = `${user.userName}: ${remoteUrls}[${lastBuiltRevision.branch[0].name}](${lastBuiltRevision.branch[0].SHA1})`;
viewBuildConsole(url);
})
}
function viewBuildConsole(url) {
const consoleApi = `${url}/consoleText`;
axios.get(consoleApi, { responseType: 'text' })
.then(function(response) {
if (response.data.indexOf('Finished:') > 0) {
console.clear();
console.log(response.data.replace(previousLog, ''));
} else {
const newLog = response.data.replace(previousLog, '');
if (newLog) {
console.clear();
console.log(response.data.replace(previousLog, ''));
previousLog = response.data;
}
setTimeout(function() {
viewBuildConsole(url);
}, 300);
}
});
}