Skip to content

Commit 47f0549

Browse files
author
Tobias Meinhardt
committed
Fix post command function
1 parent cddcfbf commit 47f0549

File tree

4 files changed

+24
-22
lines changed

4 files changed

+24
-22
lines changed

pkg/cli/cmd/hotfix.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func init() {
1818
rootCmd.AddCommand(hotfixCmd)
1919

2020
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")
21+
hotfixCmd.Flags().StringVar(&hotfixCmdOptions.PostHotfixScript, "postHotfix", "", "script that executes after switching to hotfix branch")
2222
hotfixCmd.Flags().StringArrayVar(&hotfixCmdOptions.PostHotfixCommand, "postHotfixCommand", []string{}, "commands which should be executed after switching to hotfix branch")
2323

2424
hotfixCmd.Flags().StringVar(&hotfixCmdOptions.VersionFile, "versionFile", "VERSION", "name of git-semver version file")
@@ -48,10 +48,8 @@ var hotfixCmd = &cobra.Command{
4848
g.Checkout(hotfix)
4949
util.CheckForError(err, "Checkout")
5050

51-
if util.IsSemanticVersion(args[0]) {
52-
err = s.SetNextVersion(args[0])
53-
util.CheckForError(err, "semver SetNextVersion")
54-
}
51+
err = s.SetVersion(version)
52+
util.CheckForError(err, "semver SetVersion")
5553
},
5654
PostRun: func(cmd *cobra.Command, args []string) {
5755
version := args[0]

pkg/cli/cmd/release.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,8 @@ var releaseCmd = &cobra.Command{
4747
g.Checkout(release)
4848
util.CheckForError(err, "Checkout")
4949

50-
if util.IsSemanticVersion(args[0]) {
51-
err = s.SetNextVersion(args[0])
52-
util.CheckForError(err, "semver SetNextVersion")
53-
}
50+
s.SetVersion(version)
51+
util.CheckForError(err, "semver SetVersion")
5452
},
5553
PostRun: func(cmd *cobra.Command, args []string) {
5654
version := args[0]

pkg/cli/cmd/util/semver.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@ func ProcessVersion(versionArg, versionFile, versionFileType string) (string, se
1414
g, err := GetGitClient()
1515
CheckForError(err, "GetGitClient")
1616

17-
var s semver.Service
17+
pathToRepo, err := g.GitRepoPath()
18+
CheckForError(err, "semver GitRepoPath")
19+
20+
s := semver.NewSemverService(
21+
pathToRepo,
22+
"/bin/bash",
23+
versionFile,
24+
versionFileType,
25+
)
26+
1827
if IsSemanticVersion(version) {
19-
pathToRepo, err := g.GitRepoPath()
20-
CheckForError(err, "semver GitRepoPath")
21-
s = semver.NewSemverService(
22-
pathToRepo,
23-
"/bin/bash",
24-
versionFile,
25-
versionFileType,
26-
)
2728
v, err := s.GetCurrentVersion()
2829
CheckForError(err, "semver GetNextVersion")
2930
version = v

semver/service.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type Service interface {
1414
GetCurrentVersion() (string, error)
1515
GetNextVersion(versionType string) (string, error)
1616
SetNextVersion(versionType string) error
17+
SetVersion(version string) error
1718
TagCurrentVersion() error
1819
}
1920

@@ -57,9 +58,6 @@ func (s *service) GetNextVersion(versionType string) (string, error) {
5758
}
5859

5960
func (s *service) SetNextVersion(versionType string) error {
60-
versionFilepath := s.pathToRepo + "/" + s.versionFile
61-
fs := file.NewVersionFileService(versionFilepath)
62-
6361
currentVersion, err := s.GetCurrentVersion()
6462
if err != nil {
6563
return err
@@ -77,7 +75,14 @@ func (s *service) SetNextVersion(versionType string) error {
7775

7876
log.Println("new version will be: ", nextVersion)
7977

80-
err = fs.WriteVersionFile(s.versionFileType, nextVersion)
78+
return s.SetVersion(nextVersion)
79+
}
80+
81+
func (s *service) SetVersion(version string) error {
82+
versionFilepath := s.pathToRepo + "/" + s.versionFile
83+
fs := file.NewVersionFileService(versionFilepath)
84+
85+
err := fs.WriteVersionFile(s.versionFileType, version)
8186
return err
8287
}
8388

0 commit comments

Comments
 (0)