From 47573d21059b9dbb60d29d3d8c2ca35d5a5d3f24 Mon Sep 17 00:00:00 2001 From: =?utf8?q?L=C3=A9o=20Geoffroy?= Date: Fri, 8 Nov 2024 16:24:00 +0100 Subject: [PATCH] SONAR-23527 Add changelog event when manual impact is updated during project analysis --- .../java/org/sonar/server/issue/IssueFieldsSetter.java | 8 +++++++- .../org/sonar/server/issue/IssueFieldsSetterTest.java | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/IssueFieldsSetter.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/IssueFieldsSetter.java index fada386bada..c994fff9c7f 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/IssueFieldsSetter.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/IssueFieldsSetter.java @@ -506,7 +506,13 @@ public class IssueFieldsSetter { issue.getImpacts() .stream() .filter(i -> convertToSoftwareQuality(issue.type()).equals(i.softwareQuality())) - .forEach(i -> issue.addImpact(i.softwareQuality(), ImpactSeverityMapper.mapImpactSeverity(issue.severity()), true)); + .forEach(i -> { + Severity newSeverity = ImpactSeverityMapper.mapImpactSeverity(issue.severity()); + issue.addImpact(i.softwareQuality(), newSeverity, true); + issue.setFieldChange(context, IMPACT_SEVERITY, + i.softwareQuality() + ":" + i.severity(), + i.softwareQuality() + ":" + newSeverity); + }); } if (!previousImpacts.equals(issue.getImpacts())) { diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/IssueFieldsSetterTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/IssueFieldsSetterTest.java index 58e957eae74..5ec7de36856 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/IssueFieldsSetterTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/IssueFieldsSetterTest.java @@ -28,6 +28,7 @@ import java.util.Map; import java.util.Random; import java.util.Set; import org.apache.commons.lang3.time.DateUtils; +import org.assertj.core.groups.Tuple; import org.junit.jupiter.api.Test; import org.sonar.api.issue.Issue; import org.sonar.api.issue.IssueStatus; @@ -630,6 +631,7 @@ class IssueFieldsSetterTest { boolean updated = underTest.setImpacts(issue, currentImpacts, context); assertThat(updated).isTrue(); assertThat(issue.getImpacts()).isEqualTo(newImpacts); + assertThat(issue.changes()).isEmpty(); } @Test @@ -668,6 +670,7 @@ class IssueFieldsSetterTest { assertThat(updated).isTrue(); assertThat(issue.getImpacts()).isEqualTo(Set.of(new DefaultImpact(SoftwareQuality.MAINTAINABILITY, Severity.HIGH, true), new DefaultImpact(SoftwareQuality.RELIABILITY, Severity.HIGH, false))); + assertThat(issue.changes()).isEmpty(); } @Test @@ -683,6 +686,8 @@ class IssueFieldsSetterTest { boolean updated = underTest.setImpacts(issue, currentImpacts, context); assertThat(updated).isTrue(); assertThat(issue.getImpacts()).isEqualTo(Set.of(new DefaultImpact(SoftwareQuality.MAINTAINABILITY, Severity.BLOCKER, true))); + assertThat(issue.changes()).hasSize(1).extracting(f -> f.diffs().get("impactSeverity").oldValue(), f -> f.diffs().get("impactSeverity").newValue()) + .containsExactly(Tuple.tuple("MAINTAINABILITY:LOW", "MAINTAINABILITY:BLOCKER")); } @Test @@ -697,6 +702,7 @@ class IssueFieldsSetterTest { issue.setType(RuleType.BUG); boolean updated = underTest.setImpacts(issue, currentImpacts, context); assertThat(updated).isFalse(); + assertThat(issue.changes()).isEmpty(); } @Test @@ -711,6 +717,7 @@ class IssueFieldsSetterTest { issue.setType(RuleType.BUG); boolean updated = underTest.setImpacts(issue, currentImpacts, context); assertThat(updated).isFalse(); + assertThat(issue.changes()).isEmpty(); } @Test -- 2.39.5