1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ using System . Linq ;
3
4
using System . Text . RegularExpressions ;
4
5
5
6
namespace GitVersion
@@ -22,57 +23,44 @@ public MergeMessage(string mergeMessage, Config config)
22
23
if ( mergeMessage == null )
23
24
throw new NullReferenceException ( ) ;
24
25
25
- foreach ( var entry in config . MergeMessageFormats )
26
- {
27
- var pattern = Pattern ( entry . Key , entry . Value ) ;
28
- if ( ApplyPattern ( mergeMessage , config . TagPrefix , pattern ) )
29
- {
30
- return ;
31
- }
32
- }
26
+ // Concat config messages with the defaults.
27
+ // Ensure configs are processed first.
28
+ var allPatterns = config . MergeMessageFormats
29
+ . Select ( x => Pattern ( x . Key , x . Value ) )
30
+ . Concat ( DefaultPatterns ) ;
33
31
34
- foreach ( var pattern in DefaultPatterns )
32
+ foreach ( var pattern in allPatterns )
35
33
{
36
- if ( ApplyPattern ( mergeMessage , config . TagPrefix , pattern ) )
34
+ var match = pattern . Value . Match ( mergeMessage ) ;
35
+ if ( match . Success )
37
36
{
38
- return ;
39
- }
40
- }
41
- }
37
+ MatchDefinition = pattern . Key ;
38
+ MergedBranch = match . Groups [ "SourceBranch" ] . Value ;
42
39
43
- public string MatchDefinition { get ; private set ; }
44
- public string TargetBranch { get ; private set ; }
45
- public string MergedBranch { get ; private set ; } = "" ;
46
- public bool IsMergedPullRequest => PullRequestNumber != null ;
47
- public int ? PullRequestNumber { get ; private set ; }
48
- public SemanticVersion Version { get ; private set ; }
40
+ if ( match . Groups [ "TargetBranch" ] . Success )
41
+ {
42
+ TargetBranch = match . Groups [ "TargetBranch" ] . Value ;
43
+ }
49
44
50
- private bool ApplyPattern ( string mergeMessage , string tagPrefix , KeyValuePair < string , Regex > pattern )
51
- {
52
- var match = pattern . Value . Match ( mergeMessage ) ;
53
- if ( match . Success )
54
- {
55
- MatchDefinition = pattern . Key ;
56
- MergedBranch = match . Groups [ "SourceBranch" ] . Value ;
45
+ if ( int . TryParse ( match . Groups [ "PullRequestNumber" ] . Value , out var pullNumber ) )
46
+ {
47
+ PullRequestNumber = pullNumber ;
48
+ }
57
49
58
- if ( match . Groups [ "TargetBranch" ] . Success )
59
- {
60
- TargetBranch = match . Groups [ "TargetBranch" ] . Value ;
61
- }
50
+ Version = ParseVersion ( MergedBranch , config . TagPrefix ) ;
62
51
63
- if ( int . TryParse ( match . Groups [ "PullRequestNumber" ] . Value , out var pullNumber ) )
64
- {
65
- PullRequestNumber = pullNumber ;
52
+ break ;
66
53
}
67
-
68
- Version = ParseVersion ( MergedBranch , tagPrefix ) ;
69
-
70
- return true ;
71
54
}
72
-
73
- return false ;
74
55
}
75
56
57
+ public string MatchDefinition { get ; }
58
+ public string TargetBranch { get ; }
59
+ public string MergedBranch { get ; } = "" ;
60
+ public bool IsMergedPullRequest => PullRequestNumber != null ;
61
+ public int ? PullRequestNumber { get ; }
62
+ public SemanticVersion Version { get ; }
63
+
76
64
private SemanticVersion ParseVersion ( string branchName , string tagPrefix )
77
65
{
78
66
// Remove remotes and branch prefixes like release/ feature/ hotfix/ etc
0 commit comments