-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitflow.go
70 lines (60 loc) · 1.74 KB
/
gitflow.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package gitcmd
import (
"github.com/gookit/gcli/v3"
"github.com/gookit/gcli/v3/interact"
"github.com/gookit/gcli/v3/show"
"github.com/gookit/goutil/strutil"
"github.com/inhere/kite-go/internal/apputil"
"github.com/inhere/kite-go/internal/biz/cmdbiz"
)
var CreatePRLink = &gcli.Command{
Name: "pr",
Desc: "create pull request link for current project",
Aliases: []string{"pr-link"},
}
// NewInitFlowCmd instance
func NewInitFlowCmd() *gcli.Command {
var ifOpts = struct {
cmdbiz.CommonOpts
}{}
return &gcli.Command{
Name: "init",
Desc: "init repo remote and other info for current project",
Aliases: []string{"setup"},
Config: func(c *gcli.Command) {
ifOpts.BindWorkdirDryRun(c)
},
Func: func(c *gcli.Command, args []string) (err error) {
cfg := apputil.GitCfgByCmdID(c)
lr := cfg.LoadRepo(ifOpts.Workdir)
show.AList("Current remotes", lr.RemoteLines())
defRmt := cfg.DefaultRemote
c.Infoln("Begin config remote URLs:")
defUrl := interact.Ask("Please input URL for remote "+defRmt, "", nil)
if len(defUrl) > 18 {
err := lr.Cmd("remote", "set-url", defRmt, defUrl).Run()
if err != nil {
return err
}
} else {
c.Infoln("input is invalid, skip init remote url.")
}
if !cfg.IsForkMode() {
return lr.Cmd("remote", "-v").Run()
}
srcRmt := cfg.SourceRemote
srcUrl := interact.Ask("Please input URL for remote "+srcRmt, "", nil)
if len(srcUrl) > 18 {
op := strutil.OrCond(lr.HasSourceRemote(), "set-url", "add")
err = lr.Cmd("remote", op, srcRmt, srcUrl).Run()
if err != nil {
return err
}
} else {
c.Infoln("input is invalid, skip init remote url.")
}
c.Infoln("\nNow, Git Remotes:")
return lr.Cmd("remote", "-v").Run()
},
}
}