Skip to content

Commit e804dbe

Browse files
committed
feat: OpFeatureContext support; force create merge request; feature branch name into opc;
1 parent 9818dc5 commit e804dbe

File tree

8 files changed

+133
-77
lines changed

8 files changed

+133
-77
lines changed

cmd/gitlab-flow/commands.go

+18-3
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,24 @@ func getInitCommand() *cli.Command {
5252
// gitlab-flow feature [command options] -c --conf_path
5353
func getFeatureCommand() *cli.Command {
5454
return &cli.Command{
55-
Name: "feature",
56-
Usage: "managing the works in developing.",
57-
Category: "flow",
55+
Name: "feature",
56+
Usage: "managing the works in developing.",
57+
Category: "flow",
58+
Flags: []cli.Flag{
59+
&cli.BoolFlag{
60+
Name: "force-create-mr",
61+
Value: false,
62+
Usage: "force to create Merge Request",
63+
DefaultText: "false",
64+
Required: false,
65+
},
66+
&cli.StringFlag{
67+
Name: "feature-branch-name",
68+
Aliases: []string{"-f"},
69+
Usage: "input the `featureBranchName`",
70+
Required: false,
71+
},
72+
},
5873
Subcommands: getFeatureSubCommands(),
5974
}
6075
}

cmd/gitlab-flow/commands_feature.go

+14-17
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ func getFeatureBeginSubCommand() *cli.Command {
4141
if desc == "" {
4242
return errors.New("'Description' could not be empty")
4343
}
44-
return getFlow(c).FeatureBegin(title, desc)
44+
opc := getOpFeatureContext(c)
45+
return getFlow(c).FeatureBegin(opc, title, desc)
4546
},
4647
}
4748
}
@@ -73,7 +74,8 @@ func getFeatureBeginIssueSubCommand() *cli.Command {
7374
issueTitle := c.Args().Get(0)
7475
issueDesc := c.Args().Get(1)
7576
featureBranchName := c.String("feature_branch_name")
76-
return getFlow(c).FeatureBeginIssue(featureBranchName, issueTitle, issueDesc)
77+
opc := getOpFeatureContext(c)
78+
return getFlow(c).FeatureBeginIssue(opc, featureBranchName, issueTitle, issueDesc)
7779
},
7880
}
7981
}
@@ -105,7 +107,8 @@ func getFeatureFinishIssueSubCommand() *cli.Command {
105107
Action: func(c *cli.Context) error {
106108
featureBranchName := c.String("feature_branch_name")
107109
issueBranchName := c.String("issue_branch_name")
108-
return getFlow(c).FeatureFinishIssue(featureBranchName, issueBranchName)
110+
opc := getOpFeatureContext(c)
111+
return getFlow(c).FeatureFinishIssue(opc, featureBranchName, issueBranchName)
109112
},
110113
}
111114
}
@@ -126,8 +129,8 @@ func getFeatureDebugSubCommand() *cli.Command {
126129
},
127130
},
128131
Action: func(c *cli.Context) error {
129-
featureBranchName := c.String("feature_branch_name")
130-
return getFlow(c).FeatureDebugging(featureBranchName)
132+
opc := getOpFeatureContext(c)
133+
return getFlow(c).FeatureDebugging(opc)
131134
},
132135
}
133136
}
@@ -148,8 +151,8 @@ func getFeatureTestSubCommand() *cli.Command {
148151
},
149152
},
150153
Action: func(c *cli.Context) error {
151-
featureBranchName := c.String("feature_branch_name")
152-
return getFlow(c).FeatureTest(featureBranchName)
154+
opc := getOpFeatureContext(c)
155+
return getFlow(c).FeatureTest(opc)
153156
},
154157
}
155158
}
@@ -170,8 +173,8 @@ func getFeatureReleaseSubCommand() *cli.Command {
170173
},
171174
},
172175
Action: func(c *cli.Context) error {
173-
featureBranchName := c.String("feature_branch_name")
174-
return getFlow(c).FeatureRelease(featureBranchName)
176+
opc := getOpFeatureContext(c)
177+
return getFlow(c).FeatureRelease(opc)
175178
},
176179
}
177180
}
@@ -183,12 +186,6 @@ func getFeatureResolveConflictCommand() *cli.Command {
183186
ArgsUsage: "-f, --feature_branch_name `featureBranchName`, -t, --target_branch `targetBranch`",
184187
Category: "feature",
185188
Flags: []cli.Flag{
186-
&cli.StringFlag{
187-
Name: "feature_branch_name",
188-
Aliases: []string{"-f"},
189-
Usage: "input the `featureBranchName`",
190-
Required: false,
191-
},
192189
&cli.StringFlag{
193190
Name: "target_branch",
194191
Aliases: []string{"-t"},
@@ -199,9 +196,9 @@ func getFeatureResolveConflictCommand() *cli.Command {
199196
},
200197
},
201198
Action: func(c *cli.Context) error {
202-
featureBranchName := c.String("feature_branch_name")
203199
targetBranchName := c.String("target_branch")
204-
return getFlow(c).FeatureResolveConflict(featureBranchName, types.BranchTyp(targetBranchName))
200+
opc := getOpFeatureContext(c)
201+
return getFlow(c).FeatureResolveConflict(opc, types.BranchTyp(targetBranchName))
205202
},
206203
}
207204
}

