Skip to content

Commit 3a0ae1c

Browse files
committed
feat: support language for commit message generation
- Extend the GenerateCommitMessage constructor to include a language parameter and use it in the selected language prompt logic. - Add property for commit message language with default value "English". - Add integration related configuration strings for commit message language. - Add property for CommitMessageLanguage in RepositoryConfigure. - Add language parameter to AIAssistant constructor and propagate it to GenerateCommitMessage. - Add integration configuration options in the repository settings view.
1 parent ac543db commit 3a0ae1c

13 files changed

+69
-95
lines changed

src/Commands/GenerateCommitMessage.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ public GetDiffContent(string repo, Models.DiffOption opt)
2020
}
2121
}
2222

23-
public GenerateCommitMessage(string repo, List<Models.Change> changes, CancellationToken cancelToken, Action<string> onProgress)
23+
public GenerateCommitMessage(string repo, string language, List<Models.Change> changes, CancellationToken cancelToken, Action<string> onProgress)
2424
{
2525
_repo = repo;
26+
_language = language ?? "English";
2627
_changes = changes;
2728
_cancelToken = cancelToken;
2829
_onProgress = onProgress;
@@ -70,11 +71,11 @@ public string Result()
7071
}
7172
}
7273

73-
private static string GetSelectedLanguagePrompt()
74+
private string GetSelectedLanguagePrompt()
7475
{
75-
var selectedLanguage = Models.OpenAI.SelectedLanguage == "English"
76+
var selectedLanguage = _language == "English"
7677
? string.Empty
77-
: $"{Environment.NewLine}Always write in {Models.OpenAI.SelectedLanguage}";
78+
: $"{Environment.NewLine}Always write in {_language}";
7879

7980
return selectedLanguage;
8081
}
@@ -106,5 +107,6 @@ private string GenerateSubject(string summary)
106107
private List<Models.Change> _changes;
107108
private CancellationToken _cancelToken;
108109
private Action<string> _onProgress;
110+
private readonly string _language;
109111
}
110112
}

src/Models/OpenAI.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,6 @@ public static string Model
9494
set;
9595
}
9696

97-
public static string SelectedLanguage
98-
{
99-
get;
100-
set;
101-
}
102-
10397
public static string AnalyzeDiffPrompt
10498
{
10599
get;

src/Models/RepositorySettings.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ public bool EnableSignOffForCommit
112112
set;
113113
} = false;
114114

