Skip to content

Commit e4b6f0f

Browse files
fix(amazonq): Fix for File Review payload and payload generation error for test and review (#5166)
* Fix for code diff for file review to include only file path and gitignore regex pattern error handling. * Addition of changelog * Fix to simplify try and catch block. --------- Co-authored-by: Laxman Reddy <[email protected]>
1 parent 69f79b1 commit e4b6f0f

File tree

3 files changed

+23
-34
lines changed

3 files changed

+23
-34
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type" : "bugfix",
3+
"description" : "Fix for File Review payload and Regex error for payload generation"
4+
}

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/sessionconfig/CodeScanSessionConfig.kt

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import software.aws.toolkits.jetbrains.services.codewhisperer.codescan.cannotFin
2525
import software.aws.toolkits.jetbrains.services.codewhisperer.codescan.fileTooLarge
2626
import software.aws.toolkits.jetbrains.services.codewhisperer.codescan.noFileOpenError
2727
import software.aws.toolkits.jetbrains.services.codewhisperer.codescan.noSupportedFilesError
28-
import software.aws.toolkits.jetbrains.services.codewhisperer.codescan.utils.AmazonQCodeReviewGitUtils.getGitRepositoryRoot
2928
import software.aws.toolkits.jetbrains.services.codewhisperer.codescan.utils.AmazonQCodeReviewGitUtils.getUnstagedFiles
3029
import software.aws.toolkits.jetbrains.services.codewhisperer.codescan.utils.AmazonQCodeReviewGitUtils.isGitRoot
3130
import software.aws.toolkits.jetbrains.services.codewhisperer.codescan.utils.AmazonQCodeReviewGitUtils.runGitDiffHead
@@ -163,40 +162,17 @@ class CodeScanSessionConfig(
163162
return ""
164163
}
165164
try {
166-
getGitRepositoryRoot(file)?.let { root ->
167-
// If it's a git repo, use git logic
168-
val relativePath = runCatching {
169-
file.toNioPath().relativeTo(root.toNioPath()).pathString
170-
}.getOrElse {
171-
LOG.debug { "Failed to calculate relative path: ${it.message}" }
172-
return ""
173-
}
174-
175-
return runGitDiffHead(
176-
projectName = project.name,
177-
root = root,
178-
relativeFilePath = relativePath,
179-
newFile = true
180-
)
181-
} ?: run {
182-
// For non-git repos, use project root as base
183-
val projectRootPath = projectRoot.toNioPath()
184-
val relativePath = runCatching {
185-
file.toNioPath().relativeTo(projectRootPath).pathString
186-
}.getOrElse {
187-
LOG.debug { "Failed to calculate relative path from project root: ${it.message}" }
188-
return ""
189-
}
190-
191-
return runGitDiffHead(
192-
projectName = project.name,
193-
root = projectRoot,
194-
relativeFilePath = relativePath,
195-
newFile = true // Always treat as new file for non-git repos
196-
)
165+
val projectRootNio = projectRoot.toNioPath()
166+
val fileNio = file.toNioPath()
167+
168+
return buildString {
169+
append("+++ b/")
170+
append(project.name)
171+
append('/')
172+
append(fileNio.relativeTo(projectRootNio).pathString)
197173
}
198174
} catch (e: Exception) {
199-
LOG.debug { "Failed to create git diff: ${e.message}" }
175+
LOG.debug(e) { "Failed to create git diff" }
200176
return ""
201177
}
202178
}

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/FeatureDevSessionContext.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,16 @@ class FeatureDevSessionContext(val project: Project, val maxProjectSizeBytes: Lo
8383
private val gitIgnoreFile = File(selectedSourceFolder.path, ".gitignore")
8484

8585
init {
86-
ignorePatternsWithGitIgnore = (ignorePatterns + parseGitIgnore().map { Regex(it) }).toList()
86+
ignorePatternsWithGitIgnore = try {
87+
buildList {
88+
addAll(ignorePatterns)
89+
parseGitIgnore().mapNotNull { pattern ->
90+
runCatching { Regex(pattern) }.getOrNull()
91+
}.let { addAll(it) }
92+
}
93+
} catch (e: Exception) {
94+
emptyList()
95+
}
8796
}
8897

8998
fun getProjectZip(): ZipCreationResult {

0 commit comments

Comments
 (0)