Skip to content

Commit a21ca03

Browse files
Add full changelog link with VersionTag and WebLink records (#36)
* Initial plan * Add VersionTag, WebLink records and refactor BuildInformation with full changelog support Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
1 parent d40d1d2 commit a21ca03

File tree

8 files changed

+262
-59
lines changed

8 files changed

+262
-59
lines changed

src/DemaConsulting.BuildMark/BuildInformation.cs

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,19 @@ namespace DemaConsulting.BuildMark;
2323
/// <summary>
2424
/// Represents build information for a release.
2525
/// </summary>
26-
/// <param name="FromVersion">Starting version (null if from beginning of history).</param>
27-
/// <param name="ToVersion">Ending version.</param>
28-
/// <param name="FromHash">Starting git hash (null if from beginning of history).</param>
29-
/// <param name="ToHash">Ending git hash.</param>
26+
/// <param name="BaselineVersionTag">Starting version tag (null if from beginning of history).</param>
27+
/// <param name="CurrentVersionTag">Ending version tag.</param>
3028
/// <param name="Changes">Non-bug changes performed between versions.</param>
3129
/// <param name="Bugs">Bugs fixed between versions.</param>
3230
/// <param name="KnownIssues">Known issues (unfixed or fixed but not in this build).</param>
31+
/// <param name="CompleteChangelogLink">Optional link to the full changelog (null if not available).</param>
3332
public record BuildInformation(
34-
Version? FromVersion,
35-
Version ToVersion,
36-
string? FromHash,
37-
string ToHash,
33+
VersionTag? BaselineVersionTag,
34+
VersionTag CurrentVersionTag,
3835
List<ItemInfo> Changes,
3936
List<ItemInfo> Bugs,
40-
List<ItemInfo> KnownIssues)
37+
List<ItemInfo> KnownIssues,
38+
WebLink? CompleteChangelogLink)
4139
{
4240
/// <summary>
4341
/// Generates a Markdown build report from this build information.
@@ -73,6 +71,12 @@ public string ToMarkdown(int headingDepth = 1, bool includeKnownIssues = false)
7371
AppendKnownIssuesSection(markdown, subHeading);
7472
}
7573

74+
// Add full changelog section if link is available
75+
if (CompleteChangelogLink != null)
76+
{
77+
AppendCompleteChangelogSection(markdown, subHeading);
78+
}
79+
7680
// Return the complete markdown report
7781
return markdown.ToString();
7882
}
@@ -89,14 +93,14 @@ private void AppendVersionInformation(System.Text.StringBuilder markdown, string
8993
markdown.AppendLine();
9094
markdown.AppendLine("| Field | Value |");
9195
markdown.AppendLine("|-------|-------|");
92-
markdown.AppendLine($"| **Version** | {ToVersion.Tag} |");
93-
markdown.AppendLine($"| **Commit Hash** | {ToHash} |");
96+
markdown.AppendLine($"| **Version** | {CurrentVersionTag.VersionInfo.Tag} |");
97+
markdown.AppendLine($"| **Commit Hash** | {CurrentVersionTag.CommitHash} |");
9498

9599
// Add previous version information or N/A if this is the first release
96-
if (FromVersion != null)
100+
if (BaselineVersionTag != null)
97101
{
98-
markdown.AppendLine($"| **Previous Version** | {FromVersion.Tag} |");
99-
markdown.AppendLine($"| **Previous Commit Hash** | {FromHash} |");
102+
markdown.AppendLine($"| **Previous Version** | {BaselineVersionTag.VersionInfo.Tag} |");
103+
markdown.AppendLine($"| **Previous Commit Hash** | {BaselineVersionTag.CommitHash} |");
100104
}
101105
else
102106
{
@@ -197,4 +201,18 @@ private void AppendKnownIssuesSection(System.Text.StringBuilder markdown, string
197201
// Add blank line after section
198202
markdown.AppendLine();
199203
}
204+
205+
/// <summary>
206+
/// Appends the full changelog section to the markdown report.
207+
/// </summary>
208+
/// <param name="markdown">StringBuilder containing the markdown report.</param>
209+
/// <param name="subHeading">Sub-heading prefix.</param>
210+
private void AppendCompleteChangelogSection(System.Text.StringBuilder markdown, string subHeading)
211+
{
212+
// Add full changelog section header and link
213+
markdown.AppendLine($"{subHeading} Full Changelog");
214+
markdown.AppendLine();
215+
markdown.AppendLine($"See the full changelog at [{CompleteChangelogLink!.LinkText}]({CompleteChangelogLink.TargetUrl}).");
216+
markdown.AppendLine();
217+
}
200218
}

src/DemaConsulting.BuildMark/Program.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,12 @@ private static void ProcessBuildNotes(Context context)
186186
}
187187