115+
public string CommitMessageLanguage
116+
{
117+
get;
118+
set;
119+
} = "English";
120+
115121
public void PushCommitMessage(string message)
116122
{
117123
var existIdx = CommitMessages.IndexOf(message);

src/Resources/Icons.axaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
<StreamGeometry x:Key="Icons.Init">M412 66C326 132 271 233 271 347c0 17 1 34 4 50-41-48-98-79-162-83a444 444 0 00-46 196c0 207 142 382 337 439h2c19 0 34 15 34 33 0 11-6 21-14 26l1 14C183 973 0 763 0 511 0 272 166 70 393 7A35 35 0 01414 0c19 0 34 15 34 33a33 33 0 01-36 33zm200 893c86-66 141-168 141-282 0-17-1-34-4-50 41 48 98 79 162 83a444 444 0 0046-196c0-207-142-382-337-439h-2a33 33 0 01-34-33c0-11 6-21 14-26L596 0C841 51 1024 261 1024 513c0 239-166 441-393 504A35 35 0 01610 1024a33 33 0 01-34-33 33 33 0 0136-33zM512 704a192 192 0 110-384 192 192 0 010 384z</StreamGeometry>
6262
<StreamGeometry x:Key="Icons.InteractiveRebase">M512 64A447 447 0 0064 512c0 248 200 448 448 448s448-200 448-448S760 64 512 64zM218 295h31c54 0 105 19 145 55 13 12 13 31 3 43a35 35 0 01-22 10 36 36 0 01-21-7 155 155 0 00-103-39h-31a32 32 0 01-31-31c0-18 13-31 30-31zm31 433h-31a32 32 0 01-31-31c0-16 13-31 31-31h31A154 154 0 00403 512 217 217 0 01620 295h75l-93-67a33 33 0 01-7-43 33 33 0 0143-7l205 148-205 148a29 29 0 01-18 6 32 32 0 01-31-31c0-10 4-19 13-25l93-67H620a154 154 0 00-154 154c0 122-97 220-217 220zm390 118a29 29 0 01-18 6 32 32 0 01-31-31c0-10 4-19 13-25l93-67h-75c-52 0-103-19-143-54-12-12-13-31-1-43a30 30 0 0142-3 151 151 0 00102 39h75L602 599a33 33 0 01-7-43 33 33 0 0143-7l205 148-203 151z</StreamGeometry>
6363
<StreamGeometry x:Key="Icons.Issue">M922 39H102A65 65 0 0039 106v609a65 65 0 0063 68h94v168a34 34 0 0019 31 30 30 0 0012 3 30 30 0 0022-10l182-192H922a65 65 0 0063-68V106A65 65 0 00922 39zM288 378h479a34 34 0 010 68H288a34 34 0 010-68zm0-135h479a34 34 0 010 68H288a34 34 0 010-68zm0 270h310a34 34 0 010 68H288a34 34 0 010-68z</StreamGeometry>
64-
<StreamGeometry x:Key="Icons.LanguageSelection">M480-120q-74.31 0-140-28.42-65.69-28.43-114.42-77.16-48.73-48.73-77.16-114.42Q120-405.69 120-480q0-74.54 28.42-140.12 28.43-65.57 77.16-114.3 48.73-48.73 114.42-77.16Q405.69-840 480-840q74.54 0 140.12 28.42 65.57 28.43 114.3 77.16 48.73 48.73 77.16 114.3Q840-554.54 840-480q0 74.31-28.42 140-28.43 65.69-77.16 114.42-48.73 48.73-114.3 77.16Q554.54-120 480-120Zm0-39.69q35.23-45.23 58.08-88.85 22.84-43.61 37.15-97.61H384.77q15.85 57.07 37.92 100.69 22.08 43.61 57.31 85.77Zm-50.92-6q-28-33-51.12-81.58-23.11-48.58-34.42-98.88H190.15q34.39 74.61 97.5 122.38 63.12 47.77 141.43 58.08Zm101.84 0q78.31-10.31 141.43-58.08 63.11-47.77 97.5-122.38H616.46q-15.15 51.07-38.27 99.65-23.11 48.58-47.27 80.81ZM173.85-386.15h161.38q-4.54-24.62-6.42-47.97-1.89-23.34-1.89-45.88 0-22.54 1.89-45.88 1.88-23.35 6.42-47.97H173.85q-6.54 20.77-10.2 45.27Q160-504.08 160-480t3.65 48.58q3.66 24.5 10.2 45.27Zm201.38 0h209.54q4.54-24.62 6.42-47.2 1.89-22.57 1.89-46.65t-1.89-46.65q-1.88-22.58-6.42-47.2H375.23q-4.54 24.62-6.42 47.2-1.89 22.57-1.89 46.65t1.89 46.65q1.88 22.58 6.42 47.2Zm249.54 0h161.38q6.54-20.77 10.2-45.27Q800-455.92 800-480t-3.65-48.58q-3.66-24.5-10.2-45.27H624.77q4.54 24.62 6.42 47.97 1.89 23.34 1.89 45.88 0 22.54-1.89 45.88-1.88 23.35-6.42 47.97Zm-8.31-227.7h153.39Q734.69-690 673.5-736.23q-61.19-46.23-142.58-58.85 28 36.85 50.35 84.27 22.35 47.43 35.19 96.96Zm-231.69 0h190.46q-15.85-56.3-39.08-101.84-23.23-45.54-56.15-84.62-32.92 39.08-56.15 84.62-23.23 45.54-39.08 101.84Zm-194.62 0h153.39q12.84-49.53 35.19-96.96 22.35-47.42 50.35-84.27-82.16 12.62-142.96 59.23-60.81 46.62-95.97 122Z</StreamGeometry>
6564
<StreamGeometry x:Key="Icons.LayoutHorizontal">M875 117H149C109 117 75 151 75 192v640c0 41 34 75 75 75h725c41 0 75-34 75-75V192c0-41-34-75-75-75zM139 832V192c0-6 4-11 11-11h331v661H149c-6 0-11-4-11-11zm747 0c0 6-4 11-11 11H544v-661H875c6 0 11 4 11 11v640z</StreamGeometry>
6665
<StreamGeometry x:Key="Icons.LayoutVertical">M875 117H149C109 117 75 151 75 192v640c0 41 34 75 75 75h725c41 0 75-34 75-75V192c0-41-34-75-75-75zm-725 64h725c6 0 11 4 11 11v288h-747V192c0-6 4-11 11-11zm725 661H149c-6 0-11-4-11-11V544h747V832c0 6-4 11-11 11z</StreamGeometry>
6766
<StreamGeometry x:Key="Icons.LFS">M40 9 15 23 15 31 9 28 9 20 34 5 24 0 0 14 0 34 25 48 25 28 49 14zM26 29 26 48 49 34 49 15z</StreamGeometry>

src/Resources/Locales/en_US.axaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
<x:String x:Key="Text.AddWorktree.Tracking" xml:space="preserve">Track Branch:</x:String>
2020
<x:String x:Key="Text.AddWorktree.Tracking.Toggle" xml:space="preserve">Tracking remote branch</x:String>
2121
<x:String x:Key="Text.AIAssistant" xml:space="preserve">OpenAI Assistant</x:String>
22-
<x:String x:Key="Text.AIAssistant.SelectedLanguageTip" xml:space="preserve">Language used to generate commit message</x:String>
2322
<x:String x:Key="Text.AIAssistant.Tip" xml:space="preserve">Use OpenAI to generate commit message</x:String>
2423
<x:String x:Key="Text.Apply" xml:space="preserve">Patch</x:String>
2524
<x:String x:Key="Text.Apply.Error" xml:space="preserve">Error</x:String>
@@ -145,6 +144,8 @@
145144
<x:String x:Key="Text.Configure.Git.AutoFetchIntervalSuffix" xml:space="preserve">Minute(s)</x:String>
146145
<x:String x:Key="Text.Configure.Git.DefaultRemote" xml:space="preserve">Default Remote</x:String>
147146
<x:String x:Key="Text.Configure.Git.EnableSignOff" xml:space="preserve">Enable --signoff for commit</x:String>
147+
<x:String x:Key="Text.Configure.Integration" xml:space="preserve">INTEGRATION</x:String>
148+
<x:String x:Key="Text.Configure.Integration.Language" xml:space="preserve">Commit Message Language</x:String>
148149
<x:String x:Key="Text.Configure.IssueTracker" xml:space="preserve">ISSUE TRACKER</x:String>
149150
<x:String x:Key="Text.Configure.IssueTracker.AddSampleGithub" xml:space="preserve">Add Sample Github Rule</x:String>
150151
<x:String x:Key="Text.Configure.IssueTracker.AddSampleJira" xml:space="preserve">Add Sample Jira Rule</x:String>

src/Resources/Locales/pt_BR.axaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
<x:String x:Key="Text.AddWorktree.WhatToCheckout" xml:space="preserve">O que Checar:</x:String>
2222
<x:String x:Key="Text.AddWorktree" xml:space="preserve">Adicionar Worktree</x:String>
2323
<x:String x:Key="Text.AIAssistant" xml:space="preserve">Assistente do OpenAI</x:String>
24-
<x:String x:Key="Text.AIAssistant.SelectedLanguageTip" xml:space="preserve">Idioma usado a gerar a mensagem de commit</x:String>
2524
<x:String x:Key="Text.AIAssistant.Tip" xml:space="preserve">Usar OpenAI para gerar mensagem de commit</x:String>
2625
<x:String x:Key="Text.Apply.Error.Desc" xml:space="preserve">Erros levantados e se recusa a aplicar o patch</x:String>
2726
<x:String x:Key="Text.Apply.Error" xml:space="preserve">Erro</x:String>
@@ -136,6 +135,8 @@
136135
<x:String x:Key="Text.Configure.Git.AutoFetch" xml:space="preserve">Buscar remotos automaticamente</x:String>
137136
<x:String x:Key="Text.Configure.Git.AutoFetchIntervalSuffix" xml:space="preserve">Minuto(s)</x:String>
138137
<x:String x:Key="Text.Configure.Git" xml:space="preserve">GIT</x:String>
138+
<x:String x:Key="Text.Configure.Integration" xml:space="preserve">INTEGRAÇÃO</x:String>
139+
<x:String x:Key="Text.Configure.Integration.Language" xml:space="preserve">Idioma para mensagem de commit</x:String>
139140
<x:String x:Key="Text.Configure.IssueTracker.AddSampleGithub" xml:space="preserve">Adicionar Regra de Exemplo do Github</x:String>
140141
<x:String x:Key="Text.Configure.IssueTracker.AddSampleJira" xml:space="preserve">Adicionar Regra de Exemplo do Jira</x:String>
141142
<x:String x:Key="Text.Configure.IssueTracker.NewRule" xml:space="preserve">Nova Regra</x:String>

src/ViewModels/Preference.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -316,19 +316,6 @@ public string OpenAIModel
316316
}
317317
}
318318

