Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use configured area order #273

Merged
merged 4 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions WhatsNew.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions WhatsNew.Infrastructure/Models/WhatsNewConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using DotNetDocs.Tools.GitHubCommunications;
using DotNetDocs.Tools.Utility;
using Microsoft.DotnetOrg.Ospo;
using System.Text;

namespace WhatsNew.Infrastructure.Models;

Expand Down Expand Up @@ -53,4 +54,17 @@ public class WhatsNewConfiguration
/// This is the client that makes queries to the Microsoft OSPO office API.
/// </summary>
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();
}
}
50 changes: 38 additions & 12 deletions WhatsNew.Infrastructure/Services/PageGenerationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,21 @@ public PageGenerationService(WhatsNewConfiguration configuration) =>
/// </summary>
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))
{
Expand Down Expand Up @@ -150,23 +164,30 @@ 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;

var rootDirectoryHeading = (from area in repo.Areas
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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -301,23 +323,24 @@ group c by (c.login, c.name) into stats
}
}

private async Task ProcessPullRequests()
private async Task<int> 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<int> processPRs()
{
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine($"== {repo.Owner}/{repo.Name} ({repo.Branch}) ==", Console.ForegroundColor);
Expand All @@ -328,8 +351,10 @@ async Task processPRs()
client, repo.Owner, repo.Name, repo.Branch, repo.InclusionCriteria.Labels, _configuration.DateRange);
var authorLoginFTECache = new Dictionary<string, bool?>();

var totalPRs = 0;
await foreach (var item in query.PerformQuery())
{
totalPRs++;
var prNumber = item.Number;
Console.WriteLine($"Processing PR {prNumber}");

Expand Down Expand Up @@ -358,6 +383,7 @@ async Task processPRs()
Console.WriteLine($"{index}. {distinctExcludedContributors[index - 1]}");
}
Console.WriteLine();
return totalPRs;
}
}

Expand Down
Loading