From: Philippe Perrin Date: Tue, 13 Jul 2021 07:25:41 +0000 (+0200) Subject: SONAR-15133 Fix for Gitlab project onboarding X-Git-Tag: 8.9.2.46101~1 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d714b23addb91051331ad01a7a1543b57518e052;p=sonarqube.git SONAR-15133 Fix for Gitlab project onboarding --- diff --git a/server/sonar-alm-client/src/main/java/org/sonar/alm/client/gitlab/GitlabHttpClient.java b/server/sonar-alm-client/src/main/java/org/sonar/alm/client/gitlab/GitlabHttpClient.java index 36011e4e96e..c763bf98df0 100644 --- a/server/sonar-alm-client/src/main/java/org/sonar/alm/client/gitlab/GitlabHttpClient.java +++ b/server/sonar-alm-client/src/main/java/org/sonar/alm/client/gitlab/GitlabHttpClient.java @@ -257,9 +257,13 @@ public class GitlabHttpClient { } public ProjectList searchProjects(String gitlabUrl, String personalAccessToken, @Nullable String projectName, - int pageNumber, int pageSize) { - String url = String.format("%s/projects?archived=false&simple=true&membership=true&order_by=name&sort=asc&search=%s&page=%d&per_page=%d", - gitlabUrl, projectName == null ? "" : urlEncode(projectName), pageNumber, pageSize); + @Nullable Integer pageNumber, @Nullable Integer pageSize) { + String url = String.format("%s/projects?archived=false&simple=true&membership=true&order_by=name&sort=asc&search=%s%s%s", + gitlabUrl, + projectName == null ? "" : urlEncode(projectName), + pageNumber == null ? "" : String.format("&page=%d", pageNumber), + pageSize == null ? "" : String.format("&per_page=%d", pageSize) + ); LOG.debug(String.format("get projects : [%s]", url)); Request request = new Request.Builder() diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/CheckPatAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/CheckPatAction.java index 85e7f31bd02..06a6692edeb 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/CheckPatAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/CheckPatAction.java @@ -108,7 +108,7 @@ public class CheckPatAction implements AlmIntegrationsWsAction { gitlabHttpClient.searchProjects( requireNonNull(almSettingDto.getUrl(), URL_CANNOT_BE_NULL), requireNonNull(almPatDto.getPersonalAccessToken(), PAT_CANNOT_BE_NULL), - null, 1, 10); + null, null, null); break; case GITHUB: default: diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/CheckPatActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/CheckPatActionTest.java index 5b09e6a4f9f..81c227687a4 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/CheckPatActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/CheckPatActionTest.java @@ -40,7 +40,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.Assertions.tuple; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -130,7 +129,7 @@ public class CheckPatActionTest { .execute(); assertThat(almSetting.getUrl()).isNotNull(); - verify(gitlabPrHttpClient).searchProjects(almSetting.getUrl(), PAT_SECRET, null, 1, 10); + verify(gitlabPrHttpClient).searchProjects(almSetting.getUrl(), PAT_SECRET, null, null, null); } @Test @@ -152,7 +151,7 @@ public class CheckPatActionTest { @Test public void fail_when_personal_access_token_is_invalid_for_gitlab() { - when(gitlabPrHttpClient.searchProjects(any(), any(), any(), anyInt(), anyInt())) + when(gitlabPrHttpClient.searchProjects(any(), any(), any(), any(), any())) .thenThrow(new IllegalArgumentException("Invalid personal access token")); UserDto user = db.users().insertUser(); userSession.logIn(user).addPermission(PROVISION_PROJECTS);