Skip to content

Commit

Permalink
fix: fix running issues
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Apr 16, 2023
1 parent 6574798 commit 7a84358
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 9 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Expand Up @@ -40,6 +40,7 @@ dependencies {
implementation("com.aallam.openai:openai-client:3.2.0")
implementation("org.jetbrains:markdown:0.4.1")

implementation("org.slf4j:slf4j-api:2.0.7")
// for local testting
implementation("io.github.cdimascio:dotenv-kotlin:6.4.1")
implementation(libs.ktor.client.apache)
Expand Down
4 changes: 4 additions & 0 deletions src/main/kotlin/cc/unitmesh/devti/DevtiFlow.kt
Expand Up @@ -18,6 +18,7 @@ class DevtiFlow(
val project = kanban.getProjectInfo()
val story = kanban.getStoryById(id)

// 1. check story detail is valid, if not, fill story detail
var storyDetail = story.description
if (!kanban.isValidStory(storyDetail)) {
logger.info("story detail is not valid, fill story detail")
Expand All @@ -29,6 +30,7 @@ class DevtiFlow(
kanban.updateStoryDetail(newStory)
}

// 2. get suggest endpoint
val files: List<DtClass> = analyser?.controllerList() ?: emptyList()
logger.info("start devti flow")
val targetEndpoint = flowAction.analysisEndpoint(storyDetail, files)
Expand All @@ -46,7 +48,9 @@ class DevtiFlow(
return
}

// 3. update endpoint method
val code = flowAction.needUpdateMethodForController(targetEndpoint, targetController)
analyser?.updateMethod(targetController.name, code)
logger.info("update method code: $code")
}

Expand Down
Expand Up @@ -4,4 +4,5 @@ interface CrudProcessor {
fun controllerList(): List<DtClass>
fun serviceList(): List<DtClass>
fun modelList(): List<DtClass>
fun updateMethod(targetController: String, code: String)
}
10 changes: 10 additions & 0 deletions src/main/kotlin/cc/unitmesh/devti/analysis/JavaCrudProcessor.kt
Expand Up @@ -87,4 +87,14 @@ class JavaCrudProcessor(val project: Project) : CrudProcessor {
override fun modelList(): List<DtClass> {
TODO("Not yet implemented")
}

override fun updateMethod(targetController: String, code: String) {
val targetControllerFile = controllers.first { it.name == "$targetController.java" }
val targetControllerClass = PsiTreeUtil.findChildrenOfType(targetControllerFile, PsiClass::class.java)
.firstOrNull() ?: return

val updatedClass = addMethodToClass(targetControllerClass, code)
val updatedFile = updatedClass.containingFile
updatedFile.add(updatedClass)
}
}
Expand Up @@ -27,7 +27,7 @@ class DtRunConfiguration(project: Project, name: String, factory: ConfigurationF
}

override fun getState(executor: Executor, environment: ExecutionEnvironment): RunProfileState {
return DtRunState(environment, this, storyConfig, project)
return DtRunState(environment, this, storyConfig, project, options)
}

override fun writeExternal(element: Element) {
Expand Down
24 changes: 17 additions & 7 deletions src/main/kotlin/cc/unitmesh/devti/runconfig/DtRunState.kt
@@ -1,6 +1,9 @@
package cc.unitmesh.devti.runconfig

import cc.unitmesh.devti.DevtiFlow
import cc.unitmesh.devti.analysis.JavaCrudProcessor
import cc.unitmesh.devti.kanban.impl.GitHubIssue
import cc.unitmesh.devti.prompt.openai.OpenAIAction
import cc.unitmesh.devti.runconfig.config.DevtiCreateStoryConfigure
import com.intellij.execution.ExecutionResult
import com.intellij.execution.Executor
Expand All @@ -15,20 +18,27 @@ class DtRunState(
val environment: ExecutionEnvironment,

Check warning on line 18 in src/main/kotlin/cc/unitmesh/devti/runconfig/DtRunState.kt

View workflow job for this annotation

GitHub Actions / Build

Unused symbol

Property "environment" is never used
private val configuration: DtRunConfiguration,
private val createStory: DevtiCreateStoryConfigure?,
val project: Project
val project: Project,
val options: DtRunConfigurationOptions

Check notice on line 22 in src/main/kotlin/cc/unitmesh/devti/runconfig/DtRunState.kt

View workflow job for this annotation

GitHub Actions / Build

Class member can have 'private' visibility

Property 'options' could be private
) : RunProfileState {
init {
log.warn("init")
}

// check configuration
override fun execute(executor: Executor?, runner: ProgramRunner<*>): ExecutionResult? {
val javaAuto = JavaCrudProcessor(project)
val controllerList = javaAuto.controllerList()

log.warn(controllerList.toString())
val gitHubIssue = GitHubIssue("unit-mesh/untitled", options.githubToken())
val openAIAction = OpenAIAction(options.openAiApiKey(), "gpt-3.5-turbo")
val devtiFlow = DevtiFlow(gitHubIssue, openAIAction, javaAuto)

log.warn(configuration.toString())
log.warn(createStory.toString())
log.warn(options.toString())

if (createStory == null) {
return null
}

devtiFlow.start(createStory.storyId.toString())

return null
}

Expand Down
Expand Up @@ -4,7 +4,7 @@ import cc.unitmesh.devti.language.StoryConfig
import cc.unitmesh.devti.runconfig.command.BaseConfig

class DevtiCreateStoryConfigure(
private val storyId: Int,
val storyId: Int,
private val storySource: String,
private val acs: List<String> = listOf()
) : BaseConfig() {
Expand Down

0 comments on commit 7a84358

Please sign in to comment.