return toCreateResponse(componentDto);
}
}
-
+
private String getDefaultBranchName(String pat, String projectKey, String repoSlug, String url) {
BranchesList branches = bitbucketServerRestClient.getBranches(url, pat, projectKey, repoSlug);
Optional<Branch> defaultBranch = branches.findDefaultBranch();
private ComponentDto createProject(DbSession dbSession, Repository repo, @Nullable String defaultBranchName) {
boolean visibility = projectDefaultVisibility.get(dbSession).isPrivate();
NewComponent newProject = newComponentBuilder()
- .setKey(repo.getProject().getKey() + "_" + repo.getSlug())
+ .setKey(getProjectKey(repo))
.setName(repo.getName())
.setPrivate(visibility)
.setQualifier(PROJECT)
String userUuid = userSession.isLoggedIn() ? userSession.getUuid() : null;
String userLogin = userSession.isLoggedIn() ? userSession.getLogin() : null;
- return componentUpdater.createWithoutCommit(dbSession, newProject, userUuid, userLogin, defaultBranchName, p -> {});
+ return componentUpdater.createWithoutCommit(dbSession, newProject, userUuid, userLogin, defaultBranchName, p -> {
+ });
}
private void populatePRSetting(DbSession dbSession, Repository repo, ComponentDto componentDto, AlmSettingDto almSettingDto) {
componentDto.name(), componentDto.getKey());
}
+ private static String getProjectKey(Repository repo) {
+ String key = repo.getProject().getKey() + "_" + repo.getSlug();
+ return key.replace("~", "");
+ }
+
}
import static org.sonar.db.alm.integration.pat.AlmPatsTesting.newAlmPatDto;
import static org.sonar.db.permission.GlobalPermission.PROVISION_PROJECTS;
import static org.sonar.db.permission.GlobalPermission.SCAN;
+
import java.util.Collection;
import java.util.Collections;
import java.util.List;
assertThat(db.getDbClient().projectAlmSettingDao().selectByProject(db.getSession(), projectDto.get())).isPresent();
}
+ @Test
+ public void import_project_with_tilda() {
+ UserDto user = db.users().insertUser();
+ userSession.logIn(user).addPermission(PROVISION_PROJECTS);
+ AlmSettingDto almSetting = db.almSettings().insertGitHubAlmSetting();
+ db.almPats().insert(dto -> {
+ dto.setAlmSettingUuid(almSetting.getUuid());
+ dto.setUserUuid(user.getUuid());
+ });
+ Project project = getGsonBBSProject();
+ project.setKey("~" + project.getKey());
+ Repository repo = getGsonBBSRepo(project);
+ when(bitbucketServerRestClient.getRepo(any(), any(), any(), any())).thenReturn(repo);
+ when(bitbucketServerRestClient.getBranches(any(), any(), any(), any())).thenReturn(defaultBranchesList);
+
+ Projects.CreateWsResponse response = ws.newRequest()
+ .setParam("almSetting", almSetting.getKey())
+ .setParam("projectKey", "~projectKey")
+ .setParam("repositorySlug", "repo-slug")
+ .executeProtobuf(Projects.CreateWsResponse.class);
+
+ Projects.CreateWsResponse.Project result = response.getProject();
+
+ String key = project.getKey() + "_" + repo.getSlug();
+ assertThat(result.getKey()).isNotEqualTo(key);
+ assertThat(result.getKey()).isEqualTo(key.substring(1));
+ }
+
@Test
public void fail_project_already_exist() {
UserDto user = db.users().insertUser();
when(bitbucketServerRestClient.getRepo(any(), any(), any(), any())).thenReturn(repo);
when(bitbucketServerRestClient.getBranches(any(), any(), any(), any())).thenReturn(defaultBranchesList);
-
+
ws.newRequest()
.setParam("almSetting", almSetting.getKey())
.setParam("projectKey", "projectKey")