import org.sonar.api.utils.log.Loggers;
import org.sonar.core.issue.DefaultIssue;
import org.sonar.core.issue.IssueChangeContext;
+import org.sonar.db.issue.IssueDto;
import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolder;
import org.sonar.server.computation.task.projectanalysis.component.Component;
import org.sonar.server.computation.task.projectanalysis.scm.ScmInfo;
String scmAuthor = guessScmAuthor(issue);
if (!Strings.isNullOrEmpty(scmAuthor)) {
- issueUpdater.setNewAuthor(issue, scmAuthor, changeContext);
+ 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 author = issue.authorLogin() == null ? null : scmAccountToUser.getNullable(issue.authorLogin());
+ String author = Strings.isNullOrEmpty(scmAuthor) ? null : scmAccountToUser.getNullable(scmAuthor);
String assigneeLogin = StringUtils.defaultIfEmpty(author, defaultAssignee.loadDefaultAssigneeLogin());
issueUpdater.setNewAssignee(issue, assigneeLogin, changeContext);
*/
package org.sonar.server.computation.task.projectanalysis.issue;
-import org.junit.Test;
import org.junit.Rule;
+import org.junit.Test;
import org.sonar.api.rules.RuleType;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.server.computation.task.projectanalysis.scm.ScmInfoRepositoryRule;
import org.sonar.server.issue.IssueFieldsSetter;
+import static java.util.stream.Collectors.joining;
+import static java.util.stream.IntStream.range;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
assertThat(issue.assignee()).isEqualTo("John C");
}
+ @Test
+ public void dont_store_author_too_long() throws Exception {
+ String scmAuthor = range(0, 256).mapToObj(i -> "s").collect(joining());
+ addScmUser(scmAuthor, "John C");
+ setSingleChangeset(scmAuthor, 123456789L, "rev-1");
+ DefaultIssue issue = new DefaultIssue().setLine(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 set_default_assignee_if_author_not_found() throws Exception {
addScmUser("john", null);
assertThat(issue.assignee()).isEqualTo("DefaultAssignee");
}
-
@Test
public void set_last_committer_when_line_is_bigger_than_changeset_size() throws Exception {
addScmUser("john", "John C");
import util.ProjectAnalysisRule;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.groups.Tuple.tuple;
import static util.ItUtils.newAdminWsClient;
import static util.ItUtils.setServerProperty;
// verify that SCM account matches, case-insensitive
createUser("user7", "User 7", "user7@email.com", "user7ScmAccount");
createUser("user8", "User 8", "user8@email.com", "user8SCMaccOUNT");
- // SCM accounts long then 255 chars will be ignored
- createUser("user9", "User 9", "user9@email.com", IntStream.range(0,256).mapToObj(i -> "s").collect(Collectors.joining()));
+ // SCM accounts longer than 255
+ createUser("user9", "User 9", "user9@email.com", IntStream.range(0, 256).mapToObj(i -> "s").collect(Collectors.joining()));
projectAnalysis.run();
// SCM account match, case-insensitive
verifyIssueAssignee(issues, 7, "user7");
verifyIssueAssignee(issues, 8, "user8");
- // SCM accounts long then 255 chars will be ignored
- verifyIssueAssignee(issues, 10, null);
+ // SCM accounts longer than 255 chars
+ verifyIssueAssignee(issues, 10, "user9");
}
private static void verifyIssueAssignee(List<Issue> issues, int line, @Nullable String expectedAssignee) {
// user1 is assigned to his issues. All other issues are assigned to the default assignee.
assertThat(search(IssueQuery.create().assignees("user1")).list()).hasSize(1);
- assertThat(search(IssueQuery.create().assignees("user2")).list()).hasSize(8);
+ assertThat(search(IssueQuery.create().assignees("user2")).list()).hasSize(9);
// No unassigned issues
assertThat(search(IssueQuery.create().assigned(false)).list()).isEmpty();
}
assertThat(issues).isNotEmpty();
// No author and assignee are set
- for (Issue issue : issues) {
- assertThat(issue.author()).isEmpty();
- }
+ assertThat(issues)
+ .extracting(Issue::line, Issue::author)
+ .containsExactlyInAnyOrder(
+ tuple(1, ""),
+ tuple(2, ""),
+ tuple(3, ""),
+ tuple(4, ""),
+ tuple(5, ""),
+ tuple(6, ""),
+ tuple(7, ""),
+ tuple(8, ""),
+ tuple(9, ""),
+ tuple(10, ""));
assertThat(search(IssueQuery.create().assigned(true)).list()).isEmpty();
// Run a second analysis with SCM
assertThat(issues).isNotEmpty();
// Authors and assignees are set
- for (Issue issue : issues) {
- assertThat(issue.author()).isNotEmpty();
- }
+ assertThat(issues)
+ .extracting(Issue::line, Issue::author)
+ .containsExactlyInAnyOrder(
+ tuple(1, "user1"),
+ tuple(2, "user2"),
+ tuple(3, "user3name"),
+ tuple(4, "user4name"),
+ tuple(5, "user5@email.com"),
+ tuple(6, "user6@email.com"),
+ tuple(7, "user7scmaccount"),
+ tuple(8, "user8scmaccount"),
+ tuple(9, "user8scmaccount"),
+ // SONAR-8727
+ tuple(10, ""));
assertThat(search(IssueQuery.create().assignees("user1")).list()).hasSize(1);
}