Skip to content

Commit

Permalink
Fix TagStrategy tag prefix parsing default value
Browse files Browse the repository at this point in the history
Description
===========

With the patch [#7] I added a regression. Because of a type I disabled
parsing of tags without a prefix `v`. I had no tests in place for this
behavior so this ended up in the latest `rc` build [v0.1.0-rc.4].

My intention was to set the new added field
`parseVersionsWithoutPrefixV` to true for the default constructor.
Instead I picked the groovy generated `field` for the
`setPrefixNameWithV` (`prefixNameWithV`).

I fixed the issue and added a small set of regression tests.

Changes
=======

* ![FIX] `TagStrategy` tag prefix parsing default value

[#7]:  #7
[v0.1.0-rc.4]: https://github.com/wooga/atlas-version/releases/tag/v0.1.0-rc.4
  • Loading branch information
Larusso committed Jun 5, 2020
1 parent 165dc68 commit 01d58c5
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class TagStrategy {
}

TagStrategy(boolean parseVersionsWithoutPrefixV) {
this.prefixNameWithV = parseVersionsWithoutPrefixV
this.parseVersionsWithoutPrefixV = parseVersionsWithoutPrefixV
setPrefixNameWithV(true)
}

Expand Down
55 changes: 54 additions & 1 deletion src/test/groovy/wooga/gradle/version/VersionPluginSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ class VersionPluginSpec extends ProjectSpec {
project.versionCode.toString() == expectedVersionCode.toString()

where:
nearestAny | distance | stage | scope | branchName | versionCodeScheme | expectedVersion | expectedVersionCode
nearestAny | distance | stage | scope | branchName | versionCodeScheme | expectedVersion | expectedVersionCode
_ | 1 | "snapshot" | _ | "master" | VersionCodeScheme.semver | "1.1.0-master.1" | 101000
_ | 2 | "snapshot" | "major" | "master" | VersionCodeScheme.semver | "2.0.0-master.2" | 200000
_ | 3 | "snapshot" | "minor" | "master" | VersionCodeScheme.semver | "1.1.0-master.3" | 101000
Expand Down Expand Up @@ -609,6 +609,59 @@ class VersionPluginSpec extends ProjectSpec {
scopeTitle = (scope == _) ? "unset" : scope
}

@Unroll("Finds correct nearest version #useTagPrefix from nearestNormal: #nearestNormal, nearestAny: #nearestAnyTitle, scope: #scopeTitle, stage: #stage and branch: #branchName")
def "finds nearest version tag"() {
given: "a project with specified release stage and scope"

project.ext.set('release.stage', stage)
project.ext.set('version.scheme', scheme)
if (scope != _) {
project.ext.set('release.scope', scope)
}

and: "a history"

if (branchName != "master") {
git.checkout(branch: "$branchName", startPoint: 'master', createBranch: true)
}

5.times {
git.commit(message: 'feature commit')
}

git.tag.add(name: "$tagPrefix$nearestNormal")

distance.times {
git.commit(message: 'fix commit')
}

if (nearestAny != _) {
git.tag.add(name: "$tagPrefix$nearestAny")
distance.times {
git.commit(message: 'fix commit')
}
}

when:
project.plugins.apply(PLUGIN_NAME)

then:
project.version.toString() == expectedVersion

where:
nearestAny | distance | stage | scope | scheme | branchName | prefixTag | expectedVersion
_ | 1 | "ci" | _ | VersionScheme.semver2 | "master" | true | "1.1.0-master.1"
_ | 1 | "ci" | _ | VersionScheme.semver2 | "master" | false | "1.1.0-master.1"
_ | 1 | "snapshot" | _ | VersionScheme.semver | "master" | true | "1.0.1-master00001"
_ | 1 | "snapshot" | _ | VersionScheme.semver | "master" | false | "1.0.1-master00001"

nearestNormal = '1.0.0'
nearestAnyTitle = (nearestAny == _) ? "unset" : nearestAny
scopeTitle = (scope == _) ? "unset" : scope
tagPrefix = (prefixTag) ? "v" : ""
useTagPrefix = (prefixTag) ? "with tag prefix v" : "without tag prefix"
}

@Unroll
def "project property #property is a #type"() {
given:
Expand Down

0 comments on commit 01d58c5

Please sign in to comment.