UI - Added changes since last build to update dialog

This commit is contained in:
SpoinkyNL committed 2021-02-04 20:22:04 +01:00
1 parent f343b3d0f8
commit 6c90943944
8 files changed
+690 -60

No files matched your search

@@ -7,18 +7,39 @@
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<StackPanel Margin="16">
<TextBlock Style="{StaticResource MaterialDesignHeadline6TextBlock}" TextWrapping="Wrap">
<TextBlock Style="{StaticResource MaterialDesignHeadline6TextBlock}" TextWrapping="Wrap" Margin="0 0 0 20">
Update available
</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignSubtitle1TextBlock}"
Foreground="{DynamicResource MaterialDesignBodyLight}"
Margin="0 20 0 20"
TextWrapping="Wrap">
A new Artemis update is available! 🥳<LineBreak/>
You are currently running build <Run Text="{Binding CurrentBuild, Mode=OneWay}" /> while the latest build is <Run Text="{Binding LatestBuild, Mode=OneWay}" />. <LineBreak/> <LineBreak/>
Updating Artemis will give you the latest bug(fixes), features and improvements.
</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignHeadline6TextBlock}" TextWrapping="Wrap" Margin="0 20">
Changes
</TextBlock>
<StackPanel Visibility="{Binding RetrievingChanges, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}">
<TextBlock Style="{StaticResource MaterialDesignSubtitle1TextBlock}"
Foreground="{DynamicResource MaterialDesignBodyLight}"
HorizontalAlignment="Center"
Margin="0 10">
Retrieving changes...
</TextBlock>
<ProgressBar IsIndeterminate="True" />
</StackPanel>
<ItemsControl ItemsSource="{Binding Changes}" Visibility="{Binding RetrievingChanges, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, Mode=OneWay}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" Style="{StaticResource MaterialDesignSubtitle1TextBlock}" Foreground="{DynamicResource MaterialDesignBodyLight}"></TextBlock>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0 8 0 0">
<Button Style="{StaticResource MaterialDesignFlatButton}"
Focusable="False"
@@ -1,31 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Artemis.Core;
using Artemis.UI.Services;
using Artemis.UI.Services.Models.UpdateService;
using Artemis.UI.Shared.Services;
using Newtonsoft.Json.Linq;
using Stylet;
namespace Artemis.UI.Screens.Settings.Dialogs
{
public class UpdateDialogViewModel : DialogViewModelBase
{
private readonly JToken _buildInfo;
private readonly DevOpsBuild _buildInfo;
private readonly IDialogService _dialogService;
private readonly IMessageService _messageService;
private readonly IUpdateService _updateService;
private bool _canUpdate = true;
private bool _retrievingChanges;
public UpdateDialogViewModel(JToken buildInfo, IUpdateService updateService, IDialogService dialogService)
public UpdateDialogViewModel(DevOpsBuild buildInfo, IUpdateService updateService, IDialogService dialogService, IMessageService messageService)
{
_buildInfo = buildInfo;
_updateService = updateService;
_dialogService = dialogService;
_messageService = messageService;
CurrentBuild = Constants.BuildInfo.BuildNumberDisplay;
LatestBuild = buildInfo?.SelectToken("value[0].buildNumber")?.Value<string>();
LatestBuild = buildInfo.BuildNumber;
Changes = new BindableCollection<string>();
Task.Run(GetBuildChanges);
}
public string CurrentBuild { get; }
public string LatestBuild { get; }
public BindableCollection<string> Changes { get; }
public bool RetrievingChanges
{
get => _retrievingChanges;
set => SetAndNotify(ref _retrievingChanges, value);
}
public bool CanUpdate
{
@@ -33,6 +50,41 @@ namespace Artemis.UI.Screens.Settings.Dialogs
set => SetAndNotify(ref _canUpdate, value);
}
private async Task GetBuildChanges()
{
try
{
RetrievingChanges = true;
Task<DevOpsBuild> currentTask = _updateService.GetBuildInfo(1, CurrentBuild);
Task<DevOpsBuild> latestTask = _updateService.GetBuildInfo(1, LatestBuild);
DevOpsBuild current = await currentTask;
DevOpsBuild latest = await latestTask;
if (current != null && latest != null)
{
GitHubDifference difference = await _updateService.GetBuildDifferences(current, latest);
// Only take commits with one parents (no merges)
Changes.Clear();
Changes.AddRange(difference.Commits.Where(c => c.Parents.Count == 1)
.SelectMany(c => c.Commit.Message.Split("\n"))
.Select(m => m.Trim())
.Where(m => !string.IsNullOrWhiteSpace(m))
.OrderBy(m => m)
);
}
}
catch (Exception e)
{
_messageService.ShowMessage($"Failed to retrieve build changes - {e.Message}");
}
finally
{
RetrievingChanges = false;
}
}
public async Task Update()
{
try