Skip to content

Commit fe60401

Browse files
Fix sonar issues limit 10000
1 parent 9b59883 commit fe60401

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Inspired by https://github.com/SonarCommunity/sonar-github
1616

1717
### Fixed
1818
- Fix bug with QualityGate status NONE #107
19+
- Fix sonar issues limit 10000 [#140](https://github.com/gabrie-allaigre/sonar-gitlab-plugin/issues/140)
1920
- Add test for covorage
2021

2122
**[Download 3.0.2-RC1](https://github.com/gabrie-allaigre/sonar-gitlab-plugin/releases/download/3.0.2-rc1/sonar-gitlab-plugin-3.0.2-rc1.jar)**

src/main/java/com/talanlabs/sonar/plugins/gitlab/SonarFacade.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public class SonarFacade {
5656

5757
private static final Logger LOG = Loggers.get(SonarFacade.class);
5858
private static final String LOG_MSG = "{}: {} {} {}";
59+
private static final int MAX_SEARCH_ISSUES = 10000;
5960
private final GitLabPluginConfiguration gitLabPluginConfiguration;
6061
private final WsClient wsClient;
6162
private File projectBaseDir;
@@ -225,7 +226,6 @@ public List<Issue> getNewIssues() {
225226
while (nbPage == null || page <= nbPage) {
226227
Issues.SearchWsResponse searchWsResponse = searchIssues(projectKey, refName, page);
227228
nbPage = computeNbPage(searchWsResponse.getTotal(), searchWsResponse.getPs());
228-
229229
issues.addAll(toIssues(searchWsResponse, refName));
230230

231231
page++;
@@ -257,7 +257,9 @@ private String toString(GetRequest getRequest) {
257257
}
258258

259259
private int computeNbPage(long total, int pageSize) {
260-
return (int) (total / (long) (pageSize + 1)) + 1;
260+
int maxPage = (int) (MAX_SEARCH_ISSUES / (long) (pageSize + 1)) + 1;
261+
int nbPage = (int) (total / (long) (pageSize + 1)) + 1;
262+
return Math.min(nbPage, maxPage);
261263
}
262264

263265
private List<Issue> toIssues(Issues.SearchWsResponse issuesSearchWsResponse, String branch) {

src/test/java/com/talanlabs/sonar/plugins/gitlab/SonarFacadeTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,24 @@ public void testNotEmptyGetNewIssue() throws IOException {
267267
Assertions.assertThat(issues.get(0).getFile().getAbsolutePath()).isEqualTo(new File(projectDir, "toto.java").getAbsolutePath());
268268
}
269269

270+
@Test
271+
public void test10000NewIssue() throws IOException {
272+
Issues.SearchWsResponse.Builder builder = Issues.SearchWsResponse.newBuilder().setTotal(20000).setPs(100);
273+
for (int i = 0; i < 100; i++) {
274+
builder.addIssues(Issues.Issue.newBuilder().build());
275+
}
276+
Issues.SearchWsResponse searchWsResponse = builder.build();
277+
for (int i = 0; i < 100; i++) {
278+
sonar.enqueue(new MockResponse().setResponseCode(200).addHeader("Content-Type", "application/x-protobuf").setBody(toBuffer(searchWsResponse)));
279+
}
280+
sonar.enqueue(new MockResponse().setResponseCode(400).setBody("{\"errors\":[{\"msg\":\"Can return only the first 10000 results. 10100th result asked.\"}]}"));
281+
282+
createReportTaskFile();
283+
284+
List<Issue> issues = sonarFacade.getNewIssues();
285+
Assertions.assertThat(issues).isNotNull().hasSize(10000);
286+
}
287+
270288
@Test
271289
public void tesFullPageGetNewIssue() throws IOException {
272290
tesFullPageGetNewIssueForQualifier(Qualifiers.FILE);

0 commit comments

Comments
 (0)