99 "github.com/praqma/git-phlow/githandler"
1010 "github.com/praqma/git-phlow/options"
1111 "github.com/praqma/git-phlow/executor"
12+ "strconv"
13+ "errors"
1214)
1315
1416//WrapUp ...
@@ -30,13 +32,25 @@ func WrapUp() {
3032
3133 //Retrieve branch info - current branch
3234 info := githandler .AsList (out )
33-
3435 var commitMessage string
3536
36- if options .GlobalFlagForceMessage != "" {
37- commitMessage = "close #" + strings .Split (info .Current , "-" )[0 ] + " " + options .GlobalFlagForceMessage
37+ issue , err := GetJIRAIssue (info .Current )
38+ if err != nil {
39+
40+ if options .GlobalFlagForceMessage != "" {
41+ commitMessage = "close #" + strings .Split (info .Current , "-" )[0 ] + " " + options .GlobalFlagForceMessage
42+ } else {
43+ commitMessage = "close #" + strings .Replace (info .Current , "-" , " " , - 1 )
44+ }
3845 } else {
39- commitMessage = "close #" + strings .Replace (info .Current , "-" , " " , - 1 )
46+ msg := strings .TrimPrefix (info .Current , issue )
47+
48+ if options .GlobalFlagForceMessage != "" {
49+ commitMessage = "close #" + issue + " " + options .GlobalFlagForceMessage
50+ } else {
51+ commitMessage = "close #" + issue + strings .Replace (msg , "-" , " " , - 1 )
52+ }
53+
4054 }
4155
4256 _ , err = git .Commit ("-m" , commitMessage )
@@ -47,3 +61,12 @@ func WrapUp() {
4761
4862 fmt .Fprintln (os .Stdout , commitMessage )
4963}
64+
65+ func GetJIRAIssue (branch string ) (string , error ) {
66+
67+ parts := strings .Split (branch , "-" )
68+ if _ , err := strconv .Atoi (parts [0 ]); err != nil && len (parts ) > 1 {
69+ return parts [0 ] + "-" + parts [1 ], nil
70+ }
71+ return "" , errors .New ("not a jira branch" )
72+ }
0 commit comments