]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7345 Rename Issue debt to effort in changelog
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 8 Mar 2016 18:58:49 +0000 (19:58 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 10 Mar 2016 09:44:17 +0000 (10:44 +0100)
server/sonar-server/src/main/java/org/sonar/server/issue/IssueChangelog.java
server/sonar-server/src/main/java/org/sonar/server/issue/IssueUpdater.java
server/sonar-server/src/main/resources/org/sonar/server/issue/ws/example-changelog.json
server/sonar-server/src/test/java/org/sonar/server/issue/IssueChangelogServiceTest.java
server/sonar-web/src/main/webapp/WEB-INF/app/models/issue.rb
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index add214786cf60db20893d6bb1b7357b048dec9f4..d4beab689ad8fc8f6c2a0ea38f884b140097cb23 100644 (file)
 package org.sonar.server.issue;
 
 import com.google.common.collect.Maps;
-import org.sonar.core.issue.FieldDiffs;
-import org.sonar.api.user.User;
-
-import javax.annotation.CheckForNull;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
+import javax.annotation.CheckForNull;
+import org.sonar.api.user.User;
+import org.sonar.core.issue.FieldDiffs;
 
 /**
  * @since 3.6
@@ -38,6 +37,7 @@ public class IssueChangelog {
 
   public IssueChangelog(List<FieldDiffs> changes, Collection<User> users) {
     this.changes = changes;
+    replacedTechnicalDebtByEffort(changes);
     this.usersByLogin = Maps.newHashMap();
     for (User user : users) {
       usersByLogin.put(user.login(), user);
@@ -48,6 +48,19 @@ public class IssueChangelog {
     return changes;
   }
 
+  private static void replacedTechnicalDebtByEffort(List<FieldDiffs> changes) {
+    for (FieldDiffs fieldDiffs : changes) {
+      Map<String, FieldDiffs.Diff> diffs = fieldDiffs.diffs();
+      for (Map.Entry<String, FieldDiffs.Diff> entry : diffs.entrySet()) {
+        // As "technicalDebt" couldn't been updated to "effort" in db, we need to convert it here to correctly display "effort" in WS/UI
+        if (entry.getKey().equals(IssueUpdater.TECHNICAL_DEBT)) {
+          diffs.put("effort", entry.getValue());
+          diffs.remove(entry.getKey());
+        }
+      }
+    }
+  }
+
   @CheckForNull
   public User user(FieldDiffs change) {
     if (change.userLogin() == null) {
index ed7ce1737e502da83f58bbf4d417e942eb1362b5..c8a910ad14cdbf6645112438507769607e42a497 100644 (file)
@@ -59,6 +59,10 @@ public class IssueUpdater {
   public static final String STATUS = "status";
   public static final String AUTHOR = "author";
   public static final String ACTION_PLAN = "actionPlan";
+
+  /**
+   * It should be renamed to 'effort', but it hasn't been done to prevent a massive update in database
+   */
   public static final String TECHNICAL_DEBT = "technicalDebt";
   public static final String TAGS = "tags";
 
index 9ddd968d827e4833791fe44f35766900c58ca5a9..ae03e59ec97c5c0c4fe3449d0aa87751662b12bf 100644 (file)
@@ -6,7 +6,7 @@
       "creationDate": "2014-03-04T23:03:44+0100",
       "diffs": [
         {
-          "key": "technicalDebt",
+          "key": "effort",
           "newValue": "2min"
         }
       ]
index 2086d17512c587b42bb7bdd14f83aa73b1cdfff2..d42f0d7c62b6c15b99f6b4b39978e272b10d1f5f 100644 (file)
@@ -27,12 +27,12 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.core.issue.DefaultIssue;
-import org.sonar.core.issue.FieldDiffs;
 import org.sonar.api.user.User;
 import org.sonar.api.user.UserFinder;
-import org.sonar.db.issue.IssueChangeDao;
+import org.sonar.core.issue.DefaultIssue;
+import org.sonar.core.issue.FieldDiffs;
 import org.sonar.core.user.DefaultUser;
+import org.sonar.db.issue.IssueChangeDao;
 import org.sonar.server.tester.UserSessionRule;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -84,6 +84,21 @@ public class IssueChangelogServiceTest {
     assertThat(changelog.user(userChange)).isSameAs(arthur);
   }
 
+  @Test
+  public void rename_technical_debt_change_to_effort() {
+    FieldDiffs userChange = new FieldDiffs().setUserLogin("arthur").setDiff("technicalDebt", "10min", "30min");
+    when(changeDao.selectChangelogByIssue("ABCDE")).thenReturn(Arrays.asList(userChange));
+    User arthur = new DefaultUser().setLogin("arthur").setName("Arthur");
+    when(userFinder.findByLogins(Arrays.asList("arthur"))).thenReturn(Arrays.asList(arthur));
+    when(issueService.getByKey("ABCDE")).thenReturn(new DefaultIssue().setKey("ABCDE"));
+
+    IssueChangelog changelog = service.changelog("ABCDE");
+
+    assertThat(changelog).isNotNull();
+    assertThat(changelog.changes()).hasSize(1);
+    assertThat(changelog.changes().get(0).diffs()).containsKeys("effort");
+  }
+
   @Test
   public void format_diffs() {
     FieldDiffs diffs = new FieldDiffs().setUserLogin("arthur").setDiff("severity", "MAJOR", "BLOCKER");
index 75494d5575776d37d2de9992b9676c57baf01cc2..9904bf4dfdcc7414264a139309cd96cd507e5349 100644 (file)
@@ -83,8 +83,8 @@ class Issue
         diff = entry.getValue()
         hash_diff = {}
         hash_diff[:key] = key
-        if key == 'technicalDebt'
-          # debt is store as a number of minutes in the changelog, so we first create a Duration from the value then we decode it
+        if key == 'effort'
+          # effort is store as a number of minutes in the changelog, so we first create a Duration from the value then we decode it
           hash_diff[:newValue] = Internal.durations.encode(Internal.durations.create(diff.newValue().to_i)) if diff.newValue.present?
           hash_diff[:oldValue] = Internal.durations.encode(Internal.durations.create(diff.oldValue().to_i)) if diff.oldValue.present?
         else
index 270bf9c9a6228f6868fc29aa343a00b2f7b360a5..460afafa78e3047d0ae6a7b65165a1ccc973677b 100644 (file)
@@ -760,7 +760,7 @@ issue.changelog.field.actionPlan=Action Plan
 issue.changelog.field.assignee=Assignee
 issue.changelog.field.author=Author
 issue.changelog.field.resolution=Resolution
-issue.changelog.field.technicalDebt=Technical Debt
+issue.changelog.field.effort=Effort
 issue.changelog.field.status=Status
 issue.changelog.field.tags=Tags
 issue.changelog.field.type=Type