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
19 changes: 19 additions & 0 deletions .github/codeql-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,22 @@ paths-ignore:
- '**/TestResults/**'
- '**/*.Designer.cs'
- '**/*.generated.cs'

# Query filters to exclude specific queries for certain paths
query-filters:
# Exclude warnings in generated code
- exclude:
id: cs/useless-assignment-to-local
paths:
- '**/obj/**/generated/**/*.cs'
- exclude:
id: cs/nested-if-statements
paths:
- '**/obj/**/generated/**/*.cs'
# Exclude justified generic exception handlers
- exclude:
id: cs/catch-of-all-exceptions
paths:
- src/DemaConsulting.BuildMark/Context.cs
- src/DemaConsulting.BuildMark/Program.cs
- src/DemaConsulting.BuildMark/RepoConnectors/ProcessRunner.cs
52 changes: 20 additions & 32 deletions src/DemaConsulting.BuildMark/RepoConnectors/GitHubRepoConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,23 +113,19 @@ public override async Task<List<string>> GetPullRequestsBetweenTagsAsync(Version
// No versions specified, use all of HEAD
range = "HEAD";
}
else if (from == null && to != null)
else if (from == null)
{
// Only end version specified
range = ValidateTag(to.Tag);
// Only end version specified (to is not null here)
range = ValidateTag(to!.Tag);
}
else if (to == null && from != null)
else if (to == null)
{
// Only start version specified, range to HEAD
// Only start version specified, range to HEAD (from is not null here)
range = $"{ValidateTag(from.Tag)}..HEAD";
}
else
{
// Both versions specified
if (from == null || to == null)
{
throw new InvalidOperationException("Unexpected null version");
}
// Both versions specified (both from and to are not null here)
range = $"{ValidateTag(from.Tag)}..{ValidateTag(to.Tag)}";
}

Expand All @@ -140,17 +136,14 @@ public override async Task<List<string>> GetPullRequestsBetweenTagsAsync(Version

// Extract pull request numbers from merge commit messages
// Each line is parsed for "#<number>" pattern to identify the PR
var pullRequests = new List<string>();
var regex = NumberReferenceRegex();

foreach (var line in output.Split('\n', StringSplitOptions.RemoveEmptyEntries))
{
var match = regex.Match(line);
if (match.Success)
{
pullRequests.Add(match.Groups[1].Value);
}
}
var pullRequests = output
.Split('\n', StringSplitOptions.RemoveEmptyEntries)
.Select(line => regex.Match(line))
.Where(match => match.Success)
.Select(match => match.Groups[1].Value)
.ToList();

return pullRequests;
}
Expand Down Expand Up @@ -209,20 +202,15 @@ public override async Task<string> GetIssueTypeAsync(string issueId)
var labels = output.Split('\n', StringSplitOptions.RemoveEmptyEntries);

// Map labels to standardized issue types
foreach (var label in labels)
{
var lowerLabel = label.ToLowerInvariant();
foreach (var (key, value) in LabelTypeMap)
{
if (lowerLabel.Contains(key))
{
return value;
}
}
}
var matchingType = labels
.Select(label => label.ToLowerInvariant())
.SelectMany(lowerLabel => LabelTypeMap
.Where(kvp => lowerLabel.Contains(kvp.Key))
.Select(kvp => kvp.Value))
.FirstOrDefault();

// Default type when no recognized label found
return "other";
// Return matching type or default when no recognized label found
return matchingType ?? "other";
}

/// <summary>
Expand Down
12 changes: 6 additions & 6 deletions test/DemaConsulting.BuildMark.Tests/ContextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ public void Context_WriteLine_NotSilent_WritesToConsole()
using var context = Context.Create([]);

// Capture console output
var output = new StringWriter();
using var output = new StringWriter();
var originalOut = Console.Out;
try
{
Expand Down Expand Up @@ -490,7 +490,7 @@ public void Context_WriteLine_Silent_DoesNotWriteToConsole()
using var context = Context.Create(["--silent"]);

// Capture console output
var output = new StringWriter();
using var output = new StringWriter();
var originalOut = Console.Out;
try
{
Expand Down Expand Up @@ -549,7 +549,7 @@ public void Context_WriteError_NotSilent_WritesToConsole()
using var context = Context.Create([]);

// Capture console output
var output = new StringWriter();
using var output = new StringWriter();
var originalOut = Console.Out;
try
{
Expand Down Expand Up @@ -577,7 +577,7 @@ public void Context_WriteError_Silent_DoesNotWriteToConsole()
using var context = Context.Create(["--silent"]);

// Capture console output
var output = new StringWriter();
using var output = new StringWriter();
var originalOut = Console.Out;
try
{
Expand Down Expand Up @@ -639,7 +639,7 @@ public void Context_WriteError_SetsExitCodeToOne()
Assert.AreEqual(0, context.ExitCode);

// Capture console output to avoid displaying error
var output = new StringWriter();
using var output = new StringWriter();
var originalOut = Console.Out;
try
{
Expand Down Expand Up @@ -667,7 +667,7 @@ public void Context_ExitCode_NoErrors_RemainsZero()
using var context = Context.Create([]);

// Capture console output to avoid displaying messages
var output = new StringWriter();
using var output = new StringWriter();
var originalOut = Console.Out;
try
{
Expand Down