]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-15133 Fix for Gitlab project onboarding
authorPhilippe Perrin <philippe.perrin@sonarsource.com>
Tue, 13 Jul 2021 07:25:41 +0000 (09:25 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 21 Jul 2021 20:03:33 +0000 (20:03 +0000)
server/sonar-alm-client/src/main/java/org/sonar/alm/client/gitlab/GitlabHttpClient.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/CheckPatAction.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/CheckPatActionTest.java

index 36011e4e96eba1f9554bf6f75a3e636fb48fc664..c763bf98df02ffb0e92603d373820dca213090e9 100644 (file)
@@ -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()
index 85e7f31bd024bb542f3665df8f99f5a8e0920524..06a6692edebdc439aca0f3b4cd64f67b7e1b04c3 100644 (file)
@@ -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:
index 5b09e6a4f9f6be64fd4e07fbba2682c339e7c9ed..81c227687a4d54c95243aba33de1dc3993d0c43f 100644 (file)
@@ -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);