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