diff --git a/BREAKING_CHANGES.md b/BREAKING_CHANGES.md index 93e2285091..e1ab2c4975 100644 --- a/BREAKING_CHANGES.md +++ b/BREAKING_CHANGES.md @@ -1,3 +1,7 @@ +## v6.2.0 + +* The configuration property `label-number-pattern` was removed. The functionality can be still used by changing the label and the branch name regular expression for pull-request branches. + ## v6.0.0 ### Platforms @@ -60,7 +64,7 @@ * The `useBranchName` magic string has been removed. Instead use `{BranchName}` for `label`. * The `BranchPrefixToTrim` configuration property has been removed. `RegularExpression` is now used to capture named groups instead. - * Default `RegularExpression` for feature branches is changed from `^features?[/-]` to `^features?[/-](?.+)` to support using `{BranchName}` out-of-the-box + * Default `RegularExpression` for feature branches is changed from `^features?[\/-]` to `^features?[\/-](?.+)` to support using `{BranchName}` out-of-the-box * Default `RegularExpression` for unknown branches is changed from `.*` to `(?.+)` to support using `{BranchName}` out-of-the-box * The `Mainline` mode and the related implementation has been removed completely. The new `Mainline` version strategy should be used instead. diff --git a/docs/input/docs/reference/configuration.md b/docs/input/docs/reference/configuration.md index 9f7354f2ce..f6ac35c566 100644 --- a/docs/input/docs/reference/configuration.md +++ b/docs/input/docs/reference/configuration.md @@ -100,7 +100,7 @@ branches: of-merged-branch: true when-current-commit-tagged: false track-merge-target: false - regex: ^releases?[/-](?.+) + regex: ^releases?[\/-](?.+) source-branches: - main - support @@ -116,7 +116,7 @@ branches: prevent-increment: when-current-commit-tagged: false track-merge-message: true - regex: ^features?[/-](?.+) + regex: ^features?[\/-](?.+) source-branches: - develop - main @@ -128,14 +128,13 @@ branches: pre-release-weight: 30000 pull-request: mode: ContinuousDelivery - label: PullRequest + label: PullRequest{Number} increment: Inherit prevent-increment: of-merged-branch: true when-current-commit-tagged: false - label-number-pattern: '[/-](?\d+)' track-merge-message: true - regex: ^(pull|pull\-requests|pr)[/-] + regex: ^(pull-requests|pull|pr)[\/-](?\d*) source-branches: - develop - main @@ -151,7 +150,7 @@ branches: increment: Inherit prevent-increment: when-current-commit-tagged: false - regex: ^hotfix(es)?[/-](?.+) + regex: ^hotfix(es)?[\/-](?.+) source-branches: - main - support @@ -165,7 +164,7 @@ branches: prevent-increment: of-merged-branch: true track-merge-target: false - regex: ^support[/-](?.+) + regex: ^support[\/-](?.+) source-branches: - main is-source-branch-for: [] @@ -209,7 +208,7 @@ tracks-release-branches: false is-release-branch: false is-main-branch: false ``` -snippet source | anchor +snippet source | anchor The supported built-in configuration for the `GitHubFlow` workflow (`workflow: GitHubFlow/v1`) looks like: @@ -262,7 +261,7 @@ branches: when-current-commit-tagged: false track-merge-target: false track-merge-message: true - regex: ^releases?[/-](?.+) + regex: ^releases?[\/-](?.+) source-branches: - main is-source-branch-for: [] @@ -277,7 +276,7 @@ branches: prevent-increment: when-current-commit-tagged: false track-merge-message: true - regex: ^features?[/-](?.+) + regex: ^features?[\/-](?.+) source-branches: - main - release @@ -286,14 +285,13 @@ branches: pre-release-weight: 30000 pull-request: mode: ContinuousDelivery - label: PullRequest + label: PullRequest{Number} increment: Inherit prevent-increment: of-merged-branch: true when-current-commit-tagged: false - label-number-pattern: '[/-](?\d+)' track-merge-message: true - regex: ^(pull|pull\-requests|pr)[/-] + regex: ^(pull-requests|pull|pr)[\/-](?\d*) source-branches: - main - release @@ -334,7 +332,7 @@ tracks-release-branches: false is-release-branch: false is-main-branch: false ``` -snippet source | anchor +snippet source | anchor The preview built-in configuration (experimental usage only) for the `TrunkBased` workflow (`workflow: TrunkBased/preview1`) looks like: @@ -381,7 +379,7 @@ branches: prevent-increment: when-current-commit-tagged: false track-merge-message: true - regex: ^features?[/-](?.+) + regex: ^features?[\/-](?.+) source-branches: - main is-source-branch-for: [] @@ -393,7 +391,7 @@ branches: increment: Patch prevent-increment: when-current-commit-tagged: false - regex: ^hotfix(es)?[/-](?.+) + regex: ^hotfix(es)?[\/-](?.+) source-branches: - main is-source-branch-for: [] @@ -402,14 +400,13 @@ branches: pre-release-weight: 30000 pull-request: mode: ContinuousDelivery - label: PullRequest + label: PullRequest{Number} increment: Inherit prevent-increment: of-merged-branch: true when-current-commit-tagged: false - label-number-pattern: '[/-](?\d+)' track-merge-message: true - regex: ^(pull|pull\-requests|pr)[/-] + regex: ^(pull-requests|pull|pr)[\/-](?\d*) source-branches: - main - feature @@ -444,7 +441,7 @@ tracks-release-branches: false is-release-branch: false is-main-branch: false ``` -snippet source | anchor +snippet source | anchor The details of the available options are as follows: @@ -664,77 +661,84 @@ If you have branch specific configuration upgrading to v4 will force you to upgrade. ```yaml +workflow: 'GitHubFlow/v1' branches: main: - regex: ^master$|^main$ - mode: ContinuousDelivery label: '' increment: Patch - prevent-increment-of-merged-branch-version: true + prevent-increment: + of-merged-branch: true track-merge-target: false - source-branches: [ 'develop', 'release' ] + track-merge-message: true + regex: ^master$|^main$ + source-branches: [] + is-source-branch-for: [] tracks-release-branches: false is-release-branch: false is-main-branch: true pre-release-weight: 55000 - develop: - regex: ^dev(elop)?(ment)?$ - mode: ContinuousDeployment - label: alpha - increment: Minor - prevent-increment-of-merged-branch-version: false - track-merge-target: true - source-branches: [] - tracks-release-branches: true - is-release-branch: false - is-main-branch: false - pre-release-weight: 0 release: - regex: ^releases?[/-] - mode: ContinuousDelivery + mode: ManualDeployment label: beta - increment: None - prevent-increment-of-merged-branch-version: true + increment: Patch + prevent-increment: + of-merged-branch: true + when-branch-merged: false + when-current-commit-tagged: false track-merge-target: false - source-branches: [ 'develop', 'main', 'support', 'release' ] + track-merge-message: true + regex: ^releases?[\/-](?.+) + source-branches: + - main + is-source-branch-for: [] tracks-release-branches: false is-release-branch: true is-main-branch: false pre-release-weight: 30000 feature: - regex: ^features?[/-] - mode: ContinuousDelivery + mode: ManualDeployment label: '{BranchName}' increment: Inherit - source-branches: [ 'develop', 'main', 'release', 'feature', 'support', 'hotfix' ] + prevent-increment: + when-current-commit-tagged: false + track-merge-message: true + regex: ^features?[\/-](?.+) + source-branches: + - main + - release + is-source-branch-for: [] + is-main-branch: false pre-release-weight: 30000 pull-request: - regex: ^(pull|pull\-requests|pr)[/-] mode: ContinuousDelivery - label: PullRequest + label: PullRequest{Number} increment: Inherit - label-number-pattern: '[/-](?\d+)[-/]' - source-branches: [ 'develop', 'main', 'release', 'feature', 'support', 'hotfix' ] + prevent-increment: + of-merged-branch: true + when-current-commit-tagged: false + track-merge-message: true + regex: ^(pull-requests|pull|pr)[\/-](?\d*) + source-branches: + - main + - release + - feature + is-source-branch-for: [] pre-release-weight: 30000 - hotfix: - regex: ^hotfix(es)?[/-] - mode: ContinuousDelivery - label: beta + unknown: + mode: ManualDeployment + label: '{BranchName}' increment: Inherit - source-branches: [ 'release', 'main', 'support', 'hotfix' ] - pre-release-weight: 30000 - support: - regex: ^support[/-] - mode: ContinuousDelivery - label: '' - increment: Patch - prevent-increment-of-merged-branch-version: true - track-merge-target: false - source-branches: [ 'main' ] - tracks-release-branches: false - is-release-branch: false - is-main-branch: true - pre-release-weight: 55000 + prevent-increment: + when-current-commit-tagged: false + track-merge-message: false + regex: (?.+) + source-branches: + - main + - release + - feature + - pull-request + is-source-branch-for: [] + is-main-branch: false ``` If you don't specify the regex, the built-in for that branch config will be @@ -840,9 +844,9 @@ The pre-release label to use for this branch. Use the value `{BranchName}` as a insert the value of the named group `BranchName` from the [regular expression](#regex). For example: branch `feature/foo` would become a pre-release label -of `alpha.foo` with `label: 'alpha.{BranchName}'` and `regex: '^features?[/-](?.+)'`. +of `alpha.foo` with `label: 'alpha.{BranchName}'` and `regex: '^features?[\/-](?.+)'`. -Another example: branch `features/sc-12345/some-description` would become a pre-release label of `sc-12345` with `label: '{StoryNo}'` and `regex: '^features?[/-](?sc-\d+)[-/].+'`. +Another example: branch `features/sc-12345/some-description` would become a pre-release label of `sc-12345` with `label: '{StoryNo}'` and `regex: '^features?[\/-](?sc-\d+)[-/].+'`. **Note:** To clear a default use an empty string: `label: ''` @@ -874,25 +878,28 @@ This branch related property controls the behvior whether to use the tagged (val ### label-number-pattern Pull requests require us to extract the pre-release number out of the branch -name so `refs/pulls/534/merge` builds as `PullRequest.534`. This is a regex with -a named capture group called `number`. - -If the branch `mode` is set to `ContinuousDeployment`, then the extracted -`number` is appended to the name of the pre-release label and the number portion -is the number of commits since the last label. This enables consecutive commits to -the pull request branch to generate unique full semantic version numbers when -the branch is configured to use ContinuousDeployment mode. +name so `refs/pull/534/merge` builds as `PullRequest534`. This is a regex with +a named capture group called `Number`. **Example usage:** ```yaml branches: pull-request: - mode: ContinuousDeployment - label: PullRequest + mode: ContinuousDelivery + label: PullRequest{Number} increment: Inherit - track-merge-target: true - label-number-pattern: '[/-](?\d+)[-/]' + prevent-increment: + of-merged-branch: true + when-current-commit-tagged: false + track-merge-message: true + regex: ^(pull-requests|pull|pr)[\/-](?\d*) + source-branches: + - main + - release + - feature + is-source-branch-for: [] + pre-release-weight: 30000 ``` ### track-merge-target diff --git a/docs/input/docs/reference/mdsource/configuration.source.md b/docs/input/docs/reference/mdsource/configuration.source.md index be3500ee72..5ba2cabcad 100644 --- a/docs/input/docs/reference/mdsource/configuration.source.md +++ b/docs/input/docs/reference/mdsource/configuration.source.md @@ -265,77 +265,84 @@ If you have branch specific configuration upgrading to v4 will force you to upgrade. ```yaml +workflow: 'GitHubFlow/v1' branches: main: - regex: ^master$|^main$ - mode: ContinuousDelivery label: '' increment: Patch - prevent-increment-of-merged-branch-version: true + prevent-increment: + of-merged-branch: true track-merge-target: false - source-branches: [ 'develop', 'release' ] + track-merge-message: true + regex: ^master$|^main$ + source-branches: [] + is-source-branch-for: [] tracks-release-branches: false is-release-branch: false is-main-branch: true pre-release-weight: 55000 - develop: - regex: ^dev(elop)?(ment)?$ - mode: ContinuousDeployment - label: alpha - increment: Minor - prevent-increment-of-merged-branch-version: false - track-merge-target: true - source-branches: [] - tracks-release-branches: true - is-release-branch: false - is-main-branch: false - pre-release-weight: 0 release: - regex: ^releases?[/-] - mode: ContinuousDelivery + mode: ManualDeployment label: beta - increment: None - prevent-increment-of-merged-branch-version: true + increment: Patch + prevent-increment: + of-merged-branch: true + when-branch-merged: false + when-current-commit-tagged: false track-merge-target: false - source-branches: [ 'develop', 'main', 'support', 'release' ] + track-merge-message: true + regex: ^releases?[\/-](?.+) + source-branches: + - main + is-source-branch-for: [] tracks-release-branches: false is-release-branch: true is-main-branch: false pre-release-weight: 30000 feature: - regex: ^features?[/-] - mode: ContinuousDelivery + mode: ManualDeployment label: '{BranchName}' increment: Inherit - source-branches: [ 'develop', 'main', 'release', 'feature', 'support', 'hotfix' ] + prevent-increment: + when-current-commit-tagged: false + track-merge-message: true + regex: ^features?[\/-](?.+) + source-branches: + - main + - release + is-source-branch-for: [] + is-main-branch: false pre-release-weight: 30000 pull-request: - regex: ^(pull|pull\-requests|pr)[/-] mode: ContinuousDelivery - label: PullRequest + label: PullRequest{Number} increment: Inherit - label-number-pattern: '[/-](?\d+)[-/]' - source-branches: [ 'develop', 'main', 'release', 'feature', 'support', 'hotfix' ] + prevent-increment: + of-merged-branch: true + when-current-commit-tagged: false + track-merge-message: true + regex: ^(pull-requests|pull|pr)[\/-](?\d*) + source-branches: + - main + - release + - feature + is-source-branch-for: [] pre-release-weight: 30000 - hotfix: - regex: ^hotfix(es)?[/-] - mode: ContinuousDelivery - label: beta + unknown: + mode: ManualDeployment + label: '{BranchName}' increment: Inherit - source-branches: [ 'release', 'main', 'support', 'hotfix' ] - pre-release-weight: 30000 - support: - regex: ^support[/-] - mode: ContinuousDelivery - label: '' - increment: Patch - prevent-increment-of-merged-branch-version: true - track-merge-target: false - source-branches: [ 'main' ] - tracks-release-branches: false - is-release-branch: false - is-main-branch: true - pre-release-weight: 55000 + prevent-increment: + when-current-commit-tagged: false + track-merge-message: false + regex: (?.+) + source-branches: + - main + - release + - feature + - pull-request + is-source-branch-for: [] + is-main-branch: false ``` If you don't specify the regex, the built-in for that branch config will be @@ -441,9 +448,9 @@ The pre-release label to use for this branch. Use the value `{BranchName}` as a insert the value of the named group `BranchName` from the [regular expression](#regex). For example: branch `feature/foo` would become a pre-release label -of `alpha.foo` with `label: 'alpha.{BranchName}'` and `regex: '^features?[/-](?.+)'`. +of `alpha.foo` with `label: 'alpha.{BranchName}'` and `regex: '^features?[\/-](?.+)'`. -Another example: branch `features/sc-12345/some-description` would become a pre-release label of `sc-12345` with `label: '{StoryNo}'` and `regex: '^features?[/-](?sc-\d+)[-/].+'`. +Another example: branch `features/sc-12345/some-description` would become a pre-release label of `sc-12345` with `label: '{StoryNo}'` and `regex: '^features?[\/-](?sc-\d+)[-/].+'`. **Note:** To clear a default use an empty string: `label: ''` @@ -475,25 +482,28 @@ This branch related property controls the behvior whether to use the tagged (val ### label-number-pattern Pull requests require us to extract the pre-release number out of the branch -name so `refs/pulls/534/merge` builds as `PullRequest.534`. This is a regex with -a named capture group called `number`. - -If the branch `mode` is set to `ContinuousDeployment`, then the extracted -`number` is appended to the name of the pre-release label and the number portion -is the number of commits since the last label. This enables consecutive commits to -the pull request branch to generate unique full semantic version numbers when -the branch is configured to use ContinuousDeployment mode. +name so `refs/pull/534/merge` builds as `PullRequest534`. This is a regex with +a named capture group called `Number`. **Example usage:** ```yaml branches: pull-request: - mode: ContinuousDeployment - label: PullRequest + mode: ContinuousDelivery + label: PullRequest{Number} increment: Inherit - track-merge-target: true - label-number-pattern: '[/-](?\d+)[-/]' + prevent-increment: + of-merged-branch: true + when-current-commit-tagged: false + track-merge-message: true + regex: ^(pull-requests|pull|pr)[\/-](?\d*) + source-branches: + - main + - release + - feature + is-source-branch-for: [] + pre-release-weight: 30000 ``` ### track-merge-target diff --git a/docs/input/docs/workflows/GitFlow/v1.yml b/docs/input/docs/workflows/GitFlow/v1.yml index 3eaec755f8..114ecf8e4f 100644 --- a/docs/input/docs/workflows/GitFlow/v1.yml +++ b/docs/input/docs/workflows/GitFlow/v1.yml @@ -1,4 +1,4 @@ -assembly-versioning-scheme: MajorMinorPatch +assembly-versioning-scheme: MajorMinorPatch assembly-file-versioning-scheme: MajorMinorPatch tag-prefix: '[vV]?' version-in-branch-pattern: (?[vV]?\d+(\.\d+)?(\.\d+)?).* @@ -57,7 +57,7 @@ branches: of-merged-branch: true when-current-commit-tagged: false track-merge-target: false - regex: ^releases?[/-](?.+) + regex: ^releases?[\/-](?.+) source-branches: - main - support @@ -73,7 +73,7 @@ branches: prevent-increment: when-current-commit-tagged: false track-merge-message: true - regex: ^features?[/-](?.+) + regex: ^features?[\/-](?.+) source-branches: - develop - main @@ -85,14 +85,13 @@ branches: pre-release-weight: 30000 pull-request: mode: ContinuousDelivery - label: PullRequest + label: PullRequest{Number} increment: Inherit prevent-increment: of-merged-branch: true when-current-commit-tagged: false - label-number-pattern: '[/-](?\d+)' track-merge-message: true - regex: ^(pull|pull\-requests|pr)[/-] + regex: ^(pull-requests|pull|pr)[\/-](?\d*) source-branches: - develop - main @@ -108,7 +107,7 @@ branches: increment: Inherit prevent-increment: when-current-commit-tagged: false - regex: ^hotfix(es)?[/-](?.+) + regex: ^hotfix(es)?[\/-](?.+) source-branches: - main - support @@ -122,7 +121,7 @@ branches: prevent-increment: of-merged-branch: true track-merge-target: false - regex: ^support[/-](?.+) + regex: ^support[\/-](?.+) source-branches: - main is-source-branch-for: [] diff --git a/docs/input/docs/workflows/GitHubFlow/v1.yml b/docs/input/docs/workflows/GitHubFlow/v1.yml index 0943cd01fa..bc0452231a 100644 --- a/docs/input/docs/workflows/GitHubFlow/v1.yml +++ b/docs/input/docs/workflows/GitHubFlow/v1.yml @@ -1,4 +1,4 @@ -assembly-versioning-scheme: MajorMinorPatch +assembly-versioning-scheme: MajorMinorPatch assembly-file-versioning-scheme: MajorMinorPatch tag-prefix: '[vV]?' version-in-branch-pattern: (?[vV]?\d+(\.\d+)?(\.\d+)?).* @@ -43,7 +43,7 @@ branches: when-current-commit-tagged: false track-merge-target: false track-merge-message: true - regex: ^releases?[/-](?.+) + regex: ^releases?[\/-](?.+) source-branches: - main is-source-branch-for: [] @@ -58,7 +58,7 @@ branches: prevent-increment: when-current-commit-tagged: false track-merge-message: true - regex: ^features?[/-](?.+) + regex: ^features?[\/-](?.+) source-branches: - main - release @@ -67,14 +67,13 @@ branches: pre-release-weight: 30000 pull-request: mode: ContinuousDelivery - label: PullRequest + label: PullRequest{Number} increment: Inherit prevent-increment: of-merged-branch: true when-current-commit-tagged: false - label-number-pattern: '[/-](?\d+)' track-merge-message: true - regex: ^(pull|pull\-requests|pr)[/-] + regex: ^(pull-requests|pull|pr)[\/-](?\d*) source-branches: - main - release diff --git a/docs/input/docs/workflows/TrunkBased/preview1.yml b/docs/input/docs/workflows/TrunkBased/preview1.yml index 9bfb28dae6..83d231527f 100644 --- a/docs/input/docs/workflows/TrunkBased/preview1.yml +++ b/docs/input/docs/workflows/TrunkBased/preview1.yml @@ -1,4 +1,4 @@ -assembly-versioning-scheme: MajorMinorPatch +assembly-versioning-scheme: MajorMinorPatch assembly-file-versioning-scheme: MajorMinorPatch tag-prefix: '[vV]?' version-in-branch-pattern: (?[vV]?\d+(\.\d+)?(\.\d+)?).* @@ -37,7 +37,7 @@ branches: prevent-increment: when-current-commit-tagged: false track-merge-message: true - regex: ^features?[/-](?.+) + regex: ^features?[\/-](?.+) source-branches: - main is-source-branch-for: [] @@ -49,7 +49,7 @@ branches: increment: Patch prevent-increment: when-current-commit-tagged: false - regex: ^hotfix(es)?[/-](?.+) + regex: ^hotfix(es)?[\/-](?.+) source-branches: - main is-source-branch-for: [] @@ -58,14 +58,13 @@ branches: pre-release-weight: 30000 pull-request: mode: ContinuousDelivery - label: PullRequest + label: PullRequest{Number} increment: Inherit prevent-increment: of-merged-branch: true when-current-commit-tagged: false - label-number-pattern: '[/-](?\d+)' track-merge-message: true - regex: ^(pull|pull\-requests|pr)[/-] + regex: ^(pull-requests|pull|pr)[\/-](?\d*) source-branches: - main - feature diff --git a/schemas/6.1/GitVersion.configuration.json b/schemas/6.1/GitVersion.configuration.json index c23d8a4686..a186b94b48 100644 --- a/schemas/6.1/GitVersion.configuration.json +++ b/schemas/6.1/GitVersion.configuration.json @@ -104,15 +104,6 @@ "null" ] }, - "label-number-pattern": { - "format": "regex", - "description": "The regular expression pattern to use to extract the number from the branch name. Defaults to '[/-](?\\d+)'.", - "default": "[/-](?\\d+)", - "type": [ - "string", - "null" - ] - }, "pre-release-weight": { "description": "Provides a way to translate the PreReleaseLabel to a number.", "type": [ @@ -233,15 +224,6 @@ "null" ] }, - "label-number-pattern": { - "format": "regex", - "description": "The regular expression pattern to use to extract the number from the branch name. Defaults to '[/-](?\\d+)'.", - "default": "[/-](?\\d+)", - "type": [ - "string", - "null" - ] - }, "major-version-bump-message": { "format": "regex", "description": "The regular expression to match commit messages with to perform a major version increment. Defaults to '\\+semver:\\s?(breaking|major)'", diff --git a/src/GitVersion.Configuration.Tests/Configuration/ConfigurationExtensionsTests.cs b/src/GitVersion.Configuration.Tests/Configuration/ConfigurationExtensionsTests.cs index 4edbae0b4e..97e225f752 100644 --- a/src/GitVersion.Configuration.Tests/Configuration/ConfigurationExtensionsTests.cs +++ b/src/GitVersion.Configuration.Tests/Configuration/ConfigurationExtensionsTests.cs @@ -40,8 +40,8 @@ public void EnsureIsReleaseBranchWithReferenceNameWorksAsExpected(string branchN isReleaseBranch.ShouldBe(expectedIsReleaseBranch); } - [TestCase("feature/sc-1000/Description", "^features?[/-](?.+)", "{BranchName}", "sc-1000-Description")] - [TestCase("feature/sc-1000/Description", "^features?[/-](?sc-\\d+)[-/].+", "{StoryNo}", "sc-1000")] + [TestCase("feature/sc-1000/Description", @"^features?[\/-](?.+)", "{BranchName}", "sc-1000-Description")] + [TestCase("feature/sc-1000/Description", @"^features?[\/-](?sc-\d+)[-\/].+", "{StoryNo}", "sc-1000")] public void EnsureGetBranchSpecificLabelWorksAsExpected(string branchName, string regularExpression, string label, string expectedLabel) { var configuration = GitFlowConfigurationBuilder.New diff --git a/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.CanWriteOutEffectiveConfiguration.approved.txt b/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.CanWriteOutEffectiveConfiguration.approved.txt index e3bd60b3bf..114ecf8e4f 100644 --- a/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.CanWriteOutEffectiveConfiguration.approved.txt +++ b/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.CanWriteOutEffectiveConfiguration.approved.txt @@ -57,7 +57,7 @@ branches: of-merged-branch: true when-current-commit-tagged: false track-merge-target: false - regex: ^releases?[/-](?.+) + regex: ^releases?[\/-](?.+) source-branches: - main - support @@ -73,7 +73,7 @@ branches: prevent-increment: when-current-commit-tagged: false track-merge-message: true - regex: ^features?[/-](?.+) + regex: ^features?[\/-](?.+) source-branches: - develop - main @@ -85,14 +85,13 @@ branches: pre-release-weight: 30000 pull-request: mode: ContinuousDelivery - label: PullRequest + label: PullRequest{Number} increment: Inherit prevent-increment: of-merged-branch: true when-current-commit-tagged: false - label-number-pattern: '[/-](?\d+)' track-merge-message: true - regex: ^(pull|pull\-requests|pr)[/-] + regex: ^(pull-requests|pull|pr)[\/-](?\d*) source-branches: - develop - main @@ -108,7 +107,7 @@ branches: increment: Inherit prevent-increment: when-current-commit-tagged: false - regex: ^hotfix(es)?[/-](?.+) + regex: ^hotfix(es)?[\/-](?.+) source-branches: - main - support @@ -122,7 +121,7 @@ branches: prevent-increment: of-merged-branch: true track-merge-target: false - regex: ^support[/-](?.+) + regex: ^support[\/-](?.+) source-branches: - main is-source-branch-for: [] diff --git a/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.cs b/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.cs index f693649640..ca721c3a18 100644 --- a/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.cs +++ b/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.cs @@ -103,7 +103,7 @@ public void SourceBranchesValidationShouldFailWhenMatchingBranchConfigurationIsM const string text = @" branches: bug: - regex: 'bug[/-]' + regex: 'bug[\/-]' label: bugfix source-branches: [notconfigured]"; using var _ = this.fileSystem.SetupConfigFile(path: this.repoPath, text: text); @@ -120,7 +120,7 @@ public void SourceBranchesValidationShouldSucceedForWellKnownBranches(string wel var text = $@" branches: bug: - regex: 'bug[/-]' + regex: 'bug[\/-]' label: bugfix source-branches: [{wellKnownBranchKey}]"; using var _ = this.fileSystem.SetupConfigFile(path: this.repoPath, text: text); @@ -136,13 +136,13 @@ public void CanProvideConfigForNewBranch() next-version: 2.0.0 branches: bug: - regex: 'bug[/-]' + regex: 'bug[\/-]' label: bugfix source-branches: []"; using var _ = this.fileSystem.SetupConfigFile(path: this.repoPath, text: text); var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath); - configuration.Branches["bug"].RegularExpression.ShouldBe("bug[/-]"); + configuration.Branches["bug"].RegularExpression.ShouldBe(@"bug[\/-]"); configuration.Branches["bug"].Label.ShouldBe("bugfix"); } diff --git a/src/GitVersion.Configuration.Tests/Workflows/approved/GitFlow/v1.yml b/src/GitVersion.Configuration.Tests/Workflows/approved/GitFlow/v1.yml index 3eaec755f8..114ecf8e4f 100644 --- a/src/GitVersion.Configuration.Tests/Workflows/approved/GitFlow/v1.yml +++ b/src/GitVersion.Configuration.Tests/Workflows/approved/GitFlow/v1.yml @@ -1,4 +1,4 @@ -assembly-versioning-scheme: MajorMinorPatch +assembly-versioning-scheme: MajorMinorPatch assembly-file-versioning-scheme: MajorMinorPatch tag-prefix: '[vV]?' version-in-branch-pattern: (?[vV]?\d+(\.\d+)?(\.\d+)?).* @@ -57,7 +57,7 @@ branches: of-merged-branch: true when-current-commit-tagged: false track-merge-target: false - regex: ^releases?[/-](?.+) + regex: ^releases?[\/-](?.+) source-branches: - main - support @@ -73,7 +73,7 @@ branches: prevent-increment: when-current-commit-tagged: false track-merge-message: true - regex: ^features?[/-](?.+) + regex: ^features?[\/-](?.+) source-branches: - develop - main @@ -85,14 +85,13 @@ branches: pre-release-weight: 30000 pull-request: mode: ContinuousDelivery - label: PullRequest + label: PullRequest{Number} increment: Inherit prevent-increment: of-merged-branch: true when-current-commit-tagged: false - label-number-pattern: '[/-](?\d+)' track-merge-message: true - regex: ^(pull|pull\-requests|pr)[/-] + regex: ^(pull-requests|pull|pr)[\/-](?\d*) source-branches: - develop - main @@ -108,7 +107,7 @@ branches: increment: Inherit prevent-increment: when-current-commit-tagged: false - regex: ^hotfix(es)?[/-](?.+) + regex: ^hotfix(es)?[\/-](?.+) source-branches: - main - support @@ -122,7 +121,7 @@ branches: prevent-increment: of-merged-branch: true track-merge-target: false - regex: ^support[/-](?.+) + regex: ^support[\/-](?.+) source-branches: - main is-source-branch-for: [] diff --git a/src/GitVersion.Configuration.Tests/Workflows/approved/GitHubFlow/v1.yml b/src/GitVersion.Configuration.Tests/Workflows/approved/GitHubFlow/v1.yml index 0943cd01fa..bc0452231a 100644 --- a/src/GitVersion.Configuration.Tests/Workflows/approved/GitHubFlow/v1.yml +++ b/src/GitVersion.Configuration.Tests/Workflows/approved/GitHubFlow/v1.yml @@ -1,4 +1,4 @@ -assembly-versioning-scheme: MajorMinorPatch +assembly-versioning-scheme: MajorMinorPatch assembly-file-versioning-scheme: MajorMinorPatch tag-prefix: '[vV]?' version-in-branch-pattern: (?[vV]?\d+(\.\d+)?(\.\d+)?).* @@ -43,7 +43,7 @@ branches: when-current-commit-tagged: false track-merge-target: false track-merge-message: true - regex: ^releases?[/-](?.+) + regex: ^releases?[\/-](?.+) source-branches: - main is-source-branch-for: [] @@ -58,7 +58,7 @@ branches: prevent-increment: when-current-commit-tagged: false track-merge-message: true - regex: ^features?[/-](?.+) + regex: ^features?[\/-](?.+) source-branches: - main - release @@ -67,14 +67,13 @@ branches: pre-release-weight: 30000 pull-request: mode: ContinuousDelivery - label: PullRequest + label: PullRequest{Number} increment: Inherit prevent-increment: of-merged-branch: true when-current-commit-tagged: false - label-number-pattern: '[/-](?\d+)' track-merge-message: true - regex: ^(pull|pull\-requests|pr)[/-] + regex: ^(pull-requests|pull|pr)[\/-](?\d*) source-branches: - main - release diff --git a/src/GitVersion.Configuration.Tests/Workflows/approved/TrunkBased/preview1.yml b/src/GitVersion.Configuration.Tests/Workflows/approved/TrunkBased/preview1.yml index 9bfb28dae6..83d231527f 100644 --- a/src/GitVersion.Configuration.Tests/Workflows/approved/TrunkBased/preview1.yml +++ b/src/GitVersion.Configuration.Tests/Workflows/approved/TrunkBased/preview1.yml @@ -1,4 +1,4 @@ -assembly-versioning-scheme: MajorMinorPatch +assembly-versioning-scheme: MajorMinorPatch assembly-file-versioning-scheme: MajorMinorPatch tag-prefix: '[vV]?' version-in-branch-pattern: (?[vV]?\d+(\.\d+)?(\.\d+)?).* @@ -37,7 +37,7 @@ branches: prevent-increment: when-current-commit-tagged: false track-merge-message: true - regex: ^features?[/-](?.+) + regex: ^features?[\/-](?.+) source-branches: - main is-source-branch-for: [] @@ -49,7 +49,7 @@ branches: increment: Patch prevent-increment: when-current-commit-tagged: false - regex: ^hotfix(es)?[/-](?.+) + regex: ^hotfix(es)?[\/-](?.+) source-branches: - main is-source-branch-for: [] @@ -58,14 +58,13 @@ branches: pre-release-weight: 30000 pull-request: mode: ContinuousDelivery - label: PullRequest + label: PullRequest{Number} increment: Inherit prevent-increment: of-merged-branch: true when-current-commit-tagged: false - label-number-pattern: '[/-](?\d+)' track-merge-message: true - regex: ^(pull|pull\-requests|pr)[/-] + regex: ^(pull-requests|pull|pr)[\/-](?\d*) source-branches: - main - feature diff --git a/src/GitVersion.Configuration/BranchConfiguration.cs b/src/GitVersion.Configuration/BranchConfiguration.cs index 5f8cbd07bf..06317c999a 100644 --- a/src/GitVersion.Configuration/BranchConfiguration.cs +++ b/src/GitVersion.Configuration/BranchConfiguration.cs @@ -1,5 +1,4 @@ using GitVersion.Configuration.Attributes; -using GitVersion.Core; using GitVersion.Extensions; using GitVersion.VersionCalculation; @@ -26,12 +25,6 @@ internal record BranchConfiguration : IBranchConfiguration [JsonPropertyDescription("The prevent increment configuration section.")] public PreventIncrementConfiguration PreventIncrement { get; internal set; } = new(); - [JsonPropertyName("label-number-pattern")] - [JsonPropertyDescription($"The regular expression pattern to use to extract the number from the branch name. Defaults to '{RegexPatterns.Configuration.DefaultLabelNumberPattern}'.")] - [JsonPropertyDefault(RegexPatterns.Configuration.DefaultLabelNumberPattern)] - [JsonPropertyFormat(Format.Regex)] - public string? LabelNumberPattern { get; internal set; } - [JsonPropertyName("track-merge-target")] [JsonPropertyDescription("Strategy which will look for tagged merge commits directly off the current branch.")] public bool? TrackMergeTarget { get; internal set; } @@ -97,7 +90,6 @@ public virtual IBranchConfiguration Inherit(IBranchConfiguration configuration) WhenBranchMerged = PreventIncrement.WhenBranchMerged ?? configuration.PreventIncrement.WhenBranchMerged, WhenCurrentCommitTagged = PreventIncrement.WhenCurrentCommitTagged ?? configuration.PreventIncrement.WhenCurrentCommitTagged }, - LabelNumberPattern = LabelNumberPattern ?? configuration.LabelNumberPattern, TrackMergeTarget = TrackMergeTarget ?? configuration.TrackMergeTarget, TrackMergeMessage = TrackMergeMessage ?? configuration.TrackMergeMessage, CommitMessageIncrementing = CommitMessageIncrementing ?? configuration.CommitMessageIncrementing, @@ -124,7 +116,6 @@ public virtual IBranchConfiguration Inherit(EffectiveConfiguration configuration WhenBranchMerged = PreventIncrement.WhenBranchMerged ?? configuration.PreventIncrementWhenBranchMerged, WhenCurrentCommitTagged = PreventIncrement.WhenCurrentCommitTagged ?? configuration.PreventIncrementWhenCurrentCommitTagged }, - LabelNumberPattern = LabelNumberPattern ?? configuration.LabelNumberPattern, TrackMergeTarget = TrackMergeTarget ?? configuration.TrackMergeTarget, TrackMergeMessage = TrackMergeMessage ?? configuration.TrackMergeMessage, CommitMessageIncrementing = CommitMessageIncrementing ?? configuration.CommitMessageIncrementing, diff --git a/src/GitVersion.Configuration/Builders/BranchConfigurationBuilder.cs b/src/GitVersion.Configuration/Builders/BranchConfigurationBuilder.cs index db36d2b006..18c40f8b81 100644 --- a/src/GitVersion.Configuration/Builders/BranchConfigurationBuilder.cs +++ b/src/GitVersion.Configuration/Builders/BranchConfigurationBuilder.cs @@ -12,7 +12,6 @@ internal class BranchConfigurationBuilder private bool? preventIncrementOfMergedBranch; private bool? preventIncrementWhenBranchMerged; private bool? preventIncrementWhenCurrentCommitTagged; - private string? labelNumberPattern; private bool? trackMergeTarget; private bool? trackMergeMessage; private CommitMessageIncrementMode? commitMessageIncrementing; @@ -64,12 +63,6 @@ public virtual BranchConfigurationBuilder WithPreventIncrementWhenCurrentCommitT return this; } - public virtual BranchConfigurationBuilder WithLabelNumberPattern(string? value) - { - this.labelNumberPattern = value; - return this; - } - public virtual BranchConfigurationBuilder WithTrackMergeTarget(bool? value) { this.trackMergeTarget = value; @@ -150,7 +143,6 @@ public virtual BranchConfigurationBuilder WithConfiguration(IBranchConfiguration WithPreventIncrementOfMergedBranch(value.PreventIncrement.OfMergedBranch); WithPreventIncrementWhenBranchMerged(value.PreventIncrement.WhenBranchMerged); WithPreventIncrementWhenCurrentCommitTagged(value.PreventIncrement.WhenCurrentCommitTagged); - WithLabelNumberPattern(value.LabelNumberPattern); WithTrackMergeTarget(value.TrackMergeTarget); WithTrackMergeMessage(value.TrackMergeMessage); WithCommitMessageIncrementing(value.CommitMessageIncrementing); @@ -176,7 +168,6 @@ public virtual BranchConfigurationBuilder WithConfiguration(IBranchConfiguration CommitMessageIncrementing = commitMessageIncrementing, IsMainBranch = isMainBranch, IsReleaseBranch = isReleaseBranch, - LabelNumberPattern = labelNumberPattern, PreventIncrement = new PreventIncrementConfiguration { OfMergedBranch = preventIncrementOfMergedBranch, diff --git a/src/GitVersion.Configuration/Builders/ConfigurationBuilderBase.cs b/src/GitVersion.Configuration/Builders/ConfigurationBuilderBase.cs index 80d6437579..3a7bfa3b3c 100644 --- a/src/GitVersion.Configuration/Builders/ConfigurationBuilderBase.cs +++ b/src/GitVersion.Configuration/Builders/ConfigurationBuilderBase.cs @@ -35,7 +35,6 @@ internal abstract class ConfigurationBuilderBase : IConfi private bool? preventIncrementOfMergedBranch; private bool? preventIncrementWhenBranchMerged; private bool? preventIncrementWhenCurrentCommitTagged; - private string? labelNumberPattern; private bool? trackMergeTarget; private bool? trackMergeMessage; private CommitMessageIncrementMode? commitMessageIncrementing; @@ -278,12 +277,6 @@ public virtual TConfigurationBuilder WithPreventIncrementWhenCurrentCommitTagged return (TConfigurationBuilder)this; } - public virtual TConfigurationBuilder WithLabelNumberPattern(string? value) - { - this.labelNumberPattern = value; - return (TConfigurationBuilder)this; - } - public virtual TConfigurationBuilder WithTrackMergeTarget(bool? value) { this.trackMergeTarget = value; @@ -363,7 +356,6 @@ public virtual TConfigurationBuilder WithConfiguration(IGitVersionConfiguration WithPreventIncrementOfMergedBranch(value.PreventIncrement.OfMergedBranch); WithPreventIncrementWhenBranchMerged(value.PreventIncrement.WhenBranchMerged); WithPreventIncrementWhenCurrentCommitTagged(value.PreventIncrement.WhenCurrentCommitTagged); - WithLabelNumberPattern(value.LabelNumberPattern); WithTrackMergeTarget(value.TrackMergeTarget); WithTrackMergeMessage(value.TrackMergeMessage); WithCommitMessageIncrementing(value.CommitMessageIncrementing); @@ -423,7 +415,6 @@ public virtual IGitVersionConfiguration Build() CommitMessageIncrementing = this.commitMessageIncrementing, IsMainBranch = this.isMainBranch, IsReleaseBranch = this.isReleaseBranch, - LabelNumberPattern = this.labelNumberPattern, PreventIncrement = new PreventIncrementConfiguration { OfMergedBranch = this.preventIncrementOfMergedBranch, diff --git a/src/GitVersion.Configuration/Builders/GitFlowConfigurationBuilder.cs b/src/GitVersion.Configuration/Builders/GitFlowConfigurationBuilder.cs index 0122d54b8d..09fe1afb72 100644 --- a/src/GitVersion.Configuration/Builders/GitFlowConfigurationBuilder.cs +++ b/src/GitVersion.Configuration/Builders/GitFlowConfigurationBuilder.cs @@ -139,13 +139,12 @@ private GitFlowConfigurationBuilder() this.SupportBranch.Name, this.HotfixBranch.Name ], - Label = "PullRequest", + Label = $"PullRequest{ConfigurationConstants.PullRequestNumberPlaceholder}", PreventIncrement = new PreventIncrementConfiguration { OfMergedBranch = true, WhenCurrentCommitTagged = false }, - LabelNumberPattern = RegexPatterns.Configuration.DefaultLabelNumberPattern, TrackMergeMessage = true, PreReleaseWeight = 30000 }); diff --git a/src/GitVersion.Configuration/Builders/GitHubFlowConfigurationBuilder.cs b/src/GitVersion.Configuration/Builders/GitHubFlowConfigurationBuilder.cs index b31db0c152..b470db4174 100644 --- a/src/GitVersion.Configuration/Builders/GitHubFlowConfigurationBuilder.cs +++ b/src/GitVersion.Configuration/Builders/GitHubFlowConfigurationBuilder.cs @@ -107,14 +107,13 @@ private GitHubFlowConfigurationBuilder() WithBranch(PullRequestBranch.Name).WithConfiguration(new BranchConfiguration { DeploymentMode = DeploymentMode.ContinuousDelivery, - Label = "PullRequest", + Label = $"PullRequest{ConfigurationConstants.PullRequestNumberPlaceholder}", Increment = IncrementStrategy.Inherit, PreventIncrement = new PreventIncrementConfiguration { OfMergedBranch = true, WhenCurrentCommitTagged = false }, - LabelNumberPattern = RegexPatterns.Configuration.DefaultLabelNumberPattern, RegularExpression = PullRequestBranch.RegexPattern, SourceBranches = [ diff --git a/src/GitVersion.Configuration/Builders/TrunkBasedConfigurationBuilder.cs b/src/GitVersion.Configuration/Builders/TrunkBasedConfigurationBuilder.cs index 74ccd921e6..b672ae3824 100644 --- a/src/GitVersion.Configuration/Builders/TrunkBasedConfigurationBuilder.cs +++ b/src/GitVersion.Configuration/Builders/TrunkBasedConfigurationBuilder.cs @@ -105,14 +105,13 @@ private TrunkBasedConfigurationBuilder() WithBranch(PullRequestBranch.Name).WithConfiguration(new BranchConfiguration { DeploymentMode = DeploymentMode.ContinuousDelivery, - Label = "PullRequest", + Label = $"PullRequest{ConfigurationConstants.PullRequestNumberPlaceholder}", Increment = IncrementStrategy.Inherit, PreventIncrement = new PreventIncrementConfiguration { OfMergedBranch = true, WhenCurrentCommitTagged = false }, - LabelNumberPattern = RegexPatterns.Configuration.DefaultLabelNumberPattern, RegularExpression = PullRequestBranch.RegexPattern, SourceBranches = [ diff --git a/src/GitVersion.Core.Tests/IntegrationTests/DevelopScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/DevelopScenarios.cs index 6d06396eb4..7b3908a2dc 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/DevelopScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/DevelopScenarios.cs @@ -395,7 +395,7 @@ public void WhenPreventIncrementOfMergedBranchVersionIsSetToFalseForDevelopCommi ) .WithBranch("hotfix", builder => builder .WithPreventIncrementOfMergedBranch(true) - .WithRegularExpression("^(origin/)?hotfix[/-]") + .WithRegularExpression(@"^(origin/)?hotfix[\/-]") ) .Build(); diff --git a/src/GitVersion.Core.Tests/IntegrationTests/FeatureBranchScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/FeatureBranchScenarios.cs index c0da0e2918..05cd9a46cb 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/FeatureBranchScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/FeatureBranchScenarios.cs @@ -182,10 +182,13 @@ public void CanUseBranchNameOffAReleaseBranch() fixture.AssertFullSemver("0.3.0-PROJ-1.1+4", configuration); } - [TestCase("alpha", "JIRA-123", "^features?[/-](?.+)", "alpha")] - [TestCase($"alpha.{ConfigurationConstants.BranchNamePlaceholder}", "JIRA-123", "^features?[/-](?.+)", "alpha.JIRA-123")] - [TestCase("{BranchName}-of-task-number-{TaskNumber}", "4711_this-is-a-feature", "^features?[/-](?\\d+)_(?.+)", "this-is-a-feature-of-task-number-4711")] - [TestCase("{BranchName}", "4711_this-is-a-feature", "^features?[/-](?.+)", "4711-this-is-a-feature")] + [TestCase("alpha", "JIRA-123", @"^features?[\/-](?.+)", "alpha")] + [TestCase($"alpha.{ConfigurationConstants.BranchNamePlaceholder}", "JIRA-123", @"^features?[\/-](?.+)", "alpha.JIRA-123")] + [TestCase("{BranchName}-of-task-number-{TaskNumber}", "4711_this-is-a-feature", @"^features?[\/-](?\d+)_(?.+)", "this-is-a-feature-of-task-number-4711")] + [TestCase("{BranchName}", "4711_this-is-a-feature", @"^features?[\/-](?.+)", "4711-this-is-a-feature")] + [TestCase("{BranchName}.xyz", "x_y.7.z", @"^features?[\/-](?.+)", "x-y-7-z.xyz")] + [TestCase("{BranchName}", "yourname/dash-separated-words", @".*\/(?[^\/]+)$", "dash-separated-words")] + [TestCase("{X}.{Z}-{Y}.{X}-{Z}.{X}", "xxxyyz", @"^features?[\/-](?x+)(?y+)(?z+)$", "xxx.z-yy.xxx-z.xxx")] public void ShouldUseConfiguredLabel(string label, string featureName, string regularExpression, string preReleaseLabelName) { var configuration = GitFlowConfigurationBuilder.New diff --git a/src/GitVersion.Core.Tests/IntegrationTests/MainlineDevelopmentScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/MainlineDevelopmentScenarios.cs index 8ba8ab429f..dfd3574819 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/MainlineDevelopmentScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/MainlineDevelopmentScenarios.cs @@ -26,7 +26,7 @@ private static GitFlowConfigurationBuilder GetConfigurationBuilder() => GitFlowC .WithBranch("hotfix", builder => builder .WithIsMainBranch(false).WithIncrement(IncrementStrategy.Patch) .WithDeploymentMode(DeploymentMode.ContinuousDelivery) - .WithRegularExpression("^hotfix[/-](?.+)").WithLabel("{BranchName}") + .WithRegularExpression(@"^hotfix[\/-](?.+)").WithLabel("{BranchName}") .WithSourceBranches("main") ) .WithBranch("pull-request", builder => builder diff --git a/src/GitVersion.Core.Tests/VersionCalculation/EffectiveBranchConfigurationFinderTests.cs b/src/GitVersion.Core.Tests/VersionCalculation/EffectiveBranchConfigurationFinderTests.cs index 0b90e579f5..4a4b295da0 100644 --- a/src/GitVersion.Core.Tests/VersionCalculation/EffectiveBranchConfigurationFinderTests.cs +++ b/src/GitVersion.Core.Tests/VersionCalculation/EffectiveBranchConfigurationFinderTests.cs @@ -165,7 +165,7 @@ public void UsesFirstBranchConfigWhenMultipleMatch(string branchName, IncrementS .WithBranch("release", builder => builder .WithIncrement(IncrementStrategy.Patch) .WithLabel("not-latest") - .WithRegularExpression("releases?[/-]") + .WithRegularExpression(@"releases?[\/-]") ) .Build(); diff --git a/src/GitVersion.Core.Tests/VersionCalculation/NextVersionCalculatorTests.cs b/src/GitVersion.Core.Tests/VersionCalculation/NextVersionCalculatorTests.cs index af8dd75d35..eb6340389b 100644 --- a/src/GitVersion.Core.Tests/VersionCalculation/NextVersionCalculatorTests.cs +++ b/src/GitVersion.Core.Tests/VersionCalculation/NextVersionCalculatorTests.cs @@ -68,7 +68,7 @@ public void PreReleaseLabelCanUseBranchName() var configuration = GitFlowConfigurationBuilder.New .WithNextVersion("1.0.0") .WithBranch("custom", builder => builder - .WithRegularExpression("^custom?[/-](?.+)") + .WithRegularExpression(@"^custom?[\/-](?.+)") .WithLabel(ConfigurationConstants.BranchNamePlaceholder) .WithSourceBranches() ) @@ -216,7 +216,7 @@ public void PreReleaseLabelCanUseBranchNameVariable() var configuration = GitFlowConfigurationBuilder.New .WithNextVersion("1.0.0") .WithBranch("custom", builder => builder - .WithRegularExpression("^custom?[/-](?.+)") + .WithRegularExpression(@"^custom?[\/-](?.+)") .WithLabel($"alpha.{ConfigurationConstants.BranchNamePlaceholder}") .WithDeploymentMode(DeploymentMode.ManualDeployment) .WithSourceBranches() diff --git a/src/GitVersion.Core/Configuration/ConfigurationConstants.cs b/src/GitVersion.Core/Configuration/ConfigurationConstants.cs index f8774c93ba..017990354d 100644 --- a/src/GitVersion.Core/Configuration/ConfigurationConstants.cs +++ b/src/GitVersion.Core/Configuration/ConfigurationConstants.cs @@ -24,6 +24,7 @@ internal static class ConfigurationConstants public const string DefaultAssemblyInformationalFormat = "{InformationalVersion}"; public const string DefaultCommitDateFormat = "yyyy-MM-dd"; public const string BranchNamePlaceholder = "{BranchName}"; + public const string PullRequestNumberPlaceholder = "{Number}"; public const bool DefaultUpdateBuildNumber = true; public const int DefaultTagPreReleaseWeight = 60000; diff --git a/src/GitVersion.Core/Configuration/EffectiveConfiguration.cs b/src/GitVersion.Core/Configuration/EffectiveConfiguration.cs index c7514c34cc..bd16f1f2ba 100644 --- a/src/GitVersion.Core/Configuration/EffectiveConfiguration.cs +++ b/src/GitVersion.Core/Configuration/EffectiveConfiguration.cs @@ -60,7 +60,6 @@ public EffectiveConfiguration( PreventIncrementOfMergedBranch = branchConfiguration.PreventIncrement.OfMergedBranch ?? false; PreventIncrementWhenBranchMerged = branchConfiguration.PreventIncrement.WhenBranchMerged ?? false; PreventIncrementWhenCurrentCommitTagged = branchConfiguration.PreventIncrement.WhenCurrentCommitTagged ?? true; - LabelNumberPattern = branchConfiguration.LabelNumberPattern; TrackMergeTarget = branchConfiguration.TrackMergeTarget ?? false; TrackMergeMessage = branchConfiguration.TrackMergeMessage ?? true; MajorVersionBumpMessage = configuration.MajorVersionBumpMessage; @@ -109,8 +108,6 @@ public EffectiveConfiguration( public bool PreventIncrementWhenCurrentCommitTagged { get; } - public string? LabelNumberPattern { get; } - public bool TrackMergeTarget { get; } public bool TrackMergeMessage { get; } diff --git a/src/GitVersion.Core/Configuration/IBranchConfiguration.cs b/src/GitVersion.Core/Configuration/IBranchConfiguration.cs index cf81ef3dcc..209168bb9d 100644 --- a/src/GitVersion.Core/Configuration/IBranchConfiguration.cs +++ b/src/GitVersion.Core/Configuration/IBranchConfiguration.cs @@ -14,8 +14,6 @@ public interface IBranchConfiguration IPreventIncrementConfiguration PreventIncrement { get; } - string? LabelNumberPattern { get; } - bool? TrackMergeTarget { get; } bool? TrackMergeMessage { get; } diff --git a/src/GitVersion.Core/Core/RegexPatterns.cs b/src/GitVersion.Core/Core/RegexPatterns.cs index 23f7b82d0a..4e13455b95 100644 --- a/src/GitVersion.Core/Core/RegexPatterns.cs +++ b/src/GitVersion.Core/Core/RegexPatterns.cs @@ -18,7 +18,6 @@ static RegexPatterns() Cache.TryAdd(Configuration.DefaultTagPrefixRegex.ToString(), Configuration.DefaultTagPrefixRegex); Cache.TryAdd(Configuration.DefaultVersionInBranchRegex.ToString(), Configuration.DefaultVersionInBranchRegex); - Cache.TryAdd(Configuration.DefaultLabelNumberRegex.ToString(), Configuration.DefaultLabelNumberRegex); Cache.TryAdd(Configuration.MainBranchRegex.ToString(), Configuration.MainBranchRegex); Cache.TryAdd(Configuration.DevelopBranchRegex.ToString(), Configuration.DevelopBranchRegex); Cache.TryAdd(Configuration.ReleaseBranchRegex.ToString(), Configuration.ReleaseBranchRegex); @@ -83,9 +82,6 @@ internal static class Configuration [StringSyntax(StringSyntaxAttribute.Regex)] public const string DefaultVersionInBranchPattern = @"(?[vV]?\d+(\.\d+)?(\.\d+)?).*"; - [StringSyntax(StringSyntaxAttribute.Regex)] - public const string DefaultLabelNumberPattern = @"[/-](?\d+)"; - [StringSyntax(StringSyntaxAttribute.Regex)] public const string MainBranchRegexPattern = "^master$|^main$"; @@ -93,26 +89,25 @@ internal static class Configuration public const string DevelopBranchRegexPattern = "^dev(elop)?(ment)?$"; [StringSyntax(StringSyntaxAttribute.Regex)] - public const string ReleaseBranchRegexPattern = "^releases?[/-](?.+)"; + public const string ReleaseBranchRegexPattern = @"^releases?[\/-](?.+)"; [StringSyntax(StringSyntaxAttribute.Regex)] - public const string FeatureBranchRegexPattern = "^features?[/-](?.+)"; + public const string FeatureBranchRegexPattern = @"^features?[\/-](?.+)"; [StringSyntax(StringSyntaxAttribute.Regex)] - public const string PullRequestBranchRegexPattern = @"^(pull|pull\-requests|pr)[/-]"; + public const string PullRequestBranchRegexPattern = @"^(pull-requests|pull|pr)[\/-](?\d*)"; [StringSyntax(StringSyntaxAttribute.Regex)] - public const string HotfixBranchRegexPattern = "^hotfix(es)?[/-](?.+)"; + public const string HotfixBranchRegexPattern = @"^hotfix(es)?[\/-](?.+)"; [StringSyntax(StringSyntaxAttribute.Regex)] - public const string SupportBranchRegexPattern = "^support[/-](?.+)"; + public const string SupportBranchRegexPattern = @"^support[\/-](?.+)"; [StringSyntax(StringSyntaxAttribute.Regex)] public const string UnknownBranchRegexPattern = "(?.+)"; public static Regex DefaultTagPrefixRegex { get; } = new(DefaultTagPrefixPattern, Options); public static Regex DefaultVersionInBranchRegex { get; } = new(DefaultVersionInBranchPattern, Options); - public static Regex DefaultLabelNumberRegex { get; } = new(DefaultLabelNumberPattern, Options); public static Regex MainBranchRegex { get; } = new(MainBranchRegexPattern, Options); public static Regex DevelopBranchRegex { get; } = new(DevelopBranchRegexPattern, Options); public static Regex ReleaseBranchRegex { get; } = new(ReleaseBranchRegexPattern, Options); diff --git a/src/GitVersion.Core/Extensions/ConfigurationExtensions.cs b/src/GitVersion.Core/Extensions/ConfigurationExtensions.cs index b10b2b9ae8..a1e0b4bf7a 100644 --- a/src/GitVersion.Core/Extensions/ConfigurationExtensions.cs +++ b/src/GitVersion.Core/Extensions/ConfigurationExtensions.cs @@ -90,39 +90,32 @@ public static bool IsReleaseBranch(this IGitVersionConfiguration configuration, } var effectiveBranchName = branchNameOverride ?? branchName; - if (!configuration.RegularExpression.IsNullOrWhiteSpace() && !effectiveBranchName.IsNullOrEmpty()) { - effectiveBranchName = effectiveBranchName.RegexReplace("[^a-zA-Z0-9-_]", "-"); var regex = RegexPatterns.Cache.GetOrAdd(configuration.RegularExpression); var match = regex.Match(effectiveBranchName); if (match.Success) { - // ReSharper disable once LoopCanBeConvertedToQuery foreach (var groupName in regex.GetGroupNames()) { - label = label.Replace("{" + groupName + "}", match.Groups[groupName].Value); + var groupValue = match.Groups[groupName].Value; + Lazy escapedGroupValueLazy = new(() => EscapeInvalidCharaters(groupValue)); + var placeholder = $"{{{groupName}}}"; + int index, startIndex = 0; + while ((index = label.IndexOf(placeholder, startIndex, StringComparison.InvariantCulture)) >= 0) + { + var escapedGroupValue = escapedGroupValueLazy.Value; + label = label.Remove(index, placeholder.Length).Insert(index, escapedGroupValue); + startIndex = index + escapedGroupValue.Length; + } } - - label = label.Replace('_', '-'); - } - } - - // Evaluate tag number pattern and append to prerelease tag, preserving build metadata - if (!configuration.LabelNumberPattern.IsNullOrEmpty() && !effectiveBranchName.IsNullOrEmpty()) - { - var regex = RegexPatterns.Cache.GetOrAdd(configuration.LabelNumberPattern); - var match = regex.Match(effectiveBranchName); - var numberGroup = match.Groups["number"]; - if (numberGroup.Success) - { - label += numberGroup.Value; } } - return label; } + private static string EscapeInvalidCharaters(string groupValue) => groupValue.RegexReplace(@"[^a-zA-Z0-9-]", "-"); + public static (string GitDirectory, string WorkingTreeDirectory)? FindGitDir(this IFileSystem fileSystem, string path) { string? startingDir = path; diff --git a/src/GitVersion.Core/PublicAPI.Shipped.txt b/src/GitVersion.Core/PublicAPI.Shipped.txt index d3f010c444..e8e7ed46a5 100644 --- a/src/GitVersion.Core/PublicAPI.Shipped.txt +++ b/src/GitVersion.Core/PublicAPI.Shipped.txt @@ -71,7 +71,6 @@ GitVersion.Configuration.EffectiveConfiguration.Increment.get -> GitVersion.Incr GitVersion.Configuration.EffectiveConfiguration.IsMainBranch.get -> bool GitVersion.Configuration.EffectiveConfiguration.IsReleaseBranch.get -> bool GitVersion.Configuration.EffectiveConfiguration.Label.get -> string? -GitVersion.Configuration.EffectiveConfiguration.LabelNumberPattern.get -> string? GitVersion.Configuration.EffectiveConfiguration.MajorVersionBumpMessage.get -> string? GitVersion.Configuration.EffectiveConfiguration.MinorVersionBumpMessage.get -> string? GitVersion.Configuration.EffectiveConfiguration.NextVersion.get -> string? @@ -103,7 +102,6 @@ GitVersion.Configuration.IBranchConfiguration.IsMatch(string! branchName) -> boo GitVersion.Configuration.IBranchConfiguration.IsReleaseBranch.get -> bool? GitVersion.Configuration.IBranchConfiguration.IsSourceBranchFor.get -> System.Collections.Generic.IReadOnlyCollection! GitVersion.Configuration.IBranchConfiguration.Label.get -> string? -GitVersion.Configuration.IBranchConfiguration.LabelNumberPattern.get -> string? GitVersion.Configuration.IBranchConfiguration.PreReleaseWeight.get -> int? GitVersion.Configuration.IBranchConfiguration.PreventIncrement.get -> GitVersion.Configuration.IPreventIncrementConfiguration! GitVersion.Configuration.IBranchConfiguration.RegularExpression.get -> string?