From 0323b00fad8cce2c66fb1b2a6b015aff5ca8933b Mon Sep 17 00:00:00 2001 From: =?utf8?q?L=C3=A9o=20Geoffroy?= Date: Tue, 19 Dec 2023 11:21:50 +0100 Subject: [PATCH] SONAR-21259 clean issues_fixed when branch is purged --- .../org/sonar/db/purge/PurgeCommandsIT.java | 18 +++++++++++++++++- .../java/org/sonar/db/purge/PurgeCommands.java | 7 +++++++ .../main/java/org/sonar/db/purge/PurgeDao.java | 1 + .../java/org/sonar/db/purge/PurgeMapper.java | 2 ++ .../org/sonar/db/purge/PurgeMapper.xml | 3 +++ 5 files changed, 30 insertions(+), 1 deletion(-) diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeCommandsIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeCommandsIT.java index 1da3cb6bfe1..9c042c63edf 100644 --- a/server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeCommandsIT.java +++ b/server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeCommandsIT.java @@ -42,18 +42,19 @@ import org.sonar.api.issue.impact.SoftwareQuality; import org.sonar.api.utils.System2; import org.sonar.core.util.UuidFactoryFast; import org.sonar.db.DbTester; -import org.sonar.db.dismissmessage.MessageType; import org.sonar.db.component.BranchDto; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; import org.sonar.db.component.ProjectData; import org.sonar.db.component.SnapshotDto; import org.sonar.db.dialect.Dialect; +import org.sonar.db.dismissmessage.MessageType; import org.sonar.db.duplication.DuplicationUnitDto; import org.sonar.db.entity.EntityDto; import org.sonar.db.issue.AnticipatedTransitionDto; import org.sonar.db.issue.ImpactDto; import org.sonar.db.issue.IssueDto; +import org.sonar.db.issue.IssueFixedDto; import org.sonar.db.metric.MetricDto; import org.sonar.db.newcodeperiod.NewCodePeriodType; import org.sonar.db.permission.GlobalPermission; @@ -825,6 +826,21 @@ public class PurgeCommandsIT { assertThat(anticipatedTransitionDtos.get(0).getUuid()).isEqualTo(projectDto.uuid() + "okTransition"); } + @Test + public void deleteFixedIssues_shouldDeleteFixedIssuesOnPullRequest() { + dbTester.getDbClient().issueFixedDao().insert(dbTester.getSession(), new IssueFixedDto("pull_request_uuid", "issue1")); + dbTester.getDbClient().issueFixedDao().insert(dbTester.getSession(), new IssueFixedDto("pull_request_uuid", "issue2")); + dbTester.getDbClient().issueFixedDao().insert(dbTester.getSession(), new IssueFixedDto("pull_request_uuid2", "issue3")); + + underTest.deleteIssuesFixed("pull_request_uuid"); + + assertThat(dbTester.getDbClient().issueFixedDao().selectByPullRequest(dbTester.getSession(), "pull_request_uuid")) + .isEmpty(); + + assertThat(dbTester.getDbClient().issueFixedDao().selectByPullRequest(dbTester.getSession(), "pull_request_uuid2")) + .hasSize(1); + } + private AnticipatedTransitionDto getAnticipatedTransitionsDto(String uuid, String projectUuid, Instant creationDate) { return new AnticipatedTransitionDto(uuid, projectUuid, "userUuid", "transition", null, null, null, null, "rule:key", "filePath", creationDate.toEpochMilli()); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java index e23bc26c35e..40a6b39d848 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java @@ -516,4 +516,11 @@ class PurgeCommands { session.commit(); profiler.stop(); } + + public void deleteIssuesFixed(String branchUuid) { + profiler.start("deleteIssuesFixed (issues_fixed)"); + purgeMapper.deleteIssuesFixedByBranchUuid(branchUuid); + session.commit(); + profiler.stop(); + } } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java index 8d3777e1e72..4ed7bc57e07 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java @@ -278,6 +278,7 @@ public class PurgeDao implements Dao { commands.deleteComponents(branchUuid); commands.deleteReportSchedules(branchUuid); commands.deleteReportSubscriptions(branchUuid); + commands.deleteIssuesFixed(branchUuid); } private static void deleteProject(String projectUuid, PurgeMapper mapper, PurgeCommands commands) { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java index e339a010fb8..4b916638fcf 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java @@ -192,4 +192,6 @@ public interface PurgeMapper { void deleteReportSubscriptionsByPortfolioUuids(@Param("portfolioUuids") List portfolioUuids); void deleteAnticipatedTransitionsByProjectUuidAndCreationDate(@Param("projectUuid") String projectUuid, @Param("createdAtBefore") Long createdAtBefore); + + void deleteIssuesFixedByBranchUuid(@Param("branchUuid") String branchUuid); } diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml index befd352e823..7aa1312f799 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml @@ -666,5 +666,8 @@ delete from anticipated_transitions where project_uuid = #{projectUuid,jdbcType=VARCHAR} and created_at < #{createdAtBefore,jdbcType=BIGINT} + + delete from issues_fixed where pull_request_uuid = #{branchUuid,jdbcType=VARCHAR} + -- 2.39.5