@Override public void execute() { if (listener == null) { return; } for (TrackedIssue issue : issues.all()) { collectInfo(issue); } getUsers(); for (TrackedIssue issue : issues.all()) { IssueListener.Issue newIssue = new IssueListener.Issue(); newIssue.setAssigneeLogin(issue.assignee()); newIssue.setAssigneeName(getAssigneeName(issue.assignee())); newIssue.setComponentKey(issue.componentKey()); newIssue.setKey(issue.key()); newIssue.setMessage(issue.getMessage()); newIssue.setNew(issue.isNew()); newIssue.setResolution(issue.resolution()); newIssue.setRuleKey(issue.getRuleKey().toString()); newIssue.setRuleName(getRuleName(issue.getRuleKey())); newIssue.setSeverity(issue.severity()); newIssue.setStatus(issue.status()); newIssue.setStartLine(issue.startLine()); newIssue.setStartLineOffset(issue.startLineOffset()); newIssue.setEndLine(issue.endLine()); newIssue.setEndLineOffset(issue.endLineOffset()); listener.handle(newIssue); } }
@Test public void do_not_auto_assign_existing_issues() { inputIssue.setIsNew(false); inputIssue.setAuthorLogin("charlie"); when(scmAccountCache.getNullable("charlie")).thenReturn("char.lie"); process(); assertThat(Iterators.getOnlyElement(outputIssues.traverse()).assignee()).isNull(); }
@Test public void auto_assign_new_issues() { inputIssue.setIsNew(true); inputIssue.setAuthorLogin("charlie"); when(scmAccountCache.getNullable("charlie")).thenReturn("char.lie"); process(); assertThat(Iterators.getOnlyElement(outputIssues.traverse()).assignee()).isEqualTo("char.lie"); }
@Test public void do_not_guess_author_of_existing_issues() { inputIssue.setIsNew(false); inputIssue.setLine(3); when(lineCache.lineAuthor(3)).thenReturn("charlie"); process(); assertThat(Iterators.getOnlyElement(outputIssues.traverse()).authorLogin()).isNull(); }
@Test public void do_not_fail_if_missing_author_for_new_issues() { inputIssue.setIsNew(true); inputIssue.setLine(3); when(lineCache.lineAuthor(3)).thenReturn(null); process(); assertThat(Iterators.getOnlyElement(outputIssues.traverse()).authorLogin()).isNull(); }
@Test public void do_not_copy_rule_tags_on_existing_issues() { inputIssue.setIsNew(false); rule.setTags(ImmutableSet.of("bug", "performance")); rule.setSystemTags(ImmutableSet.of("blocker")); process(); assertThat(Iterators.getOnlyElement(outputIssues.traverse()).tags()).isEmpty(); }
@Test public void guess_author_of_new_issues() { inputIssue.setIsNew(true); inputIssue.setLine(3); when(lineCache.lineAuthor(3)).thenReturn("charlie"); process(); assertThat(Iterators.getOnlyElement(outputIssues.traverse()).authorLogin()) .isEqualTo("charlie"); }
@Test public void copy_rule_tags_on_new_issues() { inputIssue.setIsNew(true); rule.setTags(ImmutableSet.of("bug", "performance")); rule.setSystemTags(ImmutableSet.of("blocker")); process(); assertThat(Iterators.getOnlyElement(outputIssues.traverse()).tags()) .containsOnly("blocker", "bug", "performance"); }
private boolean initAndAddIssue(DefaultIssue issue, @Nullable Violation violation) { RuleKey ruleKey = issue.ruleKey(); Rule rule = rules.find(ruleKey); validateRule(issue, rule); ActiveRule activeRule = activeRules.find(ruleKey); if (activeRule == null) { // rule does not exist or is not enabled -> ignore the issue return false; } updateIssue(issue, rule, activeRule); if (filters.accept(issue, violation)) { cache.put(issue); return true; } return false; }
@Test public void do_not_assign_default_assignee_when_not_found_in_index() { inputIssue.setIsNew(true); String wolinski = "wolinski"; projectSettings.setProperty(CoreProperties.DEFAULT_ISSUE_ASSIGNEE, wolinski); when(userIndex.getNullableByLogin(wolinski)).thenReturn(null); process(); assertThat(Iterators.getOnlyElement(outputIssues.traverse()).assignee()).isNull(); assertThat(logTester.logs()) .contains( String.format( "the %s property was set with an unknown login: %s", CoreProperties.DEFAULT_ISSUE_ASSIGNEE, wolinski)); }
private void processIssues(Component component) { DiskCache<DefaultIssue>.DiskAppender cacheAppender = issueCache.newAppender(); try { Tracking<DefaultIssue, DefaultIssue> tracking = tracker.track(component); issueVisitors.beforeComponent(component); fillNewOpenIssues(component, tracking, cacheAppender); fillExistingOpenIssues(component, tracking, cacheAppender); closeUnmatchedBaseIssues(component, tracking, cacheAppender); issueVisitors.afterComponent(component); } catch (Exception e) { throw new IllegalStateException( String.format("Fail to process issues of component '%s'", component.getKey()), e); } finally { cacheAppender.close(); } }
@Test public void do_not_override_author_and_assignee_set_by_old_batch_plugins() { inputIssue.setIsNew(true); // these fields were provided during project analysis, for instance // by developer cockpit or issue-assign plugins inputIssue.setAuthorLogin("charlie"); inputIssue.setAssignee("cabu"); process(); // keep the values, without trying to update them DefaultIssue cachedIssue = Iterators.getOnlyElement(outputIssues.traverse()); assertThat(cachedIssue.assignee()).isEqualTo("cabu"); assertThat(cachedIssue.authorLogin()).isEqualTo("charlie"); verifyZeroInteractions(scmAccountCache); }
private boolean initAndAddIssue(DefaultIssue issue, @Nullable Violation violation) { // TODO fail fast : if rule does not exist ActiveRule activeRule = qProfile.getActiveRule(issue.ruleKey().repository(), issue.ruleKey().rule()); if (activeRule == null || activeRule.getRule() == null) { // rule does not exist or is not enabled -> ignore the issue return false; } issue.setCreationDate(project.getAnalysisDate()); issue.setUpdateDate(project.getAnalysisDate()); if (issue.severity() == null) { issue.setSeverity(activeRule.getSeverity().name()); } issue.setRemediationCost(technicalDebtCalculator.cost(issue)); if (filters.accept(issue, violation)) { cache.put(issue); return true; } return false; }
@Test public void store_issues_on_disk() { process(); assertThat(Iterators.getOnlyElement(outputIssues.traverse()).key()).isEqualTo("ISSUE_A"); }