-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsonarqube-qualitygate-check.js
43 lines (38 loc) · 1.28 KB
/
sonarqube-qualitygate-check.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
const MESSAGE_SYMBOL = Symbol("message");
const CODE_SYMBOL = Symbol("code");
const CHECK_SUCCESSFUL_SYMBOL = Symbol("checkSuccessful");
class Result extends Object {
constructor(message, code, checkSuccessful) {
super();
this[MESSAGE_SYMBOL] = message;
this[CODE_SYMBOL] = code;
this[CHECK_SUCCESSFUL_SYMBOL] = checkSuccessful
}
get message() {
return this[MESSAGE_SYMBOL];
}
get code() {
return this[CODE_SYMBOL];
}
get checkSuccessful() {
return this[CHECK_SUCCESSFUL_SYMBOL];
}
}
module.exports = async function check(ceTask, qualityGateProjectStatus) {
const status = qualityGateProjectStatus.projectStatus.status;
process.stdout.write(`QualityGate project status: ${status}\n`);
qualityGateProjectStatus.projectStatus.conditions.forEach(condition => {
process.stdout.write(`* Metric "${condition.metricKey}": ${condition.status}\n`);
});
process.stdout.write("\n");
switch (status) {
case "ERROR":
return new Result("Quality Gate Goals missed!", 127, true);
case "WARN":
return new Result("Quality Gate Goals met WITH WARNINGS!", 0, true);
case "OK":
return new Result("Quality Gate Goals met.", 0, true);
default:
return new Result(`Unknown status of quality gate: "${status}".`, 49, false)
}
}