import java.util.Collection;
import java.util.List;
import java.util.Map;
+import org.apache.logging.log4j.util.Strings;
import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.core.issue.AnticipatedTransition;
import org.sonar.core.issue.DefaultIssue;
private Collection<AnticipatedTransition> anticipatedTransitions;
private final AnticipatedTransitionTracker<DefaultIssue, AnticipatedTransition> tracker = new AnticipatedTransitionTracker<>();
private final IssueLifecycle issueLifecycle;
-
+
private final AnticipatedTransitionRepository anticipatedTransitionRepository;
public TransitionIssuesToAnticipatedStatesVisitor(AnticipatedTransitionRepository anticipatedTransitionRepository, IssueLifecycle issueLifecycle) {
issue.setBeingClosed(true);
issue.setAnticipatedTransitions(true);
issueLifecycle.doManualTransition(issue, anticipatedTransition.getTransition(), anticipatedTransition.getUserUuid());
- issueLifecycle.addComment(issue, anticipatedTransition.getComment(), anticipatedTransition.getUserUuid());
+ String transitionComment = anticipatedTransition.getComment();
+ String comment = Strings.isNotBlank(transitionComment) ? transitionComment : "Automatically transitioned from SonarLint";
+ issueLifecycle.addComment(issue, comment, anticipatedTransition.getUserUuid());
}
}
verifyNoInteractions(issueLifecycle);
}
+ @Test
+ public void givenMatchingAnticipatedTransitionsWithEmptyComment_transitionsShouldBeAppliedToIssuesAndDefaultCommentApplied() {
+ Component component = getComponent(Component.Type.FILE);
+ when(anticipatedTransitionRepository.getAnticipatedTransitionByComponent(component)).thenReturn(getAnticipatedTransitionsWithEmptyComment("projectKey", "fileName"));
+
+ DefaultIssue issue = getDefaultIssue(1, "abcdefghi", "issue message");
+
+ underTest.beforeComponent(component);
+ underTest.onIssue(component, issue);
+
+ assertThat(issue.isBeingClosed()).isTrue();
+ assertThat(issue.hasAnticipatedTransitions()).isTrue();
+ verify(issueLifecycle).doManualTransition(issue, "wontfix", "admin");
+ verify(issueLifecycle).addComment(issue, "Automatically transitioned from SonarLint", "admin");
+ }
+
@Test
public void givenAFileComponent_theRepositoryIsHitForFetchingAnticipatedTransitions() {
Component component = getComponent(Component.Type.FILE);
return Stream.of(new AnticipatedTransition(projecKey, null, "admin", RuleKey.parse("repo:id"), "issue message", fileName, 1, "abcdefghi", "wontfix", "doing the transition in an anticipated way")).collect(Collectors.toList());
}
+ private Collection<AnticipatedTransition> getAnticipatedTransitionsWithEmptyComment(String projecKey, String fileName) {
+ return Stream.of(new AnticipatedTransition(projecKey, null, "admin", RuleKey.parse("repo:id"), "issue message", fileName, 1, "abcdefghi", "wontfix", null)).collect(Collectors.toList());
+ }
+
private Component getComponent(Component.Type type) {
ComponentImpl.Builder builder = ComponentImpl.builder(type)
.setUuid("componentUuid")