Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type" : "bugfix",
"description" : "Fix for File Review payload and Regex error for payload generation"
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import software.aws.toolkits.jetbrains.services.codewhisperer.codescan.cannotFin
import software.aws.toolkits.jetbrains.services.codewhisperer.codescan.fileTooLarge
import software.aws.toolkits.jetbrains.services.codewhisperer.codescan.noFileOpenError
import software.aws.toolkits.jetbrains.services.codewhisperer.codescan.noSupportedFilesError
import software.aws.toolkits.jetbrains.services.codewhisperer.codescan.utils.AmazonQCodeReviewGitUtils.getGitRepositoryRoot
import software.aws.toolkits.jetbrains.services.codewhisperer.codescan.utils.AmazonQCodeReviewGitUtils.getUnstagedFiles
import software.aws.toolkits.jetbrains.services.codewhisperer.codescan.utils.AmazonQCodeReviewGitUtils.isGitRoot
import software.aws.toolkits.jetbrains.services.codewhisperer.codescan.utils.AmazonQCodeReviewGitUtils.runGitDiffHead
Expand Down Expand Up @@ -163,40 +162,17 @@ class CodeScanSessionConfig(
return ""
}
try {
getGitRepositoryRoot(file)?.let { root ->
// If it's a git repo, use git logic
val relativePath = runCatching {
file.toNioPath().relativeTo(root.toNioPath()).pathString
}.getOrElse {
LOG.debug { "Failed to calculate relative path: ${it.message}" }
return ""
}

return runGitDiffHead(
projectName = project.name,
root = root,
relativeFilePath = relativePath,
newFile = true
)
} ?: run {
// For non-git repos, use project root as base
val projectRootPath = projectRoot.toNioPath()
val relativePath = runCatching {
file.toNioPath().relativeTo(projectRootPath).pathString
}.getOrElse {
LOG.debug { "Failed to calculate relative path from project root: ${it.message}" }
return ""
}

return runGitDiffHead(
projectName = project.name,
root = projectRoot,
relativeFilePath = relativePath,
newFile = true // Always treat as new file for non-git repos
)
val projectRootNio = projectRoot.toNioPath()
val fileNio = file.toNioPath()

return buildString {
append("+++ b/")
append(project.name)
append('/')
append(fileNio.relativeTo(projectRootNio).pathString)
}
} catch (e: Exception) {
LOG.debug { "Failed to create git diff: ${e.message}" }
LOG.debug(e) { "Failed to create git diff" }
return ""
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,19 @@
private val gitIgnoreFile = File(selectedSourceFolder.path, ".gitignore")

init {
ignorePatternsWithGitIgnore = (ignorePatterns + parseGitIgnore().map { Regex(it) }).toList()
ignorePatternsWithGitIgnore = try {
(
ignorePatterns + parseGitIgnore().map { pattern ->

Check notice on line 88 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/FeatureDevSessionContext.kt

View workflow job for this annotation

GitHub Actions / qodana

Call chain on collection type can be simplified

Call chain on collection type may be simplified
try {
Regex(pattern)
} catch (e: Exception) {
null
}
}.filterNotNull()
).toList()
} catch (e: Exception) {
emptyList()
}
}

fun getProjectZip(): ZipCreationResult {
Expand Down
Loading