188188
// Display build information summary
189-
context.WriteLine($"Build Version: {buildInfo.ToVersion.Tag}");
190-
context.WriteLine($"Commit Hash: {buildInfo.ToHash}");
191-
if (buildInfo.FromVersion != null)
189+
context.WriteLine($"Build Version: {buildInfo.CurrentVersionTag.VersionInfo.Tag}");
190+
context.WriteLine($"Commit Hash: {buildInfo.CurrentVersionTag.CommitHash}");
191+
if (buildInfo.BaselineVersionTag != null)
192192
{
193-
context.WriteLine($"Previous Version: {buildInfo.FromVersion.Tag}");
194-
context.WriteLine($"Previous Commit Hash: {buildInfo.FromHash}");
193+
context.WriteLine($"Previous Version: {buildInfo.BaselineVersionTag.VersionInfo.Tag}");
194+
context.WriteLine($"Previous Commit Hash: {buildInfo.BaselineVersionTag.CommitHash}");
195195
}
196196
context.WriteLine($"Changes: {buildInfo.Changes.Count}");
197197
context.WriteLine($"Bugs Fixed: {buildInfo.Bugs.Count}");

src/DemaConsulting.BuildMark/RepoConnectors/GitHubRepoConnector.cs

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,23 @@ public override async Task<BuildInformation> GetBuildInformationAsync(Version? v
9797
bugs.Sort((a, b) => a.Index.CompareTo(b.Index));
9898
knownIssues.Sort((a, b) => a.Index.CompareTo(b.Index));
9999

100+
// Build version tags from version and hash info
101+
var currentTag = new VersionTag(toVersion, toHash);
102+
var baselineTag = fromVersion != null && fromHash != null
103+
? new VersionTag(fromVersion, fromHash)
104+
: null;
105+
106+
// Generate full changelog link for GitHub
107+
var changelogLink = GenerateGitHubChangelogLink(owner, repo, fromVersion?.Tag, toVersion.Tag);
108+
100109
// Create and return build information with all collected data
101110
return new BuildInformation(
102-
fromVersion,
103-
toVersion,
104-
fromHash,
105-
toHash,
111+
baselineTag,
112+
currentTag,
106113
nonBugChanges,
107114
bugs,
108-
knownIssues);
115+
knownIssues,
116+
changelogLink);
109117
}
110118

111119
/// <summary>
@@ -720,4 +728,27 @@ private static (string owner, string repo) ParseOwnerRepo(string path)
720728
// Return parsed owner and repo
721729
return (parts[0], parts[1]);
722730
}
731+
732+
/// <summary>
733+
/// Generates a GitHub compare link for the full changelog.
734+
/// </summary>
735+
/// <param name="owner">Repository owner.</param>
736+
/// <param name="repo">Repository name.</param>
737+
/// <param name="oldTag">Old tag name (null if from beginning).</param>
738+
/// <param name="newTag">New tag name.</param>
739+
/// <returns>WebLink to GitHub compare page, or null if no baseline tag.</returns>
740+
private static WebLink? GenerateGitHubChangelogLink(string owner, string repo, string? oldTag, string newTag)
741+
{
742+
// Cannot generate comparison link without a baseline tag
743+
if (oldTag == null)
744+
{
745+
return null;
746+
}
747+
748+
// Build comparison label and URL
749+
var comparisonLabel = $"{oldTag}...{newTag}";
750+
var comparisonUrl = $"https://github.com/{owner}/{repo}/compare/{comparisonLabel}";
751+
752+
return new WebLink(comparisonLabel, comparisonUrl);
753+
}
723754
}

