Skip to content

Commit 4002a33

Browse files
author
David Hasani
committed
fix detekt
1 parent 4d18097 commit 4002a33

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/constants/CodeTransformChatItems.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ fun buildSQLMetadataValidationErrorChatContent(errorReason: String) = CodeTransf
458458

459459
fun buildCustomDependencyVersionsFileInvalidChatContent() = CodeTransformChatMessageContent(
460460
type = CodeTransformChatMessageType.FinalizedAnswer,
461-
message = "The .yaml file you uploaded does not follow the format of the sample YAML file provided.",
461+
message = "The file you uploaded does not follow the format of the sample YAML file provided.",
462462
)
463463

464464
fun buildUserCancelledChatContent() = CodeTransformChatMessageContent(

plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/controller/CodeTransformChatController.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,6 @@ class CodeTransformChatController(
370370
withContext(EDT) {
371371
val descriptor = FileChooserDescriptorFactory.createSingleFileDescriptor()
372372
.withDescription("Select metadata file")
373-
.withExtensionFilter("zip")
374373

375374
val selectedZipFile = FileChooser.chooseFile(descriptor, null, null) ?: return@withContext
376375
val extractedZip = createTempDirectory("codeTransformSQLMetadata", null)
@@ -452,9 +451,8 @@ class CodeTransformChatController(
452451
withContext(EDT) {
453452
val descriptor = FileChooserDescriptorFactory.createSingleFileDescriptor()
454453
.withDescription("Select .yaml file")
455-
.withExtensionFilter("yaml")
456454
val selectedFile = FileChooser.chooseFile(descriptor, null, null) ?: return@withContext
457-
val isValid = validateYamlFile(selectedFile.readText())
455+
val isValid = validateYamlFile(selectedFile)
458456
if (!isValid) {
459457
codeTransformChatHelper.updateLastPendingMessage(buildCustomDependencyVersionsFileInvalidChatContent())
460458
codeTransformChatHelper.addNewMessage(buildStartNewTransformFollowup())

plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformFileUtils.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import com.intellij.openapi.application.runReadAction
99
import com.intellij.openapi.fileEditor.FileDocumentManager
1010
import com.intellij.openapi.util.io.FileUtil
1111
import com.intellij.openapi.vfs.VirtualFile
12+
import com.intellij.openapi.vfs.readText
1213
import kotlinx.coroutines.withContext
1314
import software.aws.toolkits.core.utils.createParentDirectories
1415
import software.aws.toolkits.core.utils.createTemporaryZipFile
@@ -195,7 +196,12 @@ fun parseXmlDependenciesReport(pathToXmlDependency: Path): DependencyUpdatesRepo
195196
return report
196197
}
197198

198-
fun validateYamlFile(fileContents: String): Boolean {
199+
fun validateYamlFile(file: VirtualFile): Boolean {
200+
if (!file.name.lowercase().endsWith(".yaml")) {
201+
getLogger<CodeTransformChatController>().error { "Custom versions file is not a YAML file: ${file.name}"}
202+
return false
203+
}
204+
val fileContents = file.readText()
199205
val requiredKeys = listOf("dependencyManagement:", "identifier:", "targetVersion:")
200206
for (key in requiredKeys) {
201207
if (!fileContents.contains(key)) {

0 commit comments

Comments
 (0)