From 9ee29f306f685a4cde529ad84315f65eedf8ce8e Mon Sep 17 00:00:00 2001 From: JT Date: Tue, 30 May 2023 00:20:16 -0700 Subject: [PATCH 1/2] Switch between releases & branches - also adds appsettings - still wip --- .../StabilityMatrix.Tests.csproj | 1 + StabilityMatrix/Api/IGithubApi.cs | 7 ++ StabilityMatrix/App.xaml.cs | 21 +++- .../Converters/BoolNegationConverter.cs | 25 ++++ StabilityMatrix/InstallerWindow.xaml | 88 ++++++++++---- StabilityMatrix/Models/Api/GithubAuthor.cs | 13 +++ StabilityMatrix/Models/Api/GithubBranch.cs | 12 ++ StabilityMatrix/Models/Api/GithubCommit.cs | 12 ++ .../Models/Api/GithubCommitCommit.cs | 12 ++ StabilityMatrix/Models/PackageVersion.cs | 7 ++ StabilityMatrix/Models/Packages/A3WebUI.cs | 27 ++++- .../Models/Packages/BaseGitPackage.cs | 41 ++++--- .../Models/Packages/BasePackage.cs | 10 +- .../Models/Packages/DankDiffusion.cs | 23 +++- .../Models/Packages/VladAutomatic.cs | 20 +++- .../Properties/launchSettings.json | 12 +- StabilityMatrix/StabilityMatrix.csproj | 7 ++ .../ViewModels/InstallerViewModel.cs | 110 ++++++++++++++++-- StabilityMatrix/appsettings.Development.json | 3 + StabilityMatrix/appsettings.json | 3 + 20 files changed, 391 insertions(+), 63 deletions(-) create mode 100644 StabilityMatrix/Converters/BoolNegationConverter.cs create mode 100644 StabilityMatrix/Models/Api/GithubAuthor.cs create mode 100644 StabilityMatrix/Models/Api/GithubBranch.cs create mode 100644 StabilityMatrix/Models/Api/GithubCommit.cs create mode 100644 StabilityMatrix/Models/Api/GithubCommitCommit.cs create mode 100644 StabilityMatrix/Models/PackageVersion.cs create mode 100644 StabilityMatrix/appsettings.Development.json create mode 100644 StabilityMatrix/appsettings.json diff --git a/StabilityMatrix.Tests/StabilityMatrix.Tests.csproj b/StabilityMatrix.Tests/StabilityMatrix.Tests.csproj index 2f708340..0bbfafc9 100644 --- a/StabilityMatrix.Tests/StabilityMatrix.Tests.csproj +++ b/StabilityMatrix.Tests/StabilityMatrix.Tests.csproj @@ -11,6 +11,7 @@ + diff --git a/StabilityMatrix/Api/IGithubApi.cs b/StabilityMatrix/Api/IGithubApi.cs index dde0f8f4..43843a7b 100644 --- a/StabilityMatrix/Api/IGithubApi.cs +++ b/StabilityMatrix/Api/IGithubApi.cs @@ -13,4 +13,11 @@ public interface IGithubApi [Get("/repos/{username}/{repository}/releases")] Task> GetAllReleases(string username, string repository); + + [Get("/repos/{username}/{repository}/branches")] + Task> GetAllBranches(string username, string repository); + + [Get("/repos/{username}/{repository}/commits?sha={branch}")] + Task> GetAllCommits(string username, string repository, string branch, int page = 1, + [AliasAs("per_page")] int perPage = 10); } diff --git a/StabilityMatrix/App.xaml.cs b/StabilityMatrix/App.xaml.cs index e9ee477b..84f1f6bf 100644 --- a/StabilityMatrix/App.xaml.cs +++ b/StabilityMatrix/App.xaml.cs @@ -5,6 +5,7 @@ using System.IO; using System.Text.Json; using System.Text.Json.Serialization; using System.Windows; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; @@ -31,6 +32,17 @@ namespace StabilityMatrix public partial class App : Application { private ServiceProvider? serviceProvider; + + public static IConfiguration Config { get; set; } + + public App() + { + Config = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) + .AddJsonFile("appsettings.Development.json", optional: true, reloadOnChange: true) + .Build(); + } private void App_OnStartup(object sender, StartupEventArgs e) { @@ -66,7 +78,7 @@ namespace StabilityMatrix serviceCollection.AddTransient(); serviceCollection.AddSingleton(); - serviceCollection.AddSingleton(); + serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); @@ -93,6 +105,12 @@ namespace StabilityMatrix { c.BaseAddress = new Uri("https://api.github.com"); c.Timeout = TimeSpan.FromSeconds(5); + + var githubApiKey = Config["GithubApiKey"]; + if (!string.IsNullOrEmpty(githubApiKey)) + { + c.DefaultRequestHeaders.Add("Authorization", $"Bearer {githubApiKey}"); + } }) .AddPolicyHandler(retryPolicy); serviceCollection.AddRefitClient(defaultRefitSettings) @@ -149,3 +167,4 @@ namespace StabilityMatrix } } } + diff --git a/StabilityMatrix/Converters/BoolNegationConverter.cs b/StabilityMatrix/Converters/BoolNegationConverter.cs new file mode 100644 index 00000000..23508106 --- /dev/null +++ b/StabilityMatrix/Converters/BoolNegationConverter.cs @@ -0,0 +1,25 @@ +using System; +using System.Globalization; +using System.Windows.Data; + +namespace StabilityMatrix.Converters; + +[ValueConversion(typeof(bool), typeof(bool))] +public class BoolNegationConverter : IValueConverter +{ + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is bool?) + { + var boolVal = value as bool?; + return !boolVal ?? false; + } + + return false; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + return Convert(value, targetType, parameter, culture); + } +} diff --git a/StabilityMatrix/InstallerWindow.xaml b/StabilityMatrix/InstallerWindow.xaml index 4f068108..2f43cf4d 100644 --- a/StabilityMatrix/InstallerWindow.xaml +++ b/StabilityMatrix/InstallerWindow.xaml @@ -24,19 +24,27 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:xaml="clr-namespace:Markdown.Xaml;assembly=Markdown.Xaml" xmlns:api="clr-namespace:StabilityMatrix.Models.Api" - xmlns:system="clr-namespace:System;assembly=System.Runtime"> + xmlns:system="clr-namespace:System;assembly=System.Runtime" + xmlns:converters="clr-namespace:StabilityMatrix.Converters"> + + + + + + + + DocumentStyle="{StaticResource DocumentStyle}" + Heading1Style="{StaticResource H1Style}" + Heading2Style="{StaticResource H2Style}" + Heading3Style="{StaticResource H3Style}" + Heading4Style="{StaticResource H4Style}" + LinkStyle="{StaticResource LinkStyle}" + ImageStyle="{StaticResource ImageStyle}" + SeparatorStyle="{StaticResource SeparatorStyle}" + AssetPathRoot="{x:Static system:Environment.CurrentDirectory}"/> @@ -111,20 +119,52 @@ -