Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -478,14 +478,9 @@ private static void ParseSections(
return;
}

foreach (var item in sequence.Children)
{
var section = ParseSectionItem(filePath, item, issues);
if (!string.IsNullOrEmpty(section.Id) && !string.IsNullOrEmpty(section.Title))
{
sections.Add(section);
}
}
sections.AddRange(sequence.Children
.Select(item => ParseSectionItem(filePath, item, issues))
.Where(section => !string.IsNullOrEmpty(section.Id) && !string.IsNullOrEmpty(section.Title)));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,11 @@ private static (VersionTag toVersion, string toHash) DetermineTargetVersion(
}

// Find the latest tag that points to the current commit
foreach (var tagVersion in lookupData.TagVersions)
var matchingTagVersion = lookupData.TagVersions.FirstOrDefault(tv =>
lookupData.TagToCommitHash.TryGetValue(tv.Tag, out var tagHash) && tagHash == toHash);
if (matchingTagVersion is not null)
{
if (lookupData.TagToCommitHash.TryGetValue(tagVersion.Tag, out var tagHash) &&
tagHash == toHash)
{
return (tagVersion, toHash);
}
return (matchingTagVersion, toHash);
}

throw new InvalidOperationException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public async Task<List<string>> GetCommitsAsync(
{
try
{
List<string> allCommitShas = new();
List<string> allCommitShas = [];
string? afterCursor = null;
bool hasNextPage;

Expand Down Expand Up @@ -192,7 +192,7 @@ public async Task<List<ReleaseNode>> GetReleasesAsync(
{
try
{
List<ReleaseNode> allReleaseNodes = new();
List<ReleaseNode> allReleaseNodes = [];
string? afterCursor = null;
bool hasNextPage;

Expand Down Expand Up @@ -265,7 +265,7 @@ public async Task<List<int>> FindIssueIdsLinkedToPullRequestAsync(
{
try
{
List<int> allIssueNumbers = new();
List<int> allIssueNumbers = [];
string? afterCursor = null;
bool hasNextPage;

Expand Down Expand Up @@ -340,7 +340,7 @@ public async Task<List<TagNode>> GetAllTagsAsync(
{
try
{
List<TagNode> allTagNodes = new();
List<TagNode> allTagNodes = [];
string? afterCursor = null;
bool hasNextPage;

Expand Down Expand Up @@ -414,7 +414,7 @@ public async Task<List<PullRequestNode>> GetPullRequestsAsync(
{
try
{
List<PullRequestNode> allPullRequestNodes = new();
List<PullRequestNode> allPullRequestNodes = [];
string? afterCursor = null;
bool hasNextPage;

Expand Down Expand Up @@ -498,7 +498,7 @@ public async Task<List<IssueNode>> GetAllIssuesAsync(
{
try
{
List<IssueNode> allIssueNodes = new();
List<IssueNode> allIssueNodes = [];
string? afterCursor = null;
bool hasNextPage;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,9 +609,9 @@ private static int DetermineSearchStartIndex(int toIndex, int releaseCount)
string repo)
{
// Initialize collections for tracking changes
HashSet<string> allChangeIds = new();
List<ItemInfo> bugs = new();
List<ItemInfo> nonBugChanges = new();
HashSet<string> allChangeIds = [];
List<ItemInfo> bugs = [];
List<ItemInfo> nonBugChanges = [];

// Process each commit that has an associated PR
foreach (var pr in commitsInRange
Expand Down Expand Up @@ -909,7 +909,7 @@ private static async Task<IReadOnlyList<IssueInfo>> GetAllIssuesAsync(
private static List<Commit> GetCommitsInRange(IReadOnlyList<Commit> commits, string? fromHash, string toHash)
{
// Initialize collection and state tracking
List<Commit> result = new();
List<Commit> result = [];
var foundTo = false;

// Iterate through commits from newest to oldest
Expand Down
55 changes: 17 additions & 38 deletions src/DemaConsulting.BuildMark/RepoConnectors/ItemControlsParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,24 @@ private static bool IsOpeningFence(string line, out string fence)
foreach (var rawLine in blockLines)
{
var (key, value) = ParseKeyValue(rawLine);
if (key != null)
switch (key)
{
ApplyBlockLineValue(key, value!, ref visibility, ref type, ref affectedVersions);
case "visibility" when value is VisibilityPublic or VisibilityInternal:
visibility = value;
break;

case "type" when value is TypeBug or TypeFeature:
type = value;
break;

case "affected-versions" when !string.IsNullOrEmpty(value):
var parsed = VersionIntervalSet.Parse(value!);
if (parsed.Intervals.Count > 0)
{
affectedVersions = parsed;
}

break;
}
}

Expand Down Expand Up @@ -194,40 +209,4 @@ private static (string? key, string? value) ParseKeyValue(string rawLine)

return (line[..colonIdx].Trim().ToLowerInvariant(), line[(colonIdx + 1)..].Trim());
}

/// <summary>
/// Applies a recognized key-value pair to the appropriate output parameter.
/// </summary>
/// <param name="key">Lowercased key from the buildmark block line.</param>
/// <param name="value">Trimmed value from the buildmark block line.</param>
/// <param name="visibility">Current visibility value (updated if key is "visibility").</param>
/// <param name="type">Current type value (updated if key is "type").</param>
/// <param name="affectedVersions">Current affected versions (updated if key is "affected-versions").</param>
private static void ApplyBlockLineValue(
string key,
string value,
ref string? visibility,
ref string? type,
ref VersionIntervalSet? affectedVersions)
{
switch (key)
{
case "visibility" when value is VisibilityPublic or VisibilityInternal:
visibility = value;
break;

case "type" when value is TypeBug or TypeFeature:
type = value;
break;

case "affected-versions" when !string.IsNullOrEmpty(value):
var parsed = VersionIntervalSet.Parse(value);
if (parsed.Intervals.Count > 0)
{
affectedVersions = parsed;
}

break;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,9 @@ private static (List<ItemInfo> bugs, List<ItemInfo> nonBugChanges, HashSet<strin
CategorizeChanges(List<ItemInfo> changes)
{
// Initialize collections for categorized changes
HashSet<string> allChangeIds = new();
List<ItemInfo> bugs = new();
List<ItemInfo> nonBugChanges = new();
HashSet<string> allChangeIds = [];
List<ItemInfo> bugs = [];
List<ItemInfo> nonBugChanges = [];

// Process and categorize each change
foreach (var change in changes)
Expand Down Expand Up @@ -504,7 +504,7 @@ private static List<string> GetPullRequestsForTagRange(string? fromTagName, stri
private List<ItemInfo> BuildChangesFromPullRequests(List<string> prs)
{
// Initialize collection for changes
List<ItemInfo> changes = new();
List<ItemInfo> changes = [];

// Process each pull request
foreach (var pr in prs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void Configure(IReadOnlyList<RuleConfig> rules, IReadOnlyList<SectionConf
var routedDict = ItemRouter.Route(allItems.ToList(), _rules, _sections);

// Build ordered list of sections with their items, using configured section order
List<(string SectionId, string SectionTitle, IReadOnlyList<ItemInfo> Items)> result = new();
List<(string SectionId, string SectionTitle, IReadOnlyList<ItemInfo> Items)> result = [];

// Process each configured section in order
foreach (var section in _sections)
Expand Down
11 changes: 3 additions & 8 deletions src/DemaConsulting.BuildMark/Version/VersionComparable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,9 @@ public int CompareTo(PreReleaseSegment other)
// Convert each part into either numeric or text segment
for (var i = 0; i < parts.Length; i++)
{
if (int.TryParse(parts[i], out var numericValue))
{
segments[i] = new PreReleaseSegment(numericValue);
}
else
{
segments[i] = new PreReleaseSegment(parts[i]);
}
segments[i] = int.TryParse(parts[i], out var numericValue)
? new PreReleaseSegment(numericValue)
: new PreReleaseSegment(parts[i]);
}

return segments;
Expand Down
28 changes: 16 additions & 12 deletions src/DemaConsulting.BuildMark/Version/VersionInterval.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,19 @@ public bool Contains(VersionComparable version)
if (LowerBound != null)
{
var lowerBoundVersion = VersionComparable.TryCreate(LowerBound);
if (lowerBoundVersion != null)
if (lowerBoundVersion != null && IsBelowLowerBound(version.CompareTo(lowerBoundVersion), LowerInclusive))
{
var lowerComparison = version.CompareTo(lowerBoundVersion);
if (lowerComparison < 0 || (lowerComparison == 0 && !LowerInclusive))
{
return false;
}
return false;
}
}

// Reject versions above the upper bound.
if (UpperBound != null)
{
var upperBoundVersion = VersionComparable.TryCreate(UpperBound);
if (upperBoundVersion != null)
if (upperBoundVersion != null && IsAboveUpperBound(version.CompareTo(upperBoundVersion), UpperInclusive))
{
var upperComparison = version.CompareTo(upperBoundVersion);
if (upperComparison > 0 || (upperComparison == 0 && !UpperInclusive))
{
return false;
}
return false;
}
}

Expand All @@ -98,6 +90,18 @@ public bool Contains(VersionTag version)
return Contains(version.Semantic.Comparable);
}

/// <summary>
/// Returns true when a comparison result places a version below the lower bound.
/// </summary>
private static bool IsBelowLowerBound(int comparison, bool inclusive) =>
comparison < 0 || (comparison == 0 && !inclusive);

/// <summary>
/// Returns true when a comparison result places a version above the upper bound.
/// </summary>
private static bool IsAboveUpperBound(int comparison, bool inclusive) =>
comparison > 0 || (comparison == 0 && !inclusive);

/// <summary>
/// Parses a version interval from text.
/// </summary>
Expand Down
21 changes: 15 additions & 6 deletions src/DemaConsulting.BuildMark/Version/VersionIntervalSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static VersionIntervalSet Parse(string text)
{
// Walk character by character tracking bracket depth
// Split on ',' when depth==0 (these separate intervals)
List<VersionInterval> intervals = new();
List<VersionInterval> intervals = [];
var depth = 0;
var pos = 0;
var tokenStart = 0;
Expand Down Expand Up @@ -96,11 +96,7 @@ public static VersionIntervalSet Parse(string text)
}

// Advance past closing bracket and any trailing comma/whitespace
pos++;
while (pos < text.Length && (text[pos] == ',' || char.IsWhiteSpace(text[pos])))
{
pos++;
}
pos = SkipCommaAndWhitespace(text, pos + 1);
tokenStart = pos;
continue;
}
Expand All @@ -112,4 +108,17 @@ public static VersionIntervalSet Parse(string text)
// Return VersionIntervalSet wrapping the list
return new VersionIntervalSet(intervals);
}

/// <summary>
/// Advances past any comma and whitespace characters starting at <paramref name="pos"/>.
/// </summary>
private static int SkipCommaAndWhitespace(string text, int pos)
{
while (pos < text.Length && (text[pos] == ',' || char.IsWhiteSpace(text[pos])))
{
pos++;
}

return pos;
}
}
Loading