diff options
author | Philippe Perrin <philippe.perrin@sonarsource.com> | 2021-07-13 09:25:41 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2021-07-13 20:03:17 +0000 |
commit | dacad140041d2533e6dc9efd1824f6641e681f78 (patch) | |
tree | ff0a729ed082b6b36b1e42276da495307d8e0a5e /server | |
parent | ccca1896a356e5af01c02919a8c28d98422a4730 (diff) | |
download | sonarqube-dacad140041d2533e6dc9efd1824f6641e681f78.tar.gz sonarqube-dacad140041d2533e6dc9efd1824f6641e681f78.zip |
SONAR-15133 Fix for Gitlab project onboarding
Diffstat (limited to 'server')
3 files changed, 10 insertions, 7 deletions
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 4932e2db87e..1dc3b4f2e89 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 @@ -291,9 +291,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 c39513b6f9c..1d94cc4808f 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 @@ -116,7 +116,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 BITBUCKET_CLOUD: bitbucketCloudRestClient.validateAppPassword( 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 fe26b0a498e..28be2ab4c92 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 @@ -41,7 +41,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.ArgumentMatchers.anyString; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; @@ -135,7 +134,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 @@ -176,7 +175,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); |