@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_author_if_new_author_is_null() { boolean updated = underTest.setNewAuthor(issue, null, context); assertThat(updated).isFalse(); assertThat(issue.currentChange()).isNull(); assertThat(issue.mustSendNotifications()).isFalse(); }
@Test public void set_new_author() { boolean updated = underTest.setNewAuthor(issue, "simon", context); assertThat(updated).isTrue(); FieldDiffs.Diff diff = issue.currentChange().get("author"); assertThat(diff.oldValue()).isNull(); assertThat(diff.newValue()).isEqualTo("simon"); assertThat(issue.mustSendNotifications()).isFalse(); }
@Test public void fail_with_ISE_when_setting_new_author_on_issue() { issue.setAuthorLogin("simon"); thrown.expect(IllegalStateException.class); thrown.expectMessage("It's not possible to update the author with this method, please use setAuthorLogin()"); underTest.setNewAuthor(issue, "julien", 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); } } }