use of com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel in project hub-alert by blackducksoftware.
the class JiraCloudSummaryFieldLengthTestIT method summaryLength254SucceedsTest.
@Test
public void summaryLength254SucceedsTest() {
IssueCreationModel issueCreationModel = createIssueCreationModel(254);
IssueTrackerModelHolder<String> messages = new IssueTrackerModelHolder<>(List.of(issueCreationModel), List.of(), List.of());
try {
jiraCloudMessageSender.sendMessages(messages);
} catch (AlertException e) {
fail("Failed to send a message with a 254 character summary", e);
}
}
use of com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel in project hub-alert by blackducksoftware.
the class JiraCloudSummaryFieldLengthTestIT method summaryLength256FailsTest.
@Test
public void summaryLength256FailsTest() {
IssueCreationModel issueCreationModel = createIssueCreationModel(256);
IssueTrackerModelHolder<String> messages = new IssueTrackerModelHolder<>(List.of(issueCreationModel), List.of(), List.of());
try {
jiraCloudMessageSender.sendMessages(messages);
fail("Successfully sent a message with a 256 character summary which is greater than the expected maximum");
} catch (AlertException e) {
// Pass
e.printStackTrace();
}
}
use of com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel in project hub-alert by blackducksoftware.
the class JiraServerSummaryFieldLengthTestIT method summaryLength256FailsTest.
@Test
public void summaryLength256FailsTest() {
IssueCreationModel issueCreationModel = createIssueCreationModel(256);
IssueTrackerModelHolder<String> messages = new IssueTrackerModelHolder<>(List.of(issueCreationModel), List.of(), List.of());
try {
jiraServerMessageSender.sendMessages(messages);
fail("Successfully sent a message with a 256 character summary which is greater than the expected maximum");
} catch (AlertException e) {
// Pass
e.printStackTrace();
}
}
use of com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel in project hub-alert by blackducksoftware.
the class ProjectIssueModelConverter method toIssueCreationModel.
public IssueCreationModel toIssueCreationModel(ProjectIssueModel projectIssueModel, String jobName) {
String title = createTruncatedTitle(projectIssueModel);
ChunkedStringBuilder descriptionBuilder = new ChunkedStringBuilder(formatter.getMaxDescriptionLength());
String nonBreakingSpace = formatter.getNonBreakingSpace();
String jobLine = String.format("Job%sname:%s%s", nonBreakingSpace, nonBreakingSpace, jobName);
String formattedJobName = formatter.emphasize(jobLine);
descriptionBuilder.append(formattedJobName);
descriptionBuilder.append(formatter.getLineSeparator());
String projectString = linkableItemConverter.convertToString(projectIssueModel.getProject(), true);
descriptionBuilder.append(projectString);
descriptionBuilder.append(formatter.getLineSeparator());
LinkableItem projectVersion = projectIssueModel.getProjectVersion().orElse(MISSING_PROJECT_VERSION_PLACEHOLDER);
String projectVersionString = linkableItemConverter.convertToString(projectVersion, true);
descriptionBuilder.append(projectVersionString);
descriptionBuilder.append(formatter.getLineSeparator());
descriptionBuilder.append(formatter.getSectionSeparator());
descriptionBuilder.append(formatter.getLineSeparator());
IssueBomComponentDetails bomComponent = projectIssueModel.getBomComponentDetails();
List<String> bomComponentPieces = bomComponentDetailConverter.gatherAbstractBomComponentSectionPieces(bomComponent);
bomComponentPieces.forEach(descriptionBuilder::append);
createVulnerabilitySeverityStatusSectionPieces(projectIssueModel).forEach(descriptionBuilder::append);
descriptionBuilder.append(formatter.getLineSeparator());
createProjectIssueModelConcernSectionPieces(projectIssueModel, false).forEach(descriptionBuilder::append);
int newChunkSize = formatter.getMaxCommentLength() - DESCRIPTION_CONTINUED_TEXT.length() - formatter.getLineSeparator().length();
RechunkedModel rechunkedDescription = ChunkedStringBuilderRechunker.rechunk(descriptionBuilder, "No description", newChunkSize);
List<String> postCreateComments = rechunkedDescription.getRemainingChunks().stream().map(comment -> String.format("%s%s%s", DESCRIPTION_CONTINUED_TEXT, formatter.getLineSeparator(), comment)).collect(Collectors.toList());
return IssueCreationModel.project(title, rechunkedDescription.getFirstChunk(), postCreateComments, projectIssueModel);
}
use of com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel 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