From c1749fe96d7bac007268fb5a6737ce80e7b8267e Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Mon, 17 Apr 2023 22:00:48 +0800 Subject: [PATCH] fix: update template --- .../kotlin/cc/unitmesh/devti/DevtiFlow.kt | 21 ++++++++++--------- .../code/Java Controller.java.ft | 5 +++++ .../kotlin/cc/unitmesh/devti/DevtiFlowTest.kt | 12 +++++------ .../devti/analysis/JavaCrudTemplateTest.kt | 5 +++++ .../devti/prompt/openai/GptPromptTextTest.kt | 4 ++-- 5 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/main/kotlin/cc/unitmesh/devti/DevtiFlow.kt b/src/main/kotlin/cc/unitmesh/devti/DevtiFlow.kt index d99c743b7e..ed252b6896 100644 --- a/src/main/kotlin/cc/unitmesh/devti/DevtiFlow.kt +++ b/src/main/kotlin/cc/unitmesh/devti/DevtiFlow.kt @@ -65,20 +65,20 @@ class DevtiFlow( logger.warn("start devti flow") val targetEndpoint = flowAction.analysisEndpoint(storyDetail, files) // use regex match *Controller from targetEndpoint - val controller = getController(targetEndpoint) + val controller = matchControllerName(targetEndpoint) if (controller == null) { - logger.warn("no controller found from: $targetEndpoint") - return TargetEndpoint(targetEndpoint, DtClass(targetEndpoint, listOf()), false) + logger.warn("no controller found from: $controller") + return TargetEndpoint("", DtClass("", listOf()), false) } - logger.warn("target endpoint: $targetEndpoint") - val targetController = files.find { it.name == targetEndpoint } + logger.warn("target endpoint: $controller") + val targetController = files.find { it.name == controller } if (targetController == null) { - logger.warn("no controller found from: $targetEndpoint") - return TargetEndpoint(targetEndpoint, DtClass(targetEndpoint, listOf()), false) + logger.warn("no controller found from: $controller") + return TargetEndpoint(controller, DtClass(controller, listOf()), false) } - return TargetEndpoint(targetEndpoint, targetController) + return TargetEndpoint(controller, targetController) } /** @@ -123,8 +123,9 @@ class DevtiFlow( companion object { private val logger: Logger = logger() - fun getController(targetEndpoint: String): String? { - val regex = Regex("""(\w+Controller)""") + private val regex = Regex("""(\w+Controller)""") + + fun matchControllerName(targetEndpoint: String): String? { val matchResult = regex.find(targetEndpoint) return matchResult?.groupValues?.get(1) } diff --git a/src/main/resources/fileTemplates/code/Java Controller.java.ft b/src/main/resources/fileTemplates/code/Java Controller.java.ft index daadb6ba89..e883ef6e3a 100644 --- a/src/main/resources/fileTemplates/code/Java Controller.java.ft +++ b/src/main/resources/fileTemplates/code/Java Controller.java.ft @@ -1,7 +1,12 @@ package ${packageName}; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.multipart.MultipartFile; @Controller class ${controllerName} { diff --git a/src/test/kotlin/cc/unitmesh/devti/DevtiFlowTest.kt b/src/test/kotlin/cc/unitmesh/devti/DevtiFlowTest.kt index e54d37cbef..0df721423b 100644 --- a/src/test/kotlin/cc/unitmesh/devti/DevtiFlowTest.kt +++ b/src/test/kotlin/cc/unitmesh/devti/DevtiFlowTest.kt @@ -1,10 +1,6 @@ package cc.unitmesh.devti -import cc.unitmesh.devti.kanban.impl.GitHubIssue -import cc.unitmesh.devti.prompt.openai.OpenAIAction import org.junit.Test -import io.github.cdimascio.dotenv.dotenv -import org.junit.Ignore class DevtiFlowTest { // @@ -25,10 +21,14 @@ class DevtiFlowTest { // input: """BlogController""", output: BlogController @Test fun testShould_extract_controller_name() { - val controllerName = DevtiFlow.getController("返回最合适的 Controller 名字:BlogController") + val controllerName = DevtiFlow.matchControllerName("返回最合适的 Controller 名字:BlogController") assert(controllerName == "BlogController") - val controllerName2 = DevtiFlow.getController("BlogController") + val controllerName2 = DevtiFlow.matchControllerName("BlogController") assert(controllerName2 == "BlogController") + + // 适合的 Controller 名字:VideoController + val controllerName3 = DevtiFlow.matchControllerName("适合的 Controller 名字:VideoController") + assert(controllerName3 == "VideoController") } } diff --git a/src/test/kotlin/cc/unitmesh/devti/analysis/JavaCrudTemplateTest.kt b/src/test/kotlin/cc/unitmesh/devti/analysis/JavaCrudTemplateTest.kt index 722a3fd4a4..cea9fcb714 100644 --- a/src/test/kotlin/cc/unitmesh/devti/analysis/JavaCrudTemplateTest.kt +++ b/src/test/kotlin/cc/unitmesh/devti/analysis/JavaCrudTemplateTest.kt @@ -9,8 +9,13 @@ class JavaCrudTemplateTest : BasePlatformTestCase() { assertEquals( code, """package com.example; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.multipart.MultipartFile; @Controller class HelloController { diff --git a/src/test/kotlin/cc/unitmesh/devti/prompt/openai/GptPromptTextTest.kt b/src/test/kotlin/cc/unitmesh/devti/prompt/openai/GptPromptTextTest.kt index c114a94200..71683f70ea 100644 --- a/src/test/kotlin/cc/unitmesh/devti/prompt/openai/GptPromptTextTest.kt +++ b/src/test/kotlin/cc/unitmesh/devti/prompt/openai/GptPromptTextTest.kt @@ -43,9 +43,9 @@ AC 1: xxx val storyDetail = "用户故事:可以选择宝贝出行服务" val files: List = listOf(DtClass("TaxiController", emptyList()), DtClass("GpsController", emptyList())) val result = gptPromptText.fillEndpoint(storyDetail, files) - assertEquals("""请根据下面的用户故事 和 Controller 列表,返回最合适的 Controller 名字。要求: + assertEquals("""请根据下面的用户故事 和 Controller 列表。要求: -1. 只返回最合适的 Controller 名字,不需要返回所有可能的 Controller 名字。 +1. 返回最合适的 Controller 名字 2. 如果不存在合适的 Controller 名字,请返回适合的 Controller 名字。 Controller 列表: