Skip to content

Commit

Permalink
fix(sonar): fix sonar finding file location retrieve bug, which cause…
Browse files Browse the repository at this point in the history
…d GitHub validation errors on CheckRun submit
  • Loading branch information
error418 committed Oct 4, 2019
1 parent 29a7b00 commit 60caf25
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
13 changes: 6 additions & 7 deletions src/sonar/sonar-status-emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ class SonarStatusEmitter {
end: item.line,
title: `${item.severity} ${item.type} (${item.rule})`,
detail: item.message,
severity: this.severityMap[item.severity] || Swingletree.Severity.INFO
severity: this.severityMap[item.severity] || Swingletree.Severity.INFO,
metadata: {
hash: item.hash
} as Object
} as Swingletree.FileAnnotation);

// update counters
Expand All @@ -128,12 +131,6 @@ class SonarStatusEmitter {
if (item.textRange) {
annotation.start = item.textRange.startLine;
annotation.end = item.textRange.endLine;

// omit values to comply to api validation
if (annotation.start != annotation.end) {
annotation.start = item.textRange.startOffset;
annotation.end = item.textRange.endOffset;
}
}

if (annotation.path) {
Expand Down Expand Up @@ -195,6 +192,8 @@ class SonarStatusEmitter {
notificationEvent.markdown = this.templateEngine.template<SonarCheckRunSummaryTemplate>(Templates.CHECK_RUN_SUMMARY, summaryTemplateData);

this.eventBus.emit(notificationEvent);

return notificationEvent;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Content-Type: application/json; charset=utf-8
"hash": "3d6a09cb1d3c2ab9cb077ee21a0c5cae",
"textRange": {
"startLine": 14,
"endLine": 14,
"endLine": 15,
"startOffset": 46,
"endOffset": 51
},
Expand Down
14 changes: 14 additions & 0 deletions test/sonar/sonar-status-emitter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,18 @@ describe("Sonar Status Emitter", () => {
);
});

it("should set start and end lines", async () => {
analysisData.analysisEvent.project.key = "component-subproject-test";

const result = await uut.analysisCompleteHandler(analysisData);

const annotation = result.payload.annotations.find(it => {
return (it instanceof Swingletree.FileAnnotation) &&
(it as Swingletree.FileAnnotation).metadata["hash"] == "3d6a09cb1d3c2ab9cb077ee21a0c5cae";
}) as Swingletree.FileAnnotation;

expect(annotation.start).to.be.equal(14);
expect(annotation.end).to.be.equal(15);
});

});

0 comments on commit 60caf25

Please sign in to comment.