Search in sources :

Example 6 with IssueTrackerIssueResponseModel

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;
}
Also used : IssueTrackerIssueResponseModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel) IssueOperation(com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation) IssueCommentModel(com.synopsys.integration.alert.api.channel.issue.model.IssueCommentModel)

Example 7 with IssueTrackerIssueResponseModel

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());
}
Also used : IssueTrackerIssueResponseModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) IssueTrackerModelHolder(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder) ProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder) Test(org.junit.jupiter.api.Test)

Aggregations

IssueTrackerIssueResponseModel (com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel)7 IssueTrackerModelHolder (com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder)3 IssueTransitionModel (com.synopsys.integration.alert.api.channel.issue.model.IssueTransitionModel)2 ProjectIssueModel (com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel)2 ExistingIssueDetails (com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails)2 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)2 IssueOperation (com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation)2 MessageResult (com.synopsys.integration.alert.common.message.model.MessageResult)2 ProjectMessage (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage)2 Test (org.junit.jupiter.api.Test)2 IssueTrackerCallbackInfoCreator (com.synopsys.integration.alert.api.channel.issue.callback.IssueTrackerCallbackInfoCreator)1 IssueCommentModel (com.synopsys.integration.alert.api.channel.issue.model.IssueCommentModel)1 IssueCreationModel (com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel)1 IssueTrackerResponse (com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerResponse)1 IssueMissingTransitionException (com.synopsys.integration.alert.common.channel.issuetracker.exception.IssueMissingTransitionException)1 IssueTrackerCallbackInfo (com.synopsys.integration.alert.common.channel.issuetracker.message.IssueTrackerCallbackInfo)1 AlertFieldException (com.synopsys.integration.alert.common.exception.AlertFieldException)1 ProviderMessageHolder (com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder)1 LinkedList (java.util.LinkedList)1