use of com.synopsys.integration.alert.api.channel.jira.distribution.custom.MessageReplacementValues in project hub-alert by blackducksoftware.
the class JiraIssueCreator method createCustomFieldReplacementValues.
protected MessageReplacementValues createCustomFieldReplacementValues(ProjectIssueModel alertIssueSource) {
IssueBomComponentDetails bomComponent = alertIssueSource.getBomComponentDetails();
ComponentUpgradeGuidance upgradeGuidance = bomComponent.getComponentUpgradeGuidance();
Optional<String> severity = Optional.empty();
Optional<String> policyCategory = Optional.empty();
Optional<IssuePolicyDetails> issuePolicyDetails = alertIssueSource.getPolicyDetails();
Optional<IssueVulnerabilityDetails> vulnerabilityDetails = alertIssueSource.getVulnerabilityDetails();
if (issuePolicyDetails.isPresent()) {
IssuePolicyDetails policyDetails = issuePolicyDetails.get();
severity = Optional.ofNullable(policyDetails.getSeverity().getPolicyLabel());
policyCategory = bomComponent.getRelevantPolicies().stream().filter(policy -> policyDetails.getName().equals(policy.getPolicyName())).findAny().flatMap(ComponentPolicy::getCategory);
}
if (vulnerabilityDetails.isPresent()) {
severity = vulnerabilityDetails.get().getHighestSeverityAddedOrUpdated();
}
return new MessageReplacementValues.Builder(alertIssueSource.getProvider().getLabel(), alertIssueSource.getProject().getValue()).projectVersionName(alertIssueSource.getProjectVersion().map(LinkableItem::getValue).orElse(MessageReplacementValues.DEFAULT_NOTIFICATION_REPLACEMENT_VALUE)).componentName(bomComponent.getComponent().getValue()).componentVersionName(bomComponent.getComponentVersion().map(LinkableItem::getValue).orElse(MessageReplacementValues.DEFAULT_NOTIFICATION_REPLACEMENT_VALUE)).componentUsage(bomComponent.getUsage()).componentLicense(bomComponent.getLicense().getValue()).severity(severity.orElse(MessageReplacementValues.DEFAULT_NOTIFICATION_REPLACEMENT_VALUE)).policyCategory(policyCategory.orElse(MessageReplacementValues.DEFAULT_NOTIFICATION_REPLACEMENT_VALUE)).shortTermUpgradeGuidance(upgradeGuidance.getShortTermUpgradeGuidance().map(LinkableItem::getValue).orElse(MessageReplacementValues.DEFAULT_NOTIFICATION_REPLACEMENT_VALUE)).longTermUpgradeGuidance(upgradeGuidance.getLongTermUpgradeGuidance().map(LinkableItem::getValue).orElse(MessageReplacementValues.DEFAULT_NOTIFICATION_REPLACEMENT_VALUE)).build();
}
use of com.synopsys.integration.alert.api.channel.jira.distribution.custom.MessageReplacementValues in project hub-alert by blackducksoftware.
the class JiraCloudIssueCreatorTest method verifySummaryReplacingValues.
@Test
public void verifySummaryReplacingValues() throws IntegrationException {
String projectNameOrKey = "FakeProject";
JiraCloudJobDetailsModel jiraCloudJobDetailsModel = new JiraCloudJobDetailsModel(UUID.randomUUID(), false, "my@email.com", projectNameOrKey, "Task", null, null, List.of(), "testSummary {{providerName}}");
TestJiraCloudIssueCreator jiraCloudIssueCreator = createTestJiraCloudIssueCreator(projectNameOrKey, jiraCloudJobDetailsModel);
IssueCreationModel issueCreationModel = createIssueCreationModel();
String testProviderName = "providerName";
MessageReplacementValues messageReplacementValues = new MessageReplacementValues.Builder(testProviderName, "projectName").projectVersionName("projectVersionName").componentName("componentName").componentVersionName("componentVersionName").severity("severity").policyCategory("UNCATEGORIZED").build();
IssueCreationRequestModel issueCreationRequest = jiraCloudIssueCreator.createIssueCreationRequest(issueCreationModel, messageReplacementValues);
String summaryText = getSummary(issueCreationRequest);
assertEquals("testSummary " + testProviderName, summaryText);
}
use of com.synopsys.integration.alert.api.channel.jira.distribution.custom.MessageReplacementValues in project hub-alert by blackducksoftware.
the class JiraCloudIssueCreatorTest method verifyIssueSummaryReplacement.
@Test
public void verifyIssueSummaryReplacement() throws IntegrationException {
String testSummary = "testSummary";
String projectNameOrKey = "FakeProject";
JiraCloudJobDetailsModel jiraCloudJobDetailsModel = new JiraCloudJobDetailsModel(UUID.randomUUID(), false, "my@email.com", projectNameOrKey, "Task", null, null, List.of(), testSummary);
TestJiraCloudIssueCreator jiraCloudIssueCreator = createTestJiraCloudIssueCreator(projectNameOrKey, jiraCloudJobDetailsModel);
IssueCreationModel issueCreationModel = createIssueCreationModel();
MessageReplacementValues messageReplacementValues = new MessageReplacementValues.Builder("providerName", "projectName").projectVersionName("projectVersionName").componentName("componentName").componentVersionName("componentVersionName").severity("severity").policyCategory("UNCATEGORIZED").build();
IssueCreationRequestModel issueCreationRequest = jiraCloudIssueCreator.createIssueCreationRequest(issueCreationModel, messageReplacementValues);
String summaryText = getSummary(issueCreationRequest);
assertEquals(testSummary, summaryText);
}
use of com.synopsys.integration.alert.api.channel.jira.distribution.custom.MessageReplacementValues in project hub-alert by blackducksoftware.
the class JiraIssueCreator method createIssueAndExtractDetails.
@Override
protected final ExistingIssueDetails<String> createIssueAndExtractDetails(IssueCreationModel alertIssueCreationModel) throws AlertException {
MessageReplacementValues replacementValues = alertIssueCreationModel.getSource().map(this::createCustomFieldReplacementValues).orElse(new MessageReplacementValues.Builder(alertIssueCreationModel.getProvider().getLabel(), MessageReplacementValues.DEFAULT_NOTIFICATION_REPLACEMENT_VALUE).build());
T creationRequest = createIssueCreationRequest(alertIssueCreationModel, replacementValues);
try {
IssueCreationResponseModel issueCreationResponseModel = createIssue(creationRequest);
IssueResponseModel createdIssue = fetchIssue(issueCreationResponseModel.getKey());
IssueFieldsComponent createdIssueFields = createdIssue.getFields();
String issueUILink = JiraCallbackUtils.createUILink(createdIssue);
IssueCategory issueCategory = alertIssueCreationModel.getSource().map(issueCategoryRetriever::retrieveIssueCategoryFromProjectIssueModel).orElse(IssueCategory.BOM);
return new ExistingIssueDetails<>(createdIssue.getId(), createdIssue.getKey(), createdIssueFields.getSummary(), issueUILink, IssueStatus.RESOLVABLE, issueCategory);
} catch (IntegrationRestException restException) {
throw jiraErrorMessageUtility.improveRestException(restException, issueCreatorDescriptorKey, extractReporter(creationRequest));
} catch (JiraPreconditionNotMetException jiraException) {
String message = StringUtils.join(FAILED_TO_CREATE_ISSUE_MESSAGE, jiraException.getMessage(), " ");
throw new AlertException(message, jiraException);
} catch (IntegrationException intException) {
throw new AlertException(FAILED_TO_CREATE_ISSUE_MESSAGE, intException);
}
}
Aggregations