in plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/utils/CodeWhispererCodeScanIssueUtils.kt [81:185]
fun getCodeScanIssueDetailsHtml(
issue: CodeWhispererCodeScanIssue,
display: CodeScanIssueDetailsDisplayType,
fixGenerationState: CodeWhispererConstants.FixGenerationState = CodeWhispererConstants.FixGenerationState.COMPLETED,
isCopied: Boolean = false,
project: Project,
showReferenceWarning: Boolean? = false,
): String {
val suggestedFix = issue.suggestedFixes.firstOrNull()
val cweLinks = if (issue.relatedVulnerabilities.isNotEmpty()) {
issue.relatedVulnerabilities.joinToString(", ") { cwe ->
"<a href=\"https://cwe.mitre.org/data/definitions/${cwe.split("-").last()}.html\">$cwe</a>"
}
} else {
"-"
}
val projectRoot = project.basePath?.let { VirtualFileManager.getInstance().findFileByUrl(VfsUtilCore.pathToUrl(it)) } ?: project.guessProjectDir()
val filePathString = projectRoot?.let { VfsUtil.getRelativePath(issue.file, it) } ?: issue.file.path
val fileLink = "<a href=amazonq://issue/openFile-${issue.findingId}>${ filePathString } [Ln ${issue.startLine}]</a>"
val detectorLibraryLink = issue.recommendation.url?.let { "<a href=\"${issue.recommendation.url}\">${issue.detectorName}</a>" } ?: "-"
val detectorSection = """
<br />
<hr />
<table>
<thead>
<tr>
<th>${message("codewhisperer.codescan.cwe_label")}</th>
<th>${message("codewhisperer.codescan.detector_library_label")}</th>
</tr>
</thead>
<tbody>
<tr>
<td>$cweLinks</td>
<td>$detectorLibraryLink</td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th>${message("codewhisperer.codescan.file_path_label")}</th>
</tr>
</thead>
<tbody>
<tr>
<td>$fileLink</td>
</tr>
</tbody>
</table>
""".trimIndent()
val suggestedFixSection = if (showReferenceWarning == false) {
createSuggestedFixSection(issue, suggestedFix, isCopied)
} else {
"""
<div align="center" bgcolor="#2b2b2b" style="margin: 20px;">
Your settings do not allow code generation with references.
</div>
""".trimIndent()
}
val fixLoadingSection = """
<a name="fixLoadingSection"></a>
<div align="center" bgcolor="#2b2b2b" style="margin: 20px;">
<font size="7" color="#ffffff" face="Arial">
...
</font>
</div>
""".trimIndent()
val fixFailureSection = """
<a name="fixFailureSection"></a>
<div align="center" bgcolor="#2b2b2b" style="margin: 20px;">
<font size="4" color="#e6e6e6" face="Arial">
<br>Amazon Q failed to generate fix. Please try again<br>
</font>
</div>
""".trimIndent()
val commonContent = """
|${issue.recommendation.text}
|
|$detectorSection
|
|${when (fixGenerationState) {
CodeWhispererConstants.FixGenerationState.COMPLETED -> suggestedFixSection.orEmpty()
CodeWhispererConstants.FixGenerationState.GENERATING -> fixLoadingSection
CodeWhispererConstants.FixGenerationState.FAILED -> fixFailureSection
}}
""".trimMargin()
if (display == CodeScanIssueDetailsDisplayType.EditorPopup) {
return convertMarkdownToHTML(
"""
|$commonContent
""".trimMargin()
)
}
return convertMarkdownToHTML(commonContent)
}