@@ -12,6 +12,8 @@ import type {
12
12
SearchedPullRequest ,
13
13
} from '../../../git/models/pullRequest' ;
14
14
import type { RepositoryMetadata } from '../../../git/models/repositoryMetadata' ;
15
+ import { groupBy } from '../../../system/iterable' ;
16
+ import { getSettledValue } from '../../../system/promise' ;
15
17
import type { IntegrationAuthenticationProviderDescriptor } from '../authentication/integrationAuthenticationProvider' ;
16
18
import type { ProviderAuthenticationSession } from '../authentication/models' ;
17
19
import type { ResourceDescriptor } from '../integration' ;
@@ -263,7 +265,6 @@ export class BitbucketIntegration extends HostingIntegration<
263
265
session : ProviderAuthenticationSession ,
264
266
requestedRepositories ?: BitbucketRepositoryDescriptor [ ] ,
265
267
) : Promise < SearchedPullRequest [ ] | undefined > {
266
- const api = await this . getProvidersApi ( ) ;
267
268
if ( requestedRepositories != null ) {
268
269
// TODO: implement repos version
269
270
return undefined ;
@@ -278,17 +279,30 @@ export class BitbucketIntegration extends HostingIntegration<
278
279
const repos = await this . getProviderProjectsForResources ( session , workspaces ) ;
279
280
if ( repos == null || repos . length === 0 ) return undefined ;
280
281
281
- const prs = await api . getPullRequestsForRepos (
282
- HostingIntegrationId . Bitbucket ,
283
- repos . map ( repo => ( { namespace : repo . owner , name : repo . name } ) ) ,
284
- {
285
- accessToken : session . accessToken ,
286
- } ,
282
+ const api = await this . container . bitbucket ;
283
+ if ( ! api ) return undefined ;
284
+ const prsResult = await Promise . allSettled (
285
+ repos . map ( repo =>
286
+ api . getUsersPullRequestsForRepo ( this , session . accessToken , user . id , repo . owner , repo . name , {
287
+ baseUrl : this . apiBaseUrl ,
288
+ } ) ,
289
+ ) ,
287
290
) ;
288
- return prs . values . map ( pr => ( {
289
- pullRequest : this . fromBitbucketProviderPullRequest ( pr ) ,
291
+ const prs = prsResult
292
+ . map ( r => getSettledValue ( r ) )
293
+ . filter ( r => r != null )
294
+ . flat ( ) ;
295
+
296
+ const groups = groupBy ( prs , pr => ( pr . author . id === user . id ? 'authored' : 'other' ) ) ;
297
+ const authoredPrs = groups . authored . map ( pr => ( {
298
+ pullRequest : pr ,
299
+ reasons : [ 'authored' ] ,
300
+ } ) ) ;
301
+ const otherPrs = groups . other . map ( pr => ( {
302
+ pullRequest : pr ,
290
303
reasons : [ ] ,
291
304
} ) ) ;
305
+ return [ ...authoredPrs , ...otherPrs ] ;
292
306
}
293
307
294
308
protected override async searchProviderMyIssues (
@@ -298,14 +312,6 @@ export class BitbucketIntegration extends HostingIntegration<
298
312
return Promise . resolve ( undefined ) ;
299
313
}
300
314
301
- private fromBitbucketProviderPullRequest (
302
- remotePullRequest : ProviderPullRequest ,
303
- // repoDescriptors: BitbucketRemoteRepositoryDescriptor[],
304
- ) : PullRequest {
305
- remotePullRequest . graphQLId = remotePullRequest . id ;
306
- return fromProviderPullRequest ( remotePullRequest , this ) ;
307
- }
308
-
309
315
protected override async providerOnConnect ( ) : Promise < void > {
310
316
if ( this . _session == null ) return ;
311
317
0 commit comments