add simple generate changelog feature

This commit is contained in:
2024-10-13 09:22:19 +02:00
parent ee69d8af56
commit 8561fdb09b
6 changed files with 116 additions and 1 deletions

View File

@@ -1,7 +1,9 @@
using ModpackUpdater.Apps.Manager.Api.Model;
using Microsoft.Extensions.Primitives;
using ModpackUpdater.Apps.Manager.Api.Model;
using ModpackUpdater.Apps.Manager.Ui;
using ModpackUpdater.Manager;
using Pilz.UI.Extensions;
using System.Text;
using Telerik.WinControls.UI;
namespace ModpackUpdater.Apps.Manager.Features;
@@ -154,4 +156,50 @@ internal static class SharedFunctions
gridView?.EndUpdate();
rwb?.StopWaiting();
}
public static string GenerateChangelog(InstallInfos installInfos, UpdateInfo updateInfos)
{
var log = new StringBuilder();
foreach (var action in updateInfos.Actions.OrderBy(n => n.Type))
{
// Create copy
var copy = new UpdateAction();
ModpackInstaller.DuplicateTo(action, copy);
// Resolve inherit
if (!string.IsNullOrWhiteSpace(copy.InheritFrom))
ModpackInstaller.ResolveInherit(copy, installInfos);
if (string.IsNullOrWhiteSpace(copy.Name) || copy.Type != UpdateActionType.Update)
continue;
// Append bullet
log.Append('-');
// Append action indicator
log.Append(' ');
log.Append("⚒️");
// Append name
log.Append(' ');
log.Append("**");
log.Append(copy.Name);
log.Append("**");
// Append new version
if (!string.IsNullOrWhiteSpace(copy.SourceTag))
{
log.Append(' ');
log.Append('`');
log.Append(copy.SourceTag);
log.Append('`');
}
// Append new line
log.AppendLine();
}
return log.ToString().TrimEnd();
}
}

View File

@@ -0,0 +1,31 @@
using ModpackUpdater.Apps.Manager.Api.Plugins.Params;
using ModpackUpdater.Apps.Manager.LangRes;
using Pilz.Plugins.Advanced;
using Telerik.WinControls;
namespace ModpackUpdater.Apps.Manager.Features.Tools;
internal class GenerateChangelogFeature : PluginFunction, IPluginFeatureProvider<GenerateChangelogFeature>
{
public static GenerateChangelogFeature Instance { get; } = new();
public GenerateChangelogFeature() : base(FeatureTypes.Tools, "origin.genchangelog", FeatureNamesLangRes.GenerateChangelogFeature)
{
Icon = AppGlobals.Symbols.GetSvgImage(AppSymbols.time_machine, Pilz.UI.Symbols.SymbolSize.Small);
}
protected override object? ExecuteFunction(PluginFunctionParameter? @params)
{
if (@params is not MainApiParameters p || p.Api.CurWorkspace?.InstallInfos is null || p.Api.CurActionSet is not UpdateInfo updateInfos)
return null;
var changelog = SharedFunctions.GenerateChangelog(p.Api.CurWorkspace.InstallInfos, updateInfos);
if (!string.IsNullOrWhiteSpace(changelog))
{
Clipboard.SetText(changelog);
RadMessageBox.Show(p.Api.MainWindow, MsgBoxLangRes.ChangelogCopiedToClipboard, MsgBoxLangRes.ChangelogCopiedToClipboard_Title, MessageBoxButtons.OK, RadMessageIcon.Info);
}
return null;
}
}