mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-23 13:14:59 +00:00
feature: simple implementation for generating commit message by OpenAI (#456)
This commit is contained in:
parent
a63450f73f
commit
16f8e2fd0b
16 changed files with 496 additions and 30 deletions
61
src/Views/AIAssistant.axaml.cs
Normal file
61
src/Views/AIAssistant.axaml.cs
Normal file
|
@ -0,0 +1,61 @@
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Threading;
|
||||
|
||||
namespace SourceGit.Views
|
||||
{
|
||||
public partial class AIAssistant : ChromelessWindow
|
||||
{
|
||||
public AIAssistant()
|
||||
{
|
||||
_cancel = new CancellationTokenSource();
|
||||
InitializeComponent();
|
||||
ProgressMessage.Text = "Generating commit message... Please wait!";
|
||||
}
|
||||
|
||||
public void GenerateCommitMessage()
|
||||
{
|
||||
if (DataContext is ViewModels.WorkingCopy vm)
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
var message = new Commands.GenerateCommitMessage(vm.RepoPath, vm.Staged, _cancel.Token, SetDescription).Result();
|
||||
if (_cancel.IsCancellationRequested)
|
||||
return;
|
||||
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
if (DataContext is ViewModels.WorkingCopy wc)
|
||||
wc.CommitMessage = message;
|
||||
|
||||
Close();
|
||||
});
|
||||
}, _cancel.Token);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnClosing(WindowClosingEventArgs e)
|
||||
{
|
||||
base.OnClosing(e);
|
||||
_cancel.Cancel();
|
||||
}
|
||||
|
||||
private void BeginMoveWindow(object _, PointerPressedEventArgs e)
|
||||
{
|
||||
BeginMoveDrag(e);
|
||||
}
|
||||
|
||||
private void SetDescription(string message)
|
||||
{
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
ProgressMessage.Text = message;
|
||||
});
|
||||
}
|
||||
|
||||
private CancellationTokenSource _cancel;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue