public void add(DefaultIssue issue) { globalStatistics.add(issue); String userUuid = issue.assignee(); if (userUuid != null) { assigneesStatistics.computeIfAbsent(userUuid, a -> new Stats(onLeakPredicate)).add(issue); } }
@Test public void unassign_issue_if_assignee_is_empty() { Map<String, Object> properties = new HashMap<>(ImmutableMap.of("assignee", "")); underTest.verify(properties, Collections.emptyList(), userSession); boolean executeResult = underTest.execute(properties, context); assertThat(executeResult).isTrue(); assertThat(issue.assignee()).isNull(); }
@Test public void unassign_issue_if_assignee_is_null() { Map<String, Object> properties = new HashMap<>(); properties.put("assignee", null); underTest.verify(properties, Collections.emptyList(), userSession); boolean executeResult = underTest.execute(properties, context); assertThat(executeResult).isTrue(); assertThat(issue.assignee()).isNull(); }
@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 assign_to_default_assignee_if_no_author() { DefaultIssue issue = newIssueOnLines(); when(defaultAssignee.loadDefaultAssigneeUuid()).thenReturn("u123"); underTest.onIssue(FILE, issue); assertThat(issue.assignee()).isEqualTo("u123"); }
public boolean assign(DefaultIssue issue, @Nullable UserDto user, IssueChangeContext context) { String assigneeUuid = user != null ? user.getUuid() : null; if (!Objects.equals(assigneeUuid, issue.assignee())) { String newAssigneeName = user == null ? null : user.getName(); issue.setFieldChange(context, ASSIGNEE, UNUSED, newAssigneeName); issue.setAssigneeUuid(user != null ? user.getUuid() : null); issue.setUpdateDate(context.date()); issue.setChanged(true); issue.setSendNotifications(true); return true; } return false; }
private Consumer<DefaultIssue> sendNotification(BulkChangeData bulkChangeData, Map<String, UserDto> userDtoByUuid, UserDto author) { return issue -> { if (bulkChangeData.sendNotification && issue.type() != RuleType.SECURITY_HOTSPOT) { notificationService.scheduleForSending(new IssueChangeNotification() .setIssue(issue) .setAssignee(userDtoByUuid.get(issue.assignee())) .setChangeAuthor(author) .setRuleName(bulkChangeData.rulesByKey.get(issue.ruleKey()).getName()) .setProject(bulkChangeData.projectsByUuid.get(issue.projectUuid())) .setComponent(bulkChangeData.componentsByUuid.get(issue.componentUuid()))); } }; }
@Test public void assign_new_issue_to_default_assignee_if_author_not_found() { setSingleChangeset("john", 123456789L, "rev-1"); when(defaultAssignee.loadDefaultAssigneeUuid()).thenReturn("u1234"); DefaultIssue issue = newIssueOnLines(1); underTest.onIssue(FILE, issue); assertThat(issue.assignee()).isEqualTo("u1234"); }
@Test public void assign_issue() { UserDto assignee = db.users().insertUser("john"); db.organizations().addMember(issueOrganizationDto, assignee); Map<String, Object> properties = new HashMap<>(ImmutableMap.of("assignee", "john")); underTest.verify(properties, Collections.emptyList(), userSession); boolean executeResult = underTest.execute(properties, context); assertThat(executeResult).isTrue(); assertThat(issue.assignee()).isEqualTo(assignee.getUuid()); }
@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 unassign() { issue.setAssigneeUuid("user_uuid"); boolean updated = underTest.assign(issue, null, context); assertThat(updated).isTrue(); assertThat(issue.assignee()).isNull(); assertThat(issue.mustSendNotifications()).isTrue(); FieldDiffs.Diff diff = issue.currentChange().get(ASSIGNEE); assertThat(diff.oldValue()).isEqualTo(UNUSED); assertThat(diff.newValue()).isNull(); }
@Test public void assign() { UserDto user = newUserDto().setLogin("emmerik").setName("Emmerik"); boolean updated = underTest.assign(issue, user, context); assertThat(updated).isTrue(); assertThat(issue.assignee()).isEqualTo(user.getUuid()); assertThat(issue.mustSendNotifications()).isTrue(); FieldDiffs.Diff diff = issue.currentChange().get(ASSIGNEE); assertThat(diff.oldValue()).isEqualTo(UNUSED); assertThat(diff.newValue()).isEqualTo(user.getName()); }
@Test public void assign_new_issue_to_author_of_change() { addScmUser("john", "u123"); setSingleChangeset("john", 123456789L, "rev-1"); DefaultIssue issue = newIssueOnLines(1); underTest.onIssue(FILE, issue); assertThat(issue.assignee()).isEqualTo("u123"); }
@Test public void change_assignee() { UserDto user = newUserDto().setLogin("emmerik").setName("Emmerik"); issue.setAssigneeUuid("user_uuid"); boolean updated = underTest.assign(issue, user, context); assertThat(updated).isTrue(); assertThat(issue.assignee()).isEqualTo(user.getUuid()); assertThat(issue.mustSendNotifications()).isTrue(); FieldDiffs.Diff diff = issue.currentChange().get(ASSIGNEE); assertThat(diff.oldValue()).isEqualTo(UNUSED); assertThat(diff.newValue()).isEqualTo(user.getName()); }
@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(); }
private void sendIssueChangeNotification(DefaultIssue issue, Component project, Map<String, UserDto> usersDtoByUuids, NotificationStatistics notificationStatistics) { IssueChangeNotification changeNotification = new IssueChangeNotification(); changeNotification.setRuleName(rules.getByKey(issue.ruleKey()).getName()); changeNotification.setIssue(issue); changeNotification.setAssignee(usersDtoByUuids.get(issue.assignee())); changeNotification.setProject(project.getKey(), project.getName(), getBranchName(), getPullRequest()); getComponentKey(issue).ifPresent(c -> changeNotification.setComponent(c.getKey(), c.getName())); notificationStatistics.issueChangesDeliveries += service.deliver(changeNotification); notificationStatistics.issueChanges++; }
@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(); }
@Test public void flag_as_false_positive() { DefaultIssue issue = new DefaultIssue() .setKey("ABCDE") .setStatus(STATUS_OPEN) .setRuleKey(RuleKey.of("squid", "AvoidCycle")) .setAssigneeUuid("morgan"); workflow.start(); workflow.doManualTransition(issue, DefaultTransitions.FALSE_POSITIVE, IssueChangeContext.createScan(new Date())); assertThat(issue.resolution()).isEqualTo(RESOLUTION_FALSE_POSITIVE); assertThat(issue.status()).isEqualTo(STATUS_RESOLVED); // should remove assignee assertThat(issue.assignee()).isNull(); }
@Test public void wont_fix() { DefaultIssue issue = new DefaultIssue() .setKey("ABCDE") .setStatus(STATUS_OPEN) .setRuleKey(RuleKey.of("squid", "AvoidCycle")) .setAssigneeUuid("morgan"); workflow.start(); workflow.doManualTransition(issue, DefaultTransitions.WONT_FIX, IssueChangeContext.createScan(new Date())); assertThat(issue.resolution()).isEqualTo(RESOLUTION_WONT_FIX); assertThat(issue.status()).isEqualTo(STATUS_RESOLVED); // should remove assignee assertThat(issue.assignee()).isNull(); }
@Test public void assign_to_default_assignee_if_no_scm_on_issue_locations() { addScmUser("john", "John C"); Changeset changeset = Changeset.newChangesetBuilder() .setAuthor("john") .setDate(123456789L) .setRevision("rev-1") .build(); scmInfoRepository.setScmInfo(FILE_REF, changeset, changeset); DefaultIssue issue = newIssueOnLines(3); underTest.onIssue(FILE, issue); assertThat(issue.assignee()).isEqualTo("John C"); }