Browse Source

SONAR-10455 Fix bulk update of project having branches containing "/"

tags/7.5
Julien Lancelot 6 years ago
parent
commit
5d3c140d97

+ 2
- 2
server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterDao.java View File

@@ -110,8 +110,9 @@ public class ComponentKeyUpdaterDao implements Dao {
ComponentKeyUpdaterMapper mapper = session.getMapper(ComponentKeyUpdaterMapper.class);
// must SELECT first everything
Set<ResourceDto> modules = collectAllModules(projectUuid, stringToReplace, mapper);
checkNewNameOfAllModules(modules, stringToReplace, replacementString, mapper);

// add branches
// add branches (no check should be done as branch keys cannot be changed by the user)
Map<String, String> branchBaseKeys = new HashMap<>();
session.getMapper(BranchMapper.class).selectByProjectUuid(projectUuid)
.stream()
@@ -122,7 +123,6 @@ public class ComponentKeyUpdaterDao implements Dao {
branchModules.forEach(module -> branchBaseKeys.put(module.getKey(), branchBaseKey(module.getKey())));
});

checkNewNameOfAllModules(modules, stringToReplace, replacementString, mapper);
Map<ResourceDto, List<ResourceDto>> allResourcesByModuleMap = Maps.newHashMap();
for (ResourceDto module : modules) {
allResourcesByModuleMap.put(module, mapper.selectProjectResources(module.getUuid()));

+ 12
- 0
server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentKeyUpdaterDaoTest.java View File

@@ -161,6 +161,18 @@ public class ComponentKeyUpdaterDaoTest {
.forEach(map -> map.values().forEach(k -> assertThat(k.toString()).startsWith(newProjectKey)));
}

@Test
public void bulk_updateKey_on_branch_containing_slash() {
ComponentDto project = db.components().insertMainBranch();
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch/with/slash"));
String newKey = "newKey";

underTest.bulkUpdateKey(dbSession, project.uuid(), project.getKey(), newKey);

assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, newKey)).hasSize(1);
assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, ComponentDto.generateBranchKey(newKey, branch.getBranch()))).hasSize(1);
}

@Test
public void bulk_updateKey_updates_pull_requests_too() {
ComponentDto project = db.components().insertMainBranch();

Loading…
Cancel
Save