Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features/improve sep 2024 #98

Merged
merged 4 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/ScriptRunner/ScriptRunner.GUI/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@
<StyleInclude Source="/Themes/StyleClasses.axaml" />

</Application.Styles>
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceInclude Source="avares://LoadingIndicators.Avalonia/LoadingIndicators.axaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>

</Application>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using CliWrap;
using ScriptRunner.GUI.Settings;
Expand All @@ -11,7 +12,7 @@ namespace ScriptRunner.GUI.BackgroundTasks;

public interface IRepositoryClient
{
Task<bool> IsOutdated(string repoPath);
Task<(bool,string)> IsOutdated(string repoPath);
Task<bool> PullRepository(string path);
}

Expand All @@ -29,16 +30,40 @@ public CliRepositoryClient(CliCommandExecutor cliCommandExecutor)
_cliCommandExecutor = cliCommandExecutor;
}

public async Task<bool> IsOutdated(string repoPath)
public async Task<(bool,string)> IsOutdated(string repoPath)
{
_ = await ExecuteCommand(repoPath, "git", "fetch --prune origin --verbose");
if(await GetHeadBranchName(repoPath) is {} mainBranch)
{
var (_, statusForBranch) = await ExecuteCommand(repoPath, "git", $"log {mainBranch}..origin/{mainBranch} --oneline");
var outdated = string.IsNullOrWhiteSpace(statusForBranch) == false;
return (outdated, mainBranch);
}

var (success, result) = await ExecuteCommand(repoPath, "git", "status -uno");
return success && result.Contains("up to date", StringComparison.InvariantCultureIgnoreCase) == false;
var isOutdated = success && result.Contains("up to date", StringComparison.InvariantCultureIgnoreCase) == false;
return (isOutdated, "current");
}

static async Task<string?> GetHeadBranchName(string repoPath)
{
var (_, originDetectOutput) = await ExecuteCommand(repoPath, "git", "remote show origin");

// Use regular expression to match the 'HEAD branch' line
var match = Regex.Match(originDetectOutput, @"HEAD branch:\s*(\S+)");
if (match.Success)
{
return match.Groups[1].Value; // Return the branch name captured by the group
}

return null;
}

public async Task<bool> PullRepository(string path)
{
var result = await _cliCommandExecutor.Invoke(new CliCommand("git", "pull --rebase=true origin --prune --verbose", path));
_ = await ExecuteCommand(path, "git", "fetch --prune origin --verbose");
var mainBranch = await GetHeadBranchName(path) ?? "";
var result = await _cliCommandExecutor.Invoke(new CliCommand("git", $"rebase origin/{mainBranch} {mainBranch} --verbose", path));
return result.StandardError.Contains("error", StringComparison.InvariantCultureIgnoreCase) == false;
}

Expand Down Expand Up @@ -90,11 +115,15 @@ public async Task<List<OutdatedRepositoryModel>> CheckAllRepositories()
continue;
}

var isOutdated = await repositoryClient.IsOutdated(entry.Path);
var (isOutdated, branchName) = await repositoryClient.IsOutdated(entry.Path);

