Skip to content

Commit 5d8e08f

Browse files
committed
fix(commit-message): optimize commit message generation by incorporating the original commit message.
1 parent 7e93e51 commit 5d8e08f

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

src/main/kotlin/cc/unitmesh/devti/actions/vcs/CommitMessageSuggestionAction.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,11 @@ class CommitMessageSuggestionAction : ChatBaseAction() {
7070

7171
val commitMessageUi = event.getData(VcsDataKeys.COMMIT_MESSAGE_CONTROL) as CommitMessage
7272
// empty commit message before generating
73+
val originText = commitMessageUi.editorField.editor?.selectionModel?.selectedText ?: ""
7374
commitMessageUi.editorField.text = ""
7475

7576
ApplicationManager.getApplication().executeOnPooledThread() {
76-
val prompt = generateCommitMessage(diffContext, project)
77+
val prompt = generateCommitMessage(diffContext, project, originText)
7778

7879
logger.info("Start generating commit message.")
7980
logger.info(prompt)
@@ -149,7 +150,7 @@ class CommitMessageSuggestionAction : ChatBaseAction() {
149150
return builder.toString()
150151
}
151152

152-
private fun generateCommitMessage(diff: String, project: Project): String {
153+
private fun generateCommitMessage(diff: String, project: Project, originText: String): String {
153154
val templateRender = TemplateRender(GENIUS_PRACTISES)
154155
val template = templateRender.getTemplate("gen-commit-msg.vm")
155156

@@ -163,6 +164,7 @@ class CommitMessageSuggestionAction : ChatBaseAction() {
163164
templateRender.context = CommitMsgGenContext(
164165
historyExamples = historyExamples,
165166
diffContent = diff,
167+
originText = originText
166168
)
167169
val prompter = templateRender.renderTemplate(template)
168170

@@ -175,4 +177,6 @@ class CommitMessageSuggestionAction : ChatBaseAction() {
175177
data class CommitMsgGenContext(
176178
var historyExamples: String = "",
177179
var diffContent: String = "",
180+
// the origin commit message which is to be optimized
181+
val originText: String = "",
178182
)

src/main/resources/genius/en/practises/gen-commit-msg.vm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@ Follow the Conventional Commits specification, examples:
88
- fix(authentication): fix password regex pattern case
99
- feat(storage): add support for S3 storage
1010
- test(java): fix test case for user controller
11-
- docs(docs): add architecture diagram to home page
11+
- docs(architecture): add architecture diagram to home page
1212

1313
#if( $context.historyExamples.length() > 0 )
1414
Here is History Examples:
1515
$context.historyExamples
1616
#end
1717

18+
#if($context.originText.length() > 0)
19+
User want to: $context.originText
20+
#end
21+
1822
Diff:
1923

2024
```diff

src/main/resources/genius/zh/practises/gen-commit-msg.vm

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
1-
为给定的差异编写一个连贯但具有描述性的提交信息
1+
为给定的 Diff编写一个连贯但具有描述性的提交信息
22

33
- 确保包含修改了什么以及为什么。
4-
- 以不超过50个字符的祈使句形式开头
4+
- 以不超过 50 个字符的祈使句形式开头
55
- 然后留下一个空行,如有必要,继续详细说明。
66
- 说明应该少于200个字符。
77

88
遵循常规提交规范,例如:
9-
- 修复(身份验证):修复密码正则表达式模式问题
10-
- 功能(存储):添加对S3存储的支持
11-
- 测试(Java):修复用户控制器的测试用例
12-
- 文档(文档):在主页添加架构图
9+
10+
- fix(authentication): 修复密码正则表达式模式问题
11+
- feat(storage): 添加对S3存储的支持
12+
- test(java): 修复用户控制器的测试用例
13+
- docs(architecture): 在主页添加架构图
1314

1415
#if( $context.historyExamples.length() > 0 )
1516
下面是历史示例:
1617
$context.historyExamples
1718
#end
1819

19-
差异:
20+
#if( $context.originText.length() > 0 )
21+
用户想表达的是: $context.originText
22+
#end
23+
24+
Diff:
2025

2126
```diff
2227
${context.diffContent}

0 commit comments

Comments
 (0)