@@ -7,12 +7,13 @@ import type { Issue, IssueShape } from '../../../git/models/issue';
7
7
import type { IssueOrPullRequest , IssueOrPullRequestType } from '../../../git/models/issueOrPullRequest' ;
8
8
import type { PullRequest , PullRequestMergeMethod , PullRequestState } from '../../../git/models/pullRequest' ;
9
9
import type { RepositoryMetadata } from '../../../git/models/repositoryMetadata' ;
10
+ import { groupBy } from '../../../system/iterable' ;
11
+ import { getSettledValue } from '../../../system/promise' ;
10
12
import type { IntegrationAuthenticationProviderDescriptor } from '../authentication/integrationAuthenticationProvider' ;
11
13
import type { ProviderAuthenticationSession } from '../authentication/models' ;
12
14
import type { ResourceDescriptor } from '../integration' ;
13
15
import { HostingIntegration } from '../integration' ;
14
- import type { ProviderPullRequest } from './models' ;
15
- import { fromProviderPullRequest , providersMetadata } from './models' ;
16
+ import { providersMetadata } from './models' ;
16
17
17
18
const metadata = providersMetadata [ HostingIntegrationId . Bitbucket ] ;
18
19
const authProvider = Object . freeze ( { id : metadata . id , scopes : metadata . scopes } ) ;
@@ -263,7 +264,6 @@ export class BitbucketIntegration extends HostingIntegration<
263
264
session : ProviderAuthenticationSession ,
264
265
requestedRepositories ?: BitbucketRepositoryDescriptor [ ] ,
265
266
) : Promise < PullRequest [ ] | undefined > {
266
- const api = await this . getProvidersApi ( ) ;
267
267
if ( requestedRepositories != null ) {
268
268
// TODO: implement repos version
269
269
return undefined ;
@@ -278,14 +278,24 @@ export class BitbucketIntegration extends HostingIntegration<
278
278
const repos = await this . getProviderProjectsForResources ( session , workspaces ) ;
279
279
if ( repos == null || repos . length === 0 ) return undefined ;
280
280
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
+ ) ,
287
294
) ;
288
- return prs . values . map ( pr => this . fromBitbucketProviderPullRequest ( pr ) ) ;
295
+ return prsResult
296
+ . map ( r => getSettledValue ( r ) )
297
+ . filter ( r => r != null )
298
+ . flat ( ) ;
289
299
}
290
300
291
301
protected override async searchProviderMyIssues (
@@ -295,14 +305,6 @@ export class BitbucketIntegration extends HostingIntegration<
295
305
return Promise . resolve ( undefined ) ;
296
306
}
297
307
298
- private fromBitbucketProviderPullRequest (
299
- remotePullRequest : ProviderPullRequest ,
300
- // repoDescriptors: BitbucketRemoteRepositoryDescriptor[],
301
- ) : PullRequest {
302
- remotePullRequest . graphQLId = remotePullRequest . id ;
303
- return fromProviderPullRequest ( remotePullRequest , this ) ;
304
- }
305
-
306
308
protected override async providerOnConnect ( ) : Promise < void > {
307
309
if ( this . _session == null ) return ;
308
310
0 commit comments