319-
public string SelectedLanguage
320-
{
321-
get => Models.OpenAI.SelectedLanguage;
322-
set
323-
{
324-
if (value != Models.OpenAI.SelectedLanguage)
325-
{
326-
Models.OpenAI.SelectedLanguage = value;
327-
OnPropertyChanged();
328-
}
329-
}
330-
}
331-
332319
public string OpenAIAnalyzeDiffPrompt
333320
{
334321
get => Models.OpenAI.AnalyzeDiffPrompt;
@@ -604,9 +591,6 @@ Your only goal is to retrieve a single commit message.
604591
- Be as concise as possible, keep the message under 50 characters.
605592
""";
606593
}
607-
608-
if (string.IsNullOrEmpty(Models.OpenAI.SelectedLanguage))
609-
Models.OpenAI.SelectedLanguage = "English";
610594
}
611595

612596
private RepositoryNode FindNodeRecursive(string id, List<RepositoryNode> collection)

src/ViewModels/RepositoryConfigure.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ public int? AutoFetchInterval
8686
}
8787
}
8888

89+
public string CommitMessageLanguage
90+
{
91+
get => _repo.Settings.CommitMessageLanguage;
92+
set => _repo.Settings.CommitMessageLanguage = value;
93+
}
94+
8995
public AvaloniaList<Models.CommitTemplate> CommitTemplates
9096
{
9197
get => _repo.Settings.CommitTemplates;

src/ViewModels/WorkingCopy.cs

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ public void GenerateCommitMessageByAI()
414414

415415
if (_staged is { Count: > 0 })
416416
{
417-
var dialog = new Views.AIAssistant(_repo.FullPath, _staged, generated => CommitMessage = generated);
417+
var dialog = new Views.AIAssistant(_repo.FullPath, _repo.Settings.CommitMessageLanguage, _staged, generated => CommitMessage = generated);
418418
App.OpenDialog(dialog);
419419
}
420420
else
@@ -1148,38 +1148,7 @@ public ContextMenu CreateContextMenuForStagedChanges()
11481148
return menu;
11491149
}
11501150

1151-
public ContextMenu CreateContextMenuForSelectedLanguage()
1152-
{
1153-
var menu = new ContextMenu();
1154-
var selectedLanguage = string.IsNullOrEmpty(Preference.Instance.SelectedLanguage)
1155-
? "English"
1156-
: Preference.Instance.SelectedLanguage;
1157-
1158-
foreach (var locale in Locale.Supported)
1159-
{
1160-
var language = locale.Name;
1161-
1162-
var item = new MenuItem
1163-
{
1164-
Header = language,
1165-
Icon = selectedLanguage.Equals(language, StringComparison.OrdinalIgnoreCase)
1166-
? App.CreateMenuIcon("Icons.Check")
1167-
: null
1168-
};
1169-
1170-
item.Click += (_, e) =>
1171-
{
1172-
Preference.Instance.SelectedLanguage = language;
1173-
e.Handled = true;
1174-
};
1175-
1176-
menu.Items.Add(item);
1177-
}
1178-
1179-
return menu;
1180-
}
1181-
1182-
public ContextMenu CreateContextMenuForCommitMessages()
1151+
public ContextMenu CreateContextMenuForCommitMessages()
11831152
{
11841153
var menu = new ContextMenu();
11851154

src/Views/AIAssistant.axaml.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ public AIAssistant()
1717
InitializeComponent();
1818
}
1919

20-
public AIAssistant(string repo, List<Models.Change> changes, Action<string> onDone)
20+
public AIAssistant(string repo, string language, List<Models.Change> changes, Action<string> onDone)
2121
{
2222
_repo = repo;
23+
_language = language;
2324
_changes = changes;
2425
_onDone = onDone;
2526
_cancel = new CancellationTokenSource();
@@ -35,7 +36,7 @@ protected override void OnOpened(EventArgs e)
3536

3637
Task.Run(() =>
3738
{
38-
var message = new Commands.GenerateCommitMessage(_repo, _changes, _cancel.Token, SetDescription).Result();
39+
var message = new Commands.GenerateCommitMessage(_repo, _language, _changes, _cancel.Token, SetDescription).Result();
3940
if (_cancel.IsCancellationRequested)
4041
return;
4142

@@ -67,5 +68,6 @@ private void SetDescription(string message)
6768
private List<Models.Change> _changes;
6869
private Action<string> _onDone;
6970
private CancellationTokenSource _cancel;
71+
private readonly string _language;
7072
}
7173
}

0 commit comments

Comments
 (0)