@@ -70,6 +70,7 @@ class CommitMessageSuggestionAction : ChatBaseAction() {
70
70
private var selectedIssue: IssueDisplayItem ? = null
71
71
private var currentChanges: List <Change >? = null
72
72
private var currentEvent: AnActionEvent ? = null
73
+ private var isGitHubRepository: Boolean = false
73
74
74
75
override fun getActionType (): ChatActionType = ChatActionType .GEN_COMMIT_MESSAGE
75
76
@@ -86,8 +87,11 @@ class CommitMessageSuggestionAction : ChatBaseAction() {
86
87
val prompting = project.service<VcsPrompting >()
87
88
val changes: List <Change > = prompting.getChanges()
88
89
90
+ // Check if it's a GitHub repository (safe to call in BGT)
91
+ isGitHubRepository = GitHubIssue .isGitHubRepository(project)
92
+
89
93
// Update presentation text based on whether it's a GitHub repository
90
- if (GitHubIssue . isGitHubRepository(project) ) {
94
+ if (isGitHubRepository) {
91
95
e.presentation.text = " Smart Commit Message (GitHub Enhanced)"
92
96
e.presentation.description = " Generate commit message with AI or GitHub issue integration"
93
97
} else {
@@ -120,34 +124,17 @@ class CommitMessageSuggestionAction : ChatBaseAction() {
120
124
currentEvent = event
121
125
selectedIssue = null
122
126
123
- // Check if it's a GitHub repository and show options
124
- if (GitHubIssue .isGitHubRepository(project)) {
125
- showGitHubOptions(project, commitMessage, changes, event)
127
+ // For GitHub repositories, show issue selection popup directly
128
+ // For non-GitHub repositories, generate AI commit message directly
129
+ if (isGitHubRepository) {
130
+ generateGitHubIssueCommitMessage(project, commitMessage, event)
126
131
} else {
127
132
generateAICommitMessage(project, commitMessage, changes, event)
128
133
}
129
134
}
130
135
131
136
private fun getCommitMessage (e : AnActionEvent ) = e.getData(VcsDataKeys .COMMIT_MESSAGE_CONTROL ) as ? CommitMessage
132
137
133
- private fun showGitHubOptions (project : Project , commitMessage : CommitMessage , changes : List <Change >, event : AnActionEvent ) {
134
- val options = arrayOf(" Use GitHub Issue" , " Generate with AI" , " Cancel" )
135
- val choice = Messages .showDialog(
136
- project,
137
- " Choose how to generate commit message:" ,
138
- " Commit Message Generation" ,
139
- options,
140
- 0 ,
141
- Messages .getQuestionIcon()
142
- )
143
-
144
- when (choice) {
145
- 0 -> generateGitHubIssueCommitMessage(project, commitMessage, event)
146
- 1 -> generateAICommitMessage(project, commitMessage, changes, event)
147
- // 2 or -1 (Cancel or ESC) - do nothing
148
- }
149
- }
150
-
151
138
private fun generateGitHubIssueCommitMessage (project : Project , commitMessage : CommitMessage , event : AnActionEvent ) {
152
139
val task = object : Task .Backgroundable (project, " Loading GitHub issues" , true ) {
153
140
override fun run (indicator : ProgressIndicator ) {
@@ -160,22 +147,19 @@ class CommitMessageSuggestionAction : ChatBaseAction() {
160
147
indicator.fraction = 0.9
161
148
ApplicationManager .getApplication().invokeLater {
162
149
if (issues.isEmpty()) {
163
- Messages .showInfoMessage(
164
- project,
165
- " No issues found in this GitHub repository." ,
166
- " GitHub Issues"
167
- )
150
+ // No issues found, fall back to AI generation
151
+ val changes = currentChanges ? : return @invokeLater
152
+ generateAICommitMessage(project, commitMessage, changes, event)
168
153
} else {
169
154
createIssuesPopup(commitMessage, issues).showInBestPositionFor(event.dataContext)
170
155
}
171
156
}
172
157
} catch (ex: Exception ) {
173
158
ApplicationManager .getApplication().invokeLater {
174
- Messages .showErrorDialog(
175
- project,
176
- " Failed to fetch GitHub issues: ${ex.message} " ,
177
- " GitHub Issues Error"
178
- )
159
+ logger.warn(" Failed to fetch GitHub issues, falling back to AI generation" , ex)
160
+ // Fall back to AI generation when GitHub issues fetch fails
161
+ val changes = currentChanges ? : return @invokeLater
162
+ generateAICommitMessage(project, commitMessage, changes, event)
179
163
}
180
164
}
181
165
}
@@ -243,9 +227,10 @@ class CommitMessageSuggestionAction : ChatBaseAction() {
243
227
244
228
private fun createIssuesPopup (commitMessage : CommitMessage , issues : List <IssueDisplayItem >): JBPopup {
245
229
var chosenIssue: IssueDisplayItem ? = null
230
+ var selectedIndex: Int = - 1
246
231
247
232
return JBPopupFactory .getInstance().createPopupChooserBuilder(issues)
248
- .setTitle(" Select Issue" )
233
+ .setTitle(" Select GitHub Issue (ESC to skip) " )
249
234
.setVisibleRowCount(10 )
250
235
.setSelectionMode(SINGLE_SELECTION )
251
236
.setItemSelectedCallback { chosenIssue = it }
@@ -283,8 +268,12 @@ class CommitMessageSuggestionAction : ChatBaseAction() {
283
268
override fun onClosed (event : LightweightWindowEvent ) {
284
269
// IDEA-195094 Regression: New CTRL-E in "commit changes" breaks keyboard shortcuts
285
270
commitMessage.editorField.requestFocusInWindow()
286
- chosenIssue?.let { issue ->
287
- handleIssueSelection(issue, commitMessage)
271
+ if (chosenIssue != null ) {
272
+ // User selected an issue
273
+ handleIssueSelection(chosenIssue!! , commitMessage)
274
+ } else {
275
+ // User cancelled (ESC) - skip issue selection and generate with AI
276
+ handleSkipIssueSelection(commitMessage)
288
277
}
289
278
}
290
279
})
@@ -307,13 +296,26 @@ class CommitMessageSuggestionAction : ChatBaseAction() {
307
296
}
308
297
309
298
private fun handleIssueSelection (issueItem : IssueDisplayItem , commitMessage : CommitMessage ) {
299
+ // Store the selected issue for AI generation
310
300
selectedIssue = issueItem
311
301
312
- // Now generate AI commit message with issue context
313
302
val project = commitMessage.editorField.project ? : return
314
303
val changes = currentChanges ? : return
315
304
val event = currentEvent ? : return
316
305
306
+ // Generate AI commit message with issue context
307
+ generateAICommitMessage(project, commitMessage, changes, event)
308
+ }
309
+
310
+ private fun handleSkipIssueSelection (commitMessage : CommitMessage ) {
311
+ // Skip issue selection, generate with AI only
312
+ selectedIssue = null
313
+
314
+ val project = commitMessage.editorField.project ? : return
315
+ val changes = currentChanges ? : return
316
+ val event = currentEvent ? : return
317
+
318
+ // Generate AI commit message without issue context
317
319
generateAICommitMessage(project, commitMessage, changes, event)
318
320
}
319
321
0 commit comments