private void treatUnresolvedIssues(DecoratorContext context, List<Issue> unresolvedIssues) {
    Map<Integer, String> authorsByLine = null;
    for (Issue issue : unresolvedIssues) {
      logger.debug(
          "Treating unresolved issue [{}]: isNew = [{}], line = [{}], assignee = [{}]",
          issue.key(),
          issue.isNew(),
          issue.line(),
          issue.assignee());

      if (!isCandidateIssue(issue)) {
        logger.debug("Issue [{}] is not a candidate for auto assignment", issue.key());
        continue;
      }

      if (authorsByLine == null) {
        // Load authors by line for the current resource. Should be done only once per resource
        authorsByLine = getAuthorsByLineFromScm(context);
      }

      User autoAssignee = getAutoAssignee(issue, authorsByLine);
      if (autoAssignee != null) {
        logger.debug("Assigning issue [{}] to user [{}]", issue.key(), autoAssignee.login());
        assignIssue(issue, autoAssignee);
      } else {
        logger.debug("Leaving the issue [{}] unassigned", issue.key());
      }
    }
  }
 private String getUserFullName(@Nullable String login) {
   if (login == null) {
     return null;
   }
   User user = userFinder.findByLogin(login);
   if (user == null) {
     // most probably user was deleted
     return login;
   }
   return StringUtils.defaultIfBlank(user.name(), login);
 }
Example #3
0
  @Test
  public void findByLogins() throws Exception {
    UserDto david = new UserDto().setLogin("david").setName("David").setEmail("*****@*****.**");
    UserDto john = new UserDto().setLogin("john").setName("John").setEmail("*****@*****.**");
    when(dao.selectUsersByLogins(Arrays.asList("david", "john")))
        .thenReturn(Arrays.asList(david, john));

    Collection<User> users = finder.findByLogins(Arrays.asList("david", "john"));
    assertThat(users).hasSize(2);
    for (User user : users) {
      assertThat(user.login()).isIn("david", "john");
    }
  }
Example #4
0
 public boolean assign(DefaultIssue issue, @Nullable User user, IssueChangeContext context) {
   String sanitizedAssignee = null;
   if (user != null) {
     sanitizedAssignee = StringUtils.defaultIfBlank(user.login(), null);
   }
   if (!Objects.equal(sanitizedAssignee, issue.assignee())) {
     String newAssignee = user != null ? user.name() : null;
     issue.setFieldChange(context, ASSIGNEE, UNUSED, newAssignee);
     issue.setAssignee(sanitizedAssignee);
     issue.setUpdateDate(context.date());
     issue.setChanged(true);
     issue.setSendNotifications(true);
     return true;
   }
   return false;
 }
  private User getAutoAssignee(Issue issue, Map<Integer, String> authorsByLine) {
    String scmLoginName = null;
    if (issue.line() != null || authorsByLine.get(issue.line()) != null) {
      scmLoginName = authorsByLine.get(issue.line());
    }

    User autoAssignee = null;
    if (scmLoginName == null) {
      logger.debug(
          "Cannot detect automatically the login of the assignee from SCM blame for issue [{}]",
          issue.key());
      autoAssignee = getDefaultAssigneeIfAny();
      if (autoAssignee != null) {
        logger.debug(
            "Using default assignee [{}] for issue [{}]", autoAssignee.login(), issue.key());
      }
    } else {
      autoAssignee = getUserFromLoginName(scmLoginName);
    }
    return autoAssignee;
  }