use of com.synopsys.integration.alert.common.message.model.LinkableItem in project hub-alert by blackducksoftware.
the class ProjectIssueModelConverter method toIssueCommentModel.
public <T extends Serializable> IssueCommentModel<T> toIssueCommentModel(ExistingIssueDetails<T> existingIssueDetails, ProjectIssueModel projectIssueModel) {
ChunkedStringBuilder commentBuilder = new ChunkedStringBuilder(formatter.getMaxCommentLength());
LinkableItem provider = projectIssueModel.getProvider();
String commentHeader = String.format("The component was updated in %s[%s]", provider.getLabel(), provider.getValue());
commentBuilder.append(formatter.encode(commentHeader));
commentBuilder.append(formatter.getLineSeparator());
commentBuilder.append(formatter.getSectionSeparator());
commentBuilder.append(formatter.getLineSeparator());
createVulnerabilitySeverityStatusSectionPieces(projectIssueModel).forEach(commentBuilder::append);
createProjectIssueModelConcernSectionPieces(projectIssueModel, true).forEach(commentBuilder::append);
IssueBomComponentDetails bomComponent = projectIssueModel.getBomComponentDetails();
List<String> attributeStrings = bomComponentDetailConverter.gatherAttributeStrings(bomComponent);
for (String attributeString : attributeStrings) {
commentBuilder.append(formatter.getNonBreakingSpace());
commentBuilder.append(formatter.encode("-"));
commentBuilder.append(formatter.getNonBreakingSpace());
commentBuilder.append(attributeString);
commentBuilder.append(formatter.getLineSeparator());
}
List<String> chunkedComments = commentBuilder.collectCurrentChunks();
return new IssueCommentModel<>(existingIssueDetails, chunkedComments, projectIssueModel);
}
use of com.synopsys.integration.alert.common.message.model.LinkableItem in project hub-alert by blackducksoftware.
the class ProjectIssueModelConverter method createTruncatedTitle.
private String createTruncatedTitle(ProjectIssueModel projectIssueModel) {
LinkableItem provider = projectIssueModel.getProvider();
LinkableItem project = projectIssueModel.getProject();
LinkableItem projectVersion = projectIssueModel.getProjectVersion().orElse(MISSING_PROJECT_VERSION_PLACEHOLDER);
IssueBomComponentDetails bomComponent = projectIssueModel.getBomComponentDetails();
LinkableItem component = bomComponent.getComponent();
Optional<String> optionalComponentVersionValue = bomComponent.getComponentVersion().map(LinkableItem::getValue);
boolean isComponentVersionUnknown = projectIssueModel.getComponentUnknownVersionDetails().isPresent();
StringBuilder componentPieceBuilder = new StringBuilder();
componentPieceBuilder.append(component.getValue());
if (optionalComponentVersionValue.isPresent() && !isComponentVersionUnknown) {
componentPieceBuilder.append('[');
componentPieceBuilder.append(optionalComponentVersionValue.get());
componentPieceBuilder.append(']');
}
StringBuilder componentConcernPieceBuilder = new StringBuilder();
Optional<String> optionalPolicyName = projectIssueModel.getPolicyDetails().map(IssuePolicyDetails::getName);
if (optionalPolicyName.isPresent()) {
componentConcernPieceBuilder.append(COMMA_SPACE);
componentConcernPieceBuilder.append(ComponentConcernType.POLICY.getDisplayName());
componentConcernPieceBuilder.append('[');
componentConcernPieceBuilder.append(optionalPolicyName.get());
componentConcernPieceBuilder.append(']');
} else if (isComponentVersionUnknown) {
componentConcernPieceBuilder.append(COMMA_SPACE);
componentConcernPieceBuilder.append(ComponentConcernType.UNKNOWN_VERSION.getDisplayName());
} else {
componentConcernPieceBuilder.append(COMMA_SPACE);
componentConcernPieceBuilder.append(ComponentConcernType.VULNERABILITY.getDisplayName());
}
String componentConcernPiece = componentConcernPieceBuilder.toString();
String preConcernTitle = String.format("Alert - %s[%s], %s[%s], %s", provider.getLabel(), provider.getValue(), project.getValue(), projectVersion.getValue(), componentPieceBuilder);
if (preConcernTitle.length() + componentConcernPieceBuilder.length() > formatter.getMaxTitleLength()) {
if (formatter.getMaxTitleLength() > COMPONENT_CONCERN_TITLE_SECTION_CHAR_COUNT) {
preConcernTitle = StringUtils.truncate(preConcernTitle, formatter.getMaxTitleLength() - COMPONENT_CONCERN_TITLE_SECTION_CHAR_COUNT);
componentConcernPiece = StringUtils.truncate(componentConcernPieceBuilder.toString(), COMPONENT_CONCERN_TITLE_SECTION_CHAR_COUNT);
} else {
// If max title length is less than 3, then there are bigger concerns than an IllegalArgumentException
preConcernTitle = StringUtils.truncate(preConcernTitle, formatter.getMaxTitleLength() - 3);
componentConcernPiece = "...";
}
}
return preConcernTitle + componentConcernPiece;
}
use of com.synopsys.integration.alert.common.message.model.LinkableItem 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.common.message.model.LinkableItem in project hub-alert by blackducksoftware.
the class IssueTrackerTestAction method createPlaceholderProjectIssueModel.
private ProjectIssueModel createPlaceholderProjectIssueModel(Long blackDuckConfigId) {
LinkableItem providerItem = new LinkableItem("Provider Test Label", "Provider Config Test Name");
ProviderDetails providerDetails = new ProviderDetails(blackDuckConfigId, providerItem);
LinkableItem projectItem = new LinkableItem("Project Test Label", "Project Test Name");
LinkableItem projectVersionItem = new LinkableItem("Project-Version Test Label", "Project-Version Test Name");
LinkableItem componentItem = new LinkableItem("Component Test Label", "Component Test Value");
IssueBomComponentDetails bomComponentDetails = IssueBomComponentDetails.fromSearchResults(componentItem, null);
return ProjectIssueModel.bom(providerDetails, projectItem, projectVersionItem, bomComponentDetails);
}
use of com.synopsys.integration.alert.common.message.model.LinkableItem in project hub-alert by blackducksoftware.
the class BomComponentDetailConverterTest method createComponentVulnerabilities.
private static ComponentVulnerabilities createComponentVulnerabilities() {
LinkableItem vulnerability1 = creatVulnerabilityLinkableItem("CVE-001");
LinkableItem vulnerability2 = creatVulnerabilityLinkableItem("CVE-002");
LinkableItem vulnerability3 = creatVulnerabilityLinkableItem("CVE-003");
LinkableItem vulnerability4 = creatVulnerabilityLinkableItem("CVE-004");
LinkableItem vulnerability5 = creatVulnerabilityLinkableItem("CVE-005");
LinkableItem vulnerability6 = creatVulnerabilityLinkableItem("CVE-006");
return new ComponentVulnerabilities(List.of(), List.of(vulnerability1), List.of(vulnerability2, vulnerability3), List.of(vulnerability4, vulnerability5, vulnerability6));
}
Aggregations