@@ -31,8 +31,8 @@ const apiResponseLimit = 100
31
31
var _ provider.Interface = (* Provider )(nil )
32
32
33
33
type Provider struct {
34
- Client * bbv1.APIClient // temporarily keeping it after the refactor finishes, will be removed
35
- ScmClient * scm.Client
34
+ bbClient * bbv1.APIClient // temporarily keeping it after the refactor finishes, will be removed
35
+ scmClient * scm.Client
36
36
Logger * zap.SugaredLogger
37
37
run * params.Run
38
38
pacInfo * info.PacOpts
@@ -44,6 +44,22 @@ type Provider struct {
44
44
projectKey string
45
45
}
46
46
47
+ func (v Provider ) Client () * bbv1.APIClient {
48
+ return v .bbClient
49
+ }
50
+
51
+ func (v * Provider ) SetBitBucketClient (client * bbv1.APIClient ) {
52
+ v .bbClient = client
53
+ }
54
+
55
+ func (v Provider ) ScmClient () * scm.Client {
56
+ return v .scmClient
57
+ }
58
+
59
+ func (v * Provider ) SetScmClient (client * scm.Client ) {
60
+ v .scmClient = client
61
+ }
62
+
47
63
func (v * Provider ) SetPacInfo (pacInfo * info.PacOpts ) {
48
64
v .pacInfo = pacInfo
49
65
}
@@ -99,7 +115,7 @@ func (v *Provider) CreateStatus(ctx context.Context, event *info.Event, statusOp
99
115
if statusOpts .DetailsURL != "" {
100
116
detailsURL = statusOpts .DetailsURL
101
117
}
102
- if v .ScmClient == nil {
118
+ if v .scmClient == nil {
103
119
return fmt .Errorf ("no token has been set, cannot set status" )
104
120
}
105
121
@@ -119,7 +135,7 @@ func (v *Provider) CreateStatus(ctx context.Context, event *info.Event, statusOp
119
135
Desc : statusOpts .Title ,
120
136
Link : detailsURL ,
121
137
}
122
- _ , _ , err := v .ScmClient .Repositories .CreateStatus (ctx , OrgAndRepo , event .SHA , opts )
138
+ _ , _ , err := v .ScmClient () .Repositories .CreateStatus (ctx , OrgAndRepo , event .SHA , opts )
123
139
if err != nil {
124
140
return err
125
141
}
@@ -135,7 +151,7 @@ func (v *Provider) CreateStatus(ctx context.Context, event *info.Event, statusOp
135
151
input := & scm.CommentInput {
136
152
Body : bbComment ,
137
153
}
138
- _ , _ , err := v .ScmClient .PullRequests .CreateComment (ctx , OrgAndRepo , event .PullRequestNumber , input )
154
+ _ , _ , err := v .ScmClient () .PullRequests .CreateComment (ctx , OrgAndRepo , event .PullRequestNumber , input )
139
155
if err != nil {
140
156
return err
141
157
}
@@ -185,7 +201,7 @@ func (v *Provider) concatAllYamlFiles(ctx context.Context, objects []string, sha
185
201
186
202
func (v * Provider ) getRaw (ctx context.Context , runevent * info.Event , revision , path string ) (string , error ) {
187
203
repo := fmt .Sprintf ("%s/%s" , runevent .Organization , runevent .Repository )
188
- content , _ , err := v .ScmClient .Contents .Find (ctx , repo , path , revision )
204
+ content , _ , err := v .ScmClient () .Contents .Find (ctx , repo , path , revision )
189
205
if err != nil {
190
206
return "" , fmt .Errorf ("cannot find %s inside the %s repository: %w" , path , runevent .Repository , err )
191
207
}
@@ -206,7 +222,7 @@ func (v *Provider) GetTektonDir(ctx context.Context, event *info.Event, path, pr
206
222
var fileEntries []* scm.FileEntry
207
223
opts := & scm.ListOptions {Page : 1 , Size : apiResponseLimit }
208
224
for {
209
- entries , _ , err := v .ScmClient .Contents .List (ctx , orgAndRepo , path , at , opts )
225
+ entries , _ , err := v .ScmClient () .Contents .List (ctx , orgAndRepo , path , at , opts )
210
226
if err != nil {
211
227
return "" , fmt .Errorf ("cannot list content of %s directory: %w" , path , err )
212
228
}
@@ -281,11 +297,11 @@ func (v *Provider) SetClient(ctx context.Context, run *params.Run, event *info.E
281
297
282
298
ctx = context .WithValue (ctx , bbv1 .ContextBasicAuth , basicAuth )
283
299
cfg := bbv1 .NewConfiguration (event .Provider .URL )
284
- if v .Client == nil {
285
- v .Client = bbv1 .NewAPIClient (ctx , cfg )
300
+ if v .bbClient == nil {
301
+ v .bbClient = bbv1 .NewAPIClient (ctx , cfg )
286
302
}
287
303
288
- if v .ScmClient == nil {
304
+ if v .scmClient == nil {
289
305
client , err := stash .New (removeLastSegment (event .Provider .URL )) // remove `/rest` from url
290
306
if err != nil {
291
307
return err
@@ -299,10 +315,10 @@ func (v *Provider) SetClient(ctx context.Context, run *params.Run, event *info.E
299
315
),
300
316
},
301
317
}
302
- v .ScmClient = client
318
+ v .scmClient = client
303
319
}
304
320
v .run = run
305
- _ , resp , err := v .ScmClient .Users .FindLogin (ctx , event .Provider .User )
321
+ _ , resp , err := v .ScmClient () .Users .FindLogin (ctx , event .Provider .User )
306
322
if resp != nil && resp .Status == http .StatusUnauthorized {
307
323
return fmt .Errorf ("cannot get user %s with token: %w" , event .Provider .User , err )
308
324
}
@@ -315,14 +331,14 @@ func (v *Provider) SetClient(ctx context.Context, run *params.Run, event *info.E
315
331
316
332
func (v * Provider ) GetCommitInfo (_ context.Context , event * info.Event ) error {
317
333
OrgAndRepo := fmt .Sprintf ("%s/%s" , event .Organization , event .Repository )
318
- commit , _ , err := v .ScmClient .Git .FindCommit (context .Background (), OrgAndRepo , event .SHA )
334
+ commit , _ , err := v .ScmClient () .Git .FindCommit (context .Background (), OrgAndRepo , event .SHA )
319
335
if err != nil {
320
336
return err
321
337
}
322
338
event .SHATitle = sanitizeTitle (commit .Message )
323
339
event .SHAURL = fmt .Sprintf ("%s/projects/%s/repos/%s/commits/%s" , v .baseURL , v .projectKey , event .Repository , event .SHA )
324
340
325
- ref , _ , err := v .ScmClient .Git .GetDefaultBranch (context .Background (), OrgAndRepo )
341
+ ref , _ , err := v .ScmClient () .Git .GetDefaultBranch (context .Background (), OrgAndRepo )
326
342
if err != nil {
327
343
return err
328
344
}
@@ -345,7 +361,7 @@ func (v *Provider) GetFiles(ctx context.Context, runevent *info.Event) (changedf
345
361
opts := & scm.ListOptions {Page : 1 , Size : apiResponseLimit }
346
362
changedFiles := changedfiles.ChangedFiles {}
347
363
for {
348
- changes , _ , err := v .ScmClient .PullRequests .ListChanges (ctx , OrgAndRepo , runevent .PullRequestNumber , opts )
364
+ changes , _ , err := v .ScmClient () .PullRequests .ListChanges (ctx , OrgAndRepo , runevent .PullRequestNumber , opts )
349
365
if err != nil {
350
366
return changedfiles.ChangedFiles {}, fmt .Errorf ("failed to list changes for pull request: %w" , err )
351
367
}
@@ -383,7 +399,7 @@ func (v *Provider) GetFiles(ctx context.Context, runevent *info.Event) (changedf
383
399
opts := & scm.ListOptions {Page : 1 , Size : apiResponseLimit }
384
400
changedFiles := changedfiles.ChangedFiles {}
385
401
for {
386
- changes , _ , err := v .ScmClient .Git .ListChanges (ctx , OrgAndRepo , runevent .SHA , opts )
402
+ changes , _ , err := v .ScmClient () .Git .ListChanges (ctx , OrgAndRepo , runevent .SHA , opts )
387
403
if err != nil {
388
404
return changedfiles.ChangedFiles {}, fmt .Errorf ("failed to list changes for commit %s: %w" , runevent .SHA , err )
389
405
}
0 commit comments