Search in sources :

Example 1 with IssueTrackerIssueResponseModel

use of com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel in project hub-alert by blackducksoftware.

the class IssueTrackerTransitionTestAction method transitionTestIssueOrReturnFailureResult.

public Optional<MessageResult> transitionTestIssueOrReturnFailureResult(IssueOperation operation, ExistingIssueDetails<T> existingIssueDetails, ProjectIssueModel testProjectIssueModel) {
    String postTransitionComment = String.format("Successfully tested the %s operation", operation.name());
    IssueTransitionModel<T> resolveRequest = new IssueTransitionModel<>(existingIssueDetails, operation, List.of(postTransitionComment), testProjectIssueModel);
    IssueTrackerModelHolder<T> resolveRequestModelHolder = new IssueTrackerModelHolder<>(List.of(), List.of(resolveRequest), List.of());
    List<IssueTrackerIssueResponseModel<T>> transitionedIssues;
    try {
        transitionedIssues = messageSender.sendMessages(resolveRequestModelHolder);
    } catch (IssueMissingTransitionException e) {
        MessageResult issueMissingResult = handleIssueMessingTransitionException(e);
        return Optional.of(issueMissingResult);
    } catch (AlertException e) {
        MessageResult alertExceptionResult = handleAlertException(e, operation);
        return Optional.of(alertExceptionResult);
    }
    int transitionedIssuesSize = transitionedIssues.size();
    if (transitionedIssuesSize != 1) {
        String errorMessage = String.format("Expected [1] issue to be transitioned, but there were actually [%d]", transitionedIssuesSize);
        return Optional.of(new MessageResult(errorMessage, fieldStatusCreator.createWithoutField(errorMessage)));
    }
    return Optional.empty();
}
Also used : IssueTransitionModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTransitionModel) IssueTrackerIssueResponseModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel) IssueTrackerModelHolder(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder) IssueMissingTransitionException(com.synopsys.integration.alert.common.channel.issuetracker.exception.IssueMissingTransitionException) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 2 with IssueTrackerIssueResponseModel

use of com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel in project hub-alert by blackducksoftware.

the class IssueTrackerIssueTransitionerTest method transitionIssueTest.

@Test
public void transitionIssueTest() throws AlertException {
    IssueOperation testOperation = IssueOperation.RESOLVE;
    ExistingIssueDetails<String> existingIssueDetails = new ExistingIssueDetails<>("id", "key", "title", "https://link", IssueStatus.UNKNOWN, IssueCategory.BOM);
    IssueTransitionModel<String> issueTransitionModel = new IssueTransitionModel<>(existingIssueDetails, testOperation, List.of("comment 1"), null);
    IssueTrackerCallbackInfoCreator callbackInfoCreator = new IssueTrackerCallbackInfoCreator();
    IssueTrackerIssueResponseCreator issueResponseCreator = new IssueTrackerIssueResponseCreator(callbackInfoCreator);
    IssueTrackerIssueTransitioner<String> transitioner = new TestTransitioner(commenter, issueResponseCreator, "TODO", true, false);
    Optional<IssueTrackerIssueResponseModel<String>> optionalResponseModel = transitioner.transitionIssue(issueTransitionModel);
    assertTrue(optionalResponseModel.isPresent(), "Expected response model to be present");
    IssueTrackerIssueResponseModel<String> responseModel = optionalResponseModel.get();
    assertEquals(existingIssueDetails.getIssueId(), responseModel.getIssueId());
    assertEquals(existingIssueDetails.getIssueKey(), responseModel.getIssueKey());
    assertEquals(existingIssueDetails.getIssueSummary(), responseModel.getIssueTitle());
    assertEquals(existingIssueDetails.getIssueUILink(), responseModel.getIssueLink());
    assertEquals(testOperation, responseModel.getIssueOperation());
}
Also used : IssueTrackerCallbackInfoCreator(com.synopsys.integration.alert.api.channel.issue.callback.IssueTrackerCallbackInfoCreator) IssueTransitionModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTransitionModel) IssueTrackerIssueResponseModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel) ExistingIssueDetails(com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails) IssueOperation(com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation) Test(org.junit.jupiter.api.Test)

