Skip to content

Commit 5c6d099

Browse files
committed
fix: conf path and db path fixed; repository fixed; add log points;
1 parent 5db377a commit 5c6d099

File tree

9 files changed

+222
-299
lines changed

9 files changed

+222
-299
lines changed

cmd/gitlab-flow/commands.go

+9-71
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func getInitCommand() *cli.Command {
1111
return &cli.Command{
1212
Name: "init",
1313
Usage: "initialize gitlab-flow, generate default config file and sqlite DB " +
14-
"related to the path (default path is `~/.gitlab-flow/`)",
14+
"related to the path",
1515
Category: "tools",
1616
Flags: []cli.Flag{
1717
&cli.StringFlag{
@@ -26,16 +26,8 @@ func getInitCommand() *cli.Command {
2626
Required: true,
2727
Usage: "gitlab_host is the domain of YOUR gitlab server.",
2828
},
29-
&cli.StringFlag{
30-
Name: "conf_path",
31-
Aliases: []string{"c"},
32-
Value: conf.DefaultConfPath(),
33-
DefaultText: conf.DefaultConfPath(),
34-
Required: false,
35-
Usage: "conf_path is the directory which contains your config and local database.",
36-
},
3729
},
38-
ArgsUsage: "gitlab-flow init -s ACCESS_TOKEN -h GITLAB_HOST [-c CONF_PATH]",
30+
ArgsUsage: "-s ACCESS_TOKEN -h GITLAB_HOST [-c, --conf_path CONF_PATH]",
3931
Action: func(c *cli.Context) error {
4032
accessToken := c.String("access_token")
4133
host := c.String("gitlab_host")
@@ -60,55 +52,19 @@ func getInitCommand() *cli.Command {
6052
// gitlab-flow feature [command options] -c --conf_path
6153
func getFeatureCommand() *cli.Command {
6254
return &cli.Command{
63-
Name: "feature",
64-
Usage: "managing the works in developing.",
65-
ArgsUsage: "gitlab-flow hotfix [-c, --conf_path] [-v, --debug]",
66-
Category: "feature",
67-
Flags: []cli.Flag{
68-
&cli.StringFlag{
69-
Name: "conf_path",
70-
Aliases: []string{"c"},
71-
Value: conf.DefaultConfPath(),
72-
DefaultText: conf.DefaultConfPath(),
73-
Usage: "-c, --conf_path",
74-
Required: false,
75-
},
76-
&cli.BoolFlag{
77-
Name: "debug",
78-
Aliases: []string{"v"},
79-
Value: false,
80-
Usage: "-v, --debug ",
81-
Required: false,
82-
},
83-
},
55+
Name: "feature",
56+
Usage: "managing the works in developing.",
57+
Category: "feature",
8458
Subcommands: getFeatureSubCommands(),
8559
}
8660
}
8761

8862
// gitlab-flow hotfix [command options] -p --specProject
8963
func getHotfixCommand() *cli.Command {
9064
return &cli.Command{
91-
Name: "hotfix",
92-
Usage: "managing the works in hotfix.",
93-
ArgsUsage: "gitlab-flow hotfix [-c, --conf_path] [-v, --debug]",
94-
Category: "hotfix",
95-
Flags: []cli.Flag{
96-
&cli.StringFlag{
97-
Name: "conf_path",
98-
Aliases: []string{"c"},
99-
Value: conf.DefaultConfPath(),
100-
DefaultText: conf.DefaultConfPath(),
101-
Usage: "-c, --conf_path",
102-
Required: false,
103-
},
104-
&cli.BoolFlag{
105-
Name: "debug",
106-
Aliases: []string{"v"},
107-
Value: false,
108-
Usage: "-v, --debug ",
109-
Required: false,
110-
},
111-
},
65+
Name: "hotfix",
66+
Usage: "managing the works in hotfix.",
67+
Category: "hotfix",
11268
Subcommands: getHotfixSubCommands(),
11369
}
11470
}
@@ -117,26 +73,8 @@ func getHotfixCommand() *cli.Command {
11773
func getDashCommand() *cli.Command {
11874
return &cli.Command{
11975
Name: "dash",
120-
Usage: "gitlab-flow dash",
121-
Description: "overview of local development",
76+
Usage: "overview of local development",
12277
Category: "dash",
123-
Flags: []cli.Flag{
124-
&cli.StringFlag{
125-
Name: "conf_path",
126-
Aliases: []string{"c"},
127-
Value: conf.DefaultConfPath(),
128-
DefaultText: conf.DefaultConfPath(),
129-
Usage: "-c, --conf_path",
130-
Required: false,
131-
},
132-
&cli.BoolFlag{
133-
Name: "debug",
134-
Aliases: []string{"v"},
135-
Value: false,
136-
Usage: "-v, --debug ",
137-
Required: false,
138-
},
139-
},
14078
Subcommands: getDashSubCommands(),
14179
}
14280
}

cmd/gitlab-flow/commands_feature.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,15 @@ func getFeatureBeginSubCommand() *cli.Command {
3131
Description: "@title title of milestone \n\t @desc description of milestone",
3232
Category: "feature",
3333
Action: func(c *cli.Context) error {
34-
log.
35-
WithFields(log.Fields{"args": c.Args().Slice()}).
36-
Debug("create milestone and branch")
37-
3834
title := c.Args().Get(0)
3935
desc := c.Args().Get(1)
4036
if title == "" {
41-
return errors.New("title could not be empty")
37+
return errors.New("'Title' could not be empty")
4238
}
4339
if desc == "" {
44-
return errors.New("description could not be empty")
40+
return errors.New("'Description' could not be empty")
4541
}
4642
debug := c.Bool("debug")
47-
4843
confPath := c.String("conf_path")
4944
return getFlow(confPath, debug).FeatureBegin(title, desc)
5045
},

cmd/gitlab-flow/main.go

+21
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package main
33
import (
44
"os"
55

6+
"github.com/yeqown/gitlab-flow/internal/conf"
7+
68
"github.com/urfave/cli/v2"
79
"github.com/yeqown/log"
810
)
@@ -20,6 +22,7 @@ func main() {
2022
}
2123
app.Version = "v1.5.1"
2224
app.Description = `A tool for managing gitlab Feature/Milestone/Issue/MergeRequest as gitlab-flow.`
25+
app.Flags = _globalFlags
2326

2427
mountCommands(app)
2528

@@ -36,3 +39,21 @@ func mountCommands(app *cli.App) {
3639
getDashCommand(),
3740
}
3841
}
42+
43+
var _globalFlags = []cli.Flag{
44+
&cli.StringFlag{
45+
Name: "conf_path",
46+
Aliases: []string{"c"},
47+
Value: conf.DefaultConfPath(),
48+
DefaultText: "~/.gitlab-flow",
49+
Usage: "choose which `path/to/file` to load",
50+
Required: false,
51+
},
52+
&cli.BoolFlag{
53+
Name: "debug",
54+
Value: false,
55+
Usage: "--debug",
56+
DefaultText: "false",
57+
Required: false,
58+
},
59+
}

cmd/gitlab-flow/support.go

+29-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ import (
1111
)
1212

1313
func getFlow(confPath string, debug bool) internal.IFlow {
14+
setDebugEnviron(debug)
15+
log.
16+
WithFields(log.Fields{
17+
"confPath": confPath,
18+
"debug": debug,
19+
}).
20+
Debugf("getFlow called")
21+
1422
cfg, err := conf.Load(confPath, nil)
1523
if err != nil {
1624
log.
@@ -27,9 +35,29 @@ func getFlow(confPath string, debug bool) internal.IFlow {
2735

2836
// DONE(@yeqown) get cwd correctly.
2937
cwd, _ := os.Getwd()
30-
return internal.NewFlow(types.NewContext(cwd, confPath, cfg))
38+
ctx := types.NewContext(cwd, confPath, cfg)
39+
return internal.NewFlow(ctx)
3140
}
3241

3342
func getDash(confPath string, debug bool) internal.IDash {
43+
setDebugEnviron(debug)
44+
log.
45+
WithFields(log.Fields{
46+
"confPath": confPath,
47+
"debug": debug,
48+
}).
49+
Debugf("getFlow called")
50+
3451
return internal.NewDash(confPath, debug)
3552
}
53+
54+
func setDebugEnviron(debug bool) {
55+
if !debug {
56+
return
57+
}
58+
59+
// open caller report
60+
log.SetCallerReporter(true)
61+
// open debug log
62+
log.SetLogLevel(log.LevelDebug)
63+
}

internal/flow.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -94,31 +94,33 @@ const (
9494
HotfixBranchPrefix = "hotfix/"
9595
)
9696

97-
func GenFeatureBranchName(name string) string {
97+
// genFeatureBranchName
98+
func genFeatureBranchName(name string) string {
9899
if strings.HasPrefix(name, FeatureBranchPrefix) {
99100
return name
100101
}
101102

102103
return FeatureBranchPrefix + name
103104
}
104105

105-
// GenHotfixBranchName .
106-
func GenHotfixBranchName(name string) string {
106+
// genHotfixBranchName .
107+
func genHotfixBranchName(name string) string {
107108
if strings.HasPrefix(name, HotfixBranchPrefix) {
108109
return name
109110
}
110111

111112
return HotfixBranchPrefix + name
112113
}
113114

114-
func GenMRTitle(srcBranch, targetBranch string) string {
115+
// genMRTitle
116+
func genMRTitle(srcBranch, targetBranch string) string {
115117
return fmt.Sprintf("Merge %s to %s", srcBranch, targetBranch)
116118
}
117119

118-
// GenIssueBranchName .
120+
// genIssueBranchName .
119121
// @result = 1-milestoneTitle as default
120122
// fmt.Sprintf("%d-%s", issue.IID, milestone.Title)
121-
func GenIssueBranchName(name string, issueIID int) string {
123+
func genIssueBranchName(name string, issueIID int) string {
122124
if strings.HasPrefix(name, strconv.Itoa(issueIID)+"-") {
123125
return name
124126
}

0 commit comments

Comments
 (0)