public boolean setAuthorLogin(DefaultIssue issue, @Nullable String authorLogin, IssueChangeContext context) { if (!Objects.equals(authorLogin, issue.authorLogin())) { issue.setFieldChange(context, AUTHOR, issue.authorLogin(), authorLogin); issue.setAuthorLogin(authorLogin); issue.setUpdateDate(context.date()); issue.setChanged(true); // do not send notifications to prevent spam when installing the developer cockpit plugin return true; } return false; }
/** * Used to set the author when it was null */ public boolean setNewAuthor(DefaultIssue issue, @Nullable String newAuthorLogin, IssueChangeContext context) { if (isNullOrEmpty(newAuthorLogin)) { return false; } checkState(issue.authorLogin() == null, "It's not possible to update the author with this method, please use setAuthorLogin()"); issue.setFieldChange(context, AUTHOR, null, newAuthorLogin); issue.setAuthorLogin(newAuthorLogin); issue.setUpdateDate(context.date()); issue.setChanged(true); // do not send notifications to prevent spam when installing the developer cockpit plugin return true; }
@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 set_author() { boolean updated = underTest.setAuthorLogin(issue, "eric", context); assertThat(updated).isTrue(); assertThat(issue.authorLogin()).isEqualTo("eric"); FieldDiffs.Diff diff = issue.currentChange().get("author"); assertThat(diff.oldValue()).isNull(); assertThat(diff.newValue()).isEqualTo("eric"); assertThat(issue.mustSendNotifications()).isFalse(); }
@Test public void set_author_of_new_issue_if_changeset() { setSingleChangeset("john", 123456789L, "rev-1"); DefaultIssue issue = newIssueOnLines(1); underTest.onIssue(FILE, issue); assertThat(issue.authorLogin()).isEqualTo("john"); }
private void assertInitializedExternalIssue(DefaultIssue issue) { assertThat(issue.projectKey()).isEqualTo(PROJECT.getKey()); assertThat(issue.componentKey()).isEqualTo(FILE.getKey()); assertThat(issue.componentUuid()).isEqualTo(FILE.getUuid()); assertThat(issue.resolution()).isNull(); assertThat(issue.status()).isEqualTo(Issue.STATUS_OPEN); assertThat(issue.key()).isNull(); assertThat(issue.authorLogin()).isNull(); }
@Test public void assign_but_do_not_set_author_if_too_long() { String scmAuthor = range(0, 256).mapToObj(i -> "s").collect(joining()); addScmUser(scmAuthor, "John C"); setSingleChangeset(scmAuthor, 123456789L, "rev-1"); DefaultIssue issue = newIssueOnLines(1); underTest.onIssue(FILE, issue); assertThat(issue.authorLogin()).isNull(); assertThat(issue.assignee()).isEqualTo("John C"); assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("SCM account '" + scmAuthor + "' is too long to be stored as issue author"); }
@Test public void do_not_set_author_if_no_changeset() { DefaultIssue issue = newIssueOnLines(1); underTest.onIssue(FILE, issue); assertThat(issue.authorLogin()).isNull(); }
@Test public void do_not_reset_author_if_already_set() { setSingleChangeset("john", 123456789L, "rev-1"); DefaultIssue issue = newIssueOnLines(1) .setAuthorLogin("jane"); underTest.onIssue(FILE, issue); assertThat(issue.authorLogin()).isEqualTo("jane"); }
private void assertInitializedIssue(DefaultIssue issue) { assertThat(issue.projectKey()).isEqualTo(PROJECT.getKey()); assertThat(issue.componentKey()).isEqualTo(FILE.getKey()); assertThat(issue.componentUuid()).isEqualTo(FILE.getUuid()); assertThat(issue.resolution()).isNull(); assertThat(issue.status()).isEqualTo(Issue.STATUS_OPEN); assertThat(issue.key()).isNull(); assertThat(issue.authorLogin()).isNull(); assertThat(issue.effort()).isNull(); assertThat(issue.effortInMinutes()).isNull(); }
@Test public void do_not_assign_new_issue_if_no_author_in_changeset() { setSingleChangeset(null, 123456789L, "rev-1"); DefaultIssue issue = newIssueOnLines(1); underTest.onIssue(FILE, issue); assertThat(issue.authorLogin()).isNull(); assertThat(issue.assignee()).isNull(); }
@Test public void do_not_assign_issue_if_unassigned_but_already_authored() { addScmUser("john", "u1234"); setSingleChangeset("john", 123456789L, "rev-1"); DefaultIssue issue = newIssueOnLines(1) .setAuthorLogin("john") .setAssigneeUuid(null); underTest.onIssue(FILE, issue); assertThat(issue.authorLogin()).isEqualTo("john"); assertThat(issue.assignee()).isNull(); }
assertThat(issue.resolution()).isEqualTo(Issue.RESOLUTION_FIXED); assertThat(issue.assignee()).isEqualTo("julien"); assertThat(issue.authorLogin()).isEqualTo("steph"); assertThat(issue.checksum()).isEqualTo("c7b5db46591806455cf082bb348631e8"); assertThat(issue.isNew()).isTrue();
assertThat(issue.assignee()).isEqualTo("perceval"); assertThat(issue.attribute("key")).isEqualTo("value"); assertThat(issue.authorLogin()).isEqualTo("pierre"); assertThat(issue.creationDate()).isEqualTo(DateUtils.truncate(createdAt, Calendar.SECOND)); assertThat(issue.updateDate()).isEqualTo(DateUtils.truncate(updatedAt, Calendar.SECOND));
assertThat(raw.status()).isEqualTo(STATUS_CLOSED); assertThat(raw.assignee()).isEqualTo("base assignee uuid"); assertThat(raw.authorLogin()).isEqualTo("base author"); assertThat(raw.tags()).containsOnly("base tag"); assertThat(raw.effort()).isEqualTo(DEFAULT_DURATION);
assertThat(raw.status()).isEqualTo(STATUS_RESOLVED); assertThat(raw.assignee()).isEqualTo("base assignee uuid"); assertThat(raw.authorLogin()).isEqualTo("base author"); assertThat(raw.tags()).containsOnly("base tag"); assertThat(raw.effort()).isEqualTo(DEFAULT_DURATION);
assertThat(raw.updateDate()).isEqualTo(base.updateDate()); assertThat(raw.assignee()).isEqualTo("base assignee uuid"); assertThat(raw.authorLogin()).isEqualTo("base author"); assertThat(raw.tags()).containsOnly("base tag"); assertThat(raw.effort()).isEqualTo(DEFAULT_DURATION);
private void copyFields(DefaultIssue toIssue, DefaultIssue fromIssue) { toIssue.setType(fromIssue.type()); toIssue.setCreationDate(fromIssue.creationDate()); toIssue.setUpdateDate(fromIssue.updateDate()); toIssue.setCloseDate(fromIssue.closeDate()); toIssue.setResolution(fromIssue.resolution()); toIssue.setStatus(fromIssue.status()); toIssue.setAssigneeUuid(fromIssue.assignee()); toIssue.setAuthorLogin(fromIssue.authorLogin()); toIssue.setTags(fromIssue.tags()); toIssue.setAttributes(fromIssue.attributes()); toIssue.setEffort(debtCalculator.calculate(toIssue)); toIssue.setOnDisabledRule(fromIssue.isOnDisabledRule()); toIssue.setSelectedAt(fromIssue.selectedAt()); } }
.setAssigneeUuid(issue.assignee()) .setIssueAttributes(KeyValueFormat.format(issue.attributes())) .setAuthorLogin(issue.authorLogin()) .setRuleKey(issue.ruleKey().repository(), issue.ruleKey().rule()) .setExternal(issue.isFromExternalRuleEngine())
.setProjectKey(issue.projectKey()) .setIssueAttributes(KeyValueFormat.format(issue.attributes())) .setAuthorLogin(issue.authorLogin()) .setIssueCreationDate(issue.creationDate()) .setIssueCloseDate(issue.closeDate())