Example 3 with IssueTrackerIssueResponseModel

use of com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel in project hub-alert by blackducksoftware.

the class IssueTrackerProcessor method processMessages.

public final IssueTrackerResponse<T> processMessages(ProviderMessageHolder messages, String jobName) throws AlertException {
    List<IssueTrackerIssueResponseModel<T>> issueResponseModels = new LinkedList<>();
    IssueTrackerModelHolder<T> simpleMessageHolder = modelExtractor.extractSimpleMessageIssueModels(messages.getSimpleMessages(), jobName);
    List<IssueTrackerIssueResponseModel<T>> simpleMessageResponseModels = messageSender.sendMessages(simpleMessageHolder);
    issueResponseModels.addAll(simpleMessageResponseModels);
    for (ProjectMessage projectMessage : messages.getProjectMessages()) {
        IssueTrackerModelHolder<T> projectMessageHolder = modelExtractor.extractProjectMessageIssueModels(projectMessage, jobName);
        List<IssueTrackerIssueResponseModel<T>> projectMessageResponseModels = messageSender.sendMessages(projectMessageHolder);
        issueResponseModels.addAll(projectMessageResponseModels);
    }
    return new IssueTrackerResponse<>("Success", issueResponseModels);
}
Also used : IssueTrackerIssueResponseModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) IssueTrackerResponse(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerResponse) LinkedList(java.util.LinkedList)

Example 4 with IssueTrackerIssueResponseModel

use of com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel in project hub-alert by blackducksoftware.

the class IssueTrackerIssueCreator method createIssueTrackerIssue.

/**
 * This method does three things:<br />
 * 1. Creates a new issue in an issue-tracker.<br />
 * 2. If applicable, Assigns "Alert Search Properties" so that Alert can find the issue in the future.<br />
 * 3. Adds comments to the issue with any additional contextual information that the issue requires.<br />
 * @param alertIssueCreationModel - A model containing common issue-tracker fields, post-create comments, and details about the source of the model.
 * @return {@link IssueTrackerIssueResponseModel}
 * @throws AlertException Thrown if there is a problem connecting to the issue-tracker or if the issue-tracker server responds with an error.
 */
public final IssueTrackerIssueResponseModel<T> createIssueTrackerIssue(IssueCreationModel alertIssueCreationModel) throws AlertException {
    ExistingIssueDetails<T> createdIssueDetails = createIssueAndExtractDetails(alertIssueCreationModel);
    logger.debug("Created new {} issue: {}", channelKey.getDisplayName(), createdIssueDetails);
    IssueTrackerCallbackInfo callbackInfo = null;
    Optional<ProjectIssueModel> optionalSource = alertIssueCreationModel.getSource();
    if (optionalSource.isPresent()) {
        ProjectIssueModel alertIssueSource = optionalSource.get();
        assignAlertSearchProperties(createdIssueDetails, alertIssueSource);
        callbackInfo = callbackInfoCreator.createCallbackInfo(alertIssueSource).orElse(null);
    }
    addPostCreateComments(createdIssueDetails, alertIssueCreationModel, optionalSource.orElse(null));
    return new IssueTrackerIssueResponseModel<>(createdIssueDetails.getIssueId(), createdIssueDetails.getIssueKey(), createdIssueDetails.getIssueUILink(), createdIssueDetails.getIssueSummary(), IssueOperation.OPEN, callbackInfo);
}
Also used : IssueTrackerIssueResponseModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel) IssueTrackerCallbackInfo(com.synopsys.integration.alert.common.channel.issuetracker.message.IssueTrackerCallbackInfo) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel)

Example 5 with IssueTrackerIssueResponseModel

use of com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel in project hub-alert by blackducksoftware.

