Skip to content

Commit 8ecf605

Browse files
authored
use configured area order (#273)
* use configured area order Instead of sorting the configured areas in alphabetical order, use the order specified in the whatsnew.json file. Fixes #271 * add diagnostics * better diagnostic * improve diagnostic messages Transfer the quick and dirty messages I was using to help another team member to messages that will help everyone in the future.
1 parent 695f17e commit 8ecf605

File tree

3 files changed

+62
-12
lines changed

3 files changed

+62
-12
lines changed

WhatsNew.Cli/Program.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ public static async Task Main(
6969
Console.WriteLine($"Error message: {ex.Message}");
7070
return;
7171
}
72+
73+
Console.WriteLine(whatsNewConfig.LogConfigSettings());
74+
if (savefile is not null)
75+
{
76+
Console.WriteLine($"Writing output to {savefile}");
77+
} else
78+
{
79+
Console.WriteLine($"Writing output to {whatsNewConfig.SaveDir}");
80+
}
81+
7282
var pageGenService = new PageGenerationService(whatsNewConfig);
7383

7484
await pageGenService.WriteMarkdownFile(savefile);

WhatsNew.Infrastructure/Models/WhatsNewConfiguration.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using DotNetDocs.Tools.GitHubCommunications;
22
using DotNetDocs.Tools.Utility;
33
using Microsoft.DotnetOrg.Ospo;
4+
using System.Text;
45

56
namespace WhatsNew.Infrastructure.Models;
67

@@ -53,4 +54,17 @@ public class WhatsNewConfiguration
5354
/// This is the client that makes queries to the Microsoft OSPO office API.
5455
/// </summary>
5556
public OspoClient OspoClient { get; set; } = null!;
57+
58+
public string? LogConfigSettings()
59+
{
60+
StringBuilder output = new ();
61+
output.AppendLine($"Repository: {Repository.Owner}/{Repository.Name}");
62+
output.AppendLine($"Branch: {Repository.Branch}");
63+
output.AppendLine($"DocSetProductName: {Repository.DocSetProductName}");
64+
output.AppendLine($"RootDirectory: {Repository.RootDirectory}");
65+
output.AppendLine($"DateRange: {DateRange.StartDate:D} - {DateRange.EndDate:D}");
66+
output.AppendLine($"MarkdownFileName: {MarkdownFileName}");
67+
output.AppendLine($"PathToRepoRoot: {PathToRepoRoot}");
68+
return output.ToString();
69+
}
5670
}

WhatsNew.Infrastructure/Services/PageGenerationService.cs

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,21 @@ public PageGenerationService(WhatsNewConfiguration configuration) =>
4040
/// </summary>
4141
public async Task WriteMarkdownFile(string? existingMarkdownFile= null)
4242
{
43-
await ProcessPullRequests();
43+
var totalPRs = await ProcessPullRequests();
44+
45+
if (totalPRs == 0)
46+
{
47+
var color = Console.ForegroundColor;
48+
Console.ForegroundColor = ConsoleColor.Red;
49+
Console.WriteLine("No PRs found.");
50+
Console.WriteLine("This is likely a problem with one of:");
51+
Console.WriteLine("\t- the date range");
52+
Console.WriteLine("\t- the required label");
53+
Console.WriteLine("\t- GitHub permissions");
54+
Console.WriteLine("Exiting.");
55+
Console.ForegroundColor = color;
56+
return;
57+
}
4458

4559
if (string.IsNullOrWhiteSpace(existingMarkdownFile))
4660
{
@@ -150,23 +164,30 @@ private async Task WriteNewDocInformation(TextWriter stream, bool singleFile)
150164
var allDocs = from change in _majorChanges
151165
from area in repo.Areas
152166
where change.Value.Heading == area.Heading
153-
orderby area.Heading
154167
group change by area.Heading into headingGroup
155168
select headingGroup;
156169

157170
var rootDirectoryHeading = (from area in repo.Areas
158171
where area.Names.FirstOrDefault() == "."
159172
select area.Heading).FirstOrDefault();
160173

161-
foreach (var docArea in allDocs)
174+
foreach(var area in repo.Areas)
162175
{
163-
var areaHeading = docArea.Key;
164-
var isRootDirectoryArea = areaHeading == rootDirectoryHeading;
165-
166176
// Don't write anything for blank areas.
167-
if (areaHeading is null)
177+
if (area is null)
168178
continue;
169-
await stream.WriteLineAsync($"{(singleFile ? "###" : "##")} {areaHeading}");
179+
var docArea = allDocs.FirstOrDefault(da => da.Key == area.Heading);
180+
if (docArea is null)
181+
{
182+
Console.WriteLine($"No changes found for {area.Heading}");
183+
continue;
184+
} else
185+
{
186+
Console.WriteLine($"Writing changes for {area.Heading}");
187+
}
188+
var isRootDirectoryArea = area.Heading == rootDirectoryHeading;
189+
190+
await stream.WriteLineAsync($"{(singleFile ? "###" : "##")} {area.Heading}");
170191
await stream.WriteLineAsync();
171192

172193
writeDocNodes(true);
@@ -274,6 +295,7 @@ void writeDocNodes(bool isNew)
274295

275296
private async Task WriteContributorInformation(TextWriter stream)
276297
{
298+
Console.WriteLine("Writing contributors");
277299
var allContributors = from c in _contributors
278300
orderby c.login
279301
group c by (c.login, c.name) into stats
@@ -301,23 +323,24 @@ group c by (c.login, c.name) into stats
301323
}
302324
}
303325

304-
private async Task ProcessPullRequests()
326+
private async Task<int> ProcessPullRequests()
305327
{
306328
var repo = _configuration.Repository;
307329
var client = _configuration.GitHubClient;
308330
var ospoClient = _configuration.OspoClient;
309331

310-
await processPRs();
332+
var totalPRs = await processPRs();
311333

312334
// If processing a private repo, fetch the PRs & community contributors from
313335
// the accompanying public repo. Merge private results with public results.
314336
if (repo.IsPrivateRepo)
315337
{
316338
repo.Name = repo.Name.Replace(PrivateRepoNameSuffix, string.Empty);
317-
await processPRs();
339+
totalPRs += await processPRs();
318340
}
341+
return totalPRs;
319342

320-
async Task processPRs()
343+
async Task<int> processPRs()
321344
{
322345
Console.ForegroundColor = ConsoleColor.DarkMagenta;
323346
Console.WriteLine($"== {repo.Owner}/{repo.Name} ({repo.Branch}) ==", Console.ForegroundColor);
@@ -328,8 +351,10 @@ async Task processPRs()
328351
client, repo.Owner, repo.Name, repo.Branch, repo.InclusionCriteria.Labels, _configuration.DateRange);
329352
var authorLoginFTECache = new Dictionary<string, bool?>();
330353

354+
var totalPRs = 0;
331355
await foreach (var item in query.PerformQuery())
332356
{
357+
totalPRs++;
333358
var prNumber = item.Number;
334359
Console.WriteLine($"Processing PR {prNumber}");
335360

@@ -358,6 +383,7 @@ async Task processPRs()
358383
Console.WriteLine($"{index}. {distinctExcludedContributors[index - 1]}");
359384
}
360385
Console.WriteLine();
386+
return totalPRs;
361387
}
362388
}
363389

0 commit comments

Comments
 (0)