-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuildInformation.cs
More file actions
212 lines (189 loc) · 8.1 KB
/
BuildInformation.cs
File metadata and controls
212 lines (189 loc) · 8.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
// Copyright (c) DEMA Consulting
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
namespace DemaConsulting.BuildMark;
/// <summary>
/// Represents build information for a release.
/// </summary>
/// <param name="BaselineVersionTag">Starting version tag (null if from beginning of history).</param>
/// <param name="CurrentVersionTag">Ending version tag.</param>
/// <param name="Changes">Non-bug changes performed between versions.</param>
/// <param name="Bugs">Bugs fixed between versions.</param>
/// <param name="KnownIssues">Known issues (unfixed or fixed but not in this build).</param>
/// <param name="CompleteChangelogLink">Optional link to the full changelog (null if not available).</param>
public record BuildInformation(
VersionTag? BaselineVersionTag,
VersionTag CurrentVersionTag,
List<ItemInfo> Changes,
List<ItemInfo> Bugs,
List<ItemInfo> KnownIssues,
WebLink? CompleteChangelogLink)
{
/// <summary>
/// Generates a Markdown build report from this build information.
/// </summary>
/// <param name="headingDepth">Root markdown heading depth (default 1).</param>
/// <param name="includeKnownIssues">Flag for whether to include known issues (default false).</param>
/// <returns>Markdown-formatted build report.</returns>
public string ToMarkdown(int headingDepth = 1, bool includeKnownIssues = false)
{
// Build heading prefix based on requested depth
var heading = new string('#', headingDepth);
var subHeading = new string('#', headingDepth + 1);
// Start building the markdown report
var markdown = new System.Text.StringBuilder();
// Add title section
markdown.AppendLine($"{heading} Build Report");
markdown.AppendLine();
// Add version information section
AppendVersionInformation(markdown, subHeading);
// Add changes section
AppendChangesSection(markdown, subHeading);
// Add bugs fixed section
AppendBugsFixedSection(markdown, subHeading);
// Add known issues section if requested
if (includeKnownIssues)
{
AppendKnownIssuesSection(markdown, subHeading);
}
// Add full changelog section if link is available
if (CompleteChangelogLink != null)
{
AppendCompleteChangelogSection(markdown, subHeading);
}
// Return the complete markdown report
return markdown.ToString();
}
/// <summary>
/// Appends the version information section to the markdown report.
/// </summary>
/// <param name="markdown">StringBuilder containing the markdown report.</param>
/// <param name="subHeading">Sub-heading prefix.</param>
private void AppendVersionInformation(System.Text.StringBuilder markdown, string subHeading)
{
// Add version information section header and table structure
markdown.AppendLine($"{subHeading} Version Information");
markdown.AppendLine();
markdown.AppendLine("| Field | Value |");
markdown.AppendLine("|-------|-------|");
markdown.AppendLine($"| **Version** | {CurrentVersionTag.VersionInfo.Tag} |");
markdown.AppendLine($"| **Commit Hash** | {CurrentVersionTag.CommitHash} |");
// Add previous version information or N/A if this is the first release
if (BaselineVersionTag != null)
{
markdown.AppendLine($"| **Previous Version** | {BaselineVersionTag.VersionInfo.Tag} |");
markdown.AppendLine($"| **Previous Commit Hash** | {BaselineVersionTag.CommitHash} |");
}
else
{
markdown.AppendLine("| **Previous Version** | N/A |");
markdown.AppendLine("| **Previous Commit Hash** | N/A |");
}
// Add blank line after section
markdown.AppendLine();
}
/// <summary>
/// Appends the changes section to the markdown report.
/// </summary>
/// <param name="markdown">StringBuilder containing the markdown report.</param>
/// <param name="subHeading">Sub-heading prefix.</param>
private void AppendChangesSection(System.Text.StringBuilder markdown, string subHeading)
{
// Add changes section header
markdown.AppendLine($"{subHeading} Changes");
markdown.AppendLine();
// Add change items or N/A if no changes exist
if (Changes.Count > 0)
{
foreach (var issue in Changes)
{
markdown.AppendLine($"- [{issue.Id}]({issue.Url}) - {issue.Title}");
}
}
else
{
markdown.AppendLine("- N/A");
}
// Add blank line after section
markdown.AppendLine();
}
/// <summary>
/// Appends the bugs fixed section to the markdown report.
/// </summary>
/// <param name="markdown">StringBuilder containing the markdown report.</param>
/// <param name="subHeading">Sub-heading prefix.</param>
private void AppendBugsFixedSection(System.Text.StringBuilder markdown, string subHeading)
{
// Add bugs fixed section header
markdown.AppendLine($"{subHeading} Bugs Fixed");
markdown.AppendLine();
// Add bug items or N/A if no bugs were fixed
if (Bugs.Count > 0)
{
foreach (var issue in Bugs)
{
markdown.AppendLine($"- [{issue.Id}]({issue.Url}) - {issue.Title}");
}
}
else
{
markdown.AppendLine("- N/A");
}
// Add blank line after section
markdown.AppendLine();
}
/// <summary>
/// Appends the known issues section to the markdown report.
/// </summary>
/// <param name="markdown">StringBuilder containing the markdown report.</param>
/// <param name="subHeading">Sub-heading prefix.</param>
private void AppendKnownIssuesSection(System.Text.StringBuilder markdown, string subHeading)
{
// Add known issues section header
markdown.AppendLine($"{subHeading} Known Issues");
markdown.AppendLine();
// Add known issue items or N/A if no known issues exist
if (KnownIssues.Count > 0)
{
foreach (var issue in KnownIssues)
{
markdown.AppendLine($"- [{issue.Id}]({issue.Url}) - {issue.Title}");
}
}
else
{
markdown.AppendLine("- N/A");
}
// Add blank line after section
markdown.AppendLine();
}
/// <summary>
/// Appends the full changelog section to the markdown report.
/// </summary>
/// <param name="markdown">StringBuilder containing the markdown report.</param>
/// <param name="subHeading">Sub-heading prefix.</param>
private void AppendCompleteChangelogSection(System.Text.StringBuilder markdown, string subHeading)
{
// Add full changelog section header and link
markdown.AppendLine($"{subHeading} Full Changelog");
markdown.AppendLine();
markdown.AppendLine($"See the full changelog at [{CompleteChangelogLink!.LinkText}]({CompleteChangelogLink.TargetUrl}).");
markdown.AppendLine();
}
}