diff options
author | Léo Geoffroy <leo.geoffroy@sonarsource.com> | 2024-11-08 16:24:00 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-11-11 20:02:45 +0000 |
commit | 47573d21059b9dbb60d29d3d8c2ca35d5a5d3f24 (patch) | |
tree | 68e259879ccd55e518ffadeb7b257b3d3dfa0dae /server/sonar-server-common | |
parent | 60d28c06f872cfa30bd2399a977dfbc02063079d (diff) | |
download | sonarqube-47573d21059b9dbb60d29d3d8c2ca35d5a5d3f24.tar.gz sonarqube-47573d21059b9dbb60d29d3d8c2ca35d5a5d3f24.zip |
SONAR-23527 Add changelog event when manual impact is updated during project analysis
Diffstat (limited to 'server/sonar-server-common')
-rw-r--r-- | server/sonar-server-common/src/main/java/org/sonar/server/issue/IssueFieldsSetter.java | 8 | ||||
-rw-r--r-- | server/sonar-server-common/src/test/java/org/sonar/server/issue/IssueFieldsSetterTest.java | 7 |
2 files changed, 14 insertions, 1 deletions
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 |