Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitccfcbcd

Browse files
committed
feat(commit): integrate GitHub issue context into AI generation#408
Enhance AI commit message generation by incorporating selected GitHub issue information into the prompt context, allowing the AI to generate more relevant commit messages that reference the related issue and its details.
1 parent61b5395 commitccfcbcd

File tree

3 files changed

+41
-13
lines changed

3 files changed

+41
-13
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ $context.historyExamples
2424
User origin intention was: $context.originText
2525
#end
2626

27+
#if($context.issueId.length() > 0)
28+
Related GitHub Issue: #$context.issueId
29+
$context.issueDetail
30+
#end
31+
2732
Diff:
2833

2934
```diff

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ $context.historyExamples
2323
用户先前的意图是: $context.originText
2424
#end
2525

26+
#if( $context.issueId.length() > 0 )
27+
相关 GitHub Issue: #$context.issueId
28+
$context.issueDetail
29+
#end
30+
2631
代码变更(Diff):
2732

2833
```diff

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

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ class CommitMessageSuggestionAction : ChatBaseAction() {
6767
overridefungetActionUpdateThread():ActionUpdateThread=ActionUpdateThread.BGT
6868

6969
privatevar currentJob:Job?=null
70+
privatevar selectedIssue:IssueDisplayItem?=null
71+
privatevar currentChanges:List<Change>?=null
72+
privatevar currentEvent:AnActionEvent?=null
7073

7174
overridefungetActionType():ChatActionType=ChatActionType.GEN_COMMIT_MESSAGE
7275

@@ -112,6 +115,11 @@ class CommitMessageSuggestionAction : ChatBaseAction() {
112115
return
113116
}
114117

118+
// Store current state for later use
119+
currentChanges= changes
120+
currentEvent= event
121+
selectedIssue=null
122+
115123
// Check if it's a GitHub repository and show options
116124
if (GitHubIssue.isGitHubRepository(project)) {
117125
showGitHubOptions(project, commitMessage, changes, event)
@@ -299,19 +307,14 @@ class CommitMessageSuggestionAction : ChatBaseAction() {
299307
}
300308

301309
privatefunhandleIssueSelection(issueItem:IssueDisplayItem,commitMessage:CommitMessage) {
302-
val issue= issueItem.issue
303-
val message= buildString {
304-
appendLine("Selected Issue: #${issue.number}")
305-
appendLine("Title:${issue.title}")
306-
307-
if (!issue.body.isNullOrBlank()) {
308-
appendLine("\nDescription:")
309-
appendLine(issue.body)
310-
}
311-
}
310+
selectedIssue= issueItem
311+
312+
// Now generate AI commit message with issue context
313+
val project= commitMessage.editorField.project?:return
314+
val changes= currentChanges?:return
315+
val event= currentEvent?:return
312316

313-
commitMessage.setCommitMessage(message)
314-
commitMessage.editorField.selectAll()
317+
generateAICommitMessage(project, commitMessage, changes, event)
315318
}
316319

317320
privatefungenerateAICommitMessage(project:Project,commitMessage:CommitMessage,changes:List<Change>,event:AnActionEvent) {
@@ -385,10 +388,22 @@ class CommitMessageSuggestionAction : ChatBaseAction() {
385388
""
386389
}
387390

391+
val issue= selectedIssue?.issue
392+
val issueDetail=if (issue!=null) {
393+
buildString {
394+
appendLine("Title:${issue.title}")
395+
if (!issue.body.isNullOrBlank()) {
396+
appendLine("Description:${issue.body}")
397+
}
398+
}
399+
}else""
400+
388401
templateRender.context=CommitMsgGenContext(
389402
historyExamples= historyExamples,
390403
diffContent= diff,
391-
originText= originText
404+
originText= originText,
405+
issueId= issue?.number?.toString()?:"",
406+
issueDetail= issueDetail
392407
)
393408

394409
val prompter= templateRender.renderTemplate(template)
@@ -417,4 +432,7 @@ data class CommitMsgGenContext(
417432
vardiffContent:String ="",
418433
// the origin commit message which is to be optimized
419434
valoriginText:String ="",
435+
// GitHub issue information if selected
436+
valissueId:String ="",
437+
valissueDetail:String ="",
420438
) : TemplateContext

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp