diff --git a/WhatsNew.Cli/Program.cs b/WhatsNew.Cli/Program.cs index bd1e2b80..a1e50ed1 100644 --- a/WhatsNew.Cli/Program.cs +++ b/WhatsNew.Cli/Program.cs @@ -69,6 +69,16 @@ public static async Task Main( Console.WriteLine($"Error message: {ex.Message}"); return; } + + Console.WriteLine(whatsNewConfig.LogConfigSettings()); + if (savefile is not null) + { + Console.WriteLine($"Writing output to {savefile}"); + } else + { + Console.WriteLine($"Writing output to {whatsNewConfig.SaveDir}"); + } + var pageGenService = new PageGenerationService(whatsNewConfig); await pageGenService.WriteMarkdownFile(savefile); diff --git a/WhatsNew.Infrastructure/Models/WhatsNewConfiguration.cs b/WhatsNew.Infrastructure/Models/WhatsNewConfiguration.cs index 940fa67d..c0f300a4 100644 --- a/WhatsNew.Infrastructure/Models/WhatsNewConfiguration.cs +++ b/WhatsNew.Infrastructure/Models/WhatsNewConfiguration.cs @@ -1,6 +1,7 @@ using DotNetDocs.Tools.GitHubCommunications; using DotNetDocs.Tools.Utility; using Microsoft.DotnetOrg.Ospo; +using System.Text; namespace WhatsNew.Infrastructure.Models; @@ -53,4 +54,17 @@ public class WhatsNewConfiguration /// This is the client that makes queries to the Microsoft OSPO office API. /// public OspoClient OspoClient { get; set; } = null!; + + public string? LogConfigSettings() + { + StringBuilder output = new (); + output.AppendLine($"Repository: {Repository.Owner}/{Repository.Name}"); + output.AppendLine($"Branch: {Repository.Branch}"); + output.AppendLine($"DocSetProductName: {Repository.DocSetProductName}"); + output.AppendLine($"RootDirectory: {Repository.RootDirectory}"); + output.AppendLine($"DateRange: {DateRange.StartDate:D} - {DateRange.EndDate:D}"); + output.AppendLine($"MarkdownFileName: {MarkdownFileName}"); + output.AppendLine($"PathToRepoRoot: {PathToRepoRoot}"); + return output.ToString(); + } } diff --git a/WhatsNew.Infrastructure/Services/PageGenerationService.cs b/WhatsNew.Infrastructure/Services/PageGenerationService.cs index 36064e37..7077e490 100644 --- a/WhatsNew.Infrastructure/Services/PageGenerationService.cs +++ b/WhatsNew.Infrastructure/Services/PageGenerationService.cs @@ -40,7 +40,21 @@ public PageGenerationService(WhatsNewConfiguration configuration) => /// public async Task WriteMarkdownFile(string? existingMarkdownFile= null) { - await ProcessPullRequests(); + var totalPRs = await ProcessPullRequests(); + + if (totalPRs == 0) + { + var color = Console.ForegroundColor; + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("No PRs found."); + Console.WriteLine("This is likely a problem with one of:"); + Console.WriteLine("\t- the date range"); + Console.WriteLine("\t- the required label"); + Console.WriteLine("\t- GitHub permissions"); + Console.WriteLine("Exiting."); + Console.ForegroundColor = color; + return; + } if (string.IsNullOrWhiteSpace(existingMarkdownFile)) { @@ -150,7 +164,6 @@ private async Task WriteNewDocInformation(TextWriter stream, bool singleFile) var allDocs = from change in _majorChanges from area in repo.Areas where change.Value.Heading == area.Heading - orderby area.Heading group change by area.Heading into headingGroup select headingGroup; @@ -158,15 +171,23 @@ group change by area.Heading into headingGroup where area.Names.FirstOrDefault() == "." select area.Heading).FirstOrDefault(); - foreach (var docArea in allDocs) + foreach(var area in repo.Areas) { - var areaHeading = docArea.Key; - var isRootDirectoryArea = areaHeading == rootDirectoryHeading; - // Don't write anything for blank areas. - if (areaHeading is null) + if (area is null) continue; - await stream.WriteLineAsync($"{(singleFile ? "###" : "##")} {areaHeading}"); + var docArea = allDocs.FirstOrDefault(da => da.Key == area.Heading); + if (docArea is null) + { + Console.WriteLine($"No changes found for {area.Heading}"); + continue; + } else + { + Console.WriteLine($"Writing changes for {area.Heading}"); + } + var isRootDirectoryArea = area.Heading == rootDirectoryHeading; + + await stream.WriteLineAsync($"{(singleFile ? "###" : "##")} {area.Heading}"); await stream.WriteLineAsync(); writeDocNodes(true); @@ -274,6 +295,7 @@ void writeDocNodes(bool isNew) private async Task WriteContributorInformation(TextWriter stream) { + Console.WriteLine("Writing contributors"); var allContributors = from c in _contributors orderby c.login group c by (c.login, c.name) into stats @@ -301,23 +323,24 @@ group c by (c.login, c.name) into stats } } - private async Task ProcessPullRequests() + private async Task ProcessPullRequests() { var repo = _configuration.Repository; var client = _configuration.GitHubClient; var ospoClient = _configuration.OspoClient; - await processPRs(); + var totalPRs = await processPRs(); // If processing a private repo, fetch the PRs & community contributors from // the accompanying public repo. Merge private results with public results. if (repo.IsPrivateRepo) { repo.Name = repo.Name.Replace(PrivateRepoNameSuffix, string.Empty); - await processPRs(); + totalPRs += await processPRs(); } + return totalPRs; - async Task processPRs() + async Task processPRs() { Console.ForegroundColor = ConsoleColor.DarkMagenta; Console.WriteLine($"== {repo.Owner}/{repo.Name} ({repo.Branch}) ==", Console.ForegroundColor); @@ -328,8 +351,10 @@ async Task processPRs() client, repo.Owner, repo.Name, repo.Branch, repo.InclusionCriteria.Labels, _configuration.DateRange); var authorLoginFTECache = new Dictionary(); + var totalPRs = 0; await foreach (var item in query.PerformQuery()) { + totalPRs++; var prNumber = item.Number; Console.WriteLine($"Processing PR {prNumber}"); @@ -358,6 +383,7 @@ async Task processPRs() Console.WriteLine($"{index}. {distinctExcludedContributors[index - 1]}"); } Console.WriteLine(); + return totalPRs; } }