@@ -20,9 +20,19 @@ import org.ajoberstar.gradle.git.release.semver.ChangeScope
20
20
import org.ajoberstar.gradle.git.release.semver.PartialSemVerStrategy
21
21
import org.ajoberstar.gradle.git.release.semver.SemVerStrategy
22
22
import org.ajoberstar.gradle.git.release.semver.StrategyUtil
23
+ import org.gradle.api.GradleException
24
+ import org.gradle.api.Project
25
+
26
+ import java.util.regex.Pattern
27
+
28
+ import static org.ajoberstar.gradle.git.release.semver.StrategyUtil.incrementNormalFromScope
29
+ import static org.ajoberstar.gradle.git.release.semver.StrategyUtil.parseIntOrZero
23
30
24
31
class NetflixOssStrategies {
32
+ static final PartialSemVerStrategy TRAVIS_BRANCH_MAJOR_X = fromTravisPropertyPattern(~/ ^(\d +)\. x$/ )
33
+ static final PartialSemVerStrategy TRAVIS_BRANCH_MAJOR_MINOR_X = fromTravisPropertyPattern(~/ ^(\d +)\. (\d +)\. x$/ )
25
34
private static final scopes = StrategyUtil . one(Strategies.Normal . USE_SCOPE_PROP ,
35
+ TRAVIS_BRANCH_MAJOR_X , TRAVIS_BRANCH_MAJOR_MINOR_X ,
26
36
Strategies.Normal . ENFORCE_GITFLOW_BRANCH_MAJOR_X , Strategies.Normal . ENFORCE_BRANCH_MAJOR_X ,
27
37
Strategies.Normal . ENFORCE_GITFLOW_BRANCH_MAJOR_MINOR_X , Strategies.Normal . ENFORCE_BRANCH_MAJOR_MINOR_X ,
28
38
Strategies.Normal . USE_NEAREST_ANY , Strategies.Normal . useScope(ChangeScope . MINOR ))
@@ -50,4 +60,44 @@ class NetflixOssStrategies {
50
60
state. copyWith(inferredBuildMetadata : metadata)
51
61
}
52
62
}
63
+
64
+ static Project project
65
+
66
+ static final String TRAVIS_BRANCH_PROP = ' release.travisBranch'
67
+
68
+ static PartialSemVerStrategy fromTravisPropertyPattern (Pattern pattern ) {
69
+ return StrategyUtil . closure { state ->
70
+ println state
71
+ if (project. hasProperty(TRAVIS_BRANCH_PROP )) {
72
+ def branch = project. property(TRAVIS_BRANCH_PROP )
73
+ def m = branch =~ pattern
74
+ if (m) {
75
+ def major = m. groupCount() >= 1 ? parseIntOrZero(m[0 ][1 ]) : -1
76
+ def minor = m. groupCount() >= 2 ? parseIntOrZero(m[0 ][2 ]) : -1
77
+
78
+ def normal = state. nearestVersion. normal
79
+ def majorDiff = major - normal. majorVersion
80
+ def minorDiff = minor - normal. minorVersion
81
+
82
+ if (majorDiff == 1 && minor <= 0 ) {
83
+ // major is off by one and minor is either 0 or not in the branch name
84
+ return incrementNormalFromScope(state, ChangeScope . MAJOR )
85
+ } else if (minorDiff == 1 && minor > 0 ) {
86
+ // minor is off by one and specified in the branch name
87
+ return incrementNormalFromScope(state, ChangeScope . MINOR )
88
+ } else if (majorDiff == 0 && minorDiff == 0 && minor >= 0 ) {
89
+ // major and minor match, both are specified in branch name
90
+ return incrementNormalFromScope(state, ChangeScope . PATCH )
91
+ } else if (majorDiff == 0 && minor < 0 ) {
92
+ // only major specified in branch name and already matches
93
+ return state
94
+ } else {
95
+ throw new GradleException (" Invalid branch (${ state.currentBranch.name} ) for nearest normal (${ normal} )." )
96
+ }
97
+ }
98
+ }
99
+
100
+ return state
101
+ }
102
+ }
53
103
}
0 commit comments