the class IssueTrackerTestAction method testConfig.

@Override
public MessageResult testConfig(DistributionJobModel testJobModel, String jobName, @Nullable String customTopic, @Nullable String customMessage) throws AlertException {
    D distributionDetails = (D) testJobModel.getDistributionJobDetails();
    IssueTrackerMessageSender<T> messageSender = messageSenderFactory.createMessageSender(distributionDetails);
    String topicString = Optional.ofNullable(customTopic).orElse("Alert Test Topic");
    String messageString = Optional.ofNullable(customMessage).orElse("Alert Test Message");
    // TODO determine if source should be required everywhere
    ProjectIssueModel testProjectIssueModel = createPlaceholderProjectIssueModel(testJobModel.getBlackDuckGlobalConfigId());
    String postCreateComment = String.format("Created by [ Test Configuration ] in the Alert Distribution Job: %s", testJobModel.getName());
    IssueCreationModel creationRequest = IssueCreationModel.simple(topicString, messageString, List.of(postCreateComment), testProjectIssueModel.getProvider());
    IssueTrackerModelHolder<T> creationRequestModelHolder = new IssueTrackerModelHolder<>(List.of(creationRequest), List.of(), List.of());
    IssueTrackerTestActionFieldStatusCreator fieldStatusCreator = new IssueTrackerTestActionFieldStatusCreator();
    List<IssueTrackerIssueResponseModel<T>> createdIssues;
    try {
        createdIssues = messageSender.sendMessages(creationRequestModelHolder);
    } catch (AlertFieldException e) {
        logger.error("Failed to create test issue", e);
        return new MessageResult("Failed to create issue: " + e.getMessage(), e.getFieldErrors());
    } catch (AlertException e) {
        logger.error("Failed to create test issue", e);
        return new MessageResult("Failed to create issue: " + e.getMessage(), fieldStatusCreator.createWithoutField(e.getMessage()));
    }
    int createdIssuesSize = createdIssues.size();
    if (createdIssuesSize != 1) {
        String errorMessage = String.format("Expected [1] issue to be created, but there were actually [%d]", createdIssuesSize);
        return new MessageResult(errorMessage, fieldStatusCreator.createWithoutField(errorMessage));
    }
    IssueTrackerIssueResponseModel<T> createdIssue = createdIssues.get(0);
    ExistingIssueDetails<T> existingIssueDetails = new ExistingIssueDetails<>(createdIssue.getIssueId(), createdIssue.getIssueKey(), createdIssue.getIssueTitle(), createdIssue.getIssueLink(), IssueStatus.RESOLVABLE, IssueCategory.BOM);
    if (!hasResolveTransition(distributionDetails)) {
        return createSuccessMessageResult(existingIssueDetails);
    }
    IssueTrackerTransitionTestAction<T> transitionTestAction = new IssueTrackerTransitionTestAction<>(messageSender, fieldStatusCreator);
    Optional<MessageResult> optionalResolveFailure = transitionTestAction.transitionTestIssueOrReturnFailureResult(IssueOperation.RESOLVE, existingIssueDetails, testProjectIssueModel);
    if (optionalResolveFailure.isPresent()) {
        return optionalResolveFailure.get();
    }
    if (!hasReopenTransition(distributionDetails)) {
        return createSuccessMessageResult(existingIssueDetails);
    }
    return transitionTestAction.transitionTestIssueOrReturnFailureResult(IssueOperation.OPEN, existingIssueDetails, testProjectIssueModel).orElseGet(() -> transitionTestAction.transitionTestIssueOrReturnFailureResult(IssueOperation.RESOLVE, existingIssueDetails, testProjectIssueModel).orElse(createSuccessMessageResult(existingIssueDetails)));
}
Also used : IssueTrackerIssueResponseModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) AlertFieldException(com.synopsys.integration.alert.common.exception.AlertFieldException) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) IssueCreationModel(com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel) IssueTrackerModelHolder(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder) ExistingIssueDetails(com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

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