@@ -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,42 +227,23 @@ 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
- const authoredPrs = providersApi
228
- ? workspaces . map ( async ws => {
229
- const prs = await providersApi . getBitbucketPullRequestsAuthoredByUserForWorkspace (
230
- user . id ,
231
- ws . slug ,
232
- {
233
- accessToken : session . accessToken ,
234
- } ,
235
- ) ;
236
- return prs ?. map ( pr => fromProviderPullRequest ( pr , this ) ) ;
237
- } )
238
- : [ ] ;
230
+ const authoredPrs = workspaces . map ( async ws => {
231
+ const prs = await api . getBitbucketPullRequestsAuthoredByUserForWorkspace ( user . id , ws . slug , {
232
+ accessToken : session . accessToken ,
233
+ } ) ;
234
+ return prs ?. map ( pr => fromProviderPullRequest ( pr , this ) ) ;
235
+ } ) ;
239
236
240
237
const reviewingPrs = api
241
- ? workspaceRepos . map ( repo => {
242
- const [ owner , name ] = repo . split ( '/' ) ;
243
- return api . getUsersReviewingPullRequestsForRepo (
244
- this ,
245
- session . accessToken ,
246
- user . id ,
247
- owner ,
248
- name ,
249
- this . apiBaseUrl ,
250
- ) ;
251
- } )
252
- : [ ] ;
238
+ . getPullRequestsForRepos ( this . id , workspaceRepos , {
239
+ query : `state="OPEN" AND reviewers.uuid="${ user . id } "` ,
240
+ accessToken : session . accessToken ,
241
+ } )
242
+ . then ( r => r . values ?. map ( pr => fromProviderPullRequest ( pr , this ) ) ) ;
253
243
254
244
return [
255
245
...uniqueBy (
256
- await flatSettled ( [ ...authoredPrs , ... reviewingPrs ] ) ,
246
+ await flatSettled ( [ ...authoredPrs , reviewingPrs ] ) ,
257
247
pr => pr . url ,
258
248
( orig , _cur ) => orig ,
259
249
) ,
@@ -344,7 +334,7 @@ export function isBitbucketCloudDomain(domain: string | undefined): boolean {
344
334
return domain != null && bitbucketCloudDomainRegex . test ( domain ) ;
345
335
}
346
336
347
- type MaybePromiseArr < T > = Promise < T | undefined > [ ] | ( T | undefined ) [ ] ;
337
+ type MaybePromiseArr < T > = ( Promise < T | undefined > | T | undefined ) [ ] ;
348
338
349
339
async function nonnullSettled < T > ( arr : MaybePromiseArr < T > ) : Promise < T [ ] > {
350
340
const all = await Promise . allSettled ( arr ) ;
0 commit comments