@@ -207,9 +207,18 @@ export class BitbucketIntegration extends HostingIntegration<
207
207
return undefined ;
208
208
}
209
209
210
+ const api = await this . getProvidersApi ( ) ;
211
+ if ( ! api ) {
212
+ return undefined ;
213
+ }
214
+
210
215
const remotes = await flatSettled ( this . container . git . openRepositories . map ( r => r . git . remotes ( ) . getRemotes ( ) ) ) ;
211
216
const workspaceRepos = await nonnullSettled (
212
- remotes . map ( async r => ( ( await r . getIntegration ( ) ) ?. id === this . id ? r . path : undefined ) ) ,
217
+ remotes . map ( async r => {
218
+ const integration = await r . getIntegration ( ) ;
219
+ const [ namespace , name ] = r . path . split ( '/' ) ;
220
+ return integration ?. id === this . id ? { name : name , namespace : namespace } : undefined ;
221
+ } ) ,
213
222
) ;
214
223
215
224
const user = await this . getProviderCurrentAccount ( session ) ;
@@ -218,44 +227,25 @@ export class BitbucketIntegration extends HostingIntegration<
218
227
const workspaces = await this . getProviderResourcesForUser ( session ) ;
219
228
if ( workspaces == null || workspaces . length === 0 ) return undefined ;
220
229
221
- const providersApi = await this . getProvidersApi ( ) ;
222
- const api = await this . container . bitbucket ;
223
- if ( ! providersApi && ! api ) {
224
- return undefined ;
225
- }
226
-
227
230
const integration = await this . container . integrations . get ( this . id ) ;
228
231
229
- const authoredPrs = providersApi
230
- ? workspaces . map ( async ws => {
231
- const prs = await providersApi . getBitbucketPullRequestsAuthoredByUserForWorkspace (
232
- user . id ,
233
- ws . slug ,
234
- {
235
- accessToken : session . accessToken ,
236
- } ,
237
- ) ;
238
- return prs ?. map ( pr => fromProviderPullRequest ( pr , integration ) ) ;
239
- } )
240
- : [ ] ;
232
+ const authoredPrs = workspaces . map ( async ws => {
233
+ const prs = await api . getBitbucketPullRequestsAuthoredByUserForWorkspace ( user . id , ws . slug , {
234
+ accessToken : session . accessToken ,
235
+ } ) ;
236
+ return prs ?. map ( pr => fromProviderPullRequest ( pr , integration ) ) ;
237
+ } ) ;
241
238
242
239
const reviewingPrs = api
243
- ? workspaceRepos . map ( repo => {
244
- const [ owner , name ] = repo . split ( '/' ) ;
245
- return api . getUsersReviewingPullRequestsForRepo (
246
- this ,
247
- session . accessToken ,
248
- user . id ,
249
- owner ,
250
- name ,
251
- this . apiBaseUrl ,
252
- ) ;
253
- } )
254
- : [ ] ;
240
+ . getPullRequestsForRepos ( this . id , workspaceRepos , {
241
+ query : `state="OPEN" AND reviewers.uuid="${ user . id } "` ,
242
+ accessToken : session . accessToken ,
243
+ } )
244
+ . then ( r => r . values ?. map ( pr => fromProviderPullRequest ( pr , integration ) ) ) ;
255
245
256
246
return [
257
247
...uniqueBy (
258
- await flatSettled ( [ ...authoredPrs , ... reviewingPrs ] ) ,
248
+ await flatSettled ( [ ...authoredPrs , reviewingPrs ] ) ,
259
249
pr => pr . url ,
260
250
( orig , _cur ) => orig ,
261
251
) ,
@@ -346,7 +336,7 @@ export function isBitbucketCloudDomain(domain: string | undefined): boolean {
346
336
return domain != null && bitbucketCloudDomainRegex . test ( domain ) ;
347
337
}
348
338
349
- type MaybePromiseArr < T > = Promise < T | undefined > [ ] | ( T | undefined ) [ ] ;
339
+ type MaybePromiseArr < T > = ( Promise < T | undefined > | T | undefined ) [ ] ;
350
340
351
341
async function nonnullSettled < T > ( arr : MaybePromiseArr < T > ) : Promise < T [ ] > {
352
342
const all = await Promise . allSettled ( arr ) ;
0 commit comments