aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server-common
diff options
context:
space:
mode:
authorKlaudio Sinani <klaudio.sinani@sonarsource.com>2022-07-28 20:53:58 +0200
committersonartech <sonartech@sonarsource.com>2022-07-29 20:03:14 +0000
commitf3191d8b198d71a263b273271194992b47b3b84a (patch)
treefb87ecc89c9e82c08122e2423ffebcef8452c9f5 /server/sonar-server-common
parent8ba422425e92fb3a2d4dc0ff3de0d8c07a705a0f (diff)
downloadsonarqube-f3191d8b198d71a263b273271194992b47b3b84a.tar.gz
sonarqube-f3191d8b198d71a263b273271194992b47b3b84a.zip
SONAR-12077 Do not record file move events in issue changelog
Diffstat (limited to 'server/sonar-server-common')
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/issue/IssueFieldsSetter.java11
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/issue/IssueFieldsSetterTest.java33
2 files changed, 21 insertions, 23 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 bdcc5837f13..2b027eb37ac 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
@@ -329,15 +329,16 @@ public class IssueFieldsSetter {
return false;
}
- public boolean setIssueMoved(DefaultIssue issue, String newComponentUuid, IssueChangeContext context) {
+ public void setIssueComponent(DefaultIssue issue, String newComponentUuid, String newComponentKey, Date updateDate) {
if (!Objects.equals(newComponentUuid, issue.componentUuid())) {
- issue.setFieldChange(context, FILE, issue.componentUuid(), newComponentUuid);
issue.setComponentUuid(newComponentUuid);
- issue.setUpdateDate(context.date());
+ issue.setUpdateDate(updateDate);
issue.setChanged(true);
- return true;
}
- return false;
+
+ // other fields (such as module, modulePath, componentKey) are read-only and set/reset for consistency only
+ issue.setComponentKey(newComponentKey);
+ issue.setModuleUuidPath(null);
}
private static boolean relevantDateDifference(@Nullable Date left, @Nullable Date right) {
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 b70ea011845..c0835a1b701 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
@@ -21,7 +21,6 @@ package org.sonar.server.issue;
import java.util.Calendar;
import java.util.Date;
-import java.util.Map;
import java.util.Random;
import org.apache.commons.lang.time.DateUtils;
import org.junit.Test;
@@ -45,9 +44,9 @@ public class IssueFieldsSetterTest {
private final String DEFAULT_RULE_DESCRIPTION_CONTEXT_KEY = "spring";
- private DefaultIssue issue = new DefaultIssue();
- private IssueChangeContext context = IssueChangeContext.createUser(new Date(), "user_uuid");
- private IssueFieldsSetter underTest = new IssueFieldsSetter();
+ private final DefaultIssue issue = new DefaultIssue();
+ private final IssueChangeContext context = IssueChangeContext.createUser(new Date(), "user_uuid");
+ private final IssueFieldsSetter underTest = new IssueFieldsSetter();
@Test
public void assign() {
@@ -479,36 +478,34 @@ public class IssueFieldsSetterTest {
}
@Test
- public void setIssueMoved_has_no_effect_if_component_uuid_is_not_changed() {
- String componentUuid = "a";
+ public void setIssueComponent_has_no_effect_if_component_uuid_is_not_changed() {
+ String componentKey = "key";
+ String componentUuid = "uuid";
+
issue.setComponentUuid(componentUuid);
+ issue.setComponentKey(componentKey);
- underTest.setIssueMoved(issue, componentUuid, context);
+ underTest.setIssueComponent(issue, componentUuid, componentKey, context.date());
- assertThat(issue.changes()).isEmpty();
assertThat(issue.componentUuid()).isEqualTo(componentUuid);
+ assertThat(issue.componentKey()).isEqualTo(componentKey);
assertThat(issue.isChanged()).isFalse();
assertThat(issue.updateDate()).isNull();
assertThat(issue.mustSendNotifications()).isFalse();
}
@Test
- public void setIssueMoved_changes_componentUuid_adds_a_change() {
+ public void setIssueComponent_changes_component_uuid() {
String oldComponentUuid = "a";
String newComponentUuid = "b";
+ String componentKey = "key";
+
issue.setComponentUuid(oldComponentUuid);
- underTest.setIssueMoved(issue, newComponentUuid, context);
+ underTest.setIssueComponent(issue, newComponentUuid, componentKey, context.date());
- assertThat(issue.changes()).hasSize(1);
- FieldDiffs fieldDiffs = issue.changes().get(0);
- assertThat(fieldDiffs.creationDate()).isEqualTo(context.date());
- assertThat(fieldDiffs.diffs()).hasSize(1);
- Map.Entry<String, FieldDiffs.Diff> entry = fieldDiffs.diffs().entrySet().iterator().next();
- assertThat(entry.getKey()).isEqualTo("file");
- assertThat(entry.getValue().oldValue()).isEqualTo(oldComponentUuid);
- assertThat(entry.getValue().newValue()).isEqualTo(newComponentUuid);
assertThat(issue.componentUuid()).isEqualTo(newComponentUuid);
+ assertThat(issue.componentKey()).isEqualTo(componentKey);
assertThat(issue.isChanged()).isTrue();
assertThat(issue.updateDate()).isEqualTo(DateUtils.truncate(context.date(), Calendar.SECOND));
}