@Override public void onIssue(Component component, DefaultIssue issue) { if (issue.authorLogin() != null) { return; } loadScmChangesets(component); Optional<String> scmAuthor = guessScmAuthor(issue, component); if (scmAuthor.isPresent()) { if (scmAuthor.get().length() <= IssueDto.AUTHOR_MAX_SIZE) { issueUpdater.setNewAuthor(issue, scmAuthor.get(), changeContext); } else { LOGGER.debug("SCM account '{}' is too long to be stored as issue author", scmAuthor.get()); } } if (issue.assignee() == null) { String assigneeUuid = scmAuthor.map(scmAccountToUser::getNullable).orElse(null); assigneeUuid = defaultIfEmpty(assigneeUuid, defaultAssignee.loadDefaultAssigneeUuid()); issueUpdater.setNewAssignee(issue, assigneeUuid, changeContext); } }
@Test public void not_set_new_assignee_if_new_assignee_is_null() { boolean updated = underTest.setNewAssignee(issue, null, context); assertThat(updated).isFalse(); assertThat(issue.currentChange()).isNull(); assertThat(issue.mustSendNotifications()).isFalse(); }
@Test public void set_new_assignee() { boolean updated = underTest.setNewAssignee(issue, "user_uuid", context); assertThat(updated).isTrue(); assertThat(issue.assignee()).isEqualTo("user_uuid"); assertThat(issue.mustSendNotifications()).isTrue(); FieldDiffs.Diff diff = issue.currentChange().get(ASSIGNEE); assertThat(diff.oldValue()).isEqualTo(UNUSED); assertThat(diff.newValue()).isEqualTo("user_uuid"); }
@Test public void fail_with_ISE_when_setting_new_assignee_on_already_assigned_issue() { issue.setAssigneeUuid("user_uuid"); thrown.expect(IllegalStateException.class); thrown.expectMessage("It's not possible to update the assignee with this method, please use assign()"); underTest.setNewAssignee(issue, "another_user_uuid", context); }
@Override public void onIssue(Component component, DefaultIssue issue) { if (issue.authorLogin() == null) { loadScmChangesets(component); String scmAuthor = guessScmAuthor(issue); if (!isNullOrEmpty(scmAuthor)) { if (scmAuthor.length() <= IssueDto.AUTHOR_MAX_SIZE) { issueUpdater.setNewAuthor(issue, scmAuthor, changeContext); } else { LOGGER.debug("SCM account '{}' is too long to be stored as issue author", scmAuthor); } } if (issue.assignee() == null) { String assigneeUuid = isNullOrEmpty(scmAuthor) ? null : scmAccountToUser.getNullable(scmAuthor); assigneeUuid = defaultIfEmpty(assigneeUuid, defaultAssignee.loadDefaultAssigneeUuid()); issueUpdater.setNewAssignee(issue, assigneeUuid, changeContext); } } }