Skip to content

Commit 60caf25

Browse files
committed
fix(sonar): fix sonar finding file location retrieve bug, which caused GitHub validation errors on CheckRun submit
1 parent 29a7b00 commit 60caf25

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

src/sonar/sonar-status-emitter.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,10 @@ class SonarStatusEmitter {
114114
end: item.line,
115115
title: `${item.severity} ${item.type} (${item.rule})`,
116116
detail: item.message,
117-
severity: this.severityMap[item.severity] || Swingletree.Severity.INFO
117+
severity: this.severityMap[item.severity] || Swingletree.Severity.INFO,
118+
metadata: {
119+
hash: item.hash
120+
} as Object
118121
} as Swingletree.FileAnnotation);
119122

120123
// update counters
@@ -128,12 +131,6 @@ class SonarStatusEmitter {
128131
if (item.textRange) {
129132
annotation.start = item.textRange.startLine;
130133
annotation.end = item.textRange.endLine;
131-
132-
// omit values to comply to api validation
133-
if (annotation.start != annotation.end) {
134-
annotation.start = item.textRange.startOffset;
135-
annotation.end = item.textRange.endOffset;
136-
}
137134
}
138135

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

197194
this.eventBus.emit(notificationEvent);
195+
196+
return notificationEvent;
198197
}
199198
}
200199

test/mock/api/issues/search/GET--componentKeys=component-subproject-test&branch=dev&statuses=OPEN%2CCONFIRMED%2CREOPENED&resolved=false&p=1.mock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Content-Type: application/json; charset=utf-8
5555
"hash": "3d6a09cb1d3c2ab9cb077ee21a0c5cae",
5656
"textRange": {
5757
"startLine": 14,
58-
"endLine": 14,
58+
"endLine": 15,
5959
"startOffset": 46,
6060
"endOffset": 51
6161
},

test/sonar/sonar-status-emitter.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,18 @@ describe("Sonar Status Emitter", () => {
135135
);
136136
});
137137

138+
it("should set start and end lines", async () => {
139+
analysisData.analysisEvent.project.key = "component-subproject-test";
140+
141+
const result = await uut.analysisCompleteHandler(analysisData);
142+
143+
const annotation = result.payload.annotations.find(it => {
144+
return (it instanceof Swingletree.FileAnnotation) &&
145+
(it as Swingletree.FileAnnotation).metadata["hash"] == "3d6a09cb1d3c2ab9cb077ee21a0c5cae";
146+
}) as Swingletree.FileAnnotation;
147+
148+
expect(annotation.start).to.be.equal(14);
149+
expect(annotation.end).to.be.equal(15);
150+
});
151+
138152
});

0 commit comments

Comments
 (0)