56 lines
1.8 KiB
HTML
56 lines
1.8 KiB
HTML
![]() |
<dom-module id="coverage-plugin">
|
||
|
<script>
|
||
|
|
||
|
function populateWithDummyData(coverageData) {
|
||
|
coverageData['NewFile'] = {
|
||
|
linesMissingCoverage: [1, 2, 3],
|
||
|
totalLines: 5,
|
||
|
changeNum: 94,
|
||
|
patchNum: 2,
|
||
|
};
|
||
|
coverageData['/COMMIT_MSG'] = {
|
||
|
linesMissingCoverage: [3, 4, 7, 14],
|
||
|
totalLines: 14,
|
||
|
changeNum: 94,
|
||
|
patchNum: 2,
|
||
|
};
|
||
|
coverageData['DEPS'] = {
|
||
|
linesMissingCoverage: [3, 4, 7, 14],
|
||
|
totalLines: 16,
|
||
|
changeNum: 77001,
|
||
|
patchNum: 1,
|
||
|
};
|
||
|
}
|
||
|
|
||
|
Gerrit.install(plugin => {
|
||
|
const coverageData = {};
|
||
|
plugin.annotationApi().addNotifier(notifyFunc => {
|
||
|
new Promise(resolve => setTimeout(resolve, 3000)).then(
|
||
|
() => {
|
||
|
populateWithDummyData(coverageData);
|
||
|
Object.keys(coverageData).forEach(file => {
|
||
|
notifyFunc(file, 0, coverageData[file].totalLines, 'right');
|
||
|
});
|
||
|
});
|
||
|
}).addLayer(context => {
|
||
|
if (Object.keys(coverageData).length === 0) {
|
||
|
// Coverage data is not ready yet.
|
||
|
return;
|
||
|
}
|
||
|
const path = context.path;
|
||
|
const line = context.line;
|
||
|
// Highlight lines missing coverage with this background color.
|
||
|
const cssClass = Gerrit.css('background-color: #EF9B9B');
|
||
|
if (coverageData[path] &&
|
||
|
coverageData[path].changeNum === context.changeNum &&
|
||
|
coverageData[path].patchNum === context.patchNum) {
|
||
|
const linesMissingCoverage = coverageData[path].linesMissingCoverage;
|
||
|
if (linesMissingCoverage.includes(line.afterNumber)) {
|
||
|
context.annotateRange(0, line.text.length, cssClass, 'right');
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
</script>
|
||
|
</dom-module>
|