class Script {
process_incoming_request({
request
}) {
// console is a global helper to improve debug
//console.log(request.content);
if (request.content.status != "SUCCESS") {
return {
error: {
success: false,
message: "analysis finished with error, task id: " + request.content.taskId
}
};
}
let msgText = "Analysis " + request.content.project.name + " completed";
let attColor = "gray";
switch (request.content.qualityGate.status) {
case "OK":
attColor = "#00FF00";
break;
case "ERROR":
attColor = "#FF0000";
break;
default:
break;
}
let att2 = [];
request.content.qualityGate.conditions.forEach(function (condition) {
switch (condition.metric) {
case "new_reliability_rating":
att2.push({
title: "Reliability",
value: condition.status,
short: true
});
break;
case "new_security_rating":
att2.push({
title: "Security",
value: condition.status,
short: true
});
break;
case "new_maintainability_rating":
att2.push({
title: "Maintainability",
value: condition.status,
short: true
});
break;
case "new_duplicated_lines_density":
att2.push({
title: "Duplicated lines",
value: condition.status,
short: true
});
break;
case "new_coverage":
att2.push({
title: "Code coverage",
value: condition.status,
short: true
});
break;
default:
break;
}
})
let result = {
content: {
username: "SonarQube",
icon_url: "/avatar/SonarQube.jpg",
attachments: [{
color: attColor,
title: msgText,
title_link: request.content.branch.url,
fields: [{
title: "Quality Gate Status",
value: request.content.qualityGate.status,
short: true
}, {
title: "Analysed At",
value: request.content.analysedAt,
short: true
}, {
title: "Revision",
value: request.content.revision,
short: true
}, {
title: "Branch",
value: request.content.branch.name,
short: true
}
]
}
]
}
};
if (att2.length > 0) {
result.content.attachments.push({
color: attColor,
title: "Quality Indicators",
fields: att2
});
}
return result;
}
}