@@ -2,7 +2,63 @@ package cc.unitmesh.devti.actions.vcs
2
2
3
3
import cc.unitmesh.devti.actions.chat.base.ChatBaseAction
4
4
import cc.unitmesh.devti.gui.chat.ChatActionType
5
+ import cc.unitmesh.devti.gui.chat.ChatContext
6
+ import cc.unitmesh.devti.gui.sendToChatPanel
7
+ import cc.unitmesh.devti.prompting.VcsPrompting
8
+ import cc.unitmesh.devti.provider.ContextPrompter
9
+ import com.intellij.openapi.actionSystem.AnActionEvent
10
+ import com.intellij.openapi.actionSystem.CommonDataKeys
11
+ import com.intellij.openapi.components.service
12
+ import com.intellij.openapi.project.ProjectManager
13
+ import com.intellij.temporary.getElementToAction
5
14
6
15
class CommitMessageSuggestionAction : ChatBaseAction () {
7
16
override fun getActionType (): ChatActionType = ChatActionType .GEN_COMMIT_MESSAGE
17
+
18
+ override fun executeAction (event : AnActionEvent ) {
19
+ val project = event.project ? : return
20
+ val prompt = generateCommitMessage(prepareVcsContext())
21
+
22
+ sendToChatPanel(project) { panel, service ->
23
+ val chatContext = ChatContext (
24
+ getReplaceableAction(event),
25
+ prompt,
26
+ " "
27
+ )
28
+
29
+ service.handlePromptAndResponse(panel, object : ContextPrompter () {
30
+ override fun displayPrompt (): String = prompt
31
+ override fun requestPrompt (): String = prompt
32
+ }, chatContext, newChatContext = true )
33
+ }
34
+ }
35
+
36
+ private fun prepareVcsContext (): String {
37
+ val project = ProjectManager .getInstance().openProjects.firstOrNull() ? : return " "
38
+ val prompting = project.service<VcsPrompting >()
39
+
40
+ return prompting.prepareContext()
41
+ }
42
+
43
+ private fun generateCommitMessage (diff : String ): String {
44
+ return """ Write a cohesive yet descriptive commit message for a given diff.
45
+ Make sure to include both information What was changed and Why.
46
+ Start with a short sentence in imperative form, no more than 50 characters long.
47
+ Then leave an empty line and continue with a more detailed explanation, if necessary.
48
+ Explanation should have less than 200 characters.
49
+
50
+ examples:
51
+ - fix(authentication): add password regex pattern
52
+ - feat(storage): add new test cases
53
+
54
+ Diff:
55
+
56
+ ```diff
57
+ $diff
58
+ ```
59
+
60
+ """
61
+ }
62
+
63
+
8
64
}
0 commit comments