Skip to content

Commit

Permalink
Bug fix for listCodeScanFindings request by adding nextToken object f… (
Browse files Browse the repository at this point in the history
#4429)

* Bug fix for listCodeScanFindings request by adding nextToken object for pagination.

* Update .changes/next-release/bugfix-c8f493ab-c035-4df4-b46d-4ffcec8c4cbd.json

Co-authored-by: Richard Li <742829+rli@users.noreply.github.com>

---------

Co-authored-by: Richard Li <742829+rli@users.noreply.github.com>
  • Loading branch information
ashishrp-aws and rli committed May 3, 2024
1 parent e060c57 commit a26137f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type" : "bugfix",
"description" : "Amazon Q: Fix issue where items listed by Amazon Q Code Scan were duplicated or missing"
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class CodeWhispererCodeScanSession(val sessionContext: CodeScanSessionContext) {

// 6. Return the results from the ListCodeScan API.
currentCoroutineContext.ensureActive()
var listCodeScanFindingsResponse = listCodeScanFindings(jobId)
var listCodeScanFindingsResponse = listCodeScanFindings(jobId, null)
val serviceInvocationDuration = now() - serviceInvocationStartTime
codeScanResponseContext = codeScanResponseContext.copy(
serviceInvocationContext = codeScanResponseContext.serviceInvocationContext.copy(serviceInvocationDuration = serviceInvocationDuration)
Expand All @@ -198,10 +198,10 @@ class CodeWhispererCodeScanSession(val sessionContext: CodeScanSessionContext) {
val documents = mutableListOf<String>()
documents.add(listCodeScanFindingsResponse.codeScanFindings())
// coroutineContext helps to actively cancel the bigger projects quickly
withContext(coroutineContext) {
while (listCodeScanFindingsResponse.nextToken() != null && coroutineContext.isActive) {
withContext(currentCoroutineContext) {
while (listCodeScanFindingsResponse.nextToken() != null && currentCoroutineContext.isActive) {
listCodeScanFindingsResponse = listCodeScanFindings(jobId, listCodeScanFindingsResponse.nextToken())
documents.add(listCodeScanFindingsResponse.codeScanFindings())
listCodeScanFindingsResponse = listCodeScanFindings(jobId)
}
}

Expand Down Expand Up @@ -335,11 +335,12 @@ class CodeWhispererCodeScanSession(val sessionContext: CodeScanSessionContext) {
throw e
}

fun listCodeScanFindings(jobId: String): ListCodeScanFindingsResponse = try {
fun listCodeScanFindings(jobId: String, nextToken: String?): ListCodeScanFindingsResponse = try {
clientAdaptor.listCodeScanFindings(
ListCodeScanFindingsRequest.builder()
.jobId(jobId)
.codeScanFindingsSchema(CodeScanFindingsSchema.CODESCAN_FINDINGS_1_0)
.nextToken(nextToken)
.build()
)
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class CodeWhispererCodeFileScanTest : CodeWhispererCodeScanTestBase(PythonCodeIn
inOrder.verify(codeScanSessionSpy, Times(1)).createUploadUrlAndUpload(eq(file), eq("SourceCode"), anyString())
inOrder.verify(codeScanSessionSpy, Times(1)).createCodeScan(eq(CodewhispererLanguage.Python.toString()), anyString())
inOrder.verify(codeScanSessionSpy, Times(1)).getCodeScan(any())
inOrder.verify(codeScanSessionSpy, Times(1)).listCodeScanFindings(eq("jobId"))
inOrder.verify(codeScanSessionSpy, Times(1)).listCodeScanFindings(eq("jobId"), eq(null))
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class CodeWhispererCodeScanTest : CodeWhispererCodeScanTestBase(PythonCodeInsigh
inOrder.verify(codeScanSessionSpy, Times(1)).createUploadUrlAndUpload(eq(file), eq("SourceCode"), anyString())
inOrder.verify(codeScanSessionSpy, Times(1)).createCodeScan(eq(CodewhispererLanguage.Python.toString()), anyString())
inOrder.verify(codeScanSessionSpy, Times(1)).getCodeScan(any())
inOrder.verify(codeScanSessionSpy, Times(1)).listCodeScanFindings(eq("jobId"))
inOrder.verify(codeScanSessionSpy, Times(1)).listCodeScanFindings(eq("jobId"), eq(null))
}

@Test
Expand Down

0 comments on commit a26137f

Please sign in to comment.