Skip to content

Commit 05a65c5

Browse files
committed
refactor: remove class Issue
1 parent 762d5c1 commit 05a65c5

File tree

2 files changed

+35
-37
lines changed

2 files changed

+35
-37
lines changed

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

+1-34
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using SmartFormat;
2-
using System;
1+
using System;
32
using System.Diagnostics.CodeAnalysis;
43
using System.Linq;
54
using System.Text.RegularExpressions;
@@ -76,36 +75,4 @@ public int CompareTo(IssuePart? other)
7675
return a.CompareTo(b) >= 0;
7776
}
7877
}
79-
80-
public sealed class Issue
81-
{
82-
public static string RenderIssue(string issueFormat, string issue)
83-
{
84-
if (!string.IsNullOrEmpty(issueFormat))
85-
{
86-
string renderedIssue = Smart.Format(issueFormat, new { Issue = issue });
87-
return renderedIssue;
88-
}
89-
90-
if (int.TryParse(issue, out int issueNumber))
91-
{
92-
string renderedIssue = $"#{issueNumber}";
93-
return renderedIssue;
94-
}
95-
return issue;
96-
}
97-
public static string AppendNewlinesIfTrailingCodeBlock(string text)
98-
{
99-
string indentedText = @" [ \t]+[^\n]*";
100-
string emptyOrIndentedTextLines = $"(({indentedText})?\n)*";
101-
string regex = @"::\n\n" + emptyOrIndentedTextLines + indentedText + "$";
102-
bool isTrailingCodeBlock = Regex.IsMatch(text, regex);
103-
if (isTrailingCodeBlock)
104-
{
105-
return $"{text}\n\n ";
106-
}
107-
108-
return text;
109-
}
110-
}
11178
}

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

+34-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
using NF.Tool.ReleaseNoteMaker.Common.Config;
22
using NF.Tool.ReleaseNoteMaker.Common.Fragments;
3+
using SmartFormat;
34
using System;
45
using System.CodeDom.Compiler;
56
using System.Collections.Generic;
67
using System.Diagnostics.CodeAnalysis;
78
using System.IO;
89
using System.Linq;
910
using System.Text;
11+
using System.Text.RegularExpressions;
1012
using System.Threading.Tasks;
1113

1214
namespace NF.Tool.ReleaseNoteMaker.Common.Template
@@ -81,8 +83,8 @@ public sealed class TemplateRenderer
8183
List<Content> contents = new List<Content>(xs.Count);
8284
foreach (Content x in xs.OrderBy(EntryKey))
8385
{
84-
List<string> formattedIssues = x.Issues.Select(x => Issue.RenderIssue(issueFormat, x)).ToList();
85-
string text = Issue.AppendNewlinesIfTrailingCodeBlock(x.Text);
86+
List<string> formattedIssues = x.Issues.Select(x => RenderIssue(issueFormat, x)).ToList();
87+
string text = AppendNewlinesIfTrailingCodeBlock(x.Text);
8688
Content c = new Content(text, formattedIssues);
8789
contents.Add(c);
8890
}
@@ -99,7 +101,7 @@ public sealed class TemplateRenderer
99101
string categoryDisplayName = releaseNoteTypeOrNull.DisplayName;
100102
{
101103
List<string> issues = grpCategory.Select(x => x.FragmentBasename.Issue).Where(x => !string.IsNullOrEmpty(x)).OrderBy(IssuePart.IssueKey).ToList();
102-
List<string> formattedIssues = issues.Select(x => Issue.RenderIssue(issueFormat, x)).ToList();
104+
List<string> formattedIssues = issues.Select(x => RenderIssue(issueFormat, x)).ToList();
103105
categories.Add(new Category(categoryDisplayName, contents, formattedIssues));
104106
}
105107
}
@@ -222,5 +224,34 @@ internal static string TextWrap(string text, int width, string subsequentIndent)
222224
string ret = sb.ToString().TrimEnd();
223225
return ret;
224226
}
227+
228+
public static string RenderIssue(string issueFormat, string issue)
229+
{
230+
if (!string.IsNullOrEmpty(issueFormat))
231+
{
232+
string renderedIssue = Smart.Format(issueFormat, new { Issue = issue });
233+
return renderedIssue;
234+
}
235+
236+
if (int.TryParse(issue, out int issueNumber))
237+
{
238+
string renderedIssue = $"#{issueNumber}";
239+
return renderedIssue;
240+
}
241+
return issue;
242+
}
243+
public static string AppendNewlinesIfTrailingCodeBlock(string text)
244+
{
245+
string indentedText = @" [ \t]+[^\n]*";
246+
string emptyOrIndentedTextLines = $"(({indentedText})?\n)*";
247+
string regex = @"::\n\n" + emptyOrIndentedTextLines + indentedText + "$";
248+
bool isTrailingCodeBlock = Regex.IsMatch(text, regex);
249+
if (isTrailingCodeBlock)
250+
{
251+
return $"{text}\n\n ";
252+
}
253+
254+
return text;
255+
}
225256
}
226257
}

0 commit comments

Comments
 (0)