@@ -67,6 +67,9 @@ class CommitMessageSuggestionAction : ChatBaseAction() {
67
67
override fun getActionUpdateThread (): ActionUpdateThread = ActionUpdateThread .BGT
68
68
69
69
private var currentJob: Job ? = null
70
+ private var selectedIssue: IssueDisplayItem ? = null
71
+ private var currentChanges: List <Change >? = null
72
+ private var currentEvent: AnActionEvent ? = null
70
73
71
74
override fun getActionType (): ChatActionType = ChatActionType .GEN_COMMIT_MESSAGE
72
75
@@ -112,6 +115,11 @@ class CommitMessageSuggestionAction : ChatBaseAction() {
112
115
return
113
116
}
114
117
118
+ // Store current state for later use
119
+ currentChanges = changes
120
+ currentEvent = event
121
+ selectedIssue = null
122
+
115
123
// Check if it's a GitHub repository and show options
116
124
if (GitHubIssue .isGitHubRepository(project)) {
117
125
showGitHubOptions(project, commitMessage, changes, event)
@@ -299,19 +307,14 @@ class CommitMessageSuggestionAction : ChatBaseAction() {
299
307
}
300
308
301
309
private fun handleIssueSelection (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(" \n Description:" )
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
312
316
313
- commitMessage.setCommitMessage(message)
314
- commitMessage.editorField.selectAll()
317
+ generateAICommitMessage(project, commitMessage, changes, event)
315
318
}
316
319
317
320
private fun generateAICommitMessage (project : Project , commitMessage : CommitMessage , changes : List <Change >, event : AnActionEvent ) {
@@ -385,10 +388,22 @@ class CommitMessageSuggestionAction : ChatBaseAction() {
385
388
" "
386
389
}
387
390
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
+
388
401
templateRender.context = CommitMsgGenContext (
389
402
historyExamples = historyExamples,
390
403
diffContent = diff,
391
- originText = originText
404
+ originText = originText,
405
+ issueId = issue?.number?.toString() ? : " " ,
406
+ issueDetail = issueDetail
392
407
)
393
408
394
409
val prompter = templateRender.renderTemplate(template)
@@ -417,4 +432,7 @@ data class CommitMsgGenContext(
417
432
var diffContent : String = " " ,
418
433
// the origin commit message which is to be optimized
419
434
val originText : String = " " ,
435
+ // GitHub issue information if selected
436
+ val issueId : String = " " ,
437
+ val issueDetail : String = " " ,
420
438
) : TemplateContext
0 commit comments