Skip to content

Commit

Permalink
Treat empty string as an empty stage
Browse files Browse the repository at this point in the history
Instead of trying to validate an empty string as a potential valid
stage, treat it as if no stage was provided.

This fixes #60.
  • Loading branch information
ajoberstar committed Feb 27, 2018
1 parent 8c28231 commit 19e4b90
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ public StagePreReleaseStrategy(

@Override
public Version reckonTargetVersion(VcsInventory inventory, Version targetNormal) {
String stage = stageCalc.apply(inventory, targetNormal).orElse(null);
String stage = stageCalc.apply(inventory, targetNormal)
.map(String::trim)
.filter(s -> !s.isEmpty())
.orElse(null);

if (stage != null && !stages.contains(stage)) {
String message = String.format("Stage \"%s\" is not one of: %s", stage, stages);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ class StagePreReleaseStrategyTest extends Specification {
strategy(null).reckonTargetVersion(inventory, Version.valueOf('2.0.0')) == Version.valueOf('2.0.0-initial.0.5+abcdef')
}

def 'if target does not contain stage and stage is an empty string, use the default stage and add num commits and commit id'() {
expect:
strategy('').reckonTargetVersion(inventory, Version.valueOf('2.0.0')) == Version.valueOf('2.0.0-initial.0.5+abcdef')
}

def 'if target does not contain stage and stage is present, add num commits and commit id'() {
expect:
strategy(null).reckonTargetVersion(inventory, Version.valueOf('1.2.3')) == Version.valueOf('1.2.3-milestone.2.5+abcdef')
Expand Down

0 comments on commit 19e4b90

Please sign in to comment.