Skip to content

Commit

Permalink
feat: init for update story
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Apr 16, 2023
1 parent a3346c2 commit 7e582aa
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
8 changes: 8 additions & 0 deletions src/main/kotlin/cc/unitmesh/devti/DevtiFlow.kt
Expand Up @@ -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,
Expand All @@ -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<DtRunState>()
}
}
6 changes: 1 addition & 5 deletions src/main/kotlin/cc/unitmesh/devti/kanban/Kanban.kt
Expand Up @@ -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<SimpleStory>
fun getStoryById(storyId: String): SimpleStory

/**
* update story details
*/
fun updateStoryDetail(simpleStory: SimpleStory)
}
15 changes: 13 additions & 2 deletions src/main/kotlin/cc/unitmesh/devti/kanban/impl/GitHubIssue.kt
Expand Up @@ -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<SimpleStory> {
Expand All @@ -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) {
Expand Down
Expand Up @@ -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 {

Check warning on line 15 in src/main/kotlin/cc/unitmesh/devti/prompt/openai/OpenAIAction.kt

View workflow job for this annotation

GitHub Actions / Build

Constructor parameter is never used as a property

Constructor parameter is never used as a property
private val openAI: OpenAI = OpenAI(openAIKey)
Expand All @@ -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)

Check notice on line 38 in src/main/kotlin/cc/unitmesh/devti/prompt/openai/OpenAIAction.kt

View workflow job for this annotation

GitHub Actions / Build

Unnecessary local variable

Variable used only in following return and can be inlined
return@runBlocking prompt
}
}
}
2 changes: 1 addition & 1 deletion src/test/kotlin/cc/unitmesh/devti/DevtiFlowTest.kt
Expand Up @@ -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"]
Expand Down

0 comments on commit 7e582aa

Please sign in to comment.