Skip to content

Commit f4a374d

Browse files
author
Tobias Meinhardt
committed
Handle hotfixes like releases
1 parent bb05b98 commit f4a374d

File tree

2 files changed

+90
-6
lines changed

2 files changed

+90
-6
lines changed

pkg/cli/cmd/close.hotfix.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package cmd
2+
3+
import (
4+
"github.com/meinto/glow"
5+
"github.com/meinto/glow/pkg/cli/cmd/util"
6+
"github.com/meinto/glow/semver"
7+
"github.com/spf13/cobra"
8+
)
9+
10+
func init() {
11+
closeCmd.AddCommand(closeHotfixCmd)
12+
util.AddFlagsForMergeRequests(closeHotfixCmd)
13+
}
14+
15+
var closeHotfixCmd = &cobra.Command{
16+
Use: "hofix",
17+
Short: "close a release branch",
18+
Args: cobra.MinimumNArgs(1),
19+
Run: func(cmd *cobra.Command, args []string) {
20+
version := args[0]
21+
22+
if version == "current" {
23+
g, err := util.GetGitClient()
24+
util.CheckForError(err, "GetGitClient")
25+
26+
pathToRepo, err := g.GitRepoPath()
27+
util.CheckForError(err, "semver GitRepoPath")
28+
29+
s := semver.NewSemverService(
30+
pathToRepo,
31+
"/bin/bash",
32+
releaseCmdOptions.VersionFile,
33+
releaseCmdOptions.VersionFileType,
34+
)
35+
v, err := s.GetCurrentVersion()
36+
util.CheckForError(err, "semver GetCurrentVersion")
37+
version = v
38+
}
39+
40+
gp, err := util.GetGitProvider()
41+
util.CheckForError(err, "GetGitProvider")
42+
43+
currentBranch, err := glow.NewHotfix(version)
44+
util.CheckForError(err, "NewHotfix")
45+
46+
gp.Close(currentBranch)
47+
util.CheckForError(err, "Close")
48+
},
49+
}

pkg/cli/cmd/hotfix.go

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,65 @@ import (
44
"github.com/meinto/glow"
55
"github.com/meinto/glow/pkg/cli/cmd/util"
66
"github.com/spf13/cobra"
7-
"github.com/spf13/viper"
87
)
98

9+
var hotfixCmdOptions struct {
10+
Push bool
11+
PostHotfixScript string
12+
PostHotfixCommand []string
13+
VersionFile string
14+
VersionFileType string
15+
}
16+
1017
func init() {
1118
rootCmd.AddCommand(hotfixCmd)
19+
20+
hotfixCmd.Flags().BoolVar(&hotfixCmdOptions.Push, "push", false, "push created hotfix branch")
21+
hotfixCmd.Flags().StringVar(&hotfixCmdOptions.PostHotfixScript, "postHofix", "", "script that executes after switching to hotfix branch")
22+
hotfixCmd.Flags().StringArrayVar(&hotfixCmdOptions.PostHotfixCommand, "postHotfixCommand", []string{}, "commands which should be executed after switching to hotfix branch")
23+
24+
hotfixCmd.Flags().StringVar(&hotfixCmdOptions.VersionFile, "versionFile", "VERSION", "name of git-semver version file")
25+
hotfixCmd.Flags().StringVar(&hotfixCmdOptions.VersionFileType, "versionFileType", "raw", "git-semver version file type")
1226
}
1327

1428
var hotfixCmd = &cobra.Command{
1529
Use: "hotfix",
1630
Short: "create a hotfix branch",
1731
Args: cobra.MinimumNArgs(1),
1832
Run: func(cmd *cobra.Command, args []string) {
19-
hotixName := args[0]
20-
21-
hotfix, err := glow.NewHotfix(viper.GetString("author"), hotixName)
22-
util.CheckForError(err, "NewHotfix")
23-
2433
g, err := util.GetGitClient()
2534
util.CheckForError(err, "GetGitClient")
2635

36+
version, s := util.ProcessVersion(
37+
args[0],
38+
hotfixCmdOptions.VersionFile,
39+
hotfixCmdOptions.VersionFileType,
40+
)
41+
42+
hotfix, err := glow.NewHotfix(version)
43+
util.CheckForError(err, "NewHotfix")
44+
2745
err = g.Create(hotfix)
2846
util.CheckForError(err, "Create")
2947

3048
g.Checkout(hotfix)
3149
util.CheckForError(err, "Checkout")
50+
51+
if util.IsSemanticVersion(args[0]) {
52+
err = s.SetNextVersion(args[0])
53+
util.CheckForError(err, "semver SetNextVersion")
54+
}
55+
},
56+
PostRun: func(cmd *cobra.Command, args []string) {
57+
version := args[0]
58+
59+
util.PostRunWithVersion(
60+
version,
61+
hotfixCmdOptions.VersionFile,
62+
hotfixCmdOptions.VersionFileType,
63+
hotfixCmdOptions.PostHotfixScript,
64+
hotfixCmdOptions.PostHotfixCommand,
65+
hotfixCmdOptions.Push,
66+
)
3267
},
3368
}

0 commit comments

Comments
 (0)