Skip to content

Commit

Permalink
update changelog generator
Browse files Browse the repository at this point in the history
  • Loading branch information
tmathura committed Aug 3, 2020
1 parent 68d574b commit 9c64efd
Showing 1 changed file with 31 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ public async Task CreateChangelog()

if (changelogDocument.Blocks.Any(x => x.ToString().Contains("Unreleased Changes")))
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine($"Getting previous {changelogFileName} without unreleased changes (Changelog path: {changelogPath})");
var count = 0;
foreach (var element in changelogDocument.Blocks)
{
Expand All @@ -74,8 +72,30 @@ public async Task CreateChangelog()
}
count++;
}
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"Got {changelogFileName} without unreleased changes");
}
else
{
foreach (var element in changelogDocument.Blocks)
{
if (element is HeaderBlock header)
{
if (header.ToString().Contains("Release "))
{
oldChangelog += $"\n\n#{header}";
}
else
{
oldChangelog += $"\n\n##{header}";
}
}
else if (element is ListBlock listItem)
{
foreach (var listItemBlock in listItem.Items)
{
oldChangelog += $"\n - {listItemBlock.Blocks[0]}";
}
}
}
}
}

Expand Down Expand Up @@ -107,8 +127,8 @@ public async Task CreateChangelog()
var formattedDiffCommits = FormatCommits(diffCommits);
var formattedMasterCommits = FormatCommits(masterCommits);

var issues = await GetReleaseDetails(IssueTypeQualifier.Issue, $"{_repositoryOwner}/{_repositoryName}");
var pulls = await GetReleaseDetails(IssueTypeQualifier.PullRequest, $"{_repositoryOwner}/{_repositoryName}");
var issues = await GetReleaseDetails(IssueTypeQualifier.Issue, previousReleaseDate);
var pulls = await GetReleaseDetails(IssueTypeQualifier.PullRequest, previousReleaseDate);

var releaseText = string.Empty;

Expand Down Expand Up @@ -227,7 +247,7 @@ private static string FormatCommits(IEnumerable<GitHubCommit> commitsList)

foreach (var commit in commitsList)
{
formatCommits += $"\n - [{commit.Commit.Message.Replace("\n\n", "; ").Replace("\n", "; ")}]({commit.Commit.Url})";
formatCommits += $"\n - [{commit.Commit.Message.Replace("\n\n", "; ").Replace("\n", "; ")}]({commit.HtmlUrl}) ([{commit.Commit.Author.Name}]({commit.Author.HtmlUrl}))";
}

return formatCommits;
Expand All @@ -237,15 +257,14 @@ private static string FormatCommits(IEnumerable<GitHubCommit> commitsList)
/// Get release details.
/// </summary>
/// <param name="type"></param>
/// <param name="repoName"></param>
/// <param name="since"></param>
/// <returns></returns>
private async Task<string> GetReleaseDetails(IssueTypeQualifier type, string repoName)
private async Task<string> GetReleaseDetails(IssueTypeQualifier type, DateTimeOffset since)
{
var twoWeeks = DateTimeOffset.Now.Subtract(TimeSpan.FromDays(14));
var range = new DateRange(twoWeeks, SearchQualifierOperator.GreaterThanOrEqualTo);
var range = new DateRange(since, SearchQualifierOperator.GreaterThanOrEqualTo);
var request = new SearchIssuesRequest();

request.Repos.Add(repoName);
request.Repos.Add($"{_repositoryOwner}/{_repositoryName}");
request.Type = type;

if (type == IssueTypeQualifier.Issue)
Expand Down

0 comments on commit 9c64efd

Please sign in to comment.