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 #100

Merged
merged 3 commits into from
Sep 18, 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
4 changes: 3 additions & 1 deletion src/ScriptRunner/AppInstaller/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
updateDotnetToolCommand.SetHandler((packageName, version) =>
{
Console.WriteLine($"Updating dotnet tool {packageName}");
var command = string.IsNullOrWhiteSpace(version) == false? $"tool update {packageName} --global --no-cache --ignore-failed-sources --version {version}": $"tool update {packageName} --global --no-cache --ignore-failed-sources";
var command = string.IsNullOrWhiteSpace(version) == false
? $"tool update {packageName} --global --no-cache --ignore-failed-sources --version {version} --add-source https://api.nuget.org/v3/index.json"
: $"tool update {packageName} --global --no-cache --ignore-failed-sources --add-source https://api.nuget.org/v3/index.json";
var process = Process.Start("dotnet", command);
process.WaitForExit();
if (process.ExitCode != 0)
Expand Down Expand Up @@ -75,14 +77,14 @@
var archive = new ZipArchive(stream);
try
{
Directory.Delete(destination, recursive: true);

Check warning on line 80 in src/ScriptRunner/AppInstaller/Program.cs

View workflow job for this annotation

GitHub Actions / build-extension

Possible null reference argument for parameter 'path' in 'void Directory.Delete(string path, bool recursive)'.
Directory.CreateDirectory(destination);
}
catch (Exception e)
{
Console.WriteLine(e);
}
archive.ExtractToDirectory(destination);

Check warning on line 87 in src/ScriptRunner/AppInstaller/Program.cs

View workflow job for this annotation

GitHub Actions / build-extension

Possible null reference argument for parameter 'destinationDirectoryName' in 'void ZipFileExtensions.ExtractToDirectory(ZipArchive source, string destinationDirectoryName)'.
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,34 @@ public CliRepositoryClient(CliCommandExecutor cliCommandExecutor)
_ = 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 isMainBranchOutdated = await IsBranchOutdated(repoPath, mainBranch, mainBranch);
if (isMainBranchOutdated)
{
if(await GetCurrentBranchName(repoPath) is {} currentBranch && string.IsNullOrWhiteSpace(currentBranch) == false && currentBranch != mainBranch)
{
var isCurrentBranchOutdated = await IsBranchOutdated(repoPath, currentBranch, mainBranch);
if (isCurrentBranchOutdated == false)
{
return (false, mainBranch);
}
}

}
return (isMainBranchOutdated, mainBranch);
}

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

private static async Task<bool> IsBranchOutdated(string repoPath, string sourceBranch, string targetBranch)
{
var (_, statusForBranch) = await ExecuteCommand(repoPath, "git", $"log {sourceBranch}..origin/{targetBranch} --oneline");
var outdated = string.IsNullOrWhiteSpace(statusForBranch) == false;
return outdated;
}

static async Task<string?> GetHeadBranchName(string repoPath)
{
var (_, originDetectOutput) = await ExecuteCommand(repoPath, "git", "remote show origin");
Expand All @@ -58,6 +76,11 @@ public CliRepositoryClient(CliCommandExecutor cliCommandExecutor)

return null;
}
static async Task<string?> GetCurrentBranchName(string repoPath)
{
var (_, originDetectOutput) = await ExecuteCommand(repoPath, "git", "rev-parse --abbrev-ref HEAD");
return originDetectOutput;
}

public async Task<bool> PullRepository(string path)
{
Expand Down
49 changes: 31 additions & 18 deletions src/ScriptRunner/ScriptRunner.GUI/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,28 +305,13 @@ public MainWindowViewModel(ParamsPanelFactory paramsPanelFactory, VaultProvider

_appUpdateScheduler = new RealTimeScheduler(TimeSpan.FromDays(1), TimeSpan.FromHours(1), async () =>
{
var isNewerVersion = await appUpdater.CheckIsNewerVersionAvailable();
if (isNewerVersion)
{
Dispatcher.UIThread.Post(() =>
{
ShowNewVersionAvailable = true;
});
}
await RefreshInfoAbouAppUpdates();
});
_appUpdateScheduler.Run();

_outdatedRepoCheckingScheduler = new RealTimeScheduler(TimeSpan.FromHours(
4), TimeSpan.FromHours(1), async () =>
_outdatedRepoCheckingScheduler = new RealTimeScheduler(TimeSpan.FromHours(4), TimeSpan.FromHours(1), async () =>
{
var outOfDateRepos = await _configRepositoryUpdater.CheckAllRepositories();
Dispatcher.UIThread.Post(() =>
{
OutOfDateConfigRepositories.Clear();
OutOfDateConfigRepositories.AddRange(outOfDateRepos);
});


await RefreshInfoAboutRepositories();
});

_outdatedRepoCheckingScheduler.Run();
Expand All @@ -336,6 +321,28 @@ public MainWindowViewModel(ParamsPanelFactory paramsPanelFactory, VaultProvider
BuildUi();
}

private async Task RefreshInfoAbouAppUpdates()
{
var isNewerVersion = await appUpdater.CheckIsNewerVersionAvailable();
if (isNewerVersion)
{
Dispatcher.UIThread.Post(() =>
{
ShowNewVersionAvailable = true;
});
}
}

private async Task RefreshInfoAboutRepositories()
{
var outOfDateRepos = await _configRepositoryUpdater.CheckAllRepositories();
Dispatcher.UIThread.Post(() =>
{
OutOfDateConfigRepositories.Clear();
OutOfDateConfigRepositories.AddRange(outOfDateRepos);
});
}

public void CheckForUpdates()
{
appUpdater.OpenLatestReleaseLog();
Expand Down Expand Up @@ -555,6 +562,12 @@ public void OpenSettingsWindow()
}
}

public void ForceRefresh()
{
_ = RefreshInfoAbouAppUpdates();
_ = RefreshInfoAboutRepositories();
BuildUi();
}
public void RefreshSettings() => BuildUi();

public void OpenVaultWindow() => TryToOpenDialog<Vault>();
Expand Down
2 changes: 1 addition & 1 deletion src/ScriptRunner/ScriptRunner.GUI/Views/SideMenu.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<ToggleButton i:Attached.Icon="fas fa-scroll" IsChecked="{Binding IsScriptListVisible}" ToolTip.Tip="Script list"/>
<ToggleButton i:Attached.Icon="fas fa-clock" IsChecked="{Binding IsRecentListVisible}" ToolTip.Tip="Recently executed"/>
<Button i:Attached.Icon="fas fa-cog" Command="{Binding OpenSettingsWindow}" ToolTip.Tip="Configure actions sources"/>
<Button i:Attached.Icon="fas fa-sync" Command="{Binding RefreshSettings}" ToolTip.Tip="Refresh actions" />
<Button i:Attached.Icon="fas fa-sync" Command="{Binding ForceRefresh}" ToolTip.Tip="Refresh actions" />
<Button i:Attached.Icon="fas fa-lock" Command="{Binding OpenVaultWindow}" ToolTip.Tip="Open Vault" />
<Button i:Attached.Icon="fas fa-search" Click="OpenSearchBox" HotKey="{Binding SearchBoxHotKey}" ToolTip.Tip="Open Search Box (Ctrl+P)" />
</StackPanel>
Expand Down
Loading