Skip to content

Commit

Permalink
SONAR-15133 Fix for Gitlab project onboarding
Browse files Browse the repository at this point in the history
  • Loading branch information
philippe-perrin-sonarsource authored and sonartech committed Jul 21, 2021
1 parent f78a3a0 commit d714b23
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,13 @@ public List<GitLabBranch> getBranches(String gitlabUrl, String pat, Long gitlabP
}

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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private void doHandle(Request request) {
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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
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;
Expand Down Expand Up @@ -130,7 +129,7 @@ public void check_pat_for_gitlab() {
.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
Expand All @@ -152,7 +151,7 @@ public void fail_when_personal_access_token_is_invalid_for_bitbucket() {

@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);
Expand Down

0 comments on commit d714b23

Please sign in to comment.