@@ -93,6 +93,7 @@ const (
93
93
FeatureBranchPrefix = "feature/"
94
94
HotfixBranchPrefix = "hotfix/"
95
95
ConflictResolveBranchPrefix = "conflict-resolve/"
96
+ IssueBranchPrefix = "issue/"
96
97
)
97
98
98
99
// genFeatureBranchName
@@ -107,24 +108,25 @@ func genFeatureBranchName(name string) string {
107
108
// tryParseFeatureNameFrom try parse feature name from issue name or other cases.
108
109
// if branchName has no prefix, which means tryParseFeatureNameFrom could judge it.
109
110
// otherwise, branchName must have prefix, which was one of flow branch prefixes.
110
- func tryParseFeatureNameFrom (branchName string ) (string , bool ) {
111
+ func tryParseFeatureNameFrom (branchName string , comptaible bool ) (string , bool ) {
111
112
arr := strings .Split (branchName , "/" )
112
113
if len (arr ) < 2 {
113
- // FIXME(@yeqown): maybe old issue name, so try parse it.
114
- if out := parseFeaturenameFromIssueName (branchName ); out != "" {
115
- return out , true
116
- }
117
114
return "" , false
118
115
}
119
116
120
- prefix := arr [0 ]
117
+ prefix := arr [0 ] + "/"
121
118
switch prefix {
122
119
case FeatureBranchPrefix :
123
120
// pass
124
121
case HotfixBranchPrefix :
125
122
// pass
126
123
case ConflictResolveBranchPrefix :
127
124
// pass
125
+ case IssueBranchPrefix :
126
+ out := strings .Join (arr [1 :], "/" )
127
+ if out = parseFeatureFromIssueName (out , comptaible ); out != "" {
128
+ return out , true
129
+ }
128
130
case "" :
129
131
fallthrough
130
132
default :
@@ -149,30 +151,47 @@ func genHotfixBranchName(name string) string {
149
151
return HotfixBranchPrefix + name
150
152
}
151
153
152
- // genMRTitle
153
- func genMRTitle (srcBranch , targetBranch string ) string {
154
+ // genMergeRequestName generate merge request name.
155
+ func genMergeRequestName (srcBranch , targetBranch string ) string {
154
156
return fmt .Sprintf ("Merge %s into %s" , srcBranch , targetBranch )
155
157
}
156
158
157
159
// genIssueBranchName .
158
- // @result = 1-milestoneTitle as default
159
- // fmt.Sprintf("%d-%s", issue.IID, milestone.Title)
160
+ // @result = issue/milestoneTitle-1 as default
160
161
func genIssueBranchName (name string , issueIID int ) string {
161
- if strings .HasPrefix (name , strconv . Itoa ( issueIID ) + "-" ) {
162
+ if strings .HasPrefix (name , IssueBranchPrefix ) {
162
163
return name
163
164
}
164
165
165
- return fmt . Sprintf ( "%d-%s" , issueIID , name )
166
+ return IssueBranchPrefix + name + "-" + strconv . Itoa ( issueIID )
166
167
}
167
168
168
- func parseFeaturenameFromIssueName (issueName string ) string {
169
- idx := strings .Index (issueName , "-" )
169
+ // parseFeatureFromIssueName parse issue name to feature name, there are
170
+ // two different cases:
171
+ // 1. "1-milestoneName"
172
+ // 2. "issue/milestoneName-1"
173
+ //
174
+ // TODO(@yeqown): comptaible with old.
175
+ func parseFeatureFromIssueName (issueName string , compatible bool ) string {
176
+ // if comptaible, try parse "1-milestoneName"
177
+ if compatible {
178
+ // DONE(@yeqown): support "1-milestoneName"
179
+ idx := strings .Index (issueName , "-" )
180
+ if idx == - 1 {
181
+ return ""
182
+ }
183
+
184
+ return issueName [idx + 1 :]
185
+ }
186
+
187
+ issueName = strings .TrimPrefix (issueName , IssueBranchPrefix )
188
+ idx := strings .LastIndex (issueName , "-" )
170
189
if idx == - 1 {
171
190
// not errCouldNotFound
172
191
return ""
173
192
}
174
193
175
- return issueName [idx + 1 : ]
194
+ return issueName [: idx ]
176
195
}
177
196
178
197
// chooseOneProjectInteractively if there are not only one project matched from local or remote,
0 commit comments