Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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,16 @@ class FeatureDevSessionContext(val project: Project, val maxProjectSizeBytes: Lo
private val gitIgnoreFile = File(selectedSourceFolder.path, ".gitignore")

init {
ignorePatternsWithGitIgnore = (ignorePatterns + parseGitIgnore().map { Regex(it) }).toList()
ignorePatternsWithGitIgnore = try {
buildList {
addAll(ignorePatterns)
parseGitIgnore().mapNotNull { pattern ->
runCatching { Regex(pattern) }.getOrNull()
}.let { addAll(it) }
Comment on lines +89 to +91
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be simplified more but sure

}
} catch (e: Exception) {
emptyList()
}
}

fun getProjectZip(): ZipCreationResult {
Expand Down
Loading