Skip to content

Commit e9996f1

Browse files
committed
fix(prompts): notification about common branch can't be shown in dialog
1 parent 971404e commit e9996f1

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
- Open AI configuration setting `organizationId` is not used when verifying configuration.
1717
- Gemini configuration settings `projectId` and `location` are not used when verifying configuration.
18+
- Notification about common branch is shown after the prompt dialog is closed.
1819

1920
## [2.4.1] - 2024-09-19
2021

src/main/kotlin/com/github/blarc/ai/commits/intellij/plugin/AICommitsUtils.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,17 @@ object AICommitsUtils {
7373
return promptContent.replace("{hint}", hint.orEmpty())
7474
}
7575

76-
fun commonBranch(changes: List<Change>, project: Project): String {
76+
fun commonBranch(changes: List<Change>, project: Project, showNotification: Boolean = true): String {
7777
val repositoryManager = GitRepositoryManager.getInstance(project)
7878
var branch = changes.map {
7979
repositoryManager.getRepositoryForFileQuick(it.virtualFile)?.currentBranchName
8080
}.groupingBy { it }.eachCount().maxByOrNull { it.value }?.key
8181

8282
if (branch == null) {
83-
sendNotification(Notification.noCommonBranch())
83+
// Can't show notification in edit prompt dialog
84+
if (showNotification) {
85+
sendNotification(Notification.noCommonBranch())
86+
}
8487
// hardcoded fallback branch
8588
branch = "main"
8689
}

src/main/kotlin/com/github/blarc/ai/commits/intellij/plugin/settings/prompts/PromptTable.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,14 @@ class PromptTable(private val cs: CoroutineScope) {
203203
.flatMap { r -> r.stream() }
204204
.toList()
205205

206-
branch = commonBranch(changes, project)
206+
branch = commonBranch(changes, project, false)
207207
diff = computeDiff(changes, true, project)
208208

209209
withContext(Dispatchers.EDT) {
210210
setPreview(prompt.content, promptHintTextField.text)
211211
}
212212
}
213+
213214
private fun setPreview(promptContent: String, hint: String) {
214215
val constructPrompt = AICommitsUtils.constructPrompt(promptContent, diff, branch, hint, project)
215216
promptPreviewTextArea.text = constructPrompt.substring(0, constructPrompt.length.coerceAtMost(10000))

0 commit comments

Comments
 (0)