@@ -207,9 +207,18 @@ export class BitbucketIntegration extends HostingIntegration<
207207 return undefined ;
208208 }
209209
210+ const api = await this . getProvidersApi ( ) ;
211+ if ( ! api ) {
212+ return undefined ;
213+ }
214+
210215 const remotes = await flatSettled ( this . container . git . openRepositories . map ( r => r . git . remotes ( ) . getRemotes ( ) ) ) ;
211216 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+ } ) ,
213222 ) ;
214223
215224 const user = await this . getProviderCurrentAccount ( session ) ;
@@ -218,44 +227,25 @@ export class BitbucketIntegration extends HostingIntegration<
218227 const workspaces = await this . getProviderResourcesForUser ( session ) ;
219228 if ( workspaces == null || workspaces . length === 0 ) return undefined ;
220229
221- const providersApi = await this . getProvidersApi ( ) ;
222- const api = await this . container . bitbucket ;
223- if ( ! providersApi && ! api ) {
224- return undefined ;
225- }
226-
227230 const integration = await this . container . integrations . get ( this . id ) ;
228231
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+ } ) ;
241238
242239 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 ) ) ) ;
255245
256246 return [
257247 ...uniqueBy (
258- await flatSettled ( [ ...authoredPrs , ... reviewingPrs ] ) ,
248+ await flatSettled ( [ ...authoredPrs , reviewingPrs ] ) ,
259249 pr => pr . url ,
260250 ( orig , _cur ) => orig ,
261251 ) ,
@@ -346,7 +336,7 @@ export function isBitbucketCloudDomain(domain: string | undefined): boolean {
346336 return domain != null && bitbucketCloudDomainRegex . test ( domain ) ;
347337}
348338
349- type MaybePromiseArr < T > = Promise < T | undefined > [ ] | ( T | undefined ) [ ] ;
339+ type MaybePromiseArr < T > = ( Promise < T | undefined > | T | undefined ) [ ] ;
350340
351341async function nonnullSettled < T > ( arr : MaybePromiseArr < T > ) : Promise < T [ ] > {
352342 const all = await Promise . allSettled ( arr ) ;
0 commit comments