]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-23527 Add changelog event when manual impact is updated during project analysis
authorLéo Geoffroy <leo.geoffroy@sonarsource.com>
Fri, 8 Nov 2024 15:24:00 +0000 (16:24 +0100)
committersonartech <sonartech@sonarsource.com>
Mon, 11 Nov 2024 20:02:45 +0000 (20:02 +0000)
server/sonar-server-common/src/main/java/org/sonar/server/issue/IssueFieldsSetter.java
server/sonar-server-common/src/test/java/org/sonar/server/issue/IssueFieldsSetterTest.java

index fada386bada596366a9942620f7befa488663c8a..c994fff9c7fe212038ea9178403239c154e4817f 100644 (file)
@@ -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())) {
index 58e957eae741a804f98914d4ffa79dc0f2f25a4d..5ec7de36856641622c9d85c235f20112aca93389 100644 (file)
@@ -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