@@ -2,6 +2,7 @@ package com.github.blarc.ai.commits.intellij.plugin.settings
22
33import com.github.blarc.ai.commits.intellij.plugin.notifications.Notification
44import com.github.blarc.ai.commits.intellij.plugin.notifications.sendNotification
5+ import com.github.blarc.ai.commits.intellij.plugin.settings.prompt.Prompt
56import com.intellij.credentialStore.CredentialAttributes
67import com.intellij.credentialStore.Credentials
78import com.intellij.ide.passwordSafe.PasswordSafe
@@ -15,8 +16,8 @@ import com.intellij.util.xmlb.annotations.OptionTag
1516import java.util.*
1617
1718@State(
18- name = AppSettings .SERVICE_NAME ,
19- storages = [Storage (" AICommit.xml" )]
19+ name = AppSettings .SERVICE_NAME ,
20+ storages = [Storage (" AICommit.xml" )]
2021)
2122class AppSettings : PersistentStateComponent <AppSettings > {
2223
@@ -28,45 +29,25 @@ class AppSettings : PersistentStateComponent<AppSettings> {
2829 var requestSupport = true
2930 var lastVersion: String? = null
3031
31- var currentPrompt: String = " basic"
32- var prompts: MutableMap <String , String > = mutableMapOf (
33- // Generate UUIDs for game objects in Mine.py and call the function in start_game().
34- " basic" to " Write an insightful but concise Git commit message in a complete sentence in present tense for the " +
35- " following diff without prefacing it with anything, the response must be in the language {locale} and must" +
36- " not be longer than 74 characters. The sent text will be the differences between files, where deleted lines" +
37- " are prefixed with a single minus sign and added lines are prefixed with a single plus sign.\n " +
38- " {diff}" ,
39- // feat: generate unique UUIDs for game objects on Mine game start
40- " conventional" to " Write a clean and comprehensive commit message in the conventional commit convention. " +
41- " I'll send you an output of 'git diff --staged' command, and you convert " +
42- " it into a commit message. " +
43- " Do NOT preface the commit with anything. " +
44- " Do NOT add any descriptions to the commit, only commit message. " +
45- " Use the present tense. " +
46- " Lines must not be longer than 74 characters. " +
47- " Use {locale} language to answer.\n " +
48- " {diff}" ,
49- // ✨ feat(mine): Generate objects UUIDs and start team timers on game start
50- " emoji" to " Write a clean and comprehensive commit messages in the conventional commit convention. " +
51- " I'll send you an output of 'git diff --staged' command, and you convert " +
52- " it into a commit message. " +
53- " Use GitMoji convention to preface the commit. " +
54- " Do NOT add any descriptions to the commit, only commit message. " +
55- " Use the present tense. " +
56- " Lines must not be longer than 74 characters. " +
57- " Use {locale} language to answer.\n " +
58- " {diff}" ,
59- )
32+ var prompts: MutableMap <String , Prompt > = initPrompts()
33+ var currentPrompt: Prompt = prompts[" basic" ]!!
6034
6135 companion object {
6236 const val SERVICE_NAME = " com.github.blarc.ai.commits.intellij.plugin.settings.AppSettings"
6337 val instance: AppSettings
6438 get() = ApplicationManager .getApplication().getService(AppSettings ::class .java)
6539 }
6640
67- fun getPrompt (diff : String ) = prompts.getOrDefault(currentPrompt, prompts[" basic" ]!! )
68- .replace(" {locale}" , locale.displayName)
69- .replace(" {diff}" , diff)
41+ fun getPrompt (diff : String ): String {
42+ val content = currentPrompt.content
43+ content.replace(" {locale}" , locale.displayName)
44+
45+ return if (content.contains(" {diff}" )) {
46+ content.replace(" {diff}" , diff)
47+ } else {
48+ " $content \n $diff "
49+ }
50+ }
7051
7152 fun saveOpenAIToken (token : String ) {
7253 try {
@@ -84,10 +65,10 @@ class AppSettings : PersistentStateComponent<AppSettings> {
8465
8566 private fun getCredentialAttributes (title : String ): CredentialAttributes {
8667 return CredentialAttributes (
87- title,
88- null ,
89- this .javaClass,
90- false
68+ title,
69+ null ,
70+ this .javaClass,
71+ false
9172 )
9273 }
9374
@@ -104,6 +85,44 @@ class AppSettings : PersistentStateComponent<AppSettings> {
10485 }
10586 }
10687
88+ private fun initPrompts () = mutableMapOf (
89+ // Generate UUIDs for game objects in Mine.py and call the function in start_game().
90+ " basic" to Prompt (" Basic" ,
91+ " Basic prompt that generates a decent commit message." ,
92+ " Write an insightful but concise Git commit message in a complete sentence in present tense for the " +
93+ " following diff without prefacing it with anything, the response must be in the language {locale} and must " +
94+ " NOT be longer than 74 characters. The sent text will be the differences between files, where deleted lines" +
95+ " are prefixed with a single minus sign and added lines are prefixed with a single plus sign.\n " +
96+ " {diff}" ,
97+ false ),
98+ // feat: generate unique UUIDs for game objects on Mine game start
99+ " conventional" to Prompt (" Conventional" ,
100+ " Prompt for commit message in the conventional commit convention." ,
101+ " Write a clean and comprehensive commit message in the conventional commit convention. " +
102+ " I'll send you an output of 'git diff --staged' command, and you convert " +
103+ " it into a commit message. " +
104+ " Do NOT preface the commit with anything. " +
105+ " Do NOT add any descriptions to the commit, only commit message. " +
106+ " Use the present tense. " +
107+ " Lines must not be longer than 74 characters. " +
108+ " Use {locale} language to answer.\n " +
109+ " {diff}" ,
110+ false ),
111+ // ✨ feat(mine): Generate objects UUIDs and start team timers on game start
112+ " emoji" to Prompt (" Emoji" ,
113+ " Prompt for commit message in the conventional commit convention with GitMoji convention." ,
114+ " Write a clean and comprehensive commit message in the conventional commit convention. " +
115+ " I'll send you an output of 'git diff --staged' command, and you convert " +
116+ " it into a commit message. " +
117+ " Use GitMoji convention to preface the commit. " +
118+ " Do NOT add any descriptions to the commit, only commit message. " +
119+ " Use the present tense. " +
120+ " Lines must not be longer than 74 characters. " +
121+ " Use {locale} language to answer.\n " +
122+ " {diff}" ,
123+ false )
124+ )
125+
107126 class LocaleConverter : Converter <Locale >() {
108127 override fun toString (value : Locale ): String? {
109128 return value.toLanguageTag()
@@ -113,5 +132,4 @@ class AppSettings : PersistentStateComponent<AppSettings> {
113132 return Locale .forLanguageTag(value)
114133 }
115134 }
116-
117- }
135+ }
0 commit comments