use of com.synopsys.integration.alert.api.channel.issue.model.IssueTransitionModel 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();
}
use of com.synopsys.integration.alert.api.channel.issue.model.IssueTransitionModel 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.api.channel.issue.model.IssueTransitionModel 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.api.channel.issue.model.IssueTransitionModel 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.api.channel.issue.model.IssueTransitionModel 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());
}
Aggregations