Skip to content

Conversation

@arturcic
Copy link
Member

This pull request refactors how regular expressions are accessed throughout the codebase, changing calls from method invocations to property accesses. This simplifies usage and improves consistency in both implementation and tests.

Regex access refactoring:

  • Updated all usages of regex patterns in RegexPatterns from method calls (e.g., SwitchArgumentRegex()) to property accesses (e.g., SwitchArgumentRegex) in src/GitVersion.App/ArgumentParserExtensions.cs and src/GitVersion.Core.Tests/Core/RegexPatternTests.cs. [1] [2]

Test improvements:

Refactors regex patterns to utilize `GeneratedRegexAttribute` caching for improved performance and reduced memory allocation.
unifies regex definitions into a central descriptor list.
adds a default timeout to regex construction for safety.
@arturcic arturcic added this to the 6.x milestone Nov 17, 2025
@arturcic arturcic marked this pull request as ready for review November 17, 2025 10:46
Copilot AI review requested due to automatic review settings November 17, 2025 10:47
Copilot finished reviewing on behalf of arturcic November 17, 2025 10:50
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request refactors the RegexPatterns class to expose regular expressions as properties instead of methods, improving API consistency and simplifying usage across the codebase. The implementation uses conditional compilation to support both .NET 9+ (with native property support for GeneratedRegex) and earlier .NET versions (using property wrappers around generated methods).

  • Converted all GeneratedRegex methods to properties with conditional compilation for NET9_0_OR_GREATER vs earlier frameworks
  • Updated all regex usage sites from method invocations (e.g., SwitchArgumentRegex()) to property accesses (e.g., SwitchArgumentRegex)
  • Refactored the internal Cache.KnownRegexes dictionary to use a more maintainable descriptor-based approach

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/GitVersion.Core/Core/RegexPatterns.cs Refactored all regex definitions from methods to properties with NET9+ conditional compilation; restructured cache to use descriptor pattern
src/GitVersion.Testing/Helpers/ParticipantSanitizer.cs Updated SanitizeParticipantRegex() to property access
src/GitVersion.Output/AssemblyInfo/AssemblyInfoFileUpdater.cs Updated assembly attribute regex dictionary initialization and method calls to use properties
src/GitVersion.MsBuild/Helpers/AssemblyInfoFileHelper.cs Updated attribute and trivia regex switch expressions to use properties
src/GitVersion.Core/VersionCalculation/IncrementStrategyFinder.cs Updated version bump message regex assignments to use properties
src/GitVersion.Core/SemVer/SemanticVersionPreReleaseTag.cs Updated ParsePreReleaseTagRegex() to property access
src/GitVersion.Core/SemVer/SemanticVersionBuildMetaData.cs Updated parse and format metadata regex calls to use properties
src/GitVersion.Core/SemVer/SemanticVersion.cs Updated parse strict and loose regex calls to use properties
src/GitVersion.Core/MergeMessage.cs Updated merge message format regex array initialization to use properties
src/GitVersion.Core/Logging/Log.cs Updated ObscurePasswordRegex() to property access
src/GitVersion.Core/Formatting/StringFormatWithExtension.cs Updated ExpandTokensRegex() to property access
src/GitVersion.App/ArgumentParserExtensions.cs Updated SwitchArgumentRegex() to property access
src/GitVersion.Core.Tests/Core/RegexPatternTests.cs Updated all test assertions to use property access instead of method calls

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Replaces expression-bodied properties with property-backed fields for Regex initialization to ensure a consistent approach and avoid potential re-evaluations. Affects multiple regex patterns across the project.
@arturcic arturcic requested a review from asbjornu November 17, 2025 11:53
moves regex cache to bottom of the class, for better organization.
refactors regex patterns to remove the nested `Common` class for easier access and cleaner code.
@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 17, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
6.0% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@arturcic arturcic merged commit 39dd3dc into GitTools:main Nov 17, 2025
117 of 118 checks passed
@mergify
Copy link
Contributor

mergify bot commented Nov 17, 2025

Thank you @arturcic for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants