Skip to content

Commit bfb379a

Browse files
committed
fix: issue #9
handles empty beta value, also fixes the cli beta command
1 parent a6bba4d commit bfb379a

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

cmd/release/release.go

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var beta *string
2222
var tag *string
2323

2424
var semverPrompt = &survey.Select{
25-
Message: "Choose a semver version:",
25+
Message: "Choose a semver version (choose none for prerelease/beta increments):",
2626
Options: []string{"major", "minor", "patch", "none"},
2727
Default: "none",
2828
}
@@ -32,8 +32,8 @@ var betaPrompt = &survey.Confirm{
3232
}
3333

3434
var betaSuffixPrompt = &survey.Input{
35-
Message: "Enter the exiting beta suffix, will be also used for the any beta suffix?",
36-
Default: "beta",
35+
Message: "Enter the exiting beta suffix (if any)? (eg: beta or dev or canary)",
36+
Default: "",
3737
}
3838

3939
// TagVersion - struct holding the broken down tag
@@ -47,20 +47,25 @@ type TagVersion struct {
4747
// Install - add flags and other options
4848
func Install() {
4949
releaseCmd = flag.NewFlagSet("release", flag.ExitOnError)
50-
major = releaseCmd.Bool("major", false, "If release is a major one, will increment the x.0.0 ")
51-
minor = releaseCmd.Bool("minor", false, "If release is a minor one, will increment the 0.x.0 ")
52-
patch = releaseCmd.Bool("patch", false, "If release is a patch, will increment the 0.0.x ")
50+
major = releaseCmd.Bool("major", false, "If release is a *major* one, will increment the x.0.0 ")
51+
minor = releaseCmd.Bool("minor", false, "If release is a *minor* one, will increment the 0.x.0 ")
52+
patch = releaseCmd.Bool("patch", false, "If release is a *patch*, will increment the 0.0.x ")
5353
beta = releaseCmd.String("beta", "beta", "If the release is a beta, to add/increment tag with `-beta.x` or mentioned string")
5454
tag = releaseCmd.String("tag", "", "The Tag to be taken as base")
5555
}
5656

5757
// Run - execute the command
5858
func Run(args []string) {
5959

60-
var tagToUse = *tag
61-
6260
isBeta := needsQuestionnaire(args)
6361
err := releaseCmd.Parse(args)
62+
63+
var tagToUse = *tag
64+
65+
if *beta != "" {
66+
isBeta = true
67+
}
68+
6469
if err != nil {
6570
log.Fatal(err)
6671
}
@@ -135,6 +140,11 @@ func createRelease(tagString string, increaseMajor bool, increaseMinor bool, inc
135140
if err != nil {
136141
log.Fatal("Error converting to number on version.patch", version)
137142
}
143+
144+
if version.beta == "" {
145+
version.beta = "-1"
146+
}
147+
138148
betaAsInt, err := strconv.ParseInt(version.beta, 10, 32)
139149
if err != nil {
140150
log.Fatal("Error converting to number on version.beta", version)
@@ -254,7 +264,10 @@ func breakTag(tagString string) (*TagVersion, bool) {
254264
version.major = tagSplits[0]
255265
version.minor = tagSplits[1]
256266
version.patch = tagSplits[2]
257-
version.beta = tagSplits[3]
267+
268+
if len(tagSplits) > 3 {
269+
version.beta = tagSplits[3]
270+
}
258271

259272
// Check if the major version has the letter `v` in the tag
260273
if len(version.major) > 1 && strings.Contains(version.major, "v") {
@@ -272,8 +285,15 @@ func breakTag(tagString string) (*TagVersion, bool) {
272285
func getTagString() string {
273286
currentRepository := clog.OpenRepository(".")
274287
var tagRef *plumbing.Reference
288+
var err error
275289
if *tag == "" {
276-
tagRef, _, _ = clog.GetLatestTagFromRepository(currentRepository)
290+
tagRef, _, err = clog.GetLatestTagFromRepository(currentRepository)
291+
if err != nil {
292+
log.Fatalf("coulnd't retrieve given tag from your repository: Error %v", err)
293+
}
294+
}
295+
if tagRef == nil {
296+
log.Fatalf("coulnd't retrieve given tag from your repository")
277297
}
278298
onlyTag := tagRef.Name().Short()
279299
return onlyTag

0 commit comments

Comments
 (0)