if (isOutdated)
{
outOfDateRepos.Add(new OutdatedRepositoryModel(entry.Path));
outOfDateRepos.Add(new OutdatedRepositoryModel()
{
Path = entry.Path,
BranchName = branchName
});
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
namespace ScriptRunner.GUI.BackgroundTasks;
using ReactiveUI;

public class OutdatedRepositoryModel
namespace ScriptRunner.GUI.BackgroundTasks;

public class OutdatedRepositoryModel:ReactiveObject
{
public string Path { get; set; }

Check warning on line 7 in src/ScriptRunner/ScriptRunner.GUI/BackgroundTasks/OutdatedRepositoryModel.cs

View workflow job for this annotation

GitHub Actions / build-extension

Non-nullable property 'Path' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public string BranchName { get; set; }

private bool _isPulling;

public OutdatedRepositoryModel(string path)
public bool IsPulling
{
Path = path;
get => _isPulling;
set => this.RaiseAndSetIfChanged(ref _isPulling, value);
}
}
1 change: 1 addition & 0 deletions src/ScriptRunner/ScriptRunner.GUI/ScriptRunner.GUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<PackageReference Include="Avalonia.Xaml.Interactivity" Version="11.0.10.9" />
<PackageReference Include="CliWrap" Version="3.4.4" />
<PackageReference Include="LibGit2Sharp" Version="0.26.2" />
<PackageReference Include="LoadingIndicators.Avalonia" Version="11.0.11.1" />
<PackageReference Include="Markdown.Avalonia" Version="11.0.2" />
<PackageReference Include="MessageBox.Avalonia" Version="3.1.5.1" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection" Version="6.0.10" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,13 +573,22 @@ public async void PullRepoChanges(object arg)
{
if (arg is OutdatedRepositoryModel record)
{
record.IsPulling = true;
var result = false;
await Task.Run(async () => result = await _configRepositoryUpdater.RefreshRepository(record.Path));
if (result)
try
{
OutOfDateConfigRepositories.Remove(record);
RefreshSettings();
await Task.Run(async () => result = await _configRepositoryUpdater.RefreshRepository(record.Path));
}
finally
{
if (result)
{
OutOfDateConfigRepositories.Remove(record);
RefreshSettings();
}
record.IsPulling = false;
}

}
}

Expand Down
15 changes: 11 additions & 4 deletions src/ScriptRunner/ScriptRunner.GUI/Views/ActionDetailsSection.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,18 @@
<TabItem Header="History" IsSelected="{Binding !SelectedAction.HasDocs}">
<ListBox SelectedItem="{Binding SelectedRecentExecution}" ItemsSource="{Binding ExecutionLogForCurrent}">
<ListBox.ItemTemplate>


<DataTemplate x:DataType="viewModels:ExecutionLogAction">
<StackPanel Orientation="Horizontal">
<avalonia:Icon Value="fas fa-clock" />
<TextBlock Margin="10,0" Text="{Binding Description}"></TextBlock>
</StackPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>

<avalonia:Icon Value="fas fa-clock" Margin="0,5,0,0" VerticalAlignment="Top"/>
<TextBlock Grid.Column="1" VerticalAlignment="Top" TextWrapping="Wrap" Margin="10,0" Text="{Binding Description}"></TextBlock>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Expand Down
2 changes: 1 addition & 1 deletion src/ScriptRunner/ScriptRunner.GUI/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
BackgroundSource="Digger"
TintColor="Black"
TintOpacity="1"
MaterialOpacity="0.65" />
MaterialOpacity="0.85" />
</ExperimentalAcrylicBorder.Material>
</ExperimentalAcrylicBorder>
<Grid x:Name="MainGrid" Margin="0,0,0,0">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
xmlns:views="clr-namespace:ScriptRunner.GUI.Views"
xmlns:viewModels="clr-namespace:ScriptRunner.GUI.ViewModels"
xmlns:converters="clr-namespace:ScriptRunner.GUI.Converters"
xmlns:avalonia="clr-namespace:LoadingIndicators.Avalonia;assembly=LoadingIndicators.Avalonia"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:DataType="viewModels:MainWindowViewModel"
x:Class="ScriptRunner.GUI.Views.NotificationSection">
Expand All @@ -30,11 +31,13 @@
<ItemsControl ItemsSource="{Binding OutOfDateConfigRepositories}">
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="backgroundTasks:OutdatedRepositoryModel">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path}"></TextBlock>
<Button Margin="20,0,0,0" VerticalAlignment="Center"
<StackPanel Orientation="Horizontal" Margin="0,5,0,0">
<TextBlock VerticalAlignment="Center" Text="{Binding Path}"></TextBlock>
<TextBlock VerticalAlignment="Center" Margin="5,0" Text="{Binding BranchName, StringFormat='(branch: {0})'}"></TextBlock>
<Button Margin="20,0,0,0" VerticalAlignment="Center" IsEnabled="{Binding !IsPulling}"
Command="{Binding DataContext.PullRepoChanges, RelativeSource={RelativeSource AncestorType={x:Type views:MainWindow}}}"
CommandParameter="{Binding}">Pull</Button>
<avalonia:LoadingIndicator IsActive="{Binding IsPulling}" Mode="Arc" SpeedRatio="1.2" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
Expand Down
Loading