Skip to content

Commit 8387ef2

Browse files
committed
fix: handle empty section
1 parent 1efe377 commit 8387ef2

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

NF.Tool.ReleaseNoteMaker/NF.Tool.ReleaseNoteMaker.Common/Fragments/FragmentFinder.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ public static (Exception? exOrNull, FragmentResult result) FindFragments(string
5454
files = [];
5555
}
5656

57-
foreach (string fileName in files.Select(x => Path.GetFileName(x)))
57+
string[] fileNames = files.Select(x => Path.GetFileName(x)).ToArray();
58+
foreach (string fileName in fileNames)
5859
{
5960
if (ignoredFileNameSet.Any(pattern => IsMatch(fileName.ToLower(), pattern)))
6061
{
@@ -108,6 +109,11 @@ public static (Exception? exOrNull, FragmentResult result) FindFragments(string
108109

109110
fragmentContents.Add(new FragmentContent(sectionDisplayName, fragmentBaseName, data));
110111
}
112+
113+
if (fileNames.Length == 0)
114+
{
115+
fragmentContents.Add(new FragmentContent(sectionDisplayName, FragmentBasename.Empty, string.Empty));
116+
}
111117
}
112118

113119
return (null, new FragmentResult { FragmentContents = fragmentContents, FragmentFiles = fragmentFiles });

NF.Tool.ReleaseNoteMaker/NF.Tool.ReleaseNoteMaker.Common/Fragments/FragmentResult.cs

+2
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,7 @@ public sealed record class FragmentBasename(string Issue, string Category, int R
5353
// issue: release-2.0.1
5454
// category: doc
5555
// retryCount: 10
56+
57+
public static FragmentBasename Empty => new FragmentBasename(string.Empty, string.Empty, 0);
5658
}
5759
}

NF.Tool.ReleaseNoteMaker/NF.Tool.ReleaseNoteMaker.Common/Template/TemplateRenderer.cs

+8-4
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,15 @@ public sealed class TemplateRenderer
8080
}
8181

8282
string category = grpCategory.Key;
83-
string categoryDisplayName = config.Types.Find(x => x.Category == category)!.DisplayName;
83+
ReleaseNoteType? releaseNoteTypeOrNull = config.Types.Find(x => x.Category == category);
84+
if (releaseNoteTypeOrNull != null)
8485
{
85-
List<string> issues = grpCategory.Select(x => x.FragmentBasename.Issue).OrderBy(IssueParts.IssueKey).ToList();
86-
List<string> formattedIssues = issues.Select(x => Issue.RenderIssue(issueFormat, x)).ToList();
87-
categories.Add(new Category(categoryDisplayName, contents, formattedIssues));
86+
string categoryDisplayName = releaseNoteTypeOrNull.DisplayName;
87+
{
88+
List<string> issues = grpCategory.Select(x => x.FragmentBasename.Issue).OrderBy(IssueParts.IssueKey).ToList();
89+
List<string> formattedIssues = issues.Select(x => Issue.RenderIssue(issueFormat, x)).ToList();
90+
categories.Add(new Category(categoryDisplayName, contents, formattedIssues));
91+
}
8892
}
8993
}
9094

NF.Tool.ReleaseNoteMaker/NF.Tool.ReleaseNoteMaker.Tests/FormatterTests.cs

+11
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public async Task TestBasic()
7171
new FragmentContent("", new FragmentBasename("9", "feature", 0), "Foo added."),
7272
new FragmentContent("", new FragmentBasename("3", "feature", 0), "Multi-line\nhere"),
7373
new FragmentContent("", new FragmentBasename("baz", "feature", 0), "Fun!"),
74+
new FragmentContent("Names", FragmentBasename.Empty, ""),
7475
new FragmentContent("Web", new FragmentBasename("3", "bugfix", 0), "Web fixed."),
7576
new FragmentContent("Web", new FragmentBasename("2", "bugfix", 0), "Multi-line bulleted\n- fix\n- here"),
7677
};
@@ -105,6 +106,11 @@ public async Task TestBasic()
105106
- bar, #1, #9, #142
106107
107108
109+
## Names
110+
111+
No significant changes.
112+
113+
108114
## Web
109115
110116
### Bugfixes
@@ -153,6 +159,11 @@ public async Task TestBasic()
153159
[142]: https://github.com/twisted/towncrier/issues/142
154160
155161
162+
## Names
163+
164+
No significant changes.
165+
166+
156167
## Web
157168
158169
### Bugfixes

0 commit comments

Comments
 (0)