@@ -12,12 +12,13 @@ import type {
1212 SearchedPullRequest ,
1313} from '../../../git/models/pullRequest' ;
1414import type { RepositoryMetadata } from '../../../git/models/repositoryMetadata' ;
15+ import { groupBy } from '../../../system/iterable' ;
16+ import { getSettledValue } from '../../../system/promise' ;
1517import type { IntegrationAuthenticationProviderDescriptor } from '../authentication/integrationAuthenticationProvider' ;
1618import type { ProviderAuthenticationSession } from '../authentication/models' ;
1719import type { ResourceDescriptor } from '../integration' ;
1820import { HostingIntegration } from '../integration' ;
19- import type { ProviderPullRequest } from './models' ;
20- import { fromProviderPullRequest , providersMetadata } from './models' ;
21+ import { providersMetadata } from './models' ;
2122
2223const metadata = providersMetadata [ HostingIntegrationId . Bitbucket ] ;
2324const authProvider = Object . freeze ( { id : metadata . id , scopes : metadata . scopes } ) ;
@@ -268,7 +269,6 @@ export class BitbucketIntegration extends HostingIntegration<
268269 session : ProviderAuthenticationSession ,
269270 requestedRepositories ?: BitbucketRepositoryDescriptor [ ] ,
270271 ) : Promise < SearchedPullRequest [ ] | undefined > {
271- const api = await this . getProvidersApi ( ) ;
272272 if ( requestedRepositories != null ) {
273273 // TODO: implement repos version
274274 return undefined ;
@@ -283,17 +283,35 @@ export class BitbucketIntegration extends HostingIntegration<
283283 const repos = await this . getProviderProjectsForResources ( session , workspaces ) ;
284284 if ( repos == null || repos . length === 0 ) return undefined ;
285285
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+ ) ,
292299 ) ;
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 ,
295312 reasons : [ ] ,
296313 } ) ) ;
314+ return [ ...authoredPrs , ...otherPrs ] ;
297315 }
298316
299317 protected override async searchProviderMyIssues (
@@ -303,14 +321,6 @@ export class BitbucketIntegration extends HostingIntegration<
303321 return Promise . resolve ( undefined ) ;
304322 }
305323
306- private fromBitbucketProviderPullRequest (
307- remotePullRequest : ProviderPullRequest ,
308- // repoDescriptors: BitbucketRemoteRepositoryDescriptor[],
309- ) : PullRequest {
310- remotePullRequest . graphQLId = remotePullRequest . id ;
311- return fromProviderPullRequest ( remotePullRequest , this ) ;
312- }
313-
314324 protected override async providerOnConnect ( ) : Promise < void > {
315325 if ( this . _session == null ) return ;
316326
0 commit comments