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());
}
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);
}
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);
}
}
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());
}
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;
}
Aggregations