]> source.dussan.org Git - sonarqube.git/commitdiff
Keep compatibility with issue-assign and cockpit plugins 55/head
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 23 Jan 2015 10:14:22 +0000 (11:14 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 23 Jan 2015 10:14:22 +0000 (11:14 +0100)
Do not override author and assignee fields of new issues

server/sonar-server/src/main/java/org/sonar/server/computation/issue/IssueComputation.java
server/sonar-server/src/test/java/org/sonar/server/computation/issue/IssueComputationTest.java

index 01b61913eea68cdbb1b0b2ee251c2a907520e537..27ed5fc60786909597cfb24475c39c449a528dce 100644 (file)
@@ -58,15 +58,21 @@ public class IssueComputation {
   }
 
   private void guessAuthor(DefaultIssue issue) {
-    if (issue.line() != null) {
+    // issue.authorLogin() can be not-null when old developer cockpit plugin (or other plugin)
+    // is still installed and executed during analysis
+    if (issue.authorLogin() == null && issue.line() != null) {
       issue.setAuthorLogin(linesCache.lineAuthor(issue.line()));
     }
   }
 
   private void autoAssign(DefaultIssue issue) {
-    String scmAccount = issue.authorLogin();
-    if (scmAccount != null) {
-      issue.setAssignee(scmAccountCache.getNullable(scmAccount));
+    // issue.assignee() can be not-null if the issue-assign-plugin is
+    // still installed and executed during analysis
+    if (issue.assignee() == null) {
+      String scmAccount = issue.authorLogin();
+      if (scmAccount != null) {
+        issue.setAssignee(scmAccountCache.getNullable(scmAccount));
+      }
     }
   }
 
index fbade0f3bee4202a2abbd3b2f3d26a3e3751c8a7..946e0d151cc04ab04fda954de4f63936667b9d75 100644 (file)
@@ -35,6 +35,7 @@ import java.util.Arrays;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verifyZeroInteractions;
 import static org.mockito.Mockito.when;
 
 public class IssueComputationTest {
@@ -147,6 +148,24 @@ public class IssueComputationTest {
     assertThat(Iterators.getOnlyElement(issueCache.traverse()).assignee()).isNull();
   }
 
+  @Test
+  public void do_not_override_author_and_assignee_set_by_old_batch_plugins() throws Exception {
+    issue.setNew(true);
+
+    // these fields were provided during project analysis, for instance
+    // by developer cockpit or issue-assign plugins
+    issue.setAuthorLogin("charlie");
+    issue.setAssignee("cabu");
+
+    process();
+
+    // keep the values, without trying to update them
+    DefaultIssue cachedIssue = Iterators.getOnlyElement(issueCache.traverse());
+    assertThat(cachedIssue.assignee()).isEqualTo("cabu");
+    assertThat(cachedIssue.authorLogin()).isEqualTo("charlie");
+    verifyZeroInteractions(scmAccountCache);
+  }
+
   private void process() {
     sut.processComponentIssues("FILE_A", Arrays.asList(issue));
     sut.afterReportProcessing();