@@ -7,12 +7,13 @@ import type { Issue, IssueShape } from '../../../git/models/issue';
77import type { IssueOrPullRequest , IssueOrPullRequestType } from '../../../git/models/issueOrPullRequest' ;
88import type { PullRequest , PullRequestMergeMethod , PullRequestState } from '../../../git/models/pullRequest' ;
99import type { RepositoryMetadata } from '../../../git/models/repositoryMetadata' ;
10+ import { groupBy } from '../../../system/iterable' ;
11+ import { getSettledValue } from '../../../system/promise' ;
1012import type { IntegrationAuthenticationProviderDescriptor } from '../authentication/integrationAuthenticationProvider' ;
1113import type { ProviderAuthenticationSession } from '../authentication/models' ;
1214import type { ResourceDescriptor } from '../integration' ;
1315import { HostingIntegration } from '../integration' ;
14- import type { ProviderPullRequest } from './models' ;
15- import { fromProviderPullRequest , providersMetadata } from './models' ;
16+ import { providersMetadata } from './models' ;
1617
1718const metadata = providersMetadata [ HostingIntegrationId . Bitbucket ] ;
1819const authProvider = Object . freeze ( { id : metadata . id , scopes : metadata . scopes } ) ;
@@ -263,7 +264,6 @@ export class BitbucketIntegration extends HostingIntegration<
263264 session : ProviderAuthenticationSession ,
264265 requestedRepositories ?: BitbucketRepositoryDescriptor [ ] ,
265266 ) : Promise < PullRequest [ ] | undefined > {
266- const api = await this . getProvidersApi ( ) ;
267267 if ( requestedRepositories != null ) {
268268 // TODO: implement repos version
269269 return undefined ;
@@ -278,14 +278,24 @@ export class BitbucketIntegration extends HostingIntegration<
278278 const repos = await this . getProviderProjectsForResources ( session , workspaces ) ;
279279 if ( repos == null || repos . length === 0 ) return undefined ;
280280
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- } ,
281+ const api = await this . container . bitbucket ;
282+ if ( ! api ) return undefined ;
283+ const prsResult = await Promise . allSettled (
284+ repos . map ( repo =>
285+ api . getUsersPullRequestsForRepo (
286+ this ,
287+ session . accessToken ,
288+ user . id ,
289+ repo . owner ,
290+ repo . name ,
291+ this . apiBaseUrl ,
292+ ) ,
293+ ) ,
287294 ) ;
288- return prs . values . map ( pr => this . fromBitbucketProviderPullRequest ( pr ) ) ;
295+ return prsResult
296+ . map ( r => getSettledValue ( r ) )
297+ . filter ( r => r != null )
298+ . flat ( ) ;
289299 }
290300
291301 protected override async searchProviderMyIssues (
@@ -295,14 +305,6 @@ export class BitbucketIntegration extends HostingIntegration<
295305 return Promise . resolve ( undefined ) ;
296306 }
297307
298- private fromBitbucketProviderPullRequest (
299- remotePullRequest : ProviderPullRequest ,
300- // repoDescriptors: BitbucketRemoteRepositoryDescriptor[],
301- ) : PullRequest {
302- remotePullRequest . graphQLId = remotePullRequest . id ;
303- return fromProviderPullRequest ( remotePullRequest , this ) ;
304- }
305-
306308 protected override async providerOnConnect ( ) : Promise < void > {
307309 if ( this . _session == null ) return ;
308310
0 commit comments