src/DemaConsulting.BuildMark/RepoConnectors/MockRepoConnector.cs

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,23 @@ public override async Task<BuildInformation> GetBuildInformationAsync(Version? v
109109
bugs.Sort((a, b) => a.Index.CompareTo(b.Index));
110110
knownIssues.Sort((a, b) => a.Index.CompareTo(b.Index));
111111

112+
// Build version tags from version and hash info
113+
var currentTag = new VersionTag(toTagInfo, toHash.Trim());
114+
var baselineTag = fromTagInfo != null && fromHash != null
115+
? new VersionTag(fromTagInfo, fromHash.Trim())
116+
: null;
117+
118+
// Generate mock changelog link
119+
var changelogLink = GenerateMockChangelogLink(fromTagInfo?.Tag, toTagInfo.Tag);
120+
112121
// Create and return build information with all collected data
113122
return new BuildInformation(
114-
fromTagInfo,
115-
toTagInfo,
116-
fromHash?.Trim(),
117-
toHash.Trim(),
123+
baselineTag,
124+
currentTag,
118125
nonBugChanges,
119126
bugs,
120-
knownIssues);
127+
knownIssues,
128+
changelogLink);
121129
}
122130

123131
/// <summary>
@@ -526,4 +534,25 @@ private Task<List<ItemInfo>> GetOpenIssuesAsync()
526534
// Return task with open issues data
527535
return Task.FromResult(openIssuesData);
528536
}
537+
538+
/// <summary>
539+
/// Generates a mock changelog link for testing.
540+
/// </summary>
541+
/// <param name="oldTag">Old tag name (null if from beginning).</param>
542+
/// <param name="newTag">New tag name.</param>
543+
/// <returns>WebLink to mock compare page, or null if no baseline tag.</returns>
544+
private static WebLink? GenerateMockChangelogLink(string? oldTag, string newTag)
545+
{
546+
// Cannot generate comparison link without a baseline tag
547+
if (oldTag == null)
548+
{
549+
return null;
550+
}
551+
552+
// Build comparison label and URL for mock repo
553+
var comparisonLabel = $"{oldTag}...{newTag}";
554+
var comparisonUrl = $"https://github.com/example/repo/compare/{comparisonLabel}";
555+
556+
return new WebLink(comparisonLabel, comparisonUrl);
557+
}
529558
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) DEMA Consulting
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files (the "Software"), to deal
5+
// in the Software without restriction, including without limitation the rights
6+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
// copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in all
11+
// copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
// SOFTWARE.
20+
21+
namespace DemaConsulting.BuildMark;
22+
23+
/// <summary>
24+
/// Represents a version paired with its corresponding commit hash.
25+
/// </summary>
26+
/// <param name="VersionInfo">The version information.</param>
27+
/// <param name="CommitHash">The git commit hash for this version.</param>
28+
public record VersionTag(Version VersionInfo, string CommitHash);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) DEMA Consulting
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files (the "Software"), to deal
5+
// in the Software without restriction, including without limitation the rights
6+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
// copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in all
11+
// copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
// SOFTWARE.
20+
21+
namespace DemaConsulting.BuildMark;
22+
23+
/// <summary>
24+
/// Represents a hyperlink with descriptive text and target URL.
25+
/// </summary>
26+
/// <param name="LinkText">The display text for the link.</param>
27+
/// <param name="TargetUrl">The destination URL.</param>
28+
public record WebLink(string LinkText, string TargetUrl);

0 commit comments

Comments
 (0)