Search in sources :

Example 1 with IssueOperation

use of com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation 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 2 with IssueOperation

use of com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation in project hub-alert by blackducksoftware.

the class ProjectIssueModelConverter method toIssueTransitionModel.

public <T extends Serializable> IssueTransitionModel<T> toIssueTransitionModel(ExistingIssueDetails<T> existingIssueDetails, ProjectIssueModel projectIssueModel, ItemOperation requiredOperation) {
    IssueOperation issueOperation;
    if (ItemOperation.ADD.equals(requiredOperation)) {
        issueOperation = IssueOperation.OPEN;
    } else {
        issueOperation = IssueOperation.RESOLVE;
    }
    IssueCommentModel<T> commentModel = toIssueCommentModel(existingIssueDetails, projectIssueModel);
    List<String> transitionComments = new LinkedList<>(commentModel.getComments());
    LinkableItem provider = projectIssueModel.getProvider();
    ChunkedStringBuilder commentBuilder = new ChunkedStringBuilder(formatter.getMaxCommentLength());
    commentBuilder.append(String.format("The %s operation was performed on this component in %s.", requiredOperation.name(), provider.getLabel()));
    transitionComments.addAll(commentBuilder.collectCurrentChunks());
    return new IssueTransitionModel<>(existingIssueDetails, issueOperation, transitionComments, projectIssueModel);
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) IssueTransitionModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTransitionModel) ChunkedStringBuilder(com.synopsys.integration.alert.common.channel.message.ChunkedStringBuilder) IssueOperation(com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation) LinkedList(java.util.LinkedList)

Example 3 with IssueOperation

use of com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation in project hub-alert by blackducksoftware.

the class IssueTrackerIssueTransitionerTest method transitionIssueThrowsExceptionTest.

@Test
public void transitionIssueThrowsExceptionTest() throws AlertException {
    IssueOperation testOperation = IssueOperation.RESOLVE;
    IssueTransitionModel<String> issueTransitionModel = new IssueTransitionModel<>(null, testOperation, List.of("comment 1"), null);
    IssueTrackerCallbackInfoCreator callbackInfoCreator = new IssueTrackerCallbackInfoCreator();
    IssueTrackerIssueResponseCreator issueResponseCreator = new IssueTrackerIssueResponseCreator(callbackInfoCreator);
    IssueTrackerIssueCommenter<String> exceptionThrowingCommenter = Mockito.mock(IssueTrackerIssueCommenter.class);
    Mockito.when(exceptionThrowingCommenter.commentOnIssue(Mockito.any())).thenThrow(new AlertException("Test exception"));
    IssueTrackerIssueTransitioner<String> transitioner = new TestTransitioner(exceptionThrowingCommenter, issueResponseCreator, "TODO", true, true);
    try {
        transitioner.transitionIssue(issueTransitionModel);
        fail("Expected an exception to be thrown");
    } catch (IssueMissingTransitionException e) {
        assertEquals(TEST_EXCEPTION, e);
    }
}
Also used : IssueTrackerCallbackInfoCreator(com.synopsys.integration.alert.api.channel.issue.callback.IssueTrackerCallbackInfoCreator) IssueTransitionModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTransitionModel) IssueMissingTransitionException(com.synopsys.integration.alert.common.channel.issuetracker.exception.IssueMissingTransitionException) IssueOperation(com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Test(org.junit.jupiter.api.Test)

Example 4 with IssueOperation

use of com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation in project hub-alert by blackducksoftware.

the class IssueTrackerModelExtractorTest method extractProjectMessageIssueModelsTransitionTest.

@Test
public void extractProjectMessageIssueModelsTransitionTest() throws AlertException {
    ItemOperation itemOperation = ItemOperation.DELETE;
    IssueOperation issueOperation = IssueOperation.RESOLVE;
    ProjectMessage projectMessage = Mockito.mock(ProjectMessage.class);
    ExistingIssueDetails<String> existingIssueDetails = new ExistingIssueDetails<>("issue-id", "issue-key", "issue summary", "https://ui-link", IssueStatus.UNKNOWN, IssueCategory.POLICY);
    IssuePolicyDetails policyDetails = new IssuePolicyDetails("A policy", itemOperation, ComponentConcernSeverity.UNSPECIFIED_UNKNOWN);
    ProjectIssueModel projectIssueModel = ProjectIssueModel.policy(PROVIDER_DETAILS, PROJECT, PROJECT_VERSION, ISSUE_BOM_COMPONENT_DETAILS, policyDetails);
    ActionableIssueSearchResult<String> searchResult = new ActionableIssueSearchResult<>(existingIssueDetails, projectIssueModel, itemOperation);
    MockIssueTrackerMessageFormatter formatter = MockIssueTrackerMessageFormatter.withIntegerMaxValueLength();
    IssueTrackerSearcher<String> searcher = Mockito.mock(IssueTrackerSearcher.class);
    Mockito.when(searcher.findIssues(Mockito.eq(projectMessage))).thenReturn(List.of(searchResult));
    IssueTrackerModelExtractor<String> extractor = new IssueTrackerModelExtractor<>(formatter, searcher);
    IssueTrackerModelHolder<String> modelHolder = extractor.extractProjectMessageIssueModels(projectMessage, "jobName");
    List<IssueTransitionModel<String>> issueTransitionModels = modelHolder.getIssueTransitionModels();
    assertEquals(0, modelHolder.getIssueCreationModels().size());
    assertEquals(1, issueTransitionModels.size());
    assertEquals(0, modelHolder.getIssueCommentModels().size());
    IssueTransitionModel<String> transitionModel = issueTransitionModels.get(0);
    assertEquals(issueOperation, transitionModel.getIssueOperation());
}
Also used : IssueTransitionModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTransitionModel) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) MockIssueTrackerMessageFormatter(com.synopsys.integration.alert.api.channel.issue.convert.mock.MockIssueTrackerMessageFormatter) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) ActionableIssueSearchResult(com.synopsys.integration.alert.api.channel.issue.search.ActionableIssueSearchResult) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) ExistingIssueDetails(com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails) ItemOperation(com.synopsys.integration.alert.common.enumeration.ItemOperation) IssueOperation(com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation) Test(org.junit.jupiter.api.Test)

Example 5 with IssueOperation

use of com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation 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)

Aggregations

IssueOperation (com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation)6 IssueTransitionModel (com.synopsys.integration.alert.api.channel.issue.model.IssueTransitionModel)4 Test (org.junit.jupiter.api.Test)3 IssueTrackerCallbackInfoCreator (com.synopsys.integration.alert.api.channel.issue.callback.IssueTrackerCallbackInfoCreator)2 IssueTrackerIssueResponseModel (com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel)2 ExistingIssueDetails (com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails)2 MockIssueTrackerMessageFormatter (com.synopsys.integration.alert.api.channel.issue.convert.mock.MockIssueTrackerMessageFormatter)1 IssueCommentModel (com.synopsys.integration.alert.api.channel.issue.model.IssueCommentModel)1 IssuePolicyDetails (com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails)1 ProjectIssueModel (com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel)1 ActionableIssueSearchResult (com.synopsys.integration.alert.api.channel.issue.search.ActionableIssueSearchResult)1 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)1 IssueMissingTransitionException (com.synopsys.integration.alert.common.channel.issuetracker.exception.IssueMissingTransitionException)1 ChunkedStringBuilder (com.synopsys.integration.alert.common.channel.message.ChunkedStringBuilder)1 ItemOperation (com.synopsys.integration.alert.common.enumeration.ItemOperation)1 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)1 ProjectMessage (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage)1 LinkedList (java.util.LinkedList)1