Skip to content

Commit

Permalink
fix: update template
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Apr 17, 2023
1 parent b2a9df5 commit c1749fe
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 18 deletions.
21 changes: 11 additions & 10 deletions src/main/kotlin/cc/unitmesh/devti/DevtiFlow.kt
Expand Up @@ -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)
}

/**
Expand Down Expand Up @@ -123,8 +123,9 @@ class DevtiFlow(

companion object {
private val logger: Logger = logger<DtRunState>()
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)
}
Expand Down
5 changes: 5 additions & 0 deletions 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} {
Expand Down
12 changes: 6 additions & 6 deletions 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 {
//
Expand All @@ -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")
}
}
Expand Up @@ -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 {
Expand Down
Expand Up @@ -43,9 +43,9 @@ AC 1: xxx
val storyDetail = "็”จๆˆทๆ•…ไบ‹๏ผšๅฏไปฅ้€‰ๆ‹ฉๅฎ่ดๅ‡บ่กŒๆœๅŠก"
val files: List<DtClass> = 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 ๅˆ—่กจ๏ผš
Expand Down

0 comments on commit c1749fe

Please sign in to comment.