Skip to content

Commit e0a9800

Browse files
committed
close #224 deliver for jira
1 parent 17864c4 commit e0a9800

File tree

4 files changed

+33
-100
lines changed

4 files changed

+33
-100
lines changed

cmd/deliver.go

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@ package cmd
22

33
import (
44
"fmt"
5-
"os"
6-
75
"github.com/praqma/git-phlow/cmd/cmdperm"
86
"github.com/praqma/git-phlow/options"
97
"github.com/praqma/git-phlow/phlow"
10-
"github.com/praqma/git-phlow/plugins"
118
"github.com/praqma/git-phlow/ui"
129
"github.com/spf13/cobra"
1310
)
@@ -28,24 +25,8 @@ If you deliver with the 'local' option, the issue branch will be merged with you
2825
},
2926
Run: func(cmd *cobra.Command, args []string) {
3027

31-
defaultBranch, _ := plugins.GitHub.Default()
32-
//Run tests before deliver
33-
if len(args) > 0 {
34-
if err := phlow.TestDeliver(args); err != nil {
35-
fmt.Println(ui.Format.Error("!! Tests did not exit with code 0 !!"))
36-
fmt.Println(err)
37-
os.Exit(1)
38-
}
39-
fmt.Println(ui.Format.Success("Tests exited with code 0 - starting deliver process"))
40-
}
41-
42-
//If Run if local deliver
43-
if options.GlobalFlagLocal {
44-
phlow.LocalDeliver(defaultBranch)
45-
return
46-
}
47-
//Deliver with ready branch
48-
phlow.Deliver(defaultBranch)
28+
phlow.DeliverCaller()
29+
4930
},
5031
}
5132

@@ -54,5 +35,8 @@ func init() {
5435

5536
//Flag for local deliver
5637
deliverCmd.Flags().BoolVarP(&options.GlobalFlagLocal, "local", "l", false, "local delivery")
38+
5739
deliverCmd.Flags().BoolVarP(&options.GlobalFlagShowTestOutput, "showtest", "s", false, "show test output")
40+
41+
deliverCmd.Flags().StringVarP(&options.GlobalFlagTarget, "target", "t", "", "the name of the INI block in your .phlow files")
5842
}

cmd/integrate.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import (
55

66
"github.com/praqma/git-phlow/cmd/cmdperm"
77
"github.com/praqma/git-phlow/phlow"
8-
"github.com/praqma/git-phlow/plugins"
98
"github.com/praqma/git-phlow/ui"
109
"github.com/spf13/cobra"
10+
"github.com/praqma/git-phlow/setting"
1111
)
1212

1313
// integrateCmd represents the integrate command
@@ -23,11 +23,8 @@ The current branch will be merged into the default branch and pushed to the remo
2323
},
2424
Run: func(cmd *cobra.Command, args []string) {
2525

26-
defaultBranch, err := plugins.GitHub.Default()
27-
if err != nil {
28-
fmt.Println(err)
29-
}
30-
phlow.LocalDeliver(defaultBranch)
26+
conf := setting.NewProjectStg("default")
27+
phlow.LocalDeliver(conf)
3128
},
3229
}
3330

githandler/git.go

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"strings"
55

66
"github.com/praqma/git-phlow/executor"
7-
"bytes"
8-
"fmt"
97
)
108

119
//Git ...
@@ -83,34 +81,3 @@ func (os *Git) Config(argv ...string) (string, error) {
8381
}
8482
return strings.Replace(stdOut, "\n", "", -1), nil
8583
}
86-
87-
//Deprecated
88-
//FormatPatch ...
89-
//dry runs patch to see if we can auto merge
90-
func FormatPatch(buf *bytes.Buffer, remoteBranch string) (err error) {
91-
//err = executor.ExecPipeCommand(buf,
92-
// exec.Command("git", "format-patch", remoteBranch, "--stdout"),
93-
// exec.Command("git", "apply", "check"),
94-
//)
95-
return
96-
}
97-
98-
//Deprecated
99-
//StatusPorcelain ...
100-
//generates behind and ahead status
101-
func StatusPorcelain() (string, error) {
102-
out, err := executor.RunCommand("git", "status", "short", "--branch", "--porcelain")
103-
if err != nil {
104-
return "", err
105-
}
106-
return strings.TrimSpace(out), nil
107-
}
108-
109-
//Deprecated
110-
//PushRename ...
111-
func PushRename(branch, defaultBranch string) (string, error) {
112-
remote := ConfigBranchRemote(defaultBranch)
113-
str := fmt.Sprintf("%s:ready/%s", branch, branch)
114-
115-
return executor.RunCommand("git", "push", remote, str)
116-
}

