Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for remote tags which have 'refs/tags/' in front of the tag name #12

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@ class SemverGitPlugin implements Plugin<Project> {
}

def static String checkVersion(String version) {
parseVersion(version);
return version;
return formatVersion(parseVersion(version));
}

def static Object[] parseVersion(String version) {
def pattern = /^([0-9]+)\.([0-9]+)\.([0-9]+)(-([a-zA-Z0-9.-]+))?$/
def pattern = /^(?:refs\/tags\/)?([0-9]+)\.([0-9]+)\.([0-9]+)(-([a-zA-Z0-9.-]+))?$/
def matcher = version =~ pattern
def arr = matcher.collect { it }[0]
if (arr == null) {
Expand Down Expand Up @@ -124,4 +123,4 @@ class SemverGitPlugin implements Plugin<Project> {
println "Version: " + project.version
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ class SemverGitPluginTest extends GroovyTestCase {
void testParseVersion12_34_56_rc78() {
testParseVersion("12.34.56-rc78", [12,34,56,"rc78"]);
}
void testParseVersionRefsTags100() {
testParseVersion("refs/tags/1.0.0", [1,0,0,null]);
}
void testParseVersionRefsTags123() {
testParseVersion("refs/tags/1.2.3", [1,2,3,null]);
}
void testParseVersionRefsTags123beta() {
testParseVersion("refs/tags/1.2.3-beta", [1,2,3,"beta"]);
}
void testParseVersionRefsTags123snapshot() {
testParseVersion("refs/tags/1.2.3-SNAPSHOT", [1,2,3,"SNAPSHOT"]);
}
void testParseVersionRefsTags12_34_56_rc78() {
testParseVersion("refs/tags/12.34.56-rc78", [12,34,56,"rc78"]);
}
void testFailParseVersion_abc() {
shouldFail({SemverGitPlugin.parseVersion("a.b.c")});
}
Expand Down Expand Up @@ -105,4 +120,7 @@ class SemverGitPluginTest extends GroovyTestCase {
testNextVersion("1.0.0-SNAPSHOT", "1.0.0-beta", "major", "SNAPSHOT");
}

}
void testCheckVersionShouldReturnWithoutRefsTags() {
assertEquals("1.0.0-beta", SemverGitPlugin.checkVersion("refs/tags/1.0.0-beta"))
}
}