Skip to content
This repository was archived by the owner on Nov 4, 2024. It is now read-only.

Commit ae1ff2b

Browse files
committed
Merge branch 'main' into dev_marc
# Conflicts: # gradle.properties # src/main/kotlin/com/github/blarc/ai/commits/intellij/plugin/AICommitAction.kt # src/main/kotlin/com/github/blarc/ai/commits/intellij/plugin/OpenAIService.kt # src/main/kotlin/com/github/blarc/ai/commits/intellij/plugin/notifications/Notification.kt # src/main/kotlin/com/github/blarc/ai/commits/intellij/plugin/settings/AppSettings.kt # src/main/resources/messages/MyBundle.properties
2 parents a5dc258 + d200ef8 commit ae1ff2b

9 files changed

Lines changed: 91 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
# Changelog
22

33
## [Unreleased]
4+
5+
## [0.5.0] - 2023-04-04
6+
47
### Added
58
- Add button for verifying Open AI token in settings.
9+
- Check if prompt is too large for Open AI API.
10+
- Welcome and star notification.
11+
12+
### Changed
13+
- Set default Locale to English.
14+
- Target latest intellij version (2023.1).
15+
- Improve error handling.
616

17+
### Fixed
18+
- Properly serialize Locale when saving settings.
719

820
## [0.4.0] - 2023-03-29
921

@@ -26,7 +38,8 @@
2638
- Settings for locale and OpenAI token.
2739
- Create commit message only for selected files.
2840

29-
[Unreleased]: https://github.com/Blarc/ai-commits-intellij-plugin/compare/v0.4.0...HEAD
41+
[Unreleased]: https://github.com/Blarc/ai-commits-intellij-plugin/compare/v0.5.0...HEAD
42+
[0.5.0]: https://github.com/Blarc/ai-commits-intellij-plugin/compare/v0.4.0...v0.5.0
3043
[0.4.0]: https://github.com/Blarc/ai-commits-intellij-plugin/compare/v0.3.0...v0.4.0
3144
[0.3.0]: https://github.com/Blarc/ai-commits-intellij-plugin/compare/v0.2.0...v0.3.0
3245
[0.2.0]: https://github.com/Blarc/ai-commits-intellij-plugin/commits/v0.2.0

build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
44
fun properties(key: String) = project.findProperty(key).toString()
55

66
plugins {
7-
id("org.jetbrains.kotlin.jvm") version "1.8.10"
7+
id("org.jetbrains.kotlin.jvm") version "1.8.20"
88
id("org.jetbrains.intellij") version "1.13.3"
99

1010
// Gradle Changelog Plugin
@@ -114,4 +114,6 @@ dependencies {
114114
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk7")
115115
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk8")
116116
}
117+
118+
implementation("com.knuddels:jtokkit:0.1.0")
117119
}

gradle.properties

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ pluginGroup = com.github.blarc
33
pluginName = AICommits
44
pluginRepositoryUrl = https://github.com/Blarc/ai-commits-intellij-plugin
55
# SemVer format -> https://semver.org
6-
pluginVersion = 0.5.1
6+
pluginVersion = 0.5.2
77

88
# https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
9-
pluginSinceBuild = 223
9+
pluginSinceBuild = 231
1010
# pluginUntilBuild = 222.*
1111

1212
# https://github.com/JetBrains/gradle-intellij-plugin#intellij-platform-properties
@@ -29,4 +29,7 @@ gradleVersion = 8.0.2
2929
kotlin.stdlib.default.dependency = false
3030