phlow/deliver.go

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,25 @@ import (
1313
"os"
1414
)
1515

16-
//Deliver ...
17-
func Deliver(defaultBranch string) {
16+
//DeliverCaller ...
17+
//Top level deliver call, called from cmd
18+
func DeliverCaller() {
19+
INIBlock := options.GlobalFlagTarget
20+
conf := setting.NewProjectStg(INIBlock)
21+
22+
//If Run if local deliver
23+
if options.GlobalFlagLocal {
24+
LocalDeliver(conf)
25+
return
26+
}
27+
//Deliver with ready branch
28+
Deliver(conf)
29+
}
1830

31+
//Deliver ...
32+
//Push a ready branch to the remote repository
33+
func Deliver(conf *setting.ProjectSetting) {
1934
git := githandler.Git{Run: executor.RunGit}
20-
conf := setting.NewProjectStg("default")
2135

2236
ui.PhlowSpinner.Start("delivering")
2337
defer ui.PhlowSpinner.Stop()
@@ -35,8 +49,8 @@ func Deliver(defaultBranch string) {
3549
fmt.Printf("Could not deliver: %s", branchInfo.Current)
3650
return
3751
}
38-
39-
_, err = githandler.PushRename(branchInfo.Current, conf.IntegrationBranch)
52+
//git push origin name:ready/name
53+
_, err = git.Push(conf.Remote, fmt.Sprintf("%s:ready/%s", branchInfo.Current, branchInfo.Current))
4054
if err != nil {
4155
fmt.Println(err)
4256
return
@@ -45,9 +59,9 @@ func Deliver(defaultBranch string) {
4559
_, err = git.Branch("-m", branchInfo.Current, "delivered/"+branchInfo.Current)
4660
if err != nil {
4761
ui.PhlowSpinner.Stop()
48-
fmt.Fprintln(os.Stdout, "The branch have been pushed successfully to your remote, but there is a local name conflict")
49-
fmt.Fprintf(os.Stderr, "CONFLICT: your already have a branch named %s in your workspace \n", "delivered/"+branchInfo.Current)
50-
fmt.Fprintf(os.Stderr, "to mark it delivered run: git branch -m %s %s \n", branchInfo.Current, "delivered/"+branchInfo.Current)
62+
fmt.Println("The branch have been pushed successfully to your remote, but there is a local name conflict")
63+
fmt.Printf("CONFLICT: your already have a branch named %s in your workspace \n", "delivered/"+branchInfo.Current)
64+
fmt.Printf("to mark it delivered run: git branch -m %s %s \n", branchInfo.Current, "delivered/"+branchInfo.Current)
5165
os.Exit(1)
5266
return
5367
}
@@ -64,9 +78,9 @@ func Deliver(defaultBranch string) {
6478
}
6579

6680
//LocalDeliver ...
67-
func LocalDeliver(defaultBranch string) {
81+
//Delivers locally and pushes the changes to the remote
82+
func LocalDeliver(conf *setting.ProjectSetting) {
6883
git := githandler.Git{Run: executor.RunGit}
69-
conf := setting.NewProjectStg("default")
7084

7185
out, err := git.Branch("-a")
7286
branchInfo := githandler.AsList(out)
@@ -115,34 +129,5 @@ func LocalDeliver(defaultBranch string) {
115129
return
116130
}
117131
ui.PhlowSpinner.Stop()
118-
fmt.Printf("Delivered changes from %s to %s \n", ui.Format.Branch(branchInfo.Current), ui.Format.Branch(defaultBranch))
119-
}
120-
121-
//TestDeliver ...
122-
//Run tests and returns
123-
func TestDeliver(args []string) error {
124-
125-
cmd, argv := convertCommand(args)
126-
output, err := executor.RunCommand(cmd, argv...)
127-
128-
if err != nil {
129-
return err
130-
}
131-
132-
if options.GlobalFlagShowTestOutput {
133-
fmt.Println(output)
134-
}
135-
136-
return nil
137-
}
138-
139-
//ConvertCommand ...
140-
//Formats the command to ExecutorCommand
141-
func convertCommand(args []string) (string, []string) {
142-
143-
//Command with extra arguments
144-
if len(args) > 1 {
145-
return args[0], args[1:]
146-
}
147-
return args[0], []string{}
132+
fmt.Printf("Delivered changes from %s to %s \n", ui.Format.Branch(branchInfo.Current), ui.Format.Branch(conf.IntegrationBranch))
148133
}

0 commit comments

Comments
 (0)