@@ -59,10 +59,9 @@ func checkOAuthAccessToken(ctx *types.FlowContext) {
59
59
60
60
c .OAuth .AccessToken = accessToken
61
61
c .OAuth .RefreshToken = refreshToken
62
-
63
62
// update context oauth configuration
64
- ctx .Conf . OAuth .AccessToken = accessToken
65
- ctx .Conf . OAuth .RefreshToken = refreshToken
63
+ ctx .GetOAuth () .AccessToken = accessToken
64
+ ctx .GetOAuth () .RefreshToken = refreshToken
66
65
67
66
if err := conf .Save (ctx .ConfPath (), c , nil ); err != nil {
68
67
log .
@@ -88,9 +87,9 @@ func NewFlow(ctx *types.FlowContext) IFlow {
88
87
89
88
flow := & flowImpl {
90
89
ctx : ctx ,
91
- gitlabOperator : gitlabop .NewGitlabOperator (ctx .Conf . OAuth . AccessToken , ctx .Conf . GitlabAPIURL ),
92
- gitOperator : gitop .NewBasedCmd (ctx .CWD ),
93
- repo : impl .NewBasedSqlite3 (impl .ConnectDB (ctx .ConfPath (), ctx .Conf . DebugMode )),
90
+ gitlabOperator : gitlabop .NewGitlabOperator (ctx .GetOAuth (). AccessToken , ctx .APIEndpoint () ),
91
+ gitOperator : gitop .NewBasedCmd (ctx .CWD () ),
92
+ repo : impl .NewBasedSqlite3 (impl .ConnectDB (ctx .ConfPath (), ctx .IsDebug () )),
94
93
}
95
94
96
95
// if flowContext has NONE project information, so we need to fill it.
@@ -122,13 +121,13 @@ func (f flowImpl) fillContextWithProject() error {
122
121
projects , err = f .repo .QueryProjects (& repository.ProjectDO {ProjectName : projectName })
123
122
if err == nil && len (projects ) != 0 {
124
123
// locate project from local, and there are maybe more than one project.
125
- matched , err := chooseOneProjectInteractively (projects )
126
- if err == nil {
127
- f .ctx .Project = & types.ProjectBasics {
124
+ matched , err2 := chooseOneProjectInteractively (projects )
125
+ if err2 == nil {
126
+ f .ctx .InjectProject ( & types.ProjectBasics {
128
127
ID : matched .ProjectID ,
129
128
Name : matched .ProjectName ,
130
129
WebURL : matched .WebURL ,
131
- }
130
+ })
132
131
return nil
133
132
}
134
133
}
@@ -166,7 +165,7 @@ locateFromRemote:
166
165
projectDO := repository.ProjectDO {
167
166
ProjectName : projectName ,
168
167
ProjectID : v .ID ,
169
- LocalDir : f .ctx .CWD ,
168
+ LocalDir : f .ctx .CWD () ,
170
169
WebURL : v .WebURL ,
171
170
}
172
171
remoteMatched = append (remoteMatched , & projectDO )
@@ -182,11 +181,11 @@ locateFromRemote:
182
181
Warn ("could not save project" )
183
182
}
184
183
185
- f .ctx .Project = & types.ProjectBasics {
184
+ f .ctx .InjectProject ( & types.ProjectBasics {
186
185
ID : matched .ProjectID ,
187
186
Name : matched .ProjectName ,
188
187
WebURL : matched .WebURL ,
189
- }
188
+ })
190
189
return nil
191
190
}
192
191
@@ -268,7 +267,7 @@ func (f flowImpl) FeatureResolveConflict(opc *types.OpFeatureContext, targetBran
268
267
269
268
// locate feature branch
270
269
featureBranch , err := f .repo .QueryBranch (& repository.BranchDO {
271
- ProjectID : f .ctx .Project .ID ,
270
+ ProjectID : f .ctx .Project () .ID ,
272
271
BranchName : opc .FeatureBranchName ,
273
272
})
274
273
if err != nil {
@@ -303,7 +302,7 @@ func (f flowImpl) FeatureBeginIssue(opc *types.OpFeatureContext, title, desc str
303
302
opc .FeatureBranchName = genFeatureBranchName (opc .FeatureBranchName )
304
303
305
304
featureBranch , err := f .repo .QueryBranch (& repository.BranchDO {
306
- ProjectID : f .ctx .Project .ID ,
305
+ ProjectID : f .ctx .Project () .ID ,
307
306
BranchName : opc .FeatureBranchName ,
308
307
})
309
308
if err != nil {
@@ -312,7 +311,7 @@ func (f flowImpl) FeatureBeginIssue(opc *types.OpFeatureContext, title, desc str
312
311
313
312
// query milestone
314
313
milestone , err := f .repo .QueryMilestone (& repository.MilestoneDO {
315
- ProjectID : f .ctx .Project .ID ,
314
+ ProjectID : f .ctx .Project () .ID ,
316
315
MilestoneID : featureBranch .MilestoneID ,
317
316
})
318
317
if err != nil {
@@ -361,7 +360,7 @@ func (f flowImpl) FeatureFinishIssue(opc *types.OpFeatureContext, issueBranchNam
361
360
)
362
361
// locate issue branch.
363
362
if b , err := f .repo .QueryBranch (& repository.BranchDO {
364
- ProjectID : f .ctx .Project .ID ,
363
+ ProjectID : f .ctx .Project () .ID ,
365
364
BranchName : issueBranchName ,
366
365
}); err != nil {
367
366
return errors .Wrapf (err , "locate issue branch(%s) failed" , issueBranchName )
@@ -379,7 +378,7 @@ func (f flowImpl) FeatureFinishIssue(opc *types.OpFeatureContext, issueBranchNam
379
378
}
380
379
opc .FeatureBranchName = genFeatureBranchName (opc .FeatureBranchName )
381
380
//if _, err := f.repo.QueryBranch(&repository.BranchDO{
382
- // ProjectID: f.ctx.Project.ID,
381
+ // ProjectID: f.ctx.Project() .ID,
383
382
// BranchName: featureBranchName,
384
383
// MilestoneID: milestoneID,
385
384
//}); err != nil {
@@ -393,7 +392,7 @@ func (f flowImpl) FeatureFinishIssue(opc *types.OpFeatureContext, issueBranchNam
393
392
394
393
// locate MR
395
394
mr , err = f .repo .QueryMergeRequest (& repository.MergeRequestDO {
396
- ProjectID : f .ctx .Project .ID ,
395
+ ProjectID : f .ctx .Project () .ID ,
397
396
IssueIID : issueIID ,
398
397
MilestoneID : milestoneID ,
399
398
SourceBranch : issueBranchName ,
@@ -402,7 +401,7 @@ func (f flowImpl) FeatureFinishIssue(opc *types.OpFeatureContext, issueBranchNam
402
401
if err != nil && ! repository .IsErrNotFound (err ) {
403
402
log .
404
403
WithFields (log.Fields {
405
- "projectID" : f .ctx .Project .ID ,
404
+ "projectID" : f .ctx .Project () .ID ,
406
405
"issueIID" : issueIID ,
407
406
"milestoneID" : milestoneID ,
408
407
"sourceBranch" : issueBranchName ,
@@ -479,7 +478,7 @@ func (f flowImpl) HotfixFinish(hotfixBranchName string) error {
479
478
480
479
hotfixBranchName = genHotfixBranchName (hotfixBranchName )
481
480
_ , err := f .repo .QueryBranch (& repository.BranchDO {
482
- ProjectID : f .ctx .Project .ID ,
481
+ ProjectID : f .ctx .Project () .ID ,
483
482
BranchName : hotfixBranchName ,
484
483
})
485
484
if err != nil {
@@ -488,7 +487,7 @@ func (f flowImpl) HotfixFinish(hotfixBranchName string) error {
488
487
489
488
// locate issue
490
489
issue , err := f .repo .QueryIssue (& repository.IssueDO {
491
- ProjectID : f .ctx .Project .ID ,
490
+ ProjectID : f .ctx .Project () .ID ,
492
491
RelatedBranch : hotfixBranchName ,
493
492
})
494
493
if err != nil {
@@ -497,7 +496,7 @@ func (f flowImpl) HotfixFinish(hotfixBranchName string) error {
497
496
498
497
// locate MR first
499
498
mr , err := f .repo .QueryMergeRequest (& repository.MergeRequestDO {
500
- ProjectID : f .ctx .Project .ID ,
499
+ ProjectID : f .ctx .Project () .ID ,
501
500
MilestoneID : issue .MilestoneID ,
502
501
IssueIID : issue .IssueIID ,
503
502
//SourceBranch: "",
@@ -541,7 +540,7 @@ func (f flowImpl) HotfixFinish(hotfixBranchName string) error {
541
540
//
542
541
func (f flowImpl ) SyncMilestone (milestoneID int , interact bool ) error {
543
542
ctx := context .Background ()
544
- projectId := f .ctx .Project .ID
543
+ projectId := f .ctx .Project () .ID
545
544
546
545
// parameter checking
547
546
if milestoneID == 0 && ! interact {
@@ -677,7 +676,7 @@ func (f flowImpl) syncFormatResultIntoDO(
677
676
678
677
c = make (map [int ]* repository.IssueDO )
679
678
featureBranchName string
680
- projectID = f .ctx .Project .ID
679
+ projectID = f .ctx .Project () .ID
681
680
milestoneID = milestone .ID
682
681
)
683
682
@@ -779,7 +778,7 @@ func (f flowImpl) createBranch(
779
778
req := gitlabop.CreateBranchRequest {
780
779
TargetBranch : targetBranchName ,
781
780
SrcBranch : srcBranch ,
782
- ProjectID : f .ctx .Project .ID ,
781
+ ProjectID : f .ctx .Project () .ID ,
783
782
//MilestoneID: milestoneID,
784
783
//IssueID: issueIID,
785
784
}
@@ -815,7 +814,7 @@ func (f flowImpl) createBranch(
815
814
go func () {
816
815
wg .Done ()
817
816
m := repository.BranchDO {
818
- ProjectID : f .ctx .Project .ID ,
817
+ ProjectID : f .ctx .Project () .ID ,
819
818
MilestoneID : milestoneID ,
820
819
IssueIID : issueIID ,
821
820
BranchName : targetBranchName ,
@@ -845,14 +844,14 @@ func (f flowImpl) createMilestone(title, desc string) (*gitlabop.CreateMilestone
845
844
result , err := f .gitlabOperator .CreateMilestone (ctx , & gitlabop.CreateMilestoneRequest {
846
845
Title : title ,
847
846
Desc : desc ,
848
- ProjectID : f .ctx .Project .ID ,
847
+ ProjectID : f .ctx .Project () .ID ,
849
848
})
850
849
if err != nil {
851
850
return nil , errors .Wrap (err , "CreateMilestone failed" )
852
851
}
853
852
854
853
if err = f .repo .SaveMilestone (& repository.MilestoneDO {
855
- ProjectID : f .ctx .Project .ID ,
854
+ ProjectID : f .ctx .Project () .ID ,
856
855
MilestoneID : result .ID ,
857
856
Title : title ,
858
857
Desc : desc ,
@@ -878,7 +877,7 @@ func (f flowImpl) createIssue(title, desc, relatedBranch string, milestoneID int
878
877
Desc : desc ,
879
878
RelatedBranch : relatedBranch ,
880
879
MilestoneID : milestoneID ,
881
- ProjectID : f .ctx .Project .ID ,
880
+ ProjectID : f .ctx .Project () .ID ,
882
881
})
883
882
if err != nil {
884
883
return nil , errors .Wrap (err , "create Issue failed" )
@@ -888,7 +887,7 @@ func (f flowImpl) createIssue(title, desc, relatedBranch string, milestoneID int
888
887
IssueIID : result .IID ,
889
888
Title : title ,
890
889
Desc : desc ,
891
- ProjectID : f .ctx .Project .ID ,
890
+ ProjectID : f .ctx .Project () .ID ,
892
891
MilestoneID : milestoneID ,
893
892
RelatedBranch : relatedBranch ,
894
893
WebURL : result .WebURL ,
@@ -923,7 +922,7 @@ func (f flowImpl) createMergeRequest(
923
922
TargetBranch : targetBranch ,
924
923
MilestoneID : milestoneID ,
925
924
IssueIID : issueIID ,
926
- ProjectID : f .ctx .Project .ID ,
925
+ ProjectID : f .ctx .Project () .ID ,
927
926
})
928
927
if err != nil {
929
928
return nil , errors .Wrap (err , "create MR failed" )
@@ -939,7 +938,7 @@ func (f flowImpl) createMergeRequest(
939
938
Debug ("create mr success" )
940
939
941
940
if err = f .repo .SaveMergeRequest (& repository.MergeRequestDO {
942
- ProjectID : f .ctx .Project .ID ,
941
+ ProjectID : f .ctx .Project () .ID ,
943
942
MilestoneID : milestoneID ,
944
943
IssueIID : issueIID ,
945
944
MergeRequestID : result .ID ,
@@ -962,7 +961,7 @@ func (f flowImpl) createMergeRequest(
962
961
func (f flowImpl ) featureProcessMR (
963
962
featureBranchName string , targetBranchName types.BranchTyp , forceCreateMR bool ) error {
964
963
featureBranch , err := f .repo .QueryBranch (& repository.BranchDO {
965
- ProjectID : f .ctx .Project .ID ,
964
+ ProjectID : f .ctx .Project () .ID ,
966
965
BranchName : featureBranchName ,
967
966
})
968
967
if err != nil {
@@ -976,7 +975,7 @@ func (f flowImpl) featureProcessMR(
976
975
}
977
976
// query feature MR first
978
977
mr , err = f .repo .QueryMergeRequest (& repository.MergeRequestDO {
979
- ProjectID : f .ctx .Project .ID ,
978
+ ProjectID : f .ctx .Project () .ID ,
980
979
MilestoneID : featureBranch .MilestoneID ,
981
980
IssueIID : featureBranch .IssueIID ,
982
981
SourceBranch : featureBranchName ,
@@ -1032,7 +1031,7 @@ func (f flowImpl) printAndOpenBrowser(title, url string) {
1032
1031
)
1033
1032
1034
1033
_ , err1 = fmt .Fprintf (os .Stdout , _printTpl , title , url )
1035
- if f .ctx .Conf . OpenBrowser {
1034
+ if f .ctx .ShouldOpenBrowser () {
1036
1035
err2 = pkg .OpenBrowser (url )
1037
1036
}
1038
1037
log .WithFields (log.Fields {
0 commit comments