3131
# Enable Gradle Configuration Cache -> https://docs.gradle.org/current/userguide/configuration_cache.html
32-
org.gradle.unsafe.configuration-cache = true
32+
org.gradle.unsafe.configuration-cache = true
33+
34+
# Prevent OOM: https://plugins.jetbrains.com/docs/intellij/using-kotlin.html#incremental-compilation
35+
kotlin.incremental.useClasspathSnapshot=false

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.github.blarc.ai.commits.intellij.plugin
33
import com.github.blarc.ai.commits.intellij.plugin.AICommitsBundle.message
44
import com.github.blarc.ai.commits.intellij.plugin.notifications.Notification
55
import com.github.blarc.ai.commits.intellij.plugin.notifications.sendNotification
6+
import com.github.blarc.ai.commits.intellij.plugin.settings.AppSettings
67
import com.intellij.openapi.actionSystem.AnAction
78
import com.intellij.openapi.actionSystem.AnActionEvent
89
import com.intellij.openapi.diff.impl.patch.IdeaTextPatchBuilder
@@ -14,6 +15,8 @@ import com.intellij.openapi.vcs.VcsDataKeys
1415
import com.intellij.openapi.vcs.changes.Change
1516
import com.intellij.openapi.vcs.ui.CommitMessage
1617
import com.intellij.vcs.commit.AbstractCommitWorkflowHandler
18+
import com.knuddels.jtokkit.Encodings
19+
import com.knuddels.jtokkit.api.EncodingType
1720
import git4idea.repo.GitRepositoryManager
1821
import kotlinx.coroutines.DelicateCoroutinesApi
1922
import kotlinx.coroutines.Dispatchers
@@ -60,6 +63,7 @@ class AICommitAction : AnAction(), DumbAware {
6063
try {
6164
val generatedCommitMessage = openAIService.generateCommitMessage(diff, hint, 1)
6265
commitMessageField.setCommitMessage(generatedCommitMessage)
66+
AppSettings.instance.recordHit()
6367
} catch (e: Exception) {
6468
commitMessageField.setCommitMessage("Error generating commit message")
6569
sendNotification(Notification.unsuccessfulRequest(e.message ?: "Unknown error"))
@@ -105,4 +109,10 @@ class AICommitAction : AnAction(), DumbAware {
105109
}
106110
.joinToString("\n")
107111
}
112+
113+
private fun isPromptTooLarge(prompt: String): Boolean {
114+
val registry = Encodings.newDefaultEncodingRegistry()
115+
val encoding = registry.getEncoding(EncodingType.CL100K_BASE)
116+
return encoding.countTokens(prompt) > 4000
117+
}
108118
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.github.blarc.ai.commits.intellij.plugin.listeners
2+
3+
import com.github.blarc.ai.commits.intellij.plugin.AICommitsBundle
4+
import com.github.blarc.ai.commits.intellij.plugin.notifications.Notification
5+
import com.github.blarc.ai.commits.intellij.plugin.notifications.sendNotification
6+
import com.github.blarc.ai.commits.intellij.plugin.settings.AppSettings
7+
import com.intellij.openapi.project.Project
8+
import com.intellij.openapi.startup.ProjectActivity
9+
10+
class ApplicationStartupListener : ProjectActivity {
11+
12+
private var firstTime = true
13+
override suspend fun execute(project: Project) {
14+
showVersionNotification(project)
15+
}
16+
private fun showVersionNotification(project: Project) {
17+
val settings = AppSettings.instance
18+
val version = AICommitsBundle.plugin()?.version
19+
20+
if (version == settings.lastVersion) {
21+
return
22+
}
23+
24+
settings.lastVersion = version
25+
if (firstTime && version != null) {
26+
sendNotification(Notification.welcome(version), project)
27+
}
28+
firstTime = false
29+
}
30+
}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ data class Notification(
2323
companion object {
2424
private val DEFAULT_TITLE = message("notifications.title")
2525

26-
fun welcome(version: String) = Notification(message = message("notifications.welcome", version))
26+
fun welcome(version: String) = Notification(message = message("notifications.welcome", version), type = Type.TRANSIENT)
2727

2828
fun star() = Notification(
2929
message = """
30-
Finding Gitlab Template Lint useful? Show your support 💖 and ⭐ the repository 🙏.
30+
Finding Commit-GPT useful? Show your support 💖 and ⭐ the repository 🙏.
3131
""".trimIndent(),
3232
actions = setOf(
3333
NotificationAction.openRepository() {
@@ -43,7 +43,13 @@ data class Notification(
4343

4444
fun emptyDiff() = Notification(DEFAULT_TITLE, message = message("notifications.empty-diff"))
4545

46-
fun unsuccessfulRequest(message: String) = Notification(message = message("notifications.unsuccessful-request", message))
46+
fun promptTooLarge() = Notification(DEFAULT_TITLE, message = message("notifications.prompt-too-large"))
47+
48+
fun unsuccessfulRequest(message: String) = Notification(
49+
message = message("notifications.unsuccessful-request", message)
50+
)
51+
52+
fun noCommitMessage(): Notification = Notification(message = message("notifications.no-commit-message"))
4753

4854
fun unableToSaveToken() = Notification(message = message("notifications.unable-to-save-token"))
4955

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ import com.intellij.openapi.application.ApplicationManager
1010
import com.intellij.openapi.components.PersistentStateComponent
1111
import com.intellij.openapi.components.State
1212
import com.intellij.openapi.components.Storage
13+
import com.intellij.util.xmlb.Converter
1314
import com.intellij.util.xmlb.XmlSerializerUtil
14-
import java.util.Locale
15+
import com.intellij.util.xmlb.annotations.OptionTag
16+
import java.util.*
1517

1618
@State(
1719
name = AppSettings.SERVICE_NAME,
@@ -22,6 +24,8 @@ class AppSettings : PersistentStateComponent<AppSettings> {
2224
private val openAITokenTitle = "OpenAIToken"
2325
private val openAIPromptTitle = "OpenAIPrompt"
2426

27+
private var hits = 0
28+
2529
private var defaultPrompt = "Write a git commit message. " +
2630
"Use the conventional commit convention and follow best practices to maintain clear and concise commit messages. " +
2731
"The format have to be 'type(scope): short' and should not exceed 74 characters.\n" +
@@ -40,7 +44,6 @@ class AppSettings : PersistentStateComponent<AppSettings> {
4044
}
4145

4246
fun saveOpenAIToken(token: String) {
43-
println("Saving token: $token")
4447
try {
4548
PasswordSafe.instance.setPassword(getCredentialAttributes(openAITokenTitle), token)
4649
} catch (e: Exception) {
@@ -79,4 +82,11 @@ class AppSettings : PersistentStateComponent<AppSettings> {
7982
}
8083

8184

85+
fun recordHit() {
86+
hits++
87+
return
88+
if (requestSupport && (hits == 50 || hits % 100 == 0)) {
89+
sendNotification(Notification.star())
90+
}
91+
}
8292
}

src/main/resources/META-INF/plugin.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@
6363
displayType="STICKY_BALLOON"
6464
key="notification.group.important.name"
6565
/>
66+
<postStartupActivity
67+
implementation="com.github.blarc.ai.commits.intellij.plugin.listeners.ApplicationStartupListener"/>
68+
6669
</extensions>
6770

6871
<actions>

src/main/resources/messages/MyBundle.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ settings.verify.running=Verifying Open AI token...
1414
settings.verify.token-is-empty=Open AI token is empty.
1515

1616
action.background=Generating commit message
17+
action.error=Commit message could not be generated.
18+
action.unknown-error=Unknown error has occurred.
1719

1820
notifications.title=AI Commits
1921
notifications.welcome=Thanks for installing AI Commits <strong>{0}</strong>
@@ -29,6 +31,8 @@ notifications.unable-to-save-token=Unable to save token
2931
actions.do-not-ask-again = Do not ask me again.
3032
actions.take-me-there = Take me there.
3133
actions.sure-take-me-there=Sure, take me there.
34+
notifications.prompt-too-large=The diff is too large for the OpenAI API. Try reducing the number of staged changes, or write your own commit message.
35+
notifications.no-commit-message=Commit field has not been initialized correctly.
3236
settings.promptValidation=Need to include: {diffs}
3337
notifications.uses-prompt=Prompt:\n{0}
3438

0 commit comments

Comments
 (0)