cmd/gitlab-flow/support.go

+7
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ func parseGlobalFlags(c *cli.Context) globalFlags {
8282
}
8383
}
8484

85+
func getOpFeatureContext(c *cli.Context) *types.OpFeatureContext {
86+
return &types.OpFeatureContext{
87+
ForceCreateMergeRequest: c.Bool("force-create-mr"),
88+
FeatureBranchName: c.String("feature-branch-name"),
89+
}
90+
}
91+
8592
func getFlow(c *cli.Context) internal.IFlow {
8693
flags := parseGlobalFlags(c)
8794
ctx := setEnviron(flags)

docs/example.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ development resources.
66
### 0. Global flags
77

88
```sh
9-
flow [-c, --conf_path] [--debug] [--web] [-p, --project] SUB_COMMAND [options]
9+
flow [-c, --conf_path] [--debug] [--web] [-p, --project] [--force-remote] SUB_COMMAND [options]
1010
# (OPTIONAL) -c, --conf_path path/to/config_file.
1111
# (OPTIONAL) --debug verbose mode.
1212
# (OPTIONAL) --web open web browser of resource url automatically.
1313
# (OPTIONAL) -p, --project projectName of current working directory.
14+
# (OPTIONAL) --force-remote use project from remote not from local DB.
1415

1516
# example:
1617
flow -c ~/.gitlab-flow --debug init ...

internal/dash_impl.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func (d dashImpl) FeatureDetail(featureBranchName string) ([]byte, error) {
100100
featureBranchName, _ = d.gitOperator.CurrentBranch()
101101
}
102102
if featureBranchName == "" {
103-
return nil, errors.New("feature branch could not be empty")
103+
return nil, errInvalidFeatureName
104104
}
105105
featureBranchName = genFeatureBranchName(featureBranchName)
106106

internal/flow.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,24 @@ type IFlow interface {
1919
// FeatureBegin open a milestone and related to a feature branch,
2020
// then CLI would automate fetch origin branches and pull them to local.
2121
// Of course, flow would save data in local storage.
22-
FeatureBegin(title, desc string) error
22+
FeatureBegin(opc *types.OpFeatureContext, title, desc string) error
2323
// FeatureDebugging open a MergeRequest of feature branch and types.DevBranch branch.
24-
FeatureDebugging(featureBranchName string) error
24+
FeatureDebugging(opc *types.OpFeatureContext) error
2525
// FeatureTest open a MergeRequest of feature branch and types.TestBranch branch.
26-
FeatureTest(featureBranchName string) error
26+
FeatureTest(opc *types.OpFeatureContext) error
2727
// FeatureRelease open a MergeRequest of feature branch and types.MasterBranch branch.
28-
FeatureRelease(featureBranchName string) error
28+
FeatureRelease(opc *types.OpFeatureContext) error
2929
// DONE(@yeqown) this would be useful while you merge feature into master but there is conflict.
3030
// FeatureResolveConflict will checkout a new branch from target branch,
3131
// then create a merge request from current feature branch to the new branch.
3232
// newBranch = "resolve-conflict/featureBranchName-to-master"
33-
FeatureResolveConflict(featureBranchName string, targetBranch types.BranchTyp) error
33+
FeatureResolveConflict(opc *types.OpFeatureContext, targetBranch types.BranchTyp) error
3434

3535
// FeatureBeginIssue checkout a issue branch from feature branch, also open a merge request
3636
// which is from issue branch to feature branch.
37-
FeatureBeginIssue(featureBranchName string, title, desc string) error
37+
FeatureBeginIssue(opc *types.OpFeatureContext, title, desc string) error
3838
// FeatureFinishIssue open the WebURL of merge request which is from issue branch to feature branch.
39-
FeatureFinishIssue(featureBranchName, issueBranchName string) error
39+
FeatureFinishIssue(opc *types.OpFeatureContext, issueBranchName string) error
4040

4141
// HotfixStart checkout a hotfix branch from types.MasterBranch, also open a merge request
4242
// which is from hotfix branch to types.MasterBranch.
@@ -113,7 +113,7 @@ func genHotfixBranchName(name string) string {
113113

114114
// genMRTitle
115115
func genMRTitle(srcBranch, targetBranch string) string {
116-
return fmt.Sprintf("Merge %s to %s", srcBranch, targetBranch)
116+
return fmt.Sprintf("Merge %s into %s", srcBranch, targetBranch)
117117
}
118118

119119
// genIssueBranchName .

0 commit comments

Comments
 (0)