public SemanticReleaseNotes Build() { var releaseNotes = new SemanticReleaseNotes { Summary = _summary }; var userSuppliedSectionDescriptions = new Dictionary <string, string>(); if (_programArgs.ReleaseNoteSections != null && _programArgs.ReleaseNoteSections.Any()) { userSuppliedSectionDescriptions = _programArgs.ReleaseNoteSections.ToDictionary(label => label.Split('=').First(), label => label.Split('=').Last(), StringComparer.InvariantCultureIgnoreCase); } var sections = _pullRequests.SelectMany(c => c.Labels).Distinct().Where(c => userSuppliedSectionDescriptions.ContainsKey(c)).OrderBy(c => c).ToList(); var pullRequestsWithoutSection = _pullRequests.Where(pr => !userSuppliedSectionDescriptions.Keys.Intersect(pr.Labels, StringComparer.InvariantCultureIgnoreCase).Any()).ToList(); if (pullRequestsWithoutSection.Any()) { foreach (var pullRequestWithoutSection in pullRequestsWithoutSection) { pullRequestWithoutSection.Labels.Add(_programArgs.ReleaseNoteSectionlessDescription); } sections.Add(_programArgs.ReleaseNoteSectionlessDescription); userSuppliedSectionDescriptions.Add(_programArgs.ReleaseNoteSectionlessDescription, _programArgs.ReleaseNoteSectionlessDescription); } foreach (var sectionDescription in sections.Select(section => userSuppliedSectionDescriptions[section]).OrderBy(d => d).ToList()) { var section = userSuppliedSectionDescriptions.FirstOrDefault(x => x.Value == sectionDescription).Key; var sectionPullRequests = _pullRequests.Where(pr => pr.Labels.Contains(section, StringComparer.InvariantCultureIgnoreCase)).ToList(); AppendSection(releaseNotes, sectionPullRequests, sectionDescription); } return(releaseNotes); }
private void AppendSection(SemanticReleaseNotes releaseNotes, IReadOnlyCollection <PullRequestDto> pullRequests, string sectionDescription) { if (!pullRequests.Any()) { return; } var section = new SemanticReleaseSection { Name = sectionDescription }; AppendItems(section, pullRequests); releaseNotes.Sections.Add(section); }
public string Format(SemanticReleaseNotes releaseNotes) { if (!_programArgs.ReleaseNoteSectioned.Value) { return(FormatNotes(releaseNotes.Sections.SelectMany(n => n.Items))); } var markdown = new StringBuilder(); if (!_programArgs.ReleaseNoteCategorised.Value) { foreach (var section in releaseNotes.Sections) { markdown.AppendLine($"## {section.Name}"); markdown.Append(FormatNotes(section.Items)); } return(markdown.ToString()); } foreach (var section in releaseNotes.Sections) { markdown.AppendLine().AppendLine($"## {section.Name}"); var categories = section.Items.SelectMany(x => x.Categories).Distinct().OrderBy(x => x).ToList(); foreach (var category in categories) { markdown.AppendLine().AppendLine($"### {category}"); markdown.Append(FormatNotesUnderCategory(section.Items, category)); } var itemsWithoutCategories = section.Items.Where(i => !i.Categories.Any()).ToList(); if (!itemsWithoutCategories.Any()) { continue; } markdown.AppendLine().AppendLine($@"### {_programArgs.ReleaseNoteUncategorisedDescription}"); markdown.Append(FormatNotes(itemsWithoutCategories)); } return(markdown.ToString()); }