Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ mockitoKotlin = "5.4.0"
mockk = "1.13.10"
nimbus-jose-jwt = "9.40"
node-gradle = "7.0.2"
telemetryGenerator = "1.0.293"
telemetryGenerator = "1.0.295"
testLogger = "4.0.0"
testRetry = "1.5.10"
# test-only; platform provides slf4j transitively at runtime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,13 @@ internal class CodeWhispererCodeScanIssueDetailsPanel(
if (suggestedFix.code.isNotBlank()) {
sendCodeFixGeneratedTelemetryToServiceAPI(issue, false)
}
CodeWhispererTelemetryService.getInstance().sendCodeScanIssueGenerateFix(Component.Webview, issue, isRegenerate, MetricResult.Succeeded)
CodeWhispererTelemetryService.getInstance().sendCodeScanIssueGenerateFix(
Component.Webview,
issue,
isRegenerate,
MetricResult.Succeeded,
includesFix = suggestedFix.code.isNotBlank()
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,8 @@ data class CodeWhispererCodeScanIssue(
val isInvalid: Boolean = false,
var rangeHighlighter: RangeHighlighterEx? = null,
var isVisible: Boolean = true,
val autoDetected: Boolean = false,
val scanJobId: String,
) {
override fun toString(): String = title

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class CodeWhispererCodeScanSession(val sessionContext: CodeScanSessionContext) {
LOG.debug { "Rendering response to display code review results." }
}
currentCoroutineContext.ensureActive()
val issues = mapToCodeScanIssues(documents, sessionContext.project).filter { it.isVisible }
val issues = mapToCodeScanIssues(documents, sessionContext.project, jobId).filter { it.isVisible }
codeScanResponseContext = codeScanResponseContext.copy(codeScanTotalIssues = issues.count())
codeScanResponseContext = codeScanResponseContext.copy(codeScanIssuesWithFixes = issues.count { it.suggestedFixes.isNotEmpty() })
codeScanResponseContext = codeScanResponseContext.copy(reason = "Succeeded")
Expand Down Expand Up @@ -304,7 +304,7 @@ class CodeWhispererCodeScanSession(val sessionContext: CodeScanSessionContext) {
throw codeScanServerException("ListCodeReviewFindingsException: $errorMessage")
}

fun mapToCodeScanIssues(recommendations: List<String>, project: Project): List<CodeWhispererCodeScanIssue> {
fun mapToCodeScanIssues(recommendations: List<String>, project: Project, jobId: String): List<CodeWhispererCodeScanIssue> {
val scanRecommendations = recommendations.flatMap { MAPPER.readValue<List<CodeScanRecommendation>>(it) }
if (isProjectScope()) {
LOG.debug { "Total code review issues returned from service: ${scanRecommendations.size}" }
Expand Down Expand Up @@ -347,6 +347,8 @@ class CodeWhispererCodeScanSession(val sessionContext: CodeScanSessionContext) {
suggestedFixes = recommendation.remediation.suggestedFixes,
codeSnippet = recommendation.codeSnippet,
isVisible = !isIssueIgnored,
autoDetected = isAutoScan(),
scanJobId = jobId
)
}
} else {
Expand All @@ -362,6 +364,9 @@ class CodeWhispererCodeScanSession(val sessionContext: CodeScanSessionContext) {

private fun isProjectScope(): Boolean = sessionContext.codeAnalysisScope == CodeWhispererConstants.CodeAnalysisScope.PROJECT

private fun isAutoScan(): Boolean =
sessionContext.codeAnalysisScope == CodeWhispererConstants.CodeAnalysisScope.FILE && !sessionContext.sessionConfig.isInitiatedByChat()

companion object {
private val LOG = getLogger<CodeWhispererCodeScanSession>()
private val MAPPER = jacksonObjectMapper()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,9 @@ class CodeWhispererTelemetryService {
result = result,
reason = reason,
credentialStartUrl = getCodeWhispererStartUrl(issue.project),
codeFixAction = codeFixAction
codeFixAction = codeFixAction,
autoDetected = issue.autoDetected,
codewhispererCodeScanJobId = issue.scanJobId
)
}

Expand Down Expand Up @@ -402,6 +404,7 @@ class CodeWhispererTelemetryService {
isRefresh: Boolean,
result: MetricResult,
reason: String? = null,
includesFix: Boolean? = false,
) {
CodewhispererTelemetry.codeScanIssueGenerateFix(
component = component,
Expand All @@ -411,7 +414,10 @@ class CodeWhispererTelemetryService {
ruleId = issue.ruleId,
variant = if (isRefresh) "refresh" else null,
result = result,
reason = reason
reason = reason,
autoDetected = issue.autoDetected,
codewhispererCodeScanJobId = issue.scanJobId,
includesFix = includesFix
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ class CodeWhispererCodeFileScanTest : CodeWhispererCodeScanTestBase(PythonCodeIn
fakeListCodeScanFindingsResponse.codeScanFindings(),
getFakeRecommendationsOnNonExistentFile()
)
val res = codeScanSessionSpy.mapToCodeScanIssues(recommendations, project)
val res = codeScanSessionSpy.mapToCodeScanIssues(recommendations, project, "jobId")
assertThat(res).hasSize(2)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class CodeWhispererCodeScanTest : CodeWhispererCodeScanTestBase(PythonCodeInsigh
fakeListCodeScanFindingsResponse.codeScanFindings(),
getFakeRecommendationsOnNonExistentFile()
)
val res = codeScanSessionSpy.mapToCodeScanIssues(recommendations, project)
val res = codeScanSessionSpy.mapToCodeScanIssues(recommendations, project, "jobId")
assertThat(res).hasSize(2)
}

Expand All @@ -169,7 +169,7 @@ class CodeWhispererCodeScanTest : CodeWhispererCodeScanTestBase(PythonCodeInsigh
val recommendations = listOf(
fakeListCodeScanFindingsOutOfBoundsIndexResponse.codeScanFindings(),
)
val res = codeScanSessionSpy.mapToCodeScanIssues(recommendations, project)
val res = codeScanSessionSpy.mapToCodeScanIssues(recommendations, project, "jobId")
assertThat(res).hasSize(1)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,8 @@ open class CodeWhispererCodeScanTestBase(projectRule: CodeInsightTestFixtureRule
number = 11,
content = "processData(unsecureCode)"
)
)
),
scanJobId = "scanJobId"
)

// You might need these data classes depending on your implementation
Expand Down
Loading