Skip to content

Commit 8fe5e87

Browse files
committed
refactor(settings): move Git-related settings to DevOps configurable
- Relocate Git-related settings (gitType, githubToken, gitlabToken, gitlabUrl) from AutoDevSettingsState to AutoDevDevOpsSettingService. - Update UI components in DevOpsConfigurable to handle Git configuration. - Adjust dependent classes (CodeReviewAction, AutoDevRunProfileState) to use the new settings service. - Remove Git-related fields and UI elements from LLMSettingComponent.
1 parent c18d74d commit 8fe5e87

File tree

6 files changed

+103
-52
lines changed

6 files changed

+103
-52
lines changed

core/src/main/kotlin/cc/unitmesh/devti/runconfig/AutoDevRunProfileState.kt

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import cc.unitmesh.devti.llms.LlmFactory
99
import cc.unitmesh.devti.provider.DevFlowProvider
1010
import cc.unitmesh.devti.runconfig.options.AutoCRUDConfigurationOptions
1111
import cc.unitmesh.devti.settings.AutoDevSettingsState
12+
import cc.unitmesh.devti.settings.devops.devopsPromptsSettings
1213
import com.intellij.execution.ExecutionResult
1314
import com.intellij.execution.Executor
1415
import com.intellij.execution.configurations.RunProfileState
@@ -24,18 +25,11 @@ class AutoDevRunProfileState(
2425
val project: Project,
2526
val options: AutoCRUDConfigurationOptions,
2627
) : RunProfileState {
27-
private val githubToken: String
28-
private val gitlabToken: String
29-
private val gitType: String
30-
private val gitlabUrl: String
31-
32-
init {
33-
val instance = AutoDevSettingsState.getInstance()
34-
githubToken = instance.githubToken
35-
gitlabToken = instance.gitlabToken
36-
gitType = instance.gitType
37-
gitlabUrl = instance.gitlabUrl
38-
}
28+
val state = project.devopsPromptsSettings.state
29+
private val githubToken: String = state.githubToken
30+
private val gitlabToken: String = state.gitlabToken
31+
private val gitType: String = state.gitType
32+
private val gitlabUrl: String = state.gitlabUrl
3933

4034
override fun execute(executor: Executor?, runner: ProgramRunner<*>): ExecutionResult? {
4135
val kanban: Kanban = when (gitType.lowercase()) {
@@ -52,7 +46,6 @@ class AutoDevRunProfileState(
5246
}
5347
}
5448

55-
5649
// TODO: support other language
5750
val flowProvider = DevFlowProvider.flowProvider("java")
5851
if (flowProvider == null) {

core/src/main/kotlin/cc/unitmesh/devti/settings/AutoDevSettingsState.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ import java.time.format.DateTimeFormatter
1414
@Service(Service.Level.APP)
1515
@State(name = "cc.unitmesh.devti.settings.DevtiSettingsState", storages = [Storage("DevtiSettings.xml")])
1616
class AutoDevSettingsState : PersistentStateComponent<AutoDevSettingsState> {
17-
var gitType = DEFAULT_GIT_TYPE
18-
var githubToken = ""
19-
var gitlabToken = ""
20-
var gitlabUrl = ""
2117
var openAiKey = ""
2218
var openAiModel = DEFAULT_AI_MODEL
2319
var delaySeconds = ""

core/src/main/kotlin/cc/unitmesh/devti/settings/Constants.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ enum class AIEngines {
77
OpenAI, Custom
88
}
99

10-
val GIT_TYPE = arrayOf("Github" , "Gitlab")
11-
val DEFAULT_GIT_TYPE = GIT_TYPE[0]
12-
1310
enum class ResponseType {
1411
SSE, JSON;
1512
}

core/src/main/kotlin/cc/unitmesh/devti/settings/LLMSettingComponent.kt

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ class LLMSettingComponent(private val settings: AutoDevSettingsState) {
2626
private val customModelParam: LLMParam by LLMParam.creating { Editable(settings.customModel) }
2727
private val customOpenAIHostParam: LLMParam by LLMParam.creating { Editable(settings.customOpenAiHost) }
2828

29-
private val gitTypeParam: LLMParam by LLMParam.creating { ComboBox(settings.gitType, GIT_TYPE.toList()) }
30-
private val gitLabUrlParam: LLMParam by LLMParam.creating { Editable(settings.gitlabUrl) }
31-
private val gitLabTokenParam: LLMParam by LLMParam.creating { Password(settings.gitlabToken) }
32-
33-
private val gitHubTokenParam by LLMParam.creating { Password(settings.githubToken) }
3429
private val customEngineServerParam by LLMParam.creating { Editable(settings.customEngineServer) }
3530
private val customEngineTokenParam by LLMParam.creating { Password(settings.customEngineToken) }
3631

@@ -130,14 +125,6 @@ class LLMSettingComponent(private val settings: AutoDevSettingsState) {
130125
.addLLMParam(maxTokenLengthParam)
131126
.addLLMParam(delaySecondsParam)
132127
.addSeparator()
133-
.addTooltip("Select Git Type")
134-
.addLLMParam(gitTypeParam)
135-
.addTooltip("GitHub Token is for AutoCRUD Model")
136-
.addLLMParam(gitHubTokenParam)
137-
.addTooltip("GitLab options is for AutoCRUD Model")
138-
.addLLMParam(gitLabUrlParam)
139-
.addLLMParam(gitLabTokenParam)
140-
.addSeparator()
141128
.addComponent(panel {
142129
row {
143130
comment("For OpenAI LLM, config OpenAI Key & OpenAI Model & Custom OpenAI Host <a>Open Log for Debug</a>") {
@@ -164,10 +151,6 @@ class LLMSettingComponent(private val settings: AutoDevSettingsState) {
164151
private fun updateParams(settings: AutoDevSettingsState) {
165152
settings.apply {
166153
maxTokenLengthParam.value = maxTokenLength
167-
gitTypeParam.value = gitType
168-
gitHubTokenParam.value = githubToken
169-
gitLabTokenParam.value = gitlabToken
170-
gitLabUrlParam.value = gitlabUrl
171154
openAIKeyParam.value = openAiKey
172155
customModelParam.value = customModel
173156
customOpenAIHostParam.value = customOpenAiHost
@@ -187,10 +170,6 @@ class LLMSettingComponent(private val settings: AutoDevSettingsState) {
187170
fun exportSettings(destination: AutoDevSettingsState) {
188171
destination.apply {
189172
maxTokenLength = maxTokenLengthParam.value
190-
gitType = gitTypeParam.value
191-
githubToken = gitHubTokenParam.value
192-
gitlabUrl = gitLabUrlParam.value
193-
gitlabToken = gitLabTokenParam.value
194173
openAiKey = openAIKeyParam.value
195174
customModel = customModelParam.value
196175
customOpenAiHost = customOpenAIHostParam.value
@@ -209,10 +188,6 @@ class LLMSettingComponent(private val settings: AutoDevSettingsState) {
209188

210189
fun isModified(settings: AutoDevSettingsState): Boolean {
211190
return settings.maxTokenLength != maxTokenLengthParam.value ||
212-
settings.gitType != gitTypeParam.value ||
213-
settings.githubToken != gitHubTokenParam.value ||
214-
settings.gitlabUrl != gitLabUrlParam.value ||
215-
settings.gitlabToken != gitLabTokenParam.value ||
216191
settings.openAiKey != openAIKeyParam.value ||
217192
settings.customModel != customModelParam.value ||
218193
settings.aiEngine != aiEngineParam.value ||
Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,108 @@
11
package cc.unitmesh.devti.settings.devops
22

33
import cc.unitmesh.devti.AutoDevBundle
4+
import cc.unitmesh.devti.settings.custom.TeamPromptsProjectSettingsService
5+
import com.intellij.openapi.components.*
46
import com.intellij.openapi.options.BoundConfigurable
57
import com.intellij.openapi.options.Configurable
68
import com.intellij.openapi.options.ConfigurableProvider
79
import com.intellij.openapi.project.Project
810
import com.intellij.openapi.ui.DialogPanel
911
import com.intellij.ui.dsl.builder.panel
12+
import javax.swing.JComboBox
13+
import javax.swing.JPasswordField
14+
import javax.swing.JTextField
1015

1116
class AutoDevDevOpsConfigurableProvider(private val project: Project) : ConfigurableProvider() {
1217
override fun createConfigurable(): Configurable {
1318
return DevOpsConfigurable(project)
1419
}
1520
}
1621

22+
val GIT_TYPE = arrayOf("Github" , "Gitlab")
23+
val DEFAULT_GIT_TYPE = GIT_TYPE[0]
24+
1725
class DevOpsConfigurable(project: Project) : BoundConfigurable(AutoDevBundle.message("settings.autodev.devops")) {
26+
private val settings = AutoDevDevOpsSettingService.getInstance(project)
27+
28+
private lateinit var gitTypeComboBox: JComboBox<String>
29+
private lateinit var githubTokenField: JPasswordField
30+
private lateinit var gitlabUrlField: JTextField
31+
private lateinit var gitlabTokenField: JPasswordField
32+
1833
override fun createPanel(): DialogPanel {
1934
return panel {
20-
row {
21-
text("Hello, AutoDev 2.0")
35+
group("Git Configuration") {
36+
row("Git Type:") {
37+
gitTypeComboBox = comboBox(GIT_TYPE.toList()).component
38+
}
39+
row("GitHub Token:") {
40+
githubTokenField = passwordField().component
41+
}
42+
row("GitLab URL:") {
43+
gitlabUrlField = textField().component
44+
}
45+
row("GitLab Token:") {
46+
gitlabTokenField = passwordField().component
47+
}
2248
}
2349
}
2450
}
51+
52+
override fun apply() {
53+
settings.modify { state ->
54+
state.githubToken = githubTokenField.password.toString()
55+
state.gitlabUrl = gitlabUrlField.text
56+
state.gitlabToken = gitlabTokenField.password.toString()
57+
}
58+
}
59+
60+
override fun reset() {
61+
githubTokenField.text = settings.state.githubToken
62+
gitlabUrlField.text = settings.state.gitlabUrl
63+
gitlabTokenField.text = settings.state.gitlabToken
64+
}
65+
66+
override fun isModified(): Boolean {
67+
return settings.state.githubToken != githubTokenField.password.toString() ||
68+
settings.state.gitlabUrl != gitlabUrlField.text ||
69+
settings.state.gitlabToken != gitlabTokenField.password.toString()
70+
}
2571
}
72+
73+
val Project.devopsPromptsSettings: AutoDevDevOpsSettingService get() = service<AutoDevDevOpsSettingService>()
74+
75+
@Service(Service.Level.PROJECT)
76+
@State(name = "AutoDevDevOpsSettings", storages = [Storage("autodev-devops.xml")])
77+
class AutoDevDevOpsSettingService(
78+
val project: Project,
79+
) : SimplePersistentStateComponent<AutoDevDevOpsSettingService.AutoDevCoderSettings>(AutoDevCoderSettings()) {
80+
fun modify(action: (AutoDevCoderSettings) -> Unit) {
81+
action(state)
82+
}
83+
84+
companion object {
85+
@JvmStatic
86+
fun getInstance(project: Project): AutoDevDevOpsSettingService {
87+
return project.getService(AutoDevDevOpsSettingService::class.java)
88+
}
89+
}
90+
91+
abstract class AdProjectSettingsBase<T : AdProjectSettingsBase<T>> : BaseState() {
92+
abstract fun copy(): T
93+
}
94+
95+
class AutoDevCoderSettings : AdProjectSettingsBase<AutoDevCoderSettings>() {
96+
var recordingInLocal by property(false)
97+
var gitType = DEFAULT_GIT_TYPE
98+
var githubToken = ""
99+
var gitlabToken = ""
100+
var gitlabUrl = ""
101+
102+
override fun copy(): AutoDevCoderSettings {
103+
val state = AutoDevCoderSettings()
104+
state.copyFrom(this)
105+
return state
106+
}
107+
}
108+
}

exts/ext-git/src/main/kotlin/cc/unitmesh/git/actions/vcs/CodeReviewAction.kt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import cc.unitmesh.devti.provider.context.ChatContextItem
1010
import cc.unitmesh.devti.provider.context.ChatContextProvider
1111
import cc.unitmesh.devti.provider.context.ChatCreationContext
1212
import cc.unitmesh.devti.provider.context.ChatOrigin
13-
import cc.unitmesh.devti.settings.AutoDevSettingsState
1413
import cc.unitmesh.devti.settings.LanguageChangedCallback.presentationText
14+
import cc.unitmesh.devti.settings.devops.devopsPromptsSettings
1515
import cc.unitmesh.devti.template.GENIUS_PRACTISES
1616
import cc.unitmesh.devti.template.TemplateRender
1717
import cc.unitmesh.devti.template.context.TemplateContext
@@ -34,9 +34,10 @@ val githubUrlRegex: Regex = Regex("^(https?://|git://)?(www\\.)?github\\.com/[\\
3434

3535
open class CodeReviewAction : ChatBaseAction() {
3636

37-
init{
37+
init {
3838
presentationText("settings.autodev.others.codeReview", templatePresentation)
3939
}
40+
4041
override fun getActionType(): ChatActionType = ChatActionType.CODE_REVIEW
4142

4243
private val commitParser: CommitParser = CommitParser()
@@ -59,7 +60,7 @@ open class CodeReviewAction : ChatBaseAction() {
5960
return@Runnable
6061
}
6162

62-
stories = fetchKanbanByCommits(repository, details)
63+
stories = fetchKanbanByCommits(repository, details, project)
6364
}, "Prepare Repository", true, project)
6465

6566
doReviewWithChanges(project, details, selectList, stories)
@@ -109,15 +110,21 @@ open class CodeReviewAction : ChatBaseAction() {
109110
}
110111
}
111112

112-
private fun fetchKanbanByCommits(repository: Repository, details: List<VcsFullCommitDetails>): List<String> {
113+
private fun fetchKanbanByCommits(
114+
repository: Repository,
115+
details: List<VcsFullCommitDetails>,
116+
project: Project
117+
): List<String> {
113118
val stories: MutableList<String> = mutableListOf()
119+
val githubToken = project.devopsPromptsSettings.state.githubToken
120+
114121
when (repository) {
115122
is GitRepository -> {
116123
val remote = repository.info.remotes.firstOrNull() ?: return stories
117124
val url = remote.firstUrl ?: return stories
118125
if (!url.matches(githubUrlRegex)) return stories
119126

120-
val github = GitHubIssue(url, AutoDevSettingsState.getInstance().githubToken)
127+
val github = GitHubIssue(url, githubToken)
121128
details
122129
.map {
123130
commitParser.parse(it.subject).references

0 commit comments

Comments
 (0)