From 6f721b63a41d127cd5f6f001255021d8e862bfae Mon Sep 17 00:00:00 2001 From: Nils Andresen Date: Sat, 28 Oct 2023 00:09:46 +0200 Subject: [PATCH] (#77) add progess indicator when cleaning --- .../Commands/AutoCleanupCommand.cs | 38 ++++++++++++++++--- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/src/GitHubMilestoneCleaner/Commands/AutoCleanupCommand.cs b/src/GitHubMilestoneCleaner/Commands/AutoCleanupCommand.cs index 8db9b4c..3df8b4f 100644 --- a/src/GitHubMilestoneCleaner/Commands/AutoCleanupCommand.cs +++ b/src/GitHubMilestoneCleaner/Commands/AutoCleanupCommand.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; @@ -113,16 +114,41 @@ public override async Task ExecuteAsync(CommandContext context, Settings se return 0; } - foreach (var issue in toRemove) + async Task DoRemove(Action? callback = null) { - var group = grouped.First(g => g.MainIssue.Id == issue.Id || g.SubIssues.Any(i => i.Id == issue.Id)); - var comment = issue == group.MainIssue ? settings.TopIssueComment : settings.SubIssueComment; - if (!string.IsNullOrEmpty(comment)) + foreach (var issue in toRemove) { - comment = string.Format(comment, group.MainIssue.HtmlUrl); + var group = grouped.First(g => g.MainIssue.Id == issue.Id || g.SubIssues.Any(i => i.Id == issue.Id)); + var comment = issue == group.MainIssue ? settings.TopIssueComment : settings.SubIssueComment; + if (!string.IsNullOrEmpty(comment)) + { + comment = string.Format(comment, group.MainIssue.HtmlUrl); + } + + await adapter.RemoveMilestone(repo, issue, comment); + callback?.Invoke(); } + } + + if (settings.NonInteractive) + { + await DoRemove(); + } + else + { + await AnsiConsole.Progress() + .StartAsync(async ctx => + { + var inc = 100d / toRemove.Count; + var task = ctx.AddTask($"Cleaning {toRemove.Count} issues"); + await DoRemove(() => + { + task.Increment(inc); + }); - await adapter.RemoveMilestone(repo, issue, comment); + var rest = 100 - task.Percentage; + task.Increment(rest); + }); } return 0;