Skip to content

Commit 99e2662

Browse files
CopilotMalcolmnixon
andcommitted
Add Index property to ItemInfo for ordering changes by PR number
Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
1 parent 9389bdf commit 99e2662

File tree

5 files changed

+48
-8
lines changed

5 files changed

+48
-8
lines changed

src/DemaConsulting.BuildMark/BuildInformation.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ public static async Task<BuildInformation> CreateAsync(IRepoConnector connector,
197197
}
198198
}
199199

200+
// Sort all lists by Index to ensure chronological order
201+
nonBugChanges.Sort((a, b) => a.Index.CompareTo(b.Index));
202+
bugs.Sort((a, b) => a.Index.CompareTo(b.Index));
203+
knownIssues.Sort((a, b) => a.Index.CompareTo(b.Index));
204+
200205
// Create and return build information with all collected data
201206
return new BuildInformation(
202207
fromTagInfo,

src/DemaConsulting.BuildMark/ItemInfo.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ namespace DemaConsulting.BuildMark;
2727
/// <param name="Title">Item title.</param>
2828
/// <param name="Url">Item URL.</param>
2929
/// <param name="Type">Item type (bug, feature, etc.).</param>
30-
public record ItemInfo(string Id, string Title, string Url, string Type);
30+
/// <param name="Index">Numeric index for sorting (PR number for PRs, issue number for issues).</param>
31+
public record ItemInfo(string Id, string Title, string Url, string Type, int Index = 0);

src/DemaConsulting.BuildMark/RepoConnectors/GitHubRepoConnector.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,15 @@ public override async Task<List<ItemInfo>> GetChangesBetweenTagsAsync(Version? f
238238
}
239239
}
240240

241-
issueDetailsMap[issueNumber] = new ItemInfo(issueNumber, issueTitle, issueUrl, issueType);
241+
issueDetailsMap[issueNumber] = new ItemInfo(issueNumber, issueTitle, issueUrl, issueType, int.Parse(issueNumber));
242242
}
243243
}
244244
catch (Exception)
245245
{
246246
// If we can't fetch issue list, create fallback entries
247247
foreach (var issueNumber in issueNumbers)
248248
{
249-
issueDetailsMap[issueNumber] = new ItemInfo(issueNumber, $"Issue #{issueNumber}", string.Empty, "other");
249+
issueDetailsMap[issueNumber] = new ItemInfo(issueNumber, $"Issue #{issueNumber}", string.Empty, "other", int.Parse(issueNumber));
250250
}
251251
}
252252
}
@@ -301,7 +301,12 @@ public override async Task<List<ItemInfo>> GetChangesBetweenTagsAsync(Version? f
301301
}
302302
}
303303

304-
changes.Add(new ItemInfo($"#{prNumber}", prTitle, prUrl, prType));
304+
changes.Add(new ItemInfo(
305+
$"#{prNumber}",
306+
prTitle,
307+
prUrl,
308+
prType,
309+
int.Parse(prNumber)));
305310
}
306311
}
307312

@@ -404,7 +409,7 @@ public override async Task<List<ItemInfo>> GetOpenIssuesAsync()
404409
}
405410
}
406411

407-
openIssues.Add(new ItemInfo(issueNumber, issueTitle, issueUrl, issueType));
412+
openIssues.Add(new ItemInfo(issueNumber, issueTitle, issueUrl, issueType, int.Parse(issueNumber)));
408413
}
409414
catch (System.Text.Json.JsonException)
410415
{

src/DemaConsulting.BuildMark/RepoConnectors/MockRepoConnector.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,13 @@ public Task<List<ItemInfo>> GetChangesBetweenTagsAsync(Version? from, Version? t
119119
if (issues.Count > 0)
120120
{
121121
// PR has associated issues - add them as changes
122+
// Use PR number as index for chronological ordering
122123
foreach (var issueId in issues)
123124
{
124125
var title = _issueTitles.TryGetValue(issueId, out var issueTitle) ? issueTitle : $"Issue {issueId}";
125126
var url = $"https://github.com/example/repo/issues/{issueId}";
126127
var type = _issueTypes.TryGetValue(issueId, out var issueType) ? issueType : "other";
127-
changes.Add(new ItemInfo(issueId, title, url, type));
128+
changes.Add(new ItemInfo(issueId, title, url, type, int.Parse(pr)));
128129
}
129130
}
130131
else
@@ -134,7 +135,8 @@ public Task<List<ItemInfo>> GetChangesBetweenTagsAsync(Version? from, Version? t
134135
$"#{pr}",
135136
$"PR #{pr}",
136137
$"https://github.com/example/repo/pull/{pr}",
137-
"other"));
138+
"other",
139+
int.Parse(pr)));
138140
}
139141
}
140142

@@ -173,7 +175,8 @@ public Task<List<ItemInfo>> GetOpenIssuesAsync()
173175
issueId,
174176
_issueTitles.TryGetValue(issueId, out var title) ? title : $"Issue {issueId}",
175177
$"https://github.com/example/repo/issues/{issueId}",
176-
_issueTypes.TryGetValue(issueId, out var type) ? type : "other"))
178+
_issueTypes.TryGetValue(issueId, out var type) ? type : "other",
179+
int.Parse(issueId)))
177180
.ToList();
178181
return Task.FromResult(openIssuesData);
179182
}

test/DemaConsulting.BuildMark.Tests/BuildInformationTests.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,32 @@ public async Task BuildInformation_CreateAsync_CollectsIssuesCorrectly()
155155
Assert.AreEqual("5", buildInfo.KnownIssues[1].Id);
156156
}
157157

158+
/// <summary>
159+
/// Test that CreateAsync orders changes by Index (PR number).
160+
/// </summary>
161+
[TestMethod]
162+
public async Task BuildInformation_CreateAsync_OrdersChangesChronologically()
163+
{
164+
// Create build information for version with issues
165+
var connector = new MockRepoConnector();
166+
var buildInfo = await BuildInformation.CreateAsync(connector, Version.Create("ver-1.1.0"));
167+
168+
// Verify changes are ordered by Index (PR number)
169+
// Issue #1 from PR #10 should come before PR #13
170+
Assert.HasCount(2, buildInfo.Changes);
171+
Assert.AreEqual("1", buildInfo.Changes[0].Id);
172+
Assert.AreEqual(10, buildInfo.Changes[0].Index);
173+
Assert.AreEqual("#13", buildInfo.Changes[1].Id);
174+
Assert.AreEqual(13, buildInfo.Changes[1].Index);
175+
176+
// Verify Index values are in ascending order
177+
for (var i = 0; i < buildInfo.Changes.Count - 1; i++)
178+
{
179+
Assert.IsLessThanOrEqualTo(buildInfo.Changes[i + 1].Index, buildInfo.Changes[i].Index,
180+
$"Changes should be ordered by Index. Found {buildInfo.Changes[i].Index} before {buildInfo.Changes[i + 1].Index}");
181+
}
182+
}
183+
158184
/// <summary>
159185
/// Test that CreateAsync separates bug and change issues.
160186
/// </summary>

0 commit comments

Comments
 (0)