diff --git a/src/main/kotlin/cc/unitmesh/devti/DevtiFlow.kt b/src/main/kotlin/cc/unitmesh/devti/DevtiFlow.kt index d69cae6fe9..87c1a52233 100644 --- a/src/main/kotlin/cc/unitmesh/devti/DevtiFlow.kt +++ b/src/main/kotlin/cc/unitmesh/devti/DevtiFlow.kt @@ -3,6 +3,9 @@ package cc.unitmesh.devti import cc.unitmesh.devti.kanban.Kanban import cc.unitmesh.devti.kanban.SimpleStory import cc.unitmesh.devti.prompt.DevtiFlowAction +import cc.unitmesh.devti.runconfig.DtRunState +import com.intellij.openapi.diagnostic.Logger +import com.intellij.openapi.diagnostic.logger class DevtiFlow( private val kanban: Kanban, @@ -15,8 +18,13 @@ class DevtiFlow( var storyDetail = story.description if (!kanban.isValidStory(storyDetail)) { storyDetail = devtiFlowAction.fillStoryDetail(project, story.description) + logger.info("fill story detail: $storyDetail") val newStory = SimpleStory(story.id, story.title, storyDetail) kanban.updateStoryDetail(newStory) } } + + companion object { + private val logger: Logger = logger() + } } diff --git a/src/main/kotlin/cc/unitmesh/devti/kanban/Kanban.kt b/src/main/kotlin/cc/unitmesh/devti/kanban/Kanban.kt index 9efdeb82a4..c3002f0a29 100644 --- a/src/main/kotlin/cc/unitmesh/devti/kanban/Kanban.kt +++ b/src/main/kotlin/cc/unitmesh/devti/kanban/Kanban.kt @@ -2,15 +2,11 @@ package cc.unitmesh.devti.kanban interface Kanban { fun isValidStory(content: String): Boolean { - return content.startsWith("###DevTi") + return content.contains("用户故事") } fun getProjectInfo(): SimpleProjectInfo fun getStories(): List fun getStoryById(storyId: String): SimpleStory - - /** - * update story details - */ fun updateStoryDetail(simpleStory: SimpleStory) } diff --git a/src/main/kotlin/cc/unitmesh/devti/kanban/impl/GitHubIssue.kt b/src/main/kotlin/cc/unitmesh/devti/kanban/impl/GitHubIssue.kt index 1b6467ce95..931012d154 100644 --- a/src/main/kotlin/cc/unitmesh/devti/kanban/impl/GitHubIssue.kt +++ b/src/main/kotlin/cc/unitmesh/devti/kanban/impl/GitHubIssue.kt @@ -21,7 +21,7 @@ class GitHubIssue(val repoUrl: String, val token: String) : Kanban { override fun getProjectInfo(): SimpleProjectInfo { val repo = gitHub.getRepository(repoUrl) - return SimpleProjectInfo(repo.nodeId, repo.name, repo.description) + return SimpleProjectInfo(repo.fullName, repo.name, repo.description) } override fun getStories(): List { @@ -30,7 +30,18 @@ class GitHubIssue(val repoUrl: String, val token: String) : Kanban { override fun getStoryById(storyId: String): SimpleStory { val issue = gitHub.getRepository(repoUrl).getIssue(Integer.parseInt(storyId)) - return SimpleStory(issue.nodeId, issue.title, issue.body) + if (issue.comments.size == 0) { + return SimpleStory(issue.number.toString(), issue.title, issue.body) + } + + // get all comments and filter body contains "用户故事" + val comments = issue.comments + val comment = comments.find { it.body.contains("用户故事") } + if (comment != null) { + return SimpleStory(issue.number.toString(), issue.title, comment.body) + } + + return SimpleStory(issue.number.toString(), issue.title, issue.body) } override fun updateStoryDetail(simpleStory: SimpleStory) { diff --git a/src/main/kotlin/cc/unitmesh/devti/prompt/openai/OpenAIAction.kt b/src/main/kotlin/cc/unitmesh/devti/prompt/openai/OpenAIAction.kt index f19fba9fb3..8c0e2ac35e 100644 --- a/src/main/kotlin/cc/unitmesh/devti/prompt/openai/OpenAIAction.kt +++ b/src/main/kotlin/cc/unitmesh/devti/prompt/openai/OpenAIAction.kt @@ -10,6 +10,7 @@ import com.aallam.openai.api.chat.ChatMessage import com.aallam.openai.api.chat.ChatRole import com.aallam.openai.api.model.ModelId import com.aallam.openai.client.OpenAI +import kotlinx.coroutines.runBlocking class OpenAIAction(val openAIKey: String, val version: String) : AiAction, DevtiFlowAction { private val openAI: OpenAI = OpenAI(openAIKey) @@ -33,6 +34,9 @@ class OpenAIAction(val openAIKey: String, val version: String) : AiAction, Devti override fun fillStoryDetail(project: SimpleProjectInfo, story: String): String { val promptText = gptPromptText.fillStoryDetail(project, story) - return promptText + return runBlocking { + val prompt = prompt(promptText) + return@runBlocking prompt + } } } \ No newline at end of file diff --git a/src/test/kotlin/cc/unitmesh/devti/DevtiFlowTest.kt b/src/test/kotlin/cc/unitmesh/devti/DevtiFlowTest.kt index 4e67fc4f91..8ea0a5c0e2 100644 --- a/src/test/kotlin/cc/unitmesh/devti/DevtiFlowTest.kt +++ b/src/test/kotlin/cc/unitmesh/devti/DevtiFlowTest.kt @@ -9,7 +9,7 @@ import org.junit.Ignore class DevtiFlowTest { @Test -// @Ignore + @Ignore fun should_fetch_github_story() { val dotenv = dotenv() val githubToken = dotenv["GITHUB_TOKEN"]