Skip to content

Commit 66ff796

Browse files
Order changes by PR number instead of grouping by type (#24)
* Initial plan * Add Index property to ItemInfo for ordering changes by PR number Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com> * Fix test name and use PR number for issue Index ordering 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 8c734dd commit 66ff796

File tree

5 files changed

+66
-8
lines changed

5 files changed

+66
-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: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,21 @@ public override async Task<List<ItemInfo>> GetChangesBetweenTagsAsync(Version? f
189189
}
190190
}
191191

192+
// Build a map from issue number to PR number for Index assignment
193+
var issueToPrMap = new Dictionary<string, int>();
194+
foreach (var (prNumber, _, _, prIssues) in prData)
195+
{
196+
var prNumberInt = int.Parse(prNumber);
197+
foreach (var issueNumber in prIssues)
198+
{
199+
// Use the first PR that references this issue (smallest PR number)
200+
if (!issueToPrMap.ContainsKey(issueNumber) || prNumberInt < issueToPrMap[issueNumber])
201+
{
202+
issueToPrMap[issueNumber] = prNumberInt;
203+
}
204+
}
205+
}
206+
192207
// Second pass: batch fetch all issue details using issue list
193208
var issueDetailsMap = new Dictionary<string, ItemInfo>();
194209
if (issueNumbers.Count > 0)
@@ -238,15 +253,18 @@ public override async Task<List<ItemInfo>> GetChangesBetweenTagsAsync(Version? f
238253
}
239254
}
240255

241-
issueDetailsMap[issueNumber] = new ItemInfo(issueNumber, issueTitle, issueUrl, issueType);
256+
// Use PR number as Index for ordering
257+
var index = issueToPrMap.TryGetValue(issueNumber, out var prNum) ? prNum : int.Parse(issueNumber);
258+
issueDetailsMap[issueNumber] = new ItemInfo(issueNumber, issueTitle, issueUrl, issueType, index);
242259
}
243260
}
244261
catch (Exception)
245262
{
246263
// If we can't fetch issue list, create fallback entries
247264
foreach (var issueNumber in issueNumbers)
248265
{
249-
issueDetailsMap[issueNumber] = new ItemInfo(issueNumber, $"Issue #{issueNumber}", string.Empty, "other");
266+
var index = issueToPrMap.TryGetValue(issueNumber, out var prNum) ? prNum : int.Parse(issueNumber);
267+
issueDetailsMap[issueNumber] = new ItemInfo(issueNumber, $"Issue #{issueNumber}", string.Empty, "other", index);
250268
}
251269
}
252270
}
@@ -301,7 +319,12 @@ public override async Task<List<ItemInfo>> GetChangesBetweenTagsAsync(Version? f
301319
}
302320
}
303321

304-
changes.Add(new ItemInfo($"#{prNumber}", prTitle, prUrl, prType));
322+
changes.Add(new ItemInfo(
323+
$"#{prNumber}",
324+
prTitle,
325+
prUrl,
326+
prType,
327+
int.Parse(prNumber)));
305328
}
306329
}
307330

@@ -404,7 +427,7 @@ public override async Task<List<ItemInfo>> GetOpenIssuesAsync()
404427
}
405428
}
406429

407-
openIssues.Add(new ItemInfo(issueNumber, issueTitle, issueUrl, issueType));
430+
openIssues.Add(new ItemInfo(issueNumber, issueTitle, issueUrl, issueType, int.Parse(issueNumber)));
408431
}
409432
catch (System.Text.Json.JsonException)
410433
{

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_OrdersChangesByIndex()
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)