Skip to content

Commit d2873be

Browse files
committed
refactor: reorg code
1 parent cbc1d02 commit d2873be

File tree

3 files changed

+36
-48
lines changed

3 files changed

+36
-48
lines changed

src/main/kotlin/cc/unitmesh/devti/DevtiFlow.kt

Lines changed: 34 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -21,39 +21,25 @@ class DevtiFlow(
2121
private val flowAction: DevtiFlowAction,
2222
private val processor: CrudProcessor? = null
2323
) {
24-
// fun processAll(id: String) {
25-
// val storyDetail = fillStoryDetail(id)
26-
//
27-
// val target = fetchSuggestEndpoint(storyDetail)
28-
// if (target == null) {
29-
// logger.warn("no suggest endpoint found")
30-
// return
31-
// }
32-
//
33-
// updateEndpointMethod(target, storyDetail)
34-
// }
35-
3624
/**
37-
* Step 3: update endpoint method
25+
* Step 1: check story detail is valid, if not, fill story detail
3826
*/
39-
fun updateEndpointMethod(target: TargetEndpoint, storyDetail: String) {
40-
try {
41-
val code = fetchCode(target.endpoint, target.controller, storyDetail).trimIndent()
42-
if (code.isEmpty()) {
43-
logger.warn("update method code is empty, skip")
44-
} else {
45-
processor?.createControllerOrUpdateMethod(target.controller.name, code, target.hasMatchedController)
46-
}
47-
} catch (e: Exception) {
48-
logger.warn("update method failed: $e, try to fill update method 2nd")
27+
fun fillStoryDetail(id: String): String {
28+
val simpleProject = kanban.getProjectInfo()
29+
val story = kanban.getStoryById(id)
4930

50-
val code = fetchCode(target.endpoint, target.controller, storyDetail).trimIndent()
51-
if (code.isEmpty()) {
52-
logger.warn("update method code is empty, skip")
53-
} else {
54-
processor?.createControllerOrUpdateMethod(target.controller.name, code, target.hasMatchedController)
55-
}
31+
// 1. check story detail is valid, if not, fill story detail
32+
var storyDetail = story.description
33+
if (!kanban.isValidStory(storyDetail)) {
34+
logger.warn("story detail is not valid, fill story detail")
35+
36+
storyDetail = flowAction.fillStoryDetail(simpleProject, story.description)
37+
38+
val newStory = SimpleStory(story.id, story.title, storyDetail)
39+
kanban.updateStoryDetail(newStory)
5640
}
41+
logger.warn("user story detail: $storyDetail")
42+
return storyDetail
5743
}
5844

5945
/**
@@ -81,32 +67,34 @@ class DevtiFlow(
8167
}
8268

8369
/**
84-
* Step 1: check story detail is valid, if not, fill story detail
70+
* Step 3: update endpoint method
8571
*/
86-
fun fillStoryDetail(id: String): String {
87-
val simpleProject = kanban.getProjectInfo()
88-
val story = kanban.getStoryById(id)
89-
90-
// 1. check story detail is valid, if not, fill story detail
91-
var storyDetail = story.description
92-
if (!kanban.isValidStory(storyDetail)) {
93-
logger.warn("story detail is not valid, fill story detail")
94-
95-
storyDetail = flowAction.fillStoryDetail(simpleProject, story.description)
72+
fun updateEndpointMethod(target: TargetEndpoint, storyDetail: String) {
73+
try {
74+
val code = fetchEndpoint(target.endpoint, target.controller, storyDetail).trimIndent()
75+
if (code.isEmpty()) {
76+
logger.warn("update method code is empty, skip")
77+
} else {
78+
processor?.createControllerOrUpdateMethod(target.controller.name, code, target.hasMatchedController)
79+
}
80+
} catch (e: Exception) {
81+
logger.warn("update method failed: $e, try to fill update method 2nd")
9682

97-
val newStory = SimpleStory(story.id, story.title, storyDetail)
98-
kanban.updateStoryDetail(newStory)
83+
val code = fetchEndpoint(target.endpoint, target.controller, storyDetail).trimIndent()
84+
if (code.isEmpty()) {
85+
logger.warn("update method code is empty, skip")
86+
} else {
87+
processor?.createControllerOrUpdateMethod(target.controller.name, code, target.hasMatchedController)
88+
}
9989
}
100-
logger.warn("user story detail: $storyDetail")
101-
return storyDetail
10290
}
10391

104-
private fun fetchCode(
92+
private fun fetchEndpoint(
10593
targetEndpoint: String,
10694
targetController: DtClass,
10795
storyDetail: String
10896
): String {
109-
val content = flowAction.needUpdateMethodForController(targetEndpoint, targetController, storyDetail)
97+
val content = flowAction.needUpdateMethodOfController(targetEndpoint, targetController, storyDetail)
11098
val code = parseCodeFromString(content)
11199
logger.warn("update method code: $code")
112100
return code

src/main/kotlin/cc/unitmesh/devti/prompt/DevtiFlowAction.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ import cc.unitmesh.devti.kanban.SimpleProjectInfo
66
interface DevtiFlowAction {
77
fun fillStoryDetail(project: SimpleProjectInfo, story: String): String
88
fun analysisEndpoint(storyDetail: String, classes: List<DtClass>): String
9-
fun needUpdateMethodForController(targetEndpoint: String, clazz: DtClass, storyDetail: String): String
9+
fun needUpdateMethodOfController(targetEndpoint: String, clazz: DtClass, storyDetail: String): String
1010
}

src/main/kotlin/cc/unitmesh/devti/prompt/openai/OpenAIExecutor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class OpenAIExecutor(val openAIKey: String, val version: String) : AiExecutor, D
5454
}
5555
}
5656

57-
override fun needUpdateMethodForController(targetEndpoint: String, clazz: DtClass, storyDetail: String): String {
57+
override fun needUpdateMethodOfController(targetEndpoint: String, clazz: DtClass, storyDetail: String): String {
5858
val promptText = promptGenerator.updateControllerMethod(clazz, storyDetail)
5959
logger.warn("needUpdateMethodForController prompt text: $promptText")
6060
return runBlocking {

0 commit comments

Comments
 (0)