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

Commit b8e4e97

Browse files
committed
feat(settings): add OpenAI token and prompt settings
Added the ability for users to set their OpenAI token and proxy in the plugin settings. Also added a prompt settings section where users can select a locale and manage their prompts. This will provide users with more flexibility and customization options for generating commit messages.
1 parent b120931 commit b8e4e97

6 files changed

Lines changed: 26 additions & 25 deletions

File tree

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,4 @@ object AICommitsBundle : DynamicBundle(BUNDLE) {
3636
}
3737

3838
fun plugin() = PluginManagerCore.getPlugin(PluginId.getId("com.github.marc-r2.commit_gpt-intellij-plugin"))
39-
40-
4139
}

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class AppSettingsConfigurable : BoundConfigurable(message("settings.general.grou
3838
override fun createPanel() = panel {
3939

4040
group(JBLabel("OpenAI")) {
41+
// Set OpenAI token
4142
row {
4243
cell(tokenPasswordField)
4344
.label(message("settings.openAIToken"))
@@ -52,12 +53,16 @@ class AppSettingsConfigurable : BoundConfigurable(message("settings.general.grou
5253
verifyToken()
5354
}.align(AlignX.RIGHT)
5455
}
56+
57+
// Link to OpenAI API page
5558
row {
5659
comment(message("settings.openAITokenComment"))
5760
.align(AlignX.LEFT)
5861
cell(verifyLabel)
5962
.align(AlignX.RIGHT)
6063
}
64+
65+
// Set proxy
6166
row {
6267
textField()
6368
.label(message("settings.openAIProxy"))
@@ -68,16 +73,24 @@ class AppSettingsConfigurable : BoundConfigurable(message("settings.general.grou
6873
}
6974

7075
group(JBLabel("Prompt")) {
76+
// Set locale
7177
row {
72-
comboBox(Locale.getAvailableLocales().toList().sortedBy { it.displayName }, AppSettingsListCellRenderer())
73-
.label(message("settings.locale"))
74-
.bindItem(AppSettings.instance::locale.toNullableProperty())
78+
comboBox(
79+
Locale.getAvailableLocales().toList().sortedBy { it.displayName },
80+
AppSettingsListCellRenderer()
81+
)
82+
.label(message("settings.locale"))
83+
.bindItem(AppSettings.instance::locale.toNullableProperty())
7584
}
85+
86+
/// Current Prompt selection
7687
row {
7788
promptComboBox = comboBox(AppSettings.instance.prompts.values, AppSettingsListCellRenderer())
7889
.label(message("settings.prompt"))
7990
.bindItem(AppSettings.instance::currentPrompt.toNullableProperty())
8091
}
92+
93+
// Prompt table
8194
row {
8295
toolbarDecorator = ToolbarDecorator.createDecorator(promptTable.table)
8396
.setAddAction {

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,8 @@ class AppSettingsListCellRenderer : DefaultListCellRenderer() {
1616
cellHasFocus: Boolean
1717
): Component {
1818
val component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus)
19-
if (value is Locale) {
20-
text = value.displayName
21-
}
22-
if (value is Prompt) {
23-
text = value.name
24-
}
19+
if (value is Locale) text = value.displayName
20+
if (value is Prompt) text = value.name
2521
return component
2622
}
2723
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ data class Prompt(
44
var name: String = "",
55
var description: String = "",
66
var content: String = "",
7-
var canBeChanged: Boolean = true
7+
var canBeChanged: Boolean = true,
88
)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
</extensions>
7979

8080
<actions>
81+
<!-- Button to generate commit message -->
8182
<action
8283
id="AICommit.Button"
8384
text="CommitGPT"

src/main/resources/messages/MyBundle.properties

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
name=CommitGPT
2-
32
settings.title=Settings
43
settings.general.group.title=CommitGPT
54
settings.openAIToken=OpenAI token
@@ -13,35 +12,29 @@ settings.verify.valid=Open AI token is valid.
1312
settings.verify.invalid=Open AI token is not valid ({0}).
1413
settings.verify.running=Verifying Open AI token...
1514
settings.verify.token-is-empty=Open AI token is empty.
16-
1715
action.background=Generating commit message
18-
action.error=Commit message could not be generated.
19-
action.unknown-error=Unknown error has occurred.
20-
2116
notifications.title=CommitGPT
2217
notifications.welcome=Thanks for installing CommitGPT <strong>{0}</strong>
2318
notifications.unsuccessful-request=Error occurred: {0}
24-
notifications.internal-server-error=Internal server error ({0}) occurred.
25-
notifications.unknown-error=Unknown error ({0}).
2619
notification.group.important.name=CommitGPT important
2720
notification.group.general.name=CommitGPT general
2821
notifications.empty-diff=Git diff is empty.
2922
notifications.no-field=Missing commit field
30-
31-
actions.do-not-ask-again = Do not ask me again.
32-
actions.take-me-there = Take me there.
23+
actions.do-not-ask-again=Do not ask me again.
24+
actions.take-me-there=Take me there.
3325
actions.sure-take-me-there=Sure, take me there.
3426
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.
3527
notifications.no-commit-message=Commit field has not been initialized correctly.
36-
settings.promptValidation=Need to include: {diffs}
3728
notifications.uses-prompt=Prompt:\n{0}
3829
notifications.unable-to-save-token=Token could not be saved.
39-
settings.addPrompt=Add prompt
4030
settings.prompt.name=Name
4131
settings.prompt.content=Content
4232
validation.required=This value is required.
4333
validation.number=Value is not a number.
44-
settings.prompt.comment=You can use {locale} and {diff} variables to customise your prompt.
34+
settings.prompt.comment=You can use {locale}, {diff} and {hint} variables to customise your prompt.\
35+
\n{diff} will be replaced with the diff of the staged changes.\
36+
\n{locale} will be replaced with the selected locale.\
37+
\n{hint} will be replaced with the commit message hint, if you provided one.
4538
actions.update=Update
4639
actions.add=Add
4740
settings.prompt.edit.title=Edit Prompt

0 commit comments

Comments
 (0)