Skip to content

Commit

Permalink
(#77) add progess indicator when cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
nils-a committed Oct 27, 2023
1 parent 3a1abb7 commit 6f721b6
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions src/GitHubMilestoneCleaner/Commands/AutoCleanupCommand.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
Expand Down Expand Up @@ -113,16 +114,41 @@ public override async Task<int> 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;
Expand Down

0 comments on commit 6f721b6

Please sign in to comment.