From 0b6272c83cafc791550a0a71f8de552674856f7e Mon Sep 17 00:00:00 2001 From: Gabriel Allaigre Date: Mon, 3 Sep 2018 16:10:32 +0200 Subject: [PATCH] Fix #140 verify limit 10000 --- README.md | 7 ++++--- .../sonar/plugins/gitlab/SonarFacade.java | 6 ++++-- .../sonar/plugins/gitlab/SonarFacadeTest.java | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index dbc6495..26330dd 100644 --- a/README.md +++ b/README.md @@ -7,16 +7,17 @@ Inspired by https://github.com/SonarCommunity/sonar-github # Changelog -## Version 4.0.0-rc1 +## Version 4.0.0-rc2 ### Changed - Update to sonarqube 7.0 plugin version ### Fixed -- Using properties instead of depending on the deprecated, work with SonarQube 7.2 #162 (Thanks dmarin) +- Using properties instead of depending on the deprecated, work with SonarQube 7.2 [#164](https://github.com/gabrie-allaigre/sonar-gitlab-plugin/pull/164) (Thanks dmarin) - Fix others deprecated +- Fix sonar issues limit 10000 [#140](https://github.com/gabrie-allaigre/sonar-gitlab-plugin/issues/140) -**[Download 4.0.0-rc1](https://github.com/gabrie-allaigre/sonar-gitlab-plugin/releases/download/4.0.0-rc1/sonar-gitlab-plugin-4.0.0-rc1.jar)** +**[Download 4.0.0-rc2](https://github.com/gabrie-allaigre/sonar-gitlab-plugin/releases/download/4.0.0-rc2/sonar-gitlab-plugin-4.0.0-rc2.jar)** ## Version 3.0.1 diff --git a/src/main/java/com/talanlabs/sonar/plugins/gitlab/SonarFacade.java b/src/main/java/com/talanlabs/sonar/plugins/gitlab/SonarFacade.java index 44c3a06..a9a9975 100644 --- a/src/main/java/com/talanlabs/sonar/plugins/gitlab/SonarFacade.java +++ b/src/main/java/com/talanlabs/sonar/plugins/gitlab/SonarFacade.java @@ -58,6 +58,7 @@ public class SonarFacade { private static final Logger LOG = Loggers.get(SonarFacade.class); private static final String LOG_MSG = "{}: {} {} {}"; + private static final int MAX_SEARCH_ISSUES = 10000; private final GitLabPluginConfiguration gitLabPluginConfiguration; private final WsClient wsClient; private File projectBaseDir; @@ -226,7 +227,6 @@ public List getNewIssues() { while (nbPage == null || page <= nbPage) { Issues.SearchWsResponse searchWsResponse = searchIssues(projectKey, refName, page); nbPage = computeNbPage(searchWsResponse.getTotal(), searchWsResponse.getPs()); - issues.addAll(toIssues(searchWsResponse, refName)); page++; @@ -252,7 +252,9 @@ private String toString(GetRequest getRequest) { } private int computeNbPage(long total, int pageSize) { - return (int) (total / (long) (pageSize + 1)) + 1; + int maxPage = (int) (MAX_SEARCH_ISSUES / (long) (pageSize + 1)) + 1; + int nbPage = (int) (total / (long) (pageSize + 1)) + 1; + return Math.min(nbPage, maxPage); } private List toIssues(Issues.SearchWsResponse issuesSearchWsResponse, String branch) { diff --git a/src/test/java/com/talanlabs/sonar/plugins/gitlab/SonarFacadeTest.java b/src/test/java/com/talanlabs/sonar/plugins/gitlab/SonarFacadeTest.java index 90924de..30953c1 100644 --- a/src/test/java/com/talanlabs/sonar/plugins/gitlab/SonarFacadeTest.java +++ b/src/test/java/com/talanlabs/sonar/plugins/gitlab/SonarFacadeTest.java @@ -267,6 +267,24 @@ public void testNotEmptyGetNewIssue() throws IOException { Assertions.assertThat(issues.get(0).getFile().getAbsolutePath()).isEqualTo(new File(projectDir, "toto.java").getAbsolutePath()); } + @Test + public void test10000NewIssue() throws IOException { + Issues.SearchWsResponse.Builder builder = Issues.SearchWsResponse.newBuilder().setTotal(20000).setPs(100); + for (int i = 0; i < 100; i++) { + builder.addIssues(Issues.Issue.newBuilder().build()); + } + Issues.SearchWsResponse searchWsResponse = builder.build(); + for (int i = 0; i < 100; i++) { + sonar.enqueue(new MockResponse().setResponseCode(200).addHeader("Content-Type", "application/x-protobuf").setBody(toBuffer(searchWsResponse))); + } + sonar.enqueue(new MockResponse().setResponseCode(400).setBody("{\"errors\":[{\"msg\":\"Can return only the first 10000 results. 10100th result asked.\"}]}")); + + createReportTaskFile(); + + List issues = sonarFacade.getNewIssues(); + Assertions.assertThat(issues).isNotNull().hasSize(10000); + } + @Test public void tesFullPageGetNewIssue() throws IOException { tesFullPageGetNewIssueForQualifier(Qualifiers.FILE);