@@ -200,33 +200,18 @@ func (f flowImpl) FeatureBeginIssue(featureBranchName string, title, desc string
200
200
201
201
// create issue branch
202
202
issueBranchName := genIssueBranchName (milestone .Title , issue .IID )
203
- issueBranch , err : = f .createBranch (issueBranchName , featureBranch .BranchName , milestone .MilestoneID , issue .IID )
203
+ _ , err = f .createBranch (issueBranchName , featureBranch .BranchName , milestone .MilestoneID , issue .IID )
204
204
if err != nil {
205
- return err
206
- }
207
-
208
- // create mr
209
- targetBranch := featureBranch .BranchName
210
- mrTitle := genMRTitle (issueBranchName , targetBranch )
211
- mr , err := f .createMergeRequest (mrTitle , desc , milestone .MilestoneID , issue .IID , issueBranchName , targetBranch )
212
- if err != nil {
213
- return nil
205
+ return errors .Wrap (err , "create branch failed" )
214
206
}
215
- log .
216
- WithFields (log.Fields {
217
- "issue_branch" : issueBranch .WebURL ,
218
- "merge_request" : mr .WebURL ,
219
- }).
220
- Debug ("create issue finished" )
221
207
222
208
f .printAndOpenBrowser ("Open Issue" , issue .WebURL )
223
209
224
210
return nil
225
211
}
226
212
227
- // TODO(@yeqown): issue merge request should be called here, rather than FeatureBeginIssue
228
- func (f flowImpl ) FeatureFinishIssue (featureBranchName , issueBranchName string ) (err error ) {
229
- var milestoneID = 0
213
+ // DONE(@yeqown): issue merge request should be called here, rather than FeatureBeginIssue
214
+ func (f flowImpl ) FeatureFinishIssue (featureBranchName , issueBranchName string ) error {
230
215
231
216
// DONE(@yeqown): if issueBranchName is empty, make current branch name as default.
232
217
if issueBranchName == "" {
@@ -235,13 +220,20 @@ func (f flowImpl) FeatureFinishIssue(featureBranchName, issueBranchName string)
235
220
if issueBranchName == "" {
236
221
return errors .New ("issue branch could not be empty" )
237
222
}
223
+
224
+ var (
225
+ milestoneID = 0
226
+ issueIID = 0
227
+ )
228
+ // locate issue branch.
238
229
if b , err := f .repo .QueryBranch (& repository.BranchDO {
239
230
ProjectID : f .ctx .Project .ID ,
240
231
BranchName : issueBranchName ,
241
232
}); err != nil {
242
233
return errors .Wrapf (err , "locate issue branch(%s) failed" , issueBranchName )
243
234
} else {
244
235
milestoneID = b .MilestoneID
236
+ issueIID = b .IssueIID
245
237
}
246
238
247
239
// DONE(@yeqown) get feature branch name from issueBranchName
@@ -252,43 +244,66 @@ func (f flowImpl) FeatureFinishIssue(featureBranchName, issueBranchName string)
252
244
return errors .New ("feature branch could not be empty" )
253
245
}
254
246
featureBranchName = genFeatureBranchName (featureBranchName )
255
-
256
- if _ , err = f .repo .QueryBranch (& repository.BranchDO {
257
- ProjectID : f .ctx .Project .ID ,
258
- BranchName : featureBranchName ,
259
- MilestoneID : milestoneID ,
260
- }); err != nil {
261
- return errors .Wrapf (err , "locate feature branch(%s) failed" , featureBranchName )
262
- }
247
+ //if _, err := f.repo.QueryBranch(&repository.BranchDO{
248
+ // ProjectID: f.ctx.Project.ID,
249
+ // BranchName: featureBranchName,
250
+ // MilestoneID: milestoneID,
251
+ //}); err != nil {
252
+ // return errors.Wrapf(err, "locate feature branch(%s) failed", featureBranchName)
253
+ //}
263
254
264
255
// locate MR
265
256
mr , err := f .repo .QueryMergeRequest (& repository.MergeRequestDO {
266
257
ProjectID : f .ctx .Project .ID ,
258
+ IssueIID : issueIID ,
267
259
MilestoneID : milestoneID ,
268
260
SourceBranch : issueBranchName ,
269
261
TargetBranch : featureBranchName ,
270
262
})
271
- if err != nil {
263
+ if err != nil && ! repository . IsErrNotFound ( err ) {
272
264
log .
273
265
WithFields (log.Fields {
274
- "projectID" : f .ctx .Project .ID ,
275
- "milestoneID" : milestoneID ,
276
- "error" : err ,
266
+ "projectID" : f .ctx .Project .ID ,
267
+ "issueIID" : issueIID ,
268
+ "milestoneID" : milestoneID ,
269
+ "sourceBranch" : issueBranchName ,
270
+ "targetBranch" : featureBranchName ,
277
271
}).
278
- Error ("locate MR failed" )
272
+ Errorf ("locate MR failed: %v" , err )
279
273
return errors .Wrap (err , "locate MR failed" )
280
274
}
281
275
276
+ // got merge request from local
277
+ if mr != nil {
278
+ log .
279
+ WithFields (log.Fields {
280
+ "featureBranch" : featureBranchName ,
281
+ "issueBranch" : issueBranchName ,
282
+ "mergeRequestURL" : mr .WebURL ,
283
+ }).
284
+ Debug ("issue info" )
285
+
286
+ f .printAndOpenBrowser ("Issue Merge Request" , mr .WebURL )
287
+ return nil
288
+ }
289
+
290
+ // not hit, so create one
291
+ title := genMRTitle (issueBranchName , featureBranchName )
292
+ desc := ""
293
+ result , err := f .createMergeRequest (title , desc , milestoneID , issueIID , issueBranchName , featureBranchName )
294
+ if err != nil {
295
+ return errors .Wrap (err , "create issue merge request failed" )
296
+ }
297
+
282
298
log .
283
299
WithFields (log.Fields {
284
- "feature_branch" : featureBranchName ,
285
- "issue_branch" : issueBranchName ,
286
- "project_name" : f .ctx .Project .Name ,
287
- "merge_request_url" : mr .WebURL ,
300
+ "issueBranchName" : issueBranchName ,
301
+ "featureBranchName" : featureBranchName ,
302
+ "mergeRequestURL" : result .WebURL ,
288
303
}).
289
- Debug ("issue info " )
304
+ Debug ("create issue merge request finished " )
290
305
291
- f .printAndOpenBrowser ("Issue Merge Request" , mr .WebURL )
306
+ f .printAndOpenBrowser ("Issue Merge Request" , result .WebURL )
292
307
293
308
return nil
294
309
}
0 commit comments