Skip to content

Commit

Permalink
Fix sonar issues limit 10000
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrie-allaigre committed Sep 4, 2018
1 parent 9b59883 commit fe60401
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Inspired by https://github.com/SonarCommunity/sonar-github

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

**[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)**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,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;
Expand Down Expand Up @@ -225,7 +226,6 @@ public List<Issue> 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++;
Expand Down Expand Up @@ -257,7 +257,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<Issue> toIssues(Issues.SearchWsResponse issuesSearchWsResponse, String branch) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Issue> issues = sonarFacade.getNewIssues();
Assertions.assertThat(issues).isNotNull().hasSize(10000);
}

@Test
public void tesFullPageGetNewIssue() throws IOException {
tesFullPageGetNewIssueForQualifier(Qualifiers.FILE);
Expand Down

0 comments on commit fe60401

Please sign in to comment.