@@ -12,12 +12,13 @@ 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' ;
18
20
import { HostingIntegration } from '../integration' ;
19
- import type { ProviderPullRequest } from './models' ;
20
- import { fromProviderPullRequest , providersMetadata } from './models' ;
21
+ import { providersMetadata } from './models' ;
21
22
22
23
const metadata = providersMetadata [ HostingIntegrationId . Bitbucket ] ;
23
24
const authProvider = Object . freeze ( { id : metadata . id , scopes : metadata . scopes } ) ;
@@ -268,7 +269,6 @@ export class BitbucketIntegration extends HostingIntegration<
268
269
session : ProviderAuthenticationSession ,
269
270
requestedRepositories ?: BitbucketRepositoryDescriptor [ ] ,
270
271
) : Promise < SearchedPullRequest [ ] | undefined > {
271
- const api = await this . getProvidersApi ( ) ;
272
272
if ( requestedRepositories != null ) {
273
273
// TODO: implement repos version
274
274
return undefined ;
@@ -283,17 +283,35 @@ export class BitbucketIntegration extends HostingIntegration<
283
283
const repos = await this . getProviderProjectsForResources ( session , workspaces ) ;
284
284
if ( repos == null || repos . length === 0 ) return undefined ;
285
285
286
- const prs = await api . getPullRequestsForRepos (
287
- HostingIntegrationId . Bitbucket ,
288
- repos . map ( repo => ( { namespace : repo . owner , name : repo . name } ) ) ,
289
- {
290
- accessToken : session . accessToken ,
291
- } ,
286
+ const api = await this . container . bitbucket ;
287
+ if ( ! api ) return undefined ;
288
+ const prsResult = await Promise . allSettled (
289
+ repos . map ( repo =>
290
+ api . getUsersPullRequestsForRepo (
291
+ this ,
292
+ session . accessToken ,
293
+ user . id ,
294
+ repo . owner ,
295
+ repo . name ,
296
+ this . apiBaseUrl ,
297
+ ) ,
298
+ ) ,
292
299
) ;
293
- return prs . values . map ( pr => ( {
294
- pullRequest : this . fromBitbucketProviderPullRequest ( pr ) ,
300
+ const prs = prsResult
301
+ . map ( r => getSettledValue ( r ) )
302
+ . filter ( r => r != null )
303
+ . flat ( ) ;
304
+
305
+ const groups = groupBy ( prs , pr => ( pr . author . id === user . id ? 'authored' : 'other' ) ) ;
306
+ const authoredPrs = groups . authored . map ( pr => ( {
307
+ pullRequest : pr ,
308
+ reasons : [ 'authored' ] ,
309
+ } ) ) ;
310
+ const otherPrs = groups . other . map ( pr => ( {
311
+ pullRequest : pr ,
295
312
reasons : [ ] ,
296
313
} ) ) ;
314
+ return [ ...authoredPrs , ...otherPrs ] ;
297
315
}
298
316
299
317
protected override async searchProviderMyIssues (
@@ -303,14 +321,6 @@ export class BitbucketIntegration extends HostingIntegration<
303
321
return Promise . resolve ( undefined ) ;
304
322
}
305
323
306
- private fromBitbucketProviderPullRequest (
307
- remotePullRequest : ProviderPullRequest ,
308
- // repoDescriptors: BitbucketRemoteRepositoryDescriptor[],
309
- ) : PullRequest {
310
- remotePullRequest . graphQLId = remotePullRequest . id ;
311
- return fromProviderPullRequest ( remotePullRequest , this ) ;
312
- }
313
-
314
324
protected override async providerOnConnect ( ) : Promise < void > {
315
325
if ( this . _session == null ) return ;
316
326
0 commit comments