@@ -4,17 +4,59 @@ import (
44 "fmt"
55 "strings"
66
7+ "github.com/praqma/git-phlow/plugins"
8+
79 "os"
810
11+ "errors"
12+ "strconv"
13+
14+ "github.com/praqma/git-phlow/executor"
915 "github.com/praqma/git-phlow/githandler"
16+ "github.com/praqma/git-phlow/setting"
1017 "github.com/praqma/git-phlow/options"
11- "github.com/praqma/git-phlow/executor"
12- "strconv"
13- "errors"
1418)
1519
20+ //WrapUpCaller ...
21+ func WrapUpCaller () {
22+ conf := setting .NewProjectStg (options .GlobalFlagTarget )
23+
24+ if conf .Service == "jira" {
25+ WrapUp ("#close " , options .GlobalFlagForceMessage , plugins .KeyFromBranchName )
26+ return
27+ }
28+
29+ if conf .Service == "github" {
30+ WrapUp ("close #" , options .GlobalFlagForceMessage , plugins .IssueFromBranchName )
31+ return
32+ }
33+
34+ }
35+
36+ //GenerateMessage ...
37+ //generates a message from a branch with a given issue extractor
38+ func GenerateMessage (branch string , smartCommitPrefix string , extractor plugins.IssueExtractor , forceMessage string ) (string , error ) {
39+ iss , err := extractor (branch )
40+ if err != nil {
41+ return "" , err
42+ }
43+
44+ //remove the issue from the branch name
45+ branch = strings .TrimPrefix (branch , iss )
46+
47+ if forceMessage != "" {
48+ return smartCommitPrefix + iss + " " + forceMessage , nil
49+ }
50+
51+ //Replace - with white space
52+ msg := strings .Replace (branch , "-" , " " , - 1 )
53+
54+ //prepend smart commit prefix
55+ return smartCommitPrefix + iss + msg , nil
56+ }
57+
1658//WrapUp ...
17- func WrapUp () {
59+ func WrapUp (smartCommitPrefix , force string , extractor plugins. IssueExtractor ) {
1860 git := githandler.Git {Run : executor .RunGit }
1961
2062 //Add all files to index
@@ -32,34 +74,20 @@ func WrapUp() {
3274
3375 //Retrieve branch info - current branch
3476 info := githandler .AsList (out )
35- var commitMessage string
3677
37- issue , err := GetJIRAIssue (info .Current )
78+ msg , err := GenerateMessage (info .Current , smartCommitPrefix , extractor , force )
3879 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- }
45- } else {
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-
80+ fmt .Println (err )
81+ os .Exit (1 )
5482 }
5583
56- _ , err = git .Commit ("-m" , commitMessage )
84+ _ , err = git .Commit ("-m" , msg )
5785 if err != nil {
5886 fmt .Println (err )
5987 return
6088 }
6189
62- fmt .Fprintln ( os . Stdout , commitMessage )
90+ fmt .Println ( msg )
6391}
6492
6593func GetJIRAIssue (branch string ) (string , error ) {
0 commit comments