Skip to content

Commit a144135

Browse files
committed
fix: blocking some prefixes of milestone/feature/issue title
1 parent 1571a53 commit a144135

File tree

5 files changed

+33
-3
lines changed

5 files changed

+33
-3
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*.dll
55
*.so
66
*.dylib
7-
7+
.DS_Store
88
# Test binary, built with `go test -c`
99
*.test
1010

cmd/gitlab-flow/commands.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func getFeatureCommand() *cli.Command {
8080
},
8181
&cli.BoolFlag{
8282
Name: "parse-issue-compatible",
83-
Usage: "switch to parse issue name in comptaible mode",
83+
Usage: "switch to parse issue name in compatible mode",
8484
Required: false,
8585
},
8686
},

cmd/gitlab-flow/commands_feature.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func getFeatureSubCommands() cli.Commands {
2222
}
2323

2424
// getFeatureBeginSubCommand to start feature command
25-
// command: gitlab-flow feature start @title @desc
25+
// @command: gitlab-flow feature start @title @desc
2626
// @title will be used as branchName
2727
// @desc will be used as milestone information
2828
func getFeatureBeginSubCommand() *cli.Command {

internal/flow.go

+22
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,28 @@ func genIssueBranchName(name string, issueIID int) string {
166166
return IssueBranchPrefix + name + "-" + strconv.Itoa(issueIID)
167167
}
168168

169+
func blockingNamePrefix(name string) error {
170+
if len(name) == 0 || (len(name) <= 3 && name != "/") {
171+
return nil
172+
}
173+
174+
// FIXED(@yeqown): blocking some prefixes to be milestone title.
175+
blacklist := []string{
176+
"/", "bug/", "test/", "issue/", // test-like
177+
"fix/", "refactor/", "docs/", "chore/", // commit-like
178+
"master/", "develop/", "hotfix/", "release/", "feature/", // branch-like
179+
"WIP:", // others
180+
}
181+
182+
for _, pre := range blacklist {
183+
if strings.HasPrefix(name, pre) {
184+
return fmt.Errorf("title(%s) should not start with prefix(%s)", name, pre)
185+
}
186+
}
187+
188+
return nil
189+
}
190+
169191
// parseFeatureFromIssueName parse issue name to feature name, there are
170192
// two different cases:
171193
// 1. "1-milestoneName"

internal/flow_impl.go

+8
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ func (f flowImpl) FeatureBegin(opc *types.OpFeatureContext, title, desc string)
201201
}).
202202
Debug("FeatureBegin called")
203203

204+
if err := blockingNamePrefix(title); err != nil {
205+
return errors.Wrap(err, "blocking name prefix detected")
206+
}
207+
204208
// create milestone
205209
result, err := f.createMilestone(title, desc)
206210
if err != nil {
@@ -320,6 +324,10 @@ func (f flowImpl) FeatureBeginIssue(opc *types.OpFeatureContext, title, desc str
320324

321325
if len(title) == 0 {
322326
title = milestone.Title
327+
} else {
328+
if err := blockingNamePrefix(title); err != nil {
329+
return errors.Wrap(err, "blocking name prefix detected")
330+
}
323331
}
324332
if len(desc) == 0 {
325333
desc = milestone.Desc

0 commit comments

Comments
 (0)