diff options
author | Lukasz Jarocki <lukasz.jarocki@sonarsource.com> | 2022-09-30 16:34:23 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-10-12 20:03:44 +0000 |
commit | c85e433a567b8580a1fd5e185b4f5bc73b6e53e6 (patch) | |
tree | f79a436253a656aa5aa49027a51b9fc5fd1b8506 /server/sonar-ce | |
parent | cdec0dad5c29a109ad724477bdb1a517e1834046 (diff) | |
download | sonarqube-c85e433a567b8580a1fd5e185b4f5bc73b6e53e6.tar.gz sonarqube-c85e433a567b8580a1fd5e185b4f5bc73b6e53e6.zip |
SONAR-17352 Refactor component keys to not include branch suffix
Diffstat (limited to 'server/sonar-ce')
2 files changed, 10 insertions, 4 deletions
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/notification/ReportAnalysisFailureNotificationExecutionListener.java b/server/sonar-ce/src/main/java/org/sonar/ce/notification/ReportAnalysisFailureNotificationExecutionListener.java index 9c30c2f01f3..942135a776c 100644 --- a/server/sonar-ce/src/main/java/org/sonar/ce/notification/ReportAnalysisFailureNotificationExecutionListener.java +++ b/server/sonar-ce/src/main/java/org/sonar/ce/notification/ReportAnalysisFailureNotificationExecutionListener.java @@ -35,6 +35,7 @@ import org.sonar.db.DbSession; import org.sonar.db.RowNotFoundException; import org.sonar.db.ce.CeActivityDto; import org.sonar.db.ce.CeTaskTypes; +import org.sonar.db.component.BranchDto; import org.sonar.db.component.ComponentDto; import org.sonar.server.notification.NotificationService; @@ -74,10 +75,12 @@ public class ReportAnalysisFailureNotificationExecutionListener implements CeWor if (notificationService.hasProjectSubscribersForTypes(projectUuid, singleton(ReportAnalysisFailureNotification.class))) { try (DbSession dbSession = dbClient.openSession(false)) { ComponentDto projectDto = dbClient.componentDao().selectOrFailByUuid(dbSession, projectUuid); + BranchDto branchDto = dbClient.branchDao().selectByUuid(dbSession, projectDto.branchUuid()) + .orElseThrow(() -> new IllegalStateException("Could not find a branch for component uuid " + projectDto.uuid())); checkScopeAndQualifier(projectDto); CeActivityDto ceActivityDto = dbClient.ceActivityDao().selectByUuid(dbSession, ceTask.getUuid()) .orElseThrow(() -> new RowNotFoundException(format("CeActivity with uuid '%s' not found", ceTask.getUuid()))); - ReportAnalysisFailureNotificationBuilder taskFailureNotification = buildNotification(ceActivityDto, projectDto, error); + ReportAnalysisFailureNotificationBuilder taskFailureNotification = buildNotification(ceActivityDto, projectDto, branchDto, error); ReportAnalysisFailureNotification notification = taskFailureNotificationSerializer.toNotification(taskFailureNotification); notificationService.deliverEmails(singleton(notification)); @@ -98,14 +101,16 @@ public class ReportAnalysisFailureNotificationExecutionListener implements CeWor "Component %s must be a project (scope=%s, qualifier=%s)", projectDto.uuid(), scope, qualifier); } - private ReportAnalysisFailureNotificationBuilder buildNotification(CeActivityDto ceActivityDto, ComponentDto projectDto, @Nullable Throwable error) { + private ReportAnalysisFailureNotificationBuilder buildNotification(CeActivityDto ceActivityDto, ComponentDto projectDto, BranchDto branchDto, + @Nullable Throwable error) { + String projectBranch = branchDto.isMain() ? null : branchDto.getBranchKey(); Long executedAt = ceActivityDto.getExecutedAt(); return new ReportAnalysisFailureNotificationBuilder( new ReportAnalysisFailureNotificationBuilder.Project( projectDto.uuid(), projectDto.getKey(), projectDto.name(), - projectDto.getBranch()), + projectBranch), new ReportAnalysisFailureNotificationBuilder.Task( ceActivityDto.getUuid(), ceActivityDto.getSubmittedAt(), diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/notification/ReportAnalysisFailureNotificationExecutionListenerTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/notification/ReportAnalysisFailureNotificationExecutionListenerTest.java index 78815154694..c91133baf29 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/notification/ReportAnalysisFailureNotificationExecutionListenerTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/notification/ReportAnalysisFailureNotificationExecutionListenerTest.java @@ -57,6 +57,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; +import static org.sonar.db.component.BranchDto.DEFAULT_MAIN_BRANCH_NAME; import static org.sonar.db.component.ComponentTesting.newDirectory; import static org.sonar.db.component.ComponentTesting.newModuleDto; @@ -207,7 +208,7 @@ public class ReportAnalysisFailureNotificationExecutionListenerTest { assertThat(notificationProject.getName()).isEqualTo(project.name()); assertThat(notificationProject.getKey()).isEqualTo(project.getKey()); assertThat(notificationProject.getUuid()).isEqualTo(project.uuid()); - assertThat(notificationProject.getBranchName()).isEqualTo(project.getBranch()); + assertThat(notificationProject.getBranchName()).isEqualTo(DEFAULT_MAIN_BRANCH_NAME); ReportAnalysisFailureNotificationBuilder.Task notificationTask = reportAnalysisFailureNotificationBuilder.getTask(); assertThat(notificationTask.getUuid()).isEqualTo(taskUuid); assertThat(notificationTask.getCreatedAt()).isEqualTo(createdAt); |