]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7942 When there is no SCM data sonar.issues.defaultAssigneeLogin must be used
authorEric Hartmann <hartmann.eric@gmail.com>
Fri, 13 Oct 2017 16:18:41 +0000 (18:18 +0200)
committerEric Hartmann <hartmann.eric@gmail.Com>
Mon, 16 Oct 2017 07:56:20 +0000 (09:56 +0200)
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueAssigner.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/IssueAssignerTest.java

index e776ca2d7665c06092764b6bd19cb790b9d951a9..bf92afba81797ec0572dd25acea5a0b88690e1f1 100644 (file)
@@ -70,18 +70,20 @@ public class IssueAssigner extends IssueVisitor {
 
   @Override
   public void onIssue(Component component, DefaultIssue issue) {
-    boolean authorWasSet = false;
     if (issue.authorLogin() == null) {
       loadScmChangesets(component);
       String scmAuthor = guessScmAuthor(issue);
+
       if (!Strings.isNullOrEmpty(scmAuthor)) {
         issueUpdater.setNewAuthor(issue, scmAuthor, changeContext);
-        authorWasSet = true;
       }
-    }
-    if (authorWasSet && issue.assignee() == null) {
-      String assigneeLogin = StringUtils.defaultIfEmpty(scmAccountToUser.getNullable(issue.authorLogin()), defaultAssignee.loadDefaultAssigneeLogin());
-      issueUpdater.setNewAssignee(issue, assigneeLogin, changeContext);
+
+      if (issue.assignee() == null) {
+        String author = issue.authorLogin() == null ? null : scmAccountToUser.getNullable(issue.authorLogin());
+        String assigneeLogin = StringUtils.defaultIfEmpty(author, defaultAssignee.loadDefaultAssigneeLogin());
+
+        issueUpdater.setNewAssignee(issue, assigneeLogin, changeContext);
+      }
     }
   }
 
index 7780f069ae299cce8ea9d514f5130a330bcceb9a..5b29e39e9146aadec777386bcc59942a7c6acdf5 100644 (file)
@@ -158,6 +158,17 @@ public class IssueAssignerTest {
     assertThat(issue.assignee()).isEqualTo("Henry V");
   }
 
+  @Test
+  public void when_noscm_data_is_available_defaultAssignee_should_be_used() throws Exception {
+    DefaultIssue issue = new DefaultIssue().setLine(null);
+
+    when(defaultAssignee.loadDefaultAssigneeLogin()).thenReturn("DefaultAssignee");
+    underTest.onIssue(FILE, issue);
+
+    assertThat(issue.assignee()).isEqualTo("DefaultAssignee");
+  }
+
+
   @Test
   public void set_last_committer_when_line_is_bigger_than_changeset_size() throws Exception {
     addScmUser("john", "John C");