use of com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel in project hub-alert by blackducksoftware.
the class IssueTrackerIssueTransitioner method transitionIssue.
public final Optional<IssueTrackerIssueResponseModel<T>> transitionIssue(IssueTransitionModel<T> issueTransitionModel) throws AlertException {
IssueOperation issueOperation = issueTransitionModel.getIssueOperation();
ExistingIssueDetails<T> existingIssueDetails = issueTransitionModel.getExistingIssueDetails();
Optional<IssueTrackerIssueResponseModel<T>> transitionResponse = Optional.empty();
Optional<String> optionalTransitionName = retrieveJobTransitionName(issueOperation);
if (optionalTransitionName.isPresent()) {
String transitionName = optionalTransitionName.get();
boolean shouldAttemptTransition = isTransitionRequired(existingIssueDetails, issueOperation);
if (shouldAttemptTransition) {
attemptTransition(issueOperation, existingIssueDetails, transitionName);
IssueTrackerIssueResponseModel<T> transitionResponseModel = issueResponseCreator.createIssueResponse(issueTransitionModel.getSource(), existingIssueDetails, issueOperation);
transitionResponse = Optional.of(transitionResponseModel);
} else {
logger.debug("The issue is already in the status category that would result from this transition ({}). Issue Details: {}", transitionName, existingIssueDetails);
}
} else {
logger.debug("No transition name was provided so no '{}' transition will be performed. Issue Details: {}", issueOperation.name(), existingIssueDetails);
}
IssueCommentModel<T> commentRequestModel = new IssueCommentModel<>(existingIssueDetails, issueTransitionModel.getPostTransitionComments(), issueTransitionModel.getSource());
commenter.commentOnIssue(commentRequestModel);
return transitionResponse;
}
use of com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel in project hub-alert by blackducksoftware.
the class IssueTrackerProcessorTest method processMessagesTest.
@Test
public void processMessagesTest() throws AlertException {
IssueTrackerModelExtractor<String> extractor = Mockito.mock(IssueTrackerModelExtractor.class);
IssueTrackerModelHolder<String> simpleMessageResponses = new IssueTrackerModelHolder<>(List.of(), List.of(), List.of());
Mockito.when(extractor.extractSimpleMessageIssueModels(Mockito.anyList(), Mockito.any())).thenReturn(simpleMessageResponses);
IssueTrackerIssueResponseModel<String> response1 = Mockito.mock(IssueTrackerIssueResponseModel.class);
IssueTrackerIssueResponseModel<String> response2 = Mockito.mock(IssueTrackerIssueResponseModel.class);
IssueTrackerIssueResponseModel<String> response3 = Mockito.mock(IssueTrackerIssueResponseModel.class);
List<IssueTrackerIssueResponseModel<String>> simpleMessageResponse = List.of(response1, response2, response3);
IssueTrackerIssueResponseModel<String> response4 = Mockito.mock(IssueTrackerIssueResponseModel.class);
IssueTrackerIssueResponseModel<String> response5 = Mockito.mock(IssueTrackerIssueResponseModel.class);
List<IssueTrackerIssueResponseModel<String>> projectMessageResponses = List.of(response4, response5);
IssueTrackerMessageSender<String> sender = Mockito.mock(IssueTrackerMessageSender.class);
Mockito.when(sender.sendMessages(Mockito.any())).thenReturn(simpleMessageResponse, projectMessageResponses);
IssueTrackerProcessor<String> processor = new IssueTrackerProcessor<>(extractor, sender);
ProjectMessage projectMessage = Mockito.mock(ProjectMessage.class);
ProviderMessageHolder providerMessageHolder = new ProviderMessageHolder(List.of(projectMessage), List.of());
IssueTrackerResponse<String> issueTrackerResponse = processor.processMessages(providerMessageHolder, "jobName");
assertEquals(simpleMessageResponse.size() + projectMessageResponses.size(), issueTrackerResponse.getUpdatedIssues().size());
}
Aggregations