@gitkraken/core-gitlens 0.7.0 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -2
- package/dist/git/remotes/azure-devops.js +3 -3
- package/dist/git/remotes/azure-devops.js.map +1 -1
- package/dist/plus/integrations/authentication/configuredIntegrationService.js +9 -2
- package/dist/plus/integrations/authentication/configuredIntegrationService.js.map +1 -1
- package/dist/plus/integrations/authentication/integrationAuthenticationProvider.js +1 -1
- package/dist/plus/integrations/collectionMetadata.d.ts +48 -3
- package/dist/plus/integrations/collectionMetadata.js +138 -8
- package/dist/plus/integrations/collectionMetadata.js.map +1 -1
- package/dist/plus/integrations/errors.d.ts +3 -1
- package/dist/plus/integrations/errors.js +7 -3
- package/dist/plus/integrations/errors.js.map +1 -1
- package/dist/plus/integrations/index.d.ts +3 -3
- package/dist/plus/integrations/index.js.map +1 -1
- package/dist/plus/integrations/integrationService.d.ts +35 -1
- package/dist/plus/integrations/integrationService.js +90 -43
- package/dist/plus/integrations/integrationService.js.map +1 -1
- package/dist/plus/integrations/lite.js +5 -4
- package/dist/plus/integrations/lite.js.map +1 -1
- package/dist/plus/integrations/manager.d.ts +68 -23
- package/dist/plus/integrations/models/gitHostIntegration.d.ts +31 -15
- package/dist/plus/integrations/models/gitHostIntegration.js +71 -22
- package/dist/plus/integrations/models/gitHostIntegration.js.map +1 -1
- package/dist/plus/integrations/models/integration.d.ts +70 -12
- package/dist/plus/integrations/models/integration.js +56 -1
- package/dist/plus/integrations/models/integration.js.map +1 -1
- package/dist/plus/integrations/models/issueReads.d.ts +17 -0
- package/dist/plus/integrations/models/issuesIntegration.js +2 -0
- package/dist/plus/integrations/models/issuesIntegration.js.map +1 -1
- package/dist/plus/integrations/models/pullRequestReads.d.ts +26 -0
- package/dist/plus/integrations/providers/azure/azure.d.ts +66 -1
- package/dist/plus/integrations/providers/azure/azure.js +192 -12
- package/dist/plus/integrations/providers/azure/azure.js.map +1 -1
- package/dist/plus/integrations/providers/azure/search.d.ts +144 -0
- package/dist/plus/integrations/providers/azure/search.js +250 -0
- package/dist/plus/integrations/providers/azure/search.js.map +1 -0
- package/dist/plus/integrations/providers/azureDevOps.d.ts +73 -36
- package/dist/plus/integrations/providers/azureDevOps.js +191 -122
- package/dist/plus/integrations/providers/azureDevOps.js.map +1 -1
- package/dist/plus/integrations/providers/azureDevOpsServer.d.ts +176 -0
- package/dist/plus/integrations/providers/azureDevOpsServer.js +560 -0
- package/dist/plus/integrations/providers/azureDevOpsServer.js.map +1 -0
- package/dist/plus/integrations/providers/bitbucket-server/discovery.d.ts +12 -0
- package/dist/plus/integrations/providers/bitbucket-server/discovery.js +128 -0
- package/dist/plus/integrations/providers/bitbucket-server/discovery.js.map +1 -0
- package/dist/plus/integrations/providers/bitbucket-server/models.d.ts +10 -1
- package/dist/plus/integrations/providers/bitbucket-server/models.js +3 -2
- package/dist/plus/integrations/providers/bitbucket-server/models.js.map +1 -1
- package/dist/plus/integrations/providers/bitbucket-server/pullRequestSearch.d.ts +58 -0
- package/dist/plus/integrations/providers/bitbucket-server/pullRequestSearch.js +485 -0
- package/dist/plus/integrations/providers/bitbucket-server/pullRequestSearch.js.map +1 -0
- package/dist/plus/integrations/providers/bitbucket-server.d.ts +61 -3
- package/dist/plus/integrations/providers/bitbucket-server.js +114 -20
- package/dist/plus/integrations/providers/bitbucket-server.js.map +1 -1
- package/dist/plus/integrations/providers/bitbucket.d.ts +9 -1
- package/dist/plus/integrations/providers/bitbucket.js +13 -2
- package/dist/plus/integrations/providers/bitbucket.js.map +1 -1
- package/dist/plus/integrations/providers/github.d.ts +6 -6
- package/dist/plus/integrations/providers/github.js +35 -34
- package/dist/plus/integrations/providers/github.js.map +1 -1
- package/dist/plus/integrations/providers/gitlab.d.ts +6 -4
- package/dist/plus/integrations/providers/gitlab.js +32 -28
- package/dist/plus/integrations/providers/gitlab.js.map +1 -1
- package/dist/plus/integrations/providers/issueSorts.d.ts +1 -0
- package/dist/plus/integrations/providers/jira-server.d.ts +9 -0
- package/dist/plus/integrations/providers/jira-server.js +15 -7
- package/dist/plus/integrations/providers/jira-server.js.map +1 -1
- package/dist/plus/integrations/providers/jira.d.ts +9 -0
- package/dist/plus/integrations/providers/jira.js +14 -2
- package/dist/plus/integrations/providers/jira.js.map +1 -1
- package/dist/plus/integrations/providers/linear.js +2 -2
- package/dist/plus/integrations/providers/models.d.ts +10 -1
- package/dist/plus/integrations/providers/models.js +86 -0
- package/dist/plus/integrations/providers/models.js.map +1 -1
- package/dist/plus/integrations/providers/providersApi.d.ts +10 -0
- package/dist/plus/integrations/providers/providersApi.js +18 -3
- package/dist/plus/integrations/providers/providersApi.js.map +1 -1
- package/dist/plus/integrations/providers/utils.d.ts +12 -1
- package/dist/plus/integrations/providers/utils.js +36 -6
- package/dist/plus/integrations/providers/utils.js.map +1 -1
- package/dist/plus/integrations/reads/broaden.js +6 -6
- package/dist/plus/integrations/reads/broaden.js.map +1 -1
- package/dist/plus/integrations/reads/context.d.ts +1 -1
- package/dist/plus/integrations/reads/counts.d.ts +18 -4
- package/dist/plus/integrations/reads/counts.js +66 -15
- package/dist/plus/integrations/reads/counts.js.map +1 -1
- package/dist/plus/integrations/reads/cursors.js +1 -1
- package/dist/plus/integrations/reads/drains.d.ts +2 -1
- package/dist/plus/integrations/reads/drains.js +1 -1
- package/dist/plus/integrations/reads/filters.d.ts +1 -1
- package/dist/plus/integrations/reads/filters.js +17 -12
- package/dist/plus/integrations/reads/filters.js.map +1 -1
- package/dist/plus/integrations/reads/hierarchy.js +2 -2
- package/dist/plus/integrations/reads/hierarchy.js.map +1 -1
- package/dist/plus/integrations/reads/hierarchy.utils.js +1 -1
- package/dist/plus/integrations/reads/issueBatch.js +1 -1
- package/dist/plus/integrations/reads/issueTracker.js +2 -2
- package/dist/plus/integrations/reads/issues.js +2 -2
- package/dist/plus/integrations/reads/paging.js +1 -1
- package/dist/plus/integrations/reads/resolveRepository.d.ts +12 -11
- package/dist/plus/integrations/reads/resolveRepository.js +110 -19
- package/dist/plus/integrations/reads/resolveRepository.js.map +1 -1
- package/dist/plus/integrations/reads/searchIssues.js +4 -2
- package/dist/plus/integrations/reads/searchIssues.js.map +1 -1
- package/dist/plus/integrations/reads/searchPullRequests.js +9 -3
- package/dist/plus/integrations/reads/searchPullRequests.js.map +1 -1
- package/dist/plus/integrations/reads/sweeps.js +1 -1
- package/dist/plus/integrations/reads/trackerIssue.d.ts +9 -5
- package/dist/plus/integrations/reads/trackerIssue.js +15 -9
- package/dist/plus/integrations/reads/trackerIssue.js.map +1 -1
- package/dist/plus/integrations/reads/warnings.d.ts +6 -2
- package/dist/plus/integrations/reads/warnings.js +15 -19
- package/dist/plus/integrations/reads/warnings.js.map +1 -1
- package/dist/plus/integrations/results.d.ts +84 -6
- package/dist/plus/integrations/results.js +9 -2
- package/dist/plus/integrations/results.js.map +1 -1
- package/dist/plus/integrations/utils/domain.utils.d.ts +19 -0
- package/dist/plus/integrations/utils/domain.utils.js +36 -1
- package/dist/plus/integrations/utils/domain.utils.js.map +1 -1
- package/dist/plus/integrations/utils/integration.utils.d.ts +1 -0
- package/dist/plus/integrations/utils/integration.utils.js +12 -1
- package/dist/plus/integrations/utils/integration.utils.js.map +1 -1
- package/docs/integrations.md +263 -74
- package/docs/kepler-read-api-parity.md +19 -6
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"azureDevOpsServer.js","names":[],"sources":["../../../../../plus/integrations/src/providers/azureDevOpsServer.ts"],"sourcesContent":["import type { Account } from '@gitlens/git/models/author.js';\nimport type { IssueSearchCriteria } from '@gitlens/git/models/issue.js';\nimport type { PullRequest, PullRequestSearchCriteria, PullRequestSorting } from '@gitlens/git/models/pullRequest.js';\nimport { defaultPullRequestSort } from '@gitlens/git/models/pullRequest.js';\nimport { CancellationError } from '@gitlens/utils/cancellation.js';\nimport { uuid } from '@gitlens/utils/crypto.js';\nimport type { Emitter } from '@gitlens/utils/event.js';\nimport { mapBounded } from '@gitlens/utils/promise.js';\nimport { PromiseCache } from '@gitlens/utils/promiseCache.js';\nimport type { IntegrationAuthenticationProviderDescriptor } from '../authentication/integrationAuthenticationProvider.js';\nimport type { IntegrationAuthenticationService } from '../authentication/integrationAuthenticationService.js';\nimport type { ProviderAuthenticationSession, TokenWithInfo } from '../authentication/models.js';\nimport { toTokenWithInfo } from '../authentication/models.js';\nimport { GitSelfManagedHostIntegrationId, providerFanOutConcurrency } from '../constants.js';\nimport type { IntegrationServiceContext } from '../context.js';\nimport { IntegrationReadUnavailableError, RequestNotFoundError } from '../errors.js';\nimport type { IntegrationConnectionChangeEvent } from '../integrationService.js';\nimport type {\n\tIntegrationKey,\n\tProviderIssueSearchPage,\n\tProviderPullRequestCount,\n\tProviderPullRequestSearchPage,\n\tProviderSearchCount,\n} from '../models/integration.js';\nimport type { AzureOrganizationDescriptor, AzureProjectDescriptor } from './azure/models.js';\nimport type { AzurePullRequestSearchPosition } from './azure/search.js';\nimport {\n\tcompareAzurePullRequestSearchPositions,\n\tgetInvalidAzureSearchDate,\n\tisAzureWorkItemSearchFirstPage,\n\tparseAzurePullRequestSearchCursor,\n\ttoAzurePullRequestSearchCursorKey,\n\ttoAzurePullRequestSearchFilter,\n\ttoAzurePullRequestSearchPosition,\n\ttoAzureSearchPageSize,\n} from './azure/search.js';\nimport {\n\tAzureDevOpsIntegrationBase,\n\tgetAzureRepositoryApiBaseUrl,\n\tgetAzureRepositoryIdentity,\n\tsameAzureName,\n\tuniqueAzureNames,\n} from './azureDevOps.js';\nimport type {\n\tProviderApiCollectionResult,\n\tProviderAzureResource,\n\tProviderPullRequest,\n\tProviderRepoInput,\n\tProviderReposInput,\n} from './models.js';\nimport {\n\tfromProviderPullRequest,\n\tgetProviderPullRequestIdentity,\n\tprovidersMetadata,\n\tPullRequestFilter,\n\ttoProviderPullRequestStates,\n} from './models.js';\nimport type { ProvidersApi } from './providersApi.js';\n\n/**\n * Whether `value` can stand as one route segment. Encoding keeps `.` and `..` as they are, and a URL resolves them\n * as directory steps, so a name of either would address a different route than the one named.\n */\nfunction isAzureRouteSegment(value: string): boolean {\n\treturn value.length > 0 && value !== '.' && value !== '..';\n}\n\n/**\n * Runs one scope of a count probe, answering a refusal of THAT scope (see `searchUnavailable`) as the error itself,\n * which the facade reports and drops without failing the scopes around it. Anything else — a rejected credential,\n * a failed request — still rejects, so the batch reports it.\n */\nasync function refusalAsCount<T>(count: () => Promise<T>): Promise<T | IntegrationReadUnavailableError> {\n\ttry {\n\t\treturn await count();\n\t} catch (ex) {\n\t\tif (ex instanceof IntegrationReadUnavailableError) return ex;\n\n\t\tthrow ex;\n\t}\n}\n\nfunction findAzureCollection(\n\tcollections: readonly AzureOrganizationDescriptor[],\n\tname: string,\n): AzureOrganizationDescriptor | undefined {\n\treturn collections.find(c => sameAzureName(c.name, name) || c.id === name);\n}\n\n/**\n * The most pull requests one facet of a filtered pull-request search drains. Azure has no server-side text, date or\n * draft filter and no ordering, so a facet is read in full before any of them apply; past this bound the facet's\n * unread rows could sort anywhere, and the search reports itself truncated instead of guessing.\n */\nconst azurePullRequestSearchFacetLimit = 1000;\n\n/**\n * The page size a facet drain reads. The SDK's own default for both pull request reads, and the size it sizes\n * `$skip` by, so the budget above counts what was actually read.\n */\nconst azurePullRequestSearchPageSize = 100;\n\n/**\n * How many scopes of one work-item count batch query at once. The facade already runs several batches concurrently,\n * so this multiplies with it: kept small, so a large count preview can't flood a self-hosted server.\n */\nconst azureIssueCountConcurrency = 2;\n\n/**\n * How long a drained pull-request search keeps serving its continuation pages after the last one was read, and the\n * most it lives however actively it is paged. A pagination that keeps reading stays on one consistent drain; one\n * left idle, or paged for longer than that, is read again.\n */\nconst pullRequestSearchIdleTtl = 5 * 60 * 1000;\nconst pullRequestSearchMaxTtl = 30 * 60 * 1000;\n\n/**\n * How long a count reuses the drain a search of its query just read. Long enough for a count shown next to the\n * search it previews to agree with it, short enough that a count polled next to an unapplied filter stays live: the\n * window runs from the drain, not from the last count, so polling never extends it.\n */\nconst pullRequestCountReuseTtl = 60 * 1000;\n\ninterface AzurePullRequestSearchRow {\n\tpr: PullRequest;\n\tposition: AzurePullRequestSearchPosition;\n}\n\ninterface AzurePullRequestSearchDrain {\n\trows: AzurePullRequestSearchRow[];\n\ttruncated: boolean;\n}\n\n/**\n * Everything that decides a pull-request search's result set and order, as the value its cursor is fingerprinted\n * from. `pageSize` is left out on purpose: it only decides where a page ends, which the keyset cursor already\n * carries.\n */\nfunction toPullRequestSearchQuery(\n\toptions: { repos?: ProviderRepoInput[]; org?: string; criteria?: PullRequestSearchCriteria },\n\tsort: PullRequestSorting,\n): unknown {\n\tconst criteria = options.criteria;\n\treturn {\n\t\trepos: options.repos?.map(r => [r.namespace, r.project ?? null, r.name]),\n\t\torg: options.org ?? null,\n\t\trelationships: [...new Set(criteria?.relationships ?? [])].sort(),\n\t\tstates: [...new Set(criteria?.states ?? [])].sort(),\n\t\ttext: criteria?.text?.trim() ?? null,\n\t\tdraft: criteria?.draft ?? null,\n\t\tupdatedAfter: criteria?.updatedAfter ?? null,\n\t\tcreatedAfter: criteria?.createdAfter ?? null,\n\t\tsort: sort,\n\t};\n}\n\nconst serverMetadata = providersMetadata[GitSelfManagedHostIntegrationId.AzureDevOpsServer];\nconst serverAuthProvider = Object.freeze({ id: serverMetadata.id, scopes: serverMetadata.scopes });\n\nexport class AzureDevOpsServerIntegration extends AzureDevOpsIntegrationBase<GitSelfManagedHostIntegrationId.AzureDevOpsServer> {\n\treadonly authProvider: IntegrationAuthenticationProviderDescriptor = serverAuthProvider;\n\treadonly id = GitSelfManagedHostIntegrationId.AzureDevOpsServer;\n\tprotected readonly key: IntegrationKey<GitSelfManagedHostIntegrationId.AzureDevOpsServer>;\n\treadonly name: string = 'Azure DevOps Server';\n\n\tconstructor(\n\t\tctx: IntegrationServiceContext,\n\t\tauthenticationService: IntegrationAuthenticationService,\n\t\tgetProvidersApi: () => Promise<ProvidersApi>,\n\t\tdidChangeConnection: Emitter<IntegrationConnectionChangeEvent>,\n\t\treadonly domain: string,\n\t) {\n\t\tsuper(ctx, authenticationService, getProvidersApi, didChangeConnection);\n\t\tthis.key = `${this.id}:${this.domain}`;\n\t}\n\n\tprotected override apiBaseUrlFor(session: ProviderAuthenticationSession): string {\n\t\treturn this.getSelfManagedApiBaseUrl(session);\n\t}\n\n\t/**\n\t * The credential AND the installation it is used against: one integration instance serves every installation on\n\t * its host (context paths differ, the host doesn't), and the same token connected to two of them must not reuse\n\t * one installation's collections or projects on the other.\n\t */\n\tprotected override discoveryKey(session: ProviderAuthenticationSession): string {\n\t\treturn `${session.accessToken}:${this.apiBaseUrlFor(session)}`;\n\t}\n\n\tprotected override getRepositoriesApiBaseUrl(\n\t\tsession: ProviderAuthenticationSession,\n\t\trepos: ProviderReposInput,\n\t): string {\n\t\t// Requests append each repository's organization (its collection), which an address naming that collection\n\t\t// already ends with. Only repositories of a single organization can share one base; mixed ones keep the\n\t\t// address, so another collection's repository stays below it (see `resolveRepository`).\n\t\tconst owners = new Set(repos.map(r => (typeof r === 'object' ? r.namespace : undefined)));\n\t\tconst [owner] = owners;\n\t\tconst baseUrl = this.apiBaseUrlFor(session);\n\t\treturn owners.size === 1 && owner != null\n\t\t\t? getAzureRepositoryApiBaseUrl(baseUrl, { owner: owner, virtualDirectory: undefined })\n\t\t\t: baseUrl;\n\t}\n\n\tprotected override getApiOptions(\n\t\tsession: ProviderAuthenticationSession,\n\t\tdoNotConvertToPat: boolean = false,\n\t): {\n\t\ttokenWithInfo: TokenWithInfo<GitSelfManagedHostIntegrationId.AzureDevOpsServer>;\n\t\toptions: { isPAT: boolean; baseUrl?: string };\n\t} {\n\t\tconst { options, ...rest } = super.getApiOptions(session, doNotConvertToPat);\n\t\treturn {\n\t\t\t...rest,\n\t\t\toptions: { ...options, baseUrl: this.apiBaseUrlFor(session) },\n\t\t};\n\t}\n\n\tprotected override getCollectionApiOptions(\n\t\tsession: ProviderAuthenticationSession,\n\t\tcollection: string,\n\t): { isPAT: boolean; baseUrl?: string } {\n\t\treturn {\n\t\t\t...super.getCollectionApiOptions(session, collection),\n\t\t\tbaseUrl: this.collectionApiBaseUrl(session, collection),\n\t\t};\n\t}\n\n\t/** The base a request below `collection` appends to: the installation, whichever the address already ends in. */\n\tprotected override collectionApiBaseUrl(session: ProviderAuthenticationSession, collection: string): string {\n\t\treturn getAzureRepositoryApiBaseUrl(this.apiBaseUrlFor(session), {\n\t\t\towner: collection,\n\t\t\tvirtualDirectory: undefined,\n\t\t});\n\t}\n\n\t/**\n\t * Only the server level lists the collections: below one, Azure DevOps Server answers `projectCollections` with a\n\t * 404 page. On that 404 an address that names a collection reads the collection's own connection data, whose\n\t * `webApplicationRelativeDirectory` spells it, and reports it as the one collection visible there.\n\t */\n\tprotected override async requestResourcesForUser(\n\t\tsession: ProviderAuthenticationSession,\n\t\tuserId: string,\n\t): Promise<ProviderAzureResource[] | undefined> {\n\t\ttry {\n\t\t\treturn await super.requestResourcesForUser(session, userId);\n\t\t} catch (ex) {\n\t\t\tif (!(ex instanceof RequestNotFoundError)) throw ex;\n\n\t\t\tconst azure = await this.authenticationService.apis.azure;\n\t\t\tconst addressed = await azure?.getAddressedCollection(\n\t\t\t\tthis,\n\t\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\t\tthis.apiBaseUrlFor(session),\n\t\t\t);\n\t\t\tif (addressed == null) throw ex;\n\n\t\t\treturn [addressed];\n\t\t}\n\t}\n\n\t/**\n\t * The filtered work-item search: one WIQL query per page over ONE collection, then one detail read for the\n\t * page's slice. See {@link resolveWorkItemSearchScope} for why a search never spans several collections.\n\t */\n\tprotected override async searchProviderIssuesPage(\n\t\tsession: ProviderAuthenticationSession,\n\t\toptions: {\n\t\t\trepos?: ProviderRepoInput[];\n\t\t\torg?: string;\n\t\t\tcriteria?: IssueSearchCriteria;\n\t\t\tcursor?: string;\n\t\t\tpageSize?: number;\n\t\t},\n\t\tcancellation?: AbortSignal,\n\t): Promise<ProviderIssueSearchPage | undefined> {\n\t\tconst azure = await this.authenticationService.apis.azure;\n\t\tif (azure == null) return undefined;\n\n\t\tthis.assertSearchDates(options.criteria);\n\t\t// A first page re-reads the collection's projects, so a project created since discovery is known before its\n\t\t// work items can turn up in a collection-wide query; a continuation keeps the set its first page resolved.\n\t\t// The facade's page-1 marker (`broadenIssues` retries a failed first page with it) is a first page too.\n\t\tconst scope = await this.resolveWorkItemSearchScope(\n\t\t\tsession,\n\t\t\toptions.repos,\n\t\t\toptions.org,\n\t\t\tisAzureWorkItemSearchFirstPage(options.cursor),\n\t\t);\n\t\treturn azure.searchWorkItemsPage(\n\t\t\tthis,\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\tscope.collection,\n\t\t\t{\n\t\t\t\tbaseUrl: this.collectionApiBaseUrl(session, scope.collection),\n\t\t\t\tcriteria: options.criteria,\n\t\t\t\tprojectNames: scope.projectNames,\n\t\t\t\tresolveProject: name => scope.projects.find(p => sameAzureName(p.name, name)),\n\t\t\t\tcursor: options.cursor,\n\t\t\t\tpageSize: options.pageSize,\n\t\t\t},\n\t\t\tcancellation,\n\t\t);\n\t}\n\n\t/**\n\t * Counts each scope with the WIQL its search would page through, so a count never previews constraints the read\n\t * doesn't apply. A scope this provider refuses (see {@link resolveWorkItemSearchScope}) is answered as that\n\t * refusal, so the facade drops only it; a request failure still fails the batch, which the facade isolates from\n\t * the other batches.\n\t */\n\tprotected override async countProviderIssues(\n\t\tsession: ProviderAuthenticationSession,\n\t\tscopes: readonly { repos?: ProviderRepoInput[]; org?: string; criteria?: IssueSearchCriteria }[],\n\t\tcancellation?: AbortSignal,\n\t): Promise<ProviderSearchCount[] | undefined> {\n\t\tconst azure = await this.authenticationService.apis.azure;\n\t\tif (azure == null) return undefined;\n\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\t\treturn mapBounded(scopes, azureIssueCountConcurrency, s =>\n\t\t\trefusalAsCount(async () => {\n\t\t\t\tthis.assertSearchDates(s.criteria);\n\t\t\t\t// Re-reads the projects like a first search page does, so a count and the page it previews resolve\n\t\t\t\t// the same project set — a newer project can't be counted by one and refused or missed by the other.\n\t\t\t\tconst scope = await this.resolveWorkItemSearchScope(session, s.repos, s.org, true);\n\t\t\t\treturn azure.countWorkItems(\n\t\t\t\t\tthis,\n\t\t\t\t\ttokenWithInfo,\n\t\t\t\t\tscope.collection,\n\t\t\t\t\t{\n\t\t\t\t\t\tbaseUrl: this.collectionApiBaseUrl(session, scope.collection),\n\t\t\t\t\t\tcriteria: s.criteria,\n\t\t\t\t\t\tprojectNames: scope.projectNames,\n\t\t\t\t\t},\n\t\t\t\t\tcancellation,\n\t\t\t\t);\n\t\t\t}),\n\t\t);\n\t}\n\n\t/**\n\t * The ONE collection a work-item search runs in, and the projects that bound it.\n\t *\n\t * A WIQL query is collection-scoped, and ordering a union of several would need every match's details rather\n\t * than one page's, so a search never spans collections. `org` names the collection; without it the repositories'\n\t * collection is used, and without either the only collection the account can see. Anything else — repositories\n\t * in two collections, or several visible collections and nothing to choose one — is refused rather than\n\t * narrowed to whichever came first.\n\t *\n\t * Repositories bound the query by their PROJECT, since Azure work items belong to projects rather than to\n\t * repositories, and every project must be one the collection actually has: WIQL answers an unknown project name\n\t * with an empty result, which would read as \"nothing matched\".\n\t */\n\tprivate async resolveWorkItemSearchScope(\n\t\tsession: ProviderAuthenticationSession,\n\t\trepos: ProviderRepoInput[] | undefined,\n\t\torg: string | undefined,\n\t\trefreshProjects: boolean = false,\n\t): Promise<{ collection: string; projects: AzureProjectDescriptor[]; projectNames?: string[] }> {\n\t\tconst repoCollections = uniqueAzureNames(repos?.map(r => r.namespace) ?? []);\n\t\tif (repoCollections.length > 1) {\n\t\t\tthrow this.searchUnavailable(\n\t\t\t\t'the repositories span several collections; search each collection separately',\n\t\t\t);\n\t\t}\n\t\tif (org && repoCollections.length === 1 && !sameAzureName(org, repoCollections[0])) {\n\t\t\tthrow this.searchUnavailable(`the repositories are not in the '${org}' collection`);\n\t\t}\n\n\t\tconst collections = await this.getSearchCollections(session);\n\t\tconst name = org || repoCollections[0] || (collections.length === 1 ? collections[0].name : undefined);\n\t\tif (name == null) {\n\t\t\tthrow this.searchUnavailable(\n\t\t\t\t`the account can see ${collections.length} collections; pass \\`org\\` to choose the one to search`,\n\t\t\t);\n\t\t}\n\n\t\tconst collection = findAzureCollection(collections, name);\n\t\tif (collection == null) throw this.searchUnavailable(`the '${name}' collection is not visible`);\n\n\t\tconst projects = await this.getSearchProjects(session, collection, refreshProjects);\n\t\tif (!repos?.length) return { collection: collection.name, projects: projects };\n\n\t\tconst projectNames = uniqueAzureNames(\n\t\t\trepos.map(r => {\n\t\t\t\tconst projectName = getAzureRepositoryIdentity({\n\t\t\t\t\towner: r.namespace,\n\t\t\t\t\tname: r.name,\n\t\t\t\t\tproject: r.project,\n\t\t\t\t}).projectName;\n\t\t\t\tif (projectName == null) {\n\t\t\t\t\tthrow this.searchUnavailable(`repository '${r.namespace}/${r.name}' names no project`);\n\t\t\t\t}\n\n\t\t\t\tconst project = projects.find(p => sameAzureName(p.name, projectName));\n\t\t\t\tif (project == null) {\n\t\t\t\t\tthrow this.searchUnavailable(`project '${projectName}' is not visible in '${collection.name}'`);\n\t\t\t\t}\n\n\t\t\t\treturn project.name;\n\t\t\t}),\n\t\t);\n\t\treturn { collection: collection.name, projects: projects, projectNames: projectNames };\n\t}\n\n\t/**\n\t * The filtered pull-request search. Azure's pull request query can only narrow by creator, reviewer, status and\n\t * repository, so every facet is drained (see {@link drainPullRequestSearch}) and the criteria it can't express\n\t * are applied to the complete facets; the union is then ordered and served from a keyset cursor.\n\t */\n\tprotected override async searchProviderPullRequestsPage(\n\t\tsession: ProviderAuthenticationSession,\n\t\toptions: {\n\t\t\trepos?: ProviderRepoInput[];\n\t\t\torg?: string;\n\t\t\tcriteria?: PullRequestSearchCriteria;\n\t\t\tcursor?: string;\n\t\t\tpageSize?: number;\n\t\t\tsummary?: boolean;\n\t\t},\n\t\tcancellation?: AbortSignal,\n\t): Promise<ProviderPullRequestSearchPage | undefined> {\n\t\tthis.assertSearchDates(options.criteria);\n\t\tconst sort = options.criteria?.sort ?? defaultPullRequestSort;\n\t\tconst query = toPullRequestSearchQuery(options, sort);\n\t\tconst key = toAzurePullRequestSearchCursorKey(query);\n\t\tconst cursor = parseAzurePullRequestSearchCursor(options.cursor, key);\n\t\t// A first page drains fresh, into a drain of its own, and its continuations page through that one: the cache\n\t\t// keeps it alive for as long as the pagination keeps reading it (an access TTL), so rows can't move between\n\t\t// pages, and a later first page of the same query never replaces it. A continuation whose drain is gone is\n\t\t// refused, like an expired work-item snapshot: resuming against a re-drain could skip or repeat a pull request\n\t\t// whose sort date changed. The drain is keyed by credential and installation too, so a cursor handed to\n\t\t// another connection finds nothing and is refused the same way.\n\t\tconst drainId = cursor?.drain ?? uuid();\n\t\tconst drainKey = this.pullRequestSearchCacheKey(session, query, drainId);\n\t\t// A continuation only ever READS its drain: creating one under its id would be the re-drain refused above.\n\t\tconst drainFound =\n\t\t\tcursor != null\n\t\t\t\t? this._pullRequestSearches.get(drainKey)\n\t\t\t\t: this.getPullRequestSearch(this._pullRequestSearches, drainKey, session, options, sort, cancellation);\n\t\tif (drainFound == null) {\n\t\t\tthrow new Error(\n\t\t\t\t'Pull request search results expired or belong to another connection; restart the read without a cursor',\n\t\t\t);\n\t\t}\n\n\t\tconst drain = await drainFound;\n\t\tif (cursor == null) {\n\t\t\t// Also the query's latest drain, which a count of the same query reads rather than draining again. Stored\n\t\t\t// through `getOrCreate`, which applies the cache's capacity and expiry; `set` applies neither.\n\t\t\tconst latestKey = this.pullRequestSearchCacheKey(session, query);\n\t\t\tthis._latestPullRequestSearches.delete(latestKey);\n\t\t\tvoid this._latestPullRequestSearches.getOrCreate(latestKey, () => Promise.resolve(drain));\n\t\t}\n\n\t\tconst pageSize = toAzureSearchPageSize(options.pageSize, 50, 100);\n\t\tconst start =\n\t\t\tcursor == null\n\t\t\t\t? 0\n\t\t\t\t: drain.rows.findIndex(r => compareAzurePullRequestSearchPositions(r.position, cursor.after, sort) > 0);\n\t\tconst slice = start < 0 ? [] : drain.rows.slice(start, start + pageSize);\n\t\tconst page = cursor?.page ?? 1;\n\t\tconst last = slice.at(-1);\n\t\tconst hasMore = last != null && start + slice.length < drain.rows.length;\n\t\treturn {\n\t\t\tvalues: slice.map(r => r.pr),\n\t\t\tcursor: hasMore\n\t\t\t\t? JSON.stringify({ key: key, drain: drainId, page: page + 1, after: last.position })\n\t\t\t\t: undefined,\n\t\t\thasMore: hasMore,\n\t\t\tpage: page,\n\t\t\ttruncated: drain.truncated,\n\t\t\ttotalCount: drain.truncated ? undefined : drain.rows.length,\n\t\t};\n\t}\n\n\t/**\n\t * Counts each scope from the latest drain of its query, the one a search's first page just read, or drains it; see\n\t * {@link searchProviderPullRequestsPage}.\n\t */\n\tprotected override async countProviderPullRequests(\n\t\tsession: ProviderAuthenticationSession,\n\t\tscopes: readonly { repos?: ProviderRepoInput[]; org?: string; criteria?: PullRequestSearchCriteria }[],\n\t\tcancellation?: AbortSignal,\n\t): Promise<(ProviderPullRequestCount | Error)[] | undefined> {\n\t\t// One scope at a time: each is a drain that already fans out over its facets, and the facade runs several\n\t\t// batches of scopes at once, so a concurrent batch would multiply the requests reaching the server.\n\t\treturn mapBounded(scopes, 1, s =>\n\t\t\trefusalAsCount(async () => {\n\t\t\t\tthis.assertSearchDates(s.criteria);\n\t\t\t\tconst sort = s.criteria?.sort ?? defaultPullRequestSort;\n\t\t\t\tconst drain = await this.getPullRequestSearch(\n\t\t\t\t\tthis._latestPullRequestSearches,\n\t\t\t\t\tthis.pullRequestSearchCacheKey(session, toPullRequestSearchQuery(s, sort)),\n\t\t\t\t\tsession,\n\t\t\t\t\ts,\n\t\t\t\t\tsort,\n\t\t\t\t\tcancellation,\n\t\t\t\t);\n\t\t\t\t// Past the drain budget the true total is unknown, so it is reported as uncounted rather than understated.\n\t\t\t\treturn { count: drain.truncated ? undefined : drain.rows.length };\n\t\t\t}),\n\t\t);\n\t}\n\n\t/**\n\t * The drain each pagination pages through, one per first page (see {@link searchProviderPullRequestsPage}), so\n\t * the 50 most recently read paginations are kept for as long as they keep reading.\n\t */\n\tprivate readonly _pullRequestSearches = new PromiseCache<string, AzurePullRequestSearchDrain>({\n\t\tcapacity: 50,\n\t\taccessTTL: pullRequestSearchIdleTtl,\n\t\tcreateTTL: pullRequestSearchMaxTtl,\n\t});\n\t/**\n\t * Each query's latest drain, which its count reads for {@link pullRequestCountReuseTtl}. Apart from the\n\t * paginations' drains, so counting and starting searches never evicts a pagination still being read.\n\t */\n\tprivate readonly _latestPullRequestSearches = new PromiseCache<string, AzurePullRequestSearchDrain>({\n\t\tcapacity: 20,\n\t\tcreateTTL: pullRequestCountReuseTtl,\n\t});\n\n\t/**\n\t * Keyed by the query itself, not its cursor fingerprint, so two queries whose fingerprints collide can never share\n\t * a drain; by credential and installation, so two accounts or installations never read each other's results; and\n\t * by `drainId` for a pagination's own drain, left out for the query's latest one.\n\t */\n\tprivate pullRequestSearchCacheKey(\n\t\tsession: ProviderAuthenticationSession,\n\t\tquery: unknown,\n\t\tdrainId?: string,\n\t): string {\n\t\treturn JSON.stringify([session.accessToken, this.apiBaseUrlFor(session), query, drainId ?? null]);\n\t}\n\n\tprivate getPullRequestSearch(\n\t\tcache: PromiseCache<string, AzurePullRequestSearchDrain>,\n\t\tcacheKey: string,\n\t\tsession: ProviderAuthenticationSession,\n\t\toptions: { repos?: ProviderRepoInput[]; org?: string; criteria?: PullRequestSearchCriteria },\n\t\tsort: PullRequestSorting,\n\t\tcancellation: AbortSignal | undefined,\n\t): Promise<AzurePullRequestSearchDrain> {\n\t\treturn cache.getOrCreate(\n\t\t\tcacheKey,\n\t\t\t(_cacheable, signal) => this.drainPullRequestSearch(session, options, sort, signal),\n\t\t\t{ cancellation: cancellation },\n\t\t);\n\t}\n\n\t/**\n\t * Every pull request matching the search, filtered, deduplicated and ordered.\n\t *\n\t * One facet per (repository or project) × relationship: `Author` reads by creator, while `Assignee` and\n\t * `ReviewRequested` both read by reviewer, since Azure has no assignee distinct from its reviewers. Each facet is\n\t * drained to {@link azurePullRequestSearchFacetLimit}; a facet that still has more marks the whole result\n\t * truncated, because its unread rows could sort anywhere in the union. A facet that fails fails the search: a\n\t * union missing one facet would be served in an order it doesn't have.\n\t */\n\tprivate async drainPullRequestSearch(\n\t\tsession: ProviderAuthenticationSession,\n\t\toptions: { repos?: ProviderRepoInput[]; org?: string; criteria?: PullRequestSearchCriteria },\n\t\tsort: PullRequestSorting,\n\t\tcancellation: AbortSignal | undefined,\n\t): Promise<AzurePullRequestSearchDrain> {\n\t\tconst criteria = options.criteria;\n\t\t// Built before any request, so criteria it can't apply fail the search before the facets are drained.\n\t\tconst matches = toAzurePullRequestSearchFilter(criteria);\n\t\tconst relationships = new Set(criteria?.relationships ?? []);\n\t\tconst wantAuthored = relationships.has(PullRequestFilter.Author);\n\t\tconst wantReviewed =\n\t\t\trelationships.has(PullRequestFilter.Assignee) || relationships.has(PullRequestFilter.ReviewRequested);\n\n\t\t// A drain runs for a first page (or once its predecessor expired), so it re-reads the projects it fans out\n\t\t// over: an org search trusting the connection-long discovery cache would silently skip a newer project.\n\t\tconst facets = await this.resolvePullRequestSearchFacets(session, options.repos, options.org);\n\n\t\t// The current user's id is resolved PER COLLECTION: Azure DevOps Server gives one person a different\n\t\t// identity id in each collection than at the server level, and a creator/reviewer filter only matches the\n\t\t// collection's. The server-level id matches nothing there and would serve an empty result as if nobody had\n\t\t// authored anything.\n\t\tconst userIds = new Map<string, string>();\n\t\tif (relationships.size > 0) {\n\t\t\tfor (const collection of uniqueAzureNames(facets.map(f => f.collection))) {\n\t\t\t\tconst userId = await this.getFilterUserId(session, collection);\n\t\t\t\tif (userId == null) {\n\t\t\t\t\tthrow this.searchUnavailable(`the current user could not be resolved in '${collection}'`);\n\t\t\t\t}\n\n\t\t\t\tuserIds.set(collection, userId);\n\t\t\t}\n\t\t}\n\n\t\tconst filtersFor = (collection: string): { authorLogin?: string; reviewerId?: string }[] => {\n\t\t\tif (relationships.size === 0) return [{}];\n\n\t\t\tconst userId = userIds.get(collection)!;\n\t\t\treturn [\n\t\t\t\t...(wantAuthored ? [{ authorLogin: userId }] : []),\n\t\t\t\t...(wantReviewed ? [{ reviewerId: userId }] : []),\n\t\t\t];\n\t\t};\n\n\t\tconst api = await this.getProvidersApi();\n\t\tconst { tokenWithInfo, options: apiOptions } = this.getApiOptions(session);\n\t\tconst states = toProviderPullRequestStates(criteria?.states?.length ? criteria.states : 'open');\n\t\tconst drains = await mapBounded(\n\t\t\tfacets.flatMap(facet => filtersFor(facet.collection).map(filter => ({ facet: facet, filter: filter }))),\n\t\t\tproviderFanOutConcurrency,\n\t\t\tasync ({ facet, filter }) => {\n\t\t\t\tconst baseUrl = this.collectionApiBaseUrl(session, facet.collection);\n\t\t\t\tconst values: ProviderPullRequest[] = [];\n\t\t\t\tlet page = 1;\n\t\t\t\tfor (let read = 1; ; read++) {\n\t\t\t\t\tif (cancellation?.aborted) throw new CancellationError();\n\n\t\t\t\t\tconst input = {\n\t\t\t\t\t\t...apiOptions,\n\t\t\t\t\t\t...filter,\n\t\t\t\t\t\tstates: states,\n\t\t\t\t\t\tpage: page,\n\t\t\t\t\t\tpageSize: azurePullRequestSearchPageSize,\n\t\t\t\t\t\tbaseUrl: baseUrl,\n\t\t\t\t\t};\n\t\t\t\t\tconst result =\n\t\t\t\t\t\tfacet.repository != null\n\t\t\t\t\t\t\t? await api\n\t\t\t\t\t\t\t\t\t.getPullRequestsForRepo(\n\t\t\t\t\t\t\t\t\t\ttokenWithInfo,\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tnamespace: facet.collection,\n\t\t\t\t\t\t\t\t\t\t\tname: facet.repository,\n\t\t\t\t\t\t\t\t\t\t\tproject: facet.project.name,\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\tinput,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t.then(r => ({\n\t\t\t\t\t\t\t\t\t\tvalues: r.values,\n\t\t\t\t\t\t\t\t\t\tmore: r.paging?.more === true,\n\t\t\t\t\t\t\t\t\t\tnextPage: r.paging?.nextPage,\n\t\t\t\t\t\t\t\t\t}))\n\t\t\t\t\t\t\t: await api\n\t\t\t\t\t\t\t\t\t.getPullRequestsForAzureProject(\n\t\t\t\t\t\t\t\t\t\ttokenWithInfo,\n\t\t\t\t\t\t\t\t\t\t{ namespace: facet.collection, project: facet.project.name },\n\t\t\t\t\t\t\t\t\t\tinput,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t.then(r =>\n\t\t\t\t\t\t\t\t\t\tr != null\n\t\t\t\t\t\t\t\t\t\t\t? { values: r.data, more: r.hasMore, nextPage: r.nextPage ?? undefined }\n\t\t\t\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\tif (result == null) throw new Error('Azure DevOps returned no pull request page');\n\n\t\t\t\t\tvalues.push(...result.values);\n\t\t\t\t\tif (!result.more) return { facet: facet, values: values, truncated: false };\n\t\t\t\t\t// Follows the page the provider says comes next rather than assuming one: a continuation that\n\t\t\t\t\t// doesn't advance would re-read or skip rows, so it fails the facet — and with it the search —\n\t\t\t\t\t// instead of serving a union built from it.\n\t\t\t\t\tif (result.nextPage == null || result.nextPage <= page) {\n\t\t\t\t\t\tthrow new Error('Azure DevOps returned no advancing pull request continuation');\n\t\t\t\t\t}\n\t\t\t\t\t// The budget counts pages READ, not rows kept: several states are one `status=all` query the SDK\n\t\t\t\t\t// narrows client-side, so counting survivors would keep paging through rows it discards.\n\t\t\t\t\tif (read * azurePullRequestSearchPageSize >= azurePullRequestSearchFacetLimit) {\n\t\t\t\t\t\treturn { facet: facet, values: values, truncated: true };\n\t\t\t\t\t}\n\n\t\t\t\t\tpage = result.nextPage;\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\n\t\tconst rows = new Map<string, AzurePullRequestSearchRow>();\n\t\tfor (const { facet, values } of drains) {\n\t\t\tfor (const pr of values) {\n\t\t\t\tif (!matches(pr)) continue;\n\n\t\t\t\tconst identity =\n\t\t\t\t\tgetProviderPullRequestIdentity(pr) ?? `project:${facet.collection}/${facet.project.name}:${pr.id}`;\n\t\t\t\tif (rows.has(identity)) continue;\n\n\t\t\t\trows.set(identity, {\n\t\t\t\t\tpr: fromProviderPullRequest(pr, this, {\n\t\t\t\t\t\tproject: facet.project,\n\t\t\t\t\t\tcurrentAccountId: userIds.get(facet.collection),\n\t\t\t\t\t}),\n\t\t\t\t\tposition: toAzurePullRequestSearchPosition(pr, sort, identity),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\trows: [...rows.values()].sort((a, b) =>\n\t\t\t\tcompareAzurePullRequestSearchPositions(a.position, b.position, sort),\n\t\t\t),\n\t\t\ttruncated: drains.some(d => d.truncated),\n\t\t};\n\t}\n\n\t/**\n\t * The repositories or projects a pull-request search reads, each with its collection and project descriptor.\n\t *\n\t * Repositories are read one by one; an `org` is its collection's projects; a search bounded only by the current\n\t * user reads every project the account can see, the same breadth as the account-wide pull request read.\n\t */\n\tprivate async resolvePullRequestSearchFacets(\n\t\tsession: ProviderAuthenticationSession,\n\t\trepos: ProviderRepoInput[] | undefined,\n\t\torg: string | undefined,\n\t): Promise<{ collection: string; project: AzureProjectDescriptor; repository?: string }[]> {\n\t\tconst collections = await this.getSearchCollections(session);\n\t\tconst collectionFor = (name: string): AzureOrganizationDescriptor => {\n\t\t\tconst collection = findAzureCollection(collections, name);\n\t\t\tif (collection == null) throw this.searchUnavailable(`the '${name}' collection is not visible`);\n\n\t\t\treturn collection;\n\t\t};\n\n\t\tif (repos?.length) {\n\t\t\tif (org && repos.some(r => !sameAzureName(r.namespace, org))) {\n\t\t\t\tthrow this.searchUnavailable(`the repositories are not all in the '${org}' collection`);\n\t\t\t}\n\n\t\t\t// One discovery per distinct collection, however many of its repositories the search names.\n\t\t\tconst projectsByCollection = new Map<string, Promise<AzureProjectDescriptor[]>>();\n\t\t\tconst projectsOf = (collection: AzureOrganizationDescriptor): Promise<AzureProjectDescriptor[]> => {\n\t\t\t\tlet projects = projectsByCollection.get(collection.id);\n\t\t\t\tif (projects == null) {\n\t\t\t\t\tprojects = this.getSearchProjects(session, collection, true);\n\t\t\t\t\tprojectsByCollection.set(collection.id, projects);\n\t\t\t\t}\n\t\t\t\treturn projects;\n\t\t\t};\n\n\t\t\treturn Promise.all(\n\t\t\t\trepos.map(async r => {\n\t\t\t\t\tconst collection = collectionFor(r.namespace);\n\t\t\t\t\tconst identity = getAzureRepositoryIdentity({\n\t\t\t\t\t\towner: r.namespace,\n\t\t\t\t\t\tname: r.name,\n\t\t\t\t\t\tproject: r.project,\n\t\t\t\t\t});\n\t\t\t\t\tif (identity.projectName == null) {\n\t\t\t\t\t\tthrow this.searchUnavailable(`repository '${r.namespace}/${r.name}' names no project`);\n\t\t\t\t\t}\n\t\t\t\t\t// The repository becomes a URL segment the SDK encodes but doesn't validate, and a segment of `..`\n\t\t\t\t\t// survives encoding and resolves to the project-wide route: refused rather than widened.\n\t\t\t\t\tif (!isAzureRouteSegment(identity.repositoryName)) {\n\t\t\t\t\t\tthrow this.searchUnavailable(`repository '${r.namespace}/${r.name}' is not a valid name`);\n\t\t\t\t\t}\n\n\t\t\t\t\tconst project = (await projectsOf(collection)).find(p =>\n\t\t\t\t\t\tsameAzureName(p.name, identity.projectName!),\n\t\t\t\t\t);\n\t\t\t\t\tif (project == null) {\n\t\t\t\t\t\tthrow this.searchUnavailable(\n\t\t\t\t\t\t\t`project '${identity.projectName}' is not visible in '${collection.name}'`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn { collection: collection.name, project: project, repository: identity.repositoryName };\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\tconst scoped = org ? [collectionFor(org)] : collections;\n\t\tconst projects = await Promise.all(scoped.map(c => this.getSearchProjects(session, c, true)));\n\t\treturn projects.flat().map(p => ({ collection: p.resourceName, project: p }));\n\t}\n\n\tprivate readonly _collectionUserIds = new PromiseCache<string, string | undefined>({ capacity: 50 });\n\n\t/**\n\t * The current user's identity id in `collection`, read from the collection's own connection data, which is\n\t * what Azure's creator and reviewer filters compare against. Cached per credential and collection, since it\n\t * can't change for either.\n\t */\n\tprotected override getFilterUserId(\n\t\tsession: ProviderAuthenticationSession,\n\t\tcollection: string,\n\t): Promise<string | undefined> {\n\t\tconst baseUrl = this.collectionApiBaseUrl(session, collection);\n\t\treturn this._collectionUserIds.getOrCreate(\n\t\t\tJSON.stringify([session.accessToken, baseUrl, collection.toLowerCase()]),\n\t\t\tasync cacheable => {\n\t\t\t\tconst azure = await this.authenticationService.apis.azure;\n\t\t\t\tconst user = await azure?.getCurrentUserOnServer(\n\t\t\t\t\tthis,\n\t\t\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\t\t\t`${baseUrl}/${encodeURIComponent(collection)}`,\n\t\t\t\t);\n\t\t\t\t// A miss is not cached: the lookup degrades to `undefined` on a transient failure, and caching that\n\t\t\t\t// would refuse every relationship search in the collection until the connection is dropped.\n\t\t\t\tif (user?.id == null) {\n\t\t\t\t\tcacheable.invalidate();\n\t\t\t\t}\n\n\t\t\t\treturn user?.id;\n\t\t\t},\n\t\t);\n\t}\n\n\t/** Every collection the account can see, or a refusal when discovery itself failed. */\n\tprivate async getSearchCollections(session: ProviderAuthenticationSession): Promise<AzureOrganizationDescriptor[]> {\n\t\tconst collections = await this.getProviderResourcesForUser(session);\n\t\tif (collections == null) throw this.searchUnavailable('the account’s collections could not be read');\n\n\t\treturn collections;\n\t}\n\n\t/**\n\t * A collection's projects, refused when discovery was incomplete: a search bounded by an incomplete project set\n\t * would silently omit the missing projects' matches. `refresh` re-reads them rather than trusting the discovery\n\t * cache, which lives for the whole connection and so doesn't know a project created since.\n\t */\n\tprivate async getSearchProjects(\n\t\tsession: ProviderAuthenticationSession,\n\t\tcollection: AzureOrganizationDescriptor,\n\t\trefresh: boolean = false,\n\t): Promise<AzureProjectDescriptor[]> {\n\t\tconst projects = refresh\n\t\t\t? await this.refreshSearchProjects(session, collection)\n\t\t\t: await this.getProviderProjectsForResources(session, [collection]);\n\t\tif (projects.metadata != null && projects.metadata.completeness !== 'complete') {\n\t\t\tthrow this.searchUnavailable(`the projects of the '${collection.name}' collection could not all be read`);\n\t\t}\n\n\t\treturn projects.values;\n\t}\n\n\tprivate readonly _projectRefreshes = new Map<\n\t\tstring,\n\t\tPromise<ProviderApiCollectionResult<AzureProjectDescriptor>>\n\t>();\n\n\t/**\n\t * Re-reads a collection's projects, sharing one read among the refreshes IN FLIGHT at once — a count batch or a\n\t * multi-repository drain refreshes the same collection once per scope, and each would otherwise re-read every\n\t * project page. Nothing outlives the read, so the next search still sees a project created after it.\n\t */\n\tprivate refreshSearchProjects(\n\t\tsession: ProviderAuthenticationSession,\n\t\tcollection: AzureOrganizationDescriptor,\n\t): Promise<ProviderApiCollectionResult<AzureProjectDescriptor>> {\n\t\tconst key = `${this.discoveryKey(session)}:${collection.id}`;\n\t\tlet pending = this._projectRefreshes.get(key);\n\t\tif (pending == null) {\n\t\t\tpending = this.getProviderProjectsForResources(session, [collection], true).finally(() => {\n\t\t\t\tthis._projectRefreshes.delete(key);\n\t\t\t});\n\t\t\tthis._projectRefreshes.set(key, pending);\n\t\t}\n\n\t\treturn pending;\n\t}\n\n\t/**\n\t * Refuses dates the search can't apply before anything is read. The facade only checks that dates are\n\t * supported, not their shape, and a refusal here stays with its own scope in a count batch.\n\t */\n\tprivate assertSearchDates(criteria: { updatedAfter?: string; createdAfter?: string } | undefined): void {\n\t\tconst invalid = getInvalidAzureSearchDate(criteria);\n\t\tif (invalid != null) throw this.searchUnavailable(invalid);\n\t}\n\n\tprivate searchUnavailable(reason: string): IntegrationReadUnavailableError {\n\t\treturn new IntegrationReadUnavailableError(this.name, `search refused: ${reason}.`);\n\t}\n\n\tprotected override providerOnDisconnect(): void {\n\t\tsuper.providerOnDisconnect();\n\t\tthis._pullRequestSearches.clear();\n\t\tthis._latestPullRequestSearches.clear();\n\t\tthis._collectionUserIds.clear();\n\t}\n\n\tprotected override async _requestForCurrentUser(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<Account | undefined> {\n\t\tconst azure = await this.authenticationService.apis.azure;\n\t\tconst user = azure\n\t\t\t? await azure.getCurrentUserOnServer(this, toTokenWithInfo(this.id, session), this.apiBaseUrlFor(session))\n\t\t\t: undefined;\n\t\treturn user\n\t\t\t? {\n\t\t\t\t\tprovider: this,\n\t\t\t\t\tid: user.id,\n\t\t\t\t\tname: user.name ?? undefined,\n\t\t\t\t\temail: user.email ?? undefined,\n\t\t\t\t\tavatarUrl: user.avatarUrl ?? undefined,\n\t\t\t\t\tusername: user.username ?? undefined,\n\t\t\t\t}\n\t\t\t: undefined;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA+DA,SAAS,oBAAoB,OAAwB;CACpD,OAAO,MAAM,SAAS,KAAK,UAAU,OAAO,UAAU;AACvD;;;;;;AAOA,eAAe,eAAkB,OAAuE;CACvG,IAAI;EACH,OAAO,MAAM,MAAM;CACpB,SAAS,IAAI;EACZ,IAAI,cAAc,iCAAiC,OAAO;EAE1D,MAAM;CACP;AACD;AAEA,SAAS,oBACR,aACA,MAC0C;CAC1C,OAAO,YAAY,MAAK,MAAK,cAAc,EAAE,MAAM,IAAI,KAAK,EAAE,OAAO,IAAI;AAC1E;;;;;;AAOA,MAAM,mCAAmC;;;;;AAMzC,MAAM,iCAAiC;;;;;AAMvC,MAAM,6BAA6B;;;;;;AAOnC,MAAM,2BAA2B;AACjC,MAAM,0BAA0B;;;;;;AAOhC,MAAM,2BAA2B;;;;;;AAiBjC,SAAS,yBACR,SACA,MACU;CACV,MAAM,WAAW,QAAQ;CACzB,OAAO;EACN,OAAO,QAAQ,OAAO,KAAI,MAAK;GAAC,EAAE;GAAW,EAAE,WAAW;GAAM,EAAE;EAAI,CAAC;EACvE,KAAK,QAAQ,OAAO;EACpB,eAAe,CAAC,GAAG,IAA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,QACV,MAAM,MAAM,uBAAuB,MAAM,gBAAgB,KAAK,IAAI,OAAO,GAAG,KAAK,cAAc,OAAO,CAAC,IACvG,KAAA;EACH,OAAO,OACJ;GACA,UAAU;GACV,IAAI,KAAK;GACT,MAAM,KAAK,QAAQ,KAAA;GACnB,OAAO,KAAK,SAAS,KAAA;GACrB,WAAW,KAAK,aAAa,KAAA;GAC7B,UAAU,KAAK,YAAY,KAAA;EAC5B,IACC,KAAA;CACJ;AACD"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TokenWithInfo } from "../../authentication/models.js";
|
|
2
|
+
import { GitSelfManagedHostIntegrationId } from "../../constants.js";
|
|
3
|
+
import { ProviderOrganization } from "../../results.js";
|
|
4
|
+
import { ProviderApiPagedResult, ProviderRepository, ProviderRequestFunction } from "../models.js";
|
|
5
|
+
//#region ../plus/integrations/src/providers/bitbucket-server/discovery.d.ts
|
|
6
|
+
export declare function requestBitbucketServerProjects(request: ProviderRequestFunction, token: TokenWithInfo<GitSelfManagedHostIntegrationId.BitbucketServer>, baseUrl: string, connectionId: string, cursor?: string): Promise<ProviderApiPagedResult<ProviderOrganization>>;
|
|
7
|
+
export declare function requestBitbucketServerRepositories(request: ProviderRequestFunction, token: TokenWithInfo<GitSelfManagedHostIntegrationId.BitbucketServer>, baseUrl: string, connectionId: string, options?: {
|
|
8
|
+
project?: string;
|
|
9
|
+
cursor?: string;
|
|
10
|
+
}): Promise<ProviderApiPagedResult<ProviderRepository>>;
|
|
11
|
+
//#endregion
|
|
12
|
+
//# sourceMappingURL=discovery.d.ts.map
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { sha256 } from "../../../../utils/crypto.js";
|
|
2
|
+
import { throwProviderError } from "../providerErrors.js";
|
|
3
|
+
//#region ../plus/integrations/src/providers/bitbucket-server/discovery.ts
|
|
4
|
+
function parseCursor(cursor, scope) {
|
|
5
|
+
if (cursor == null) return {
|
|
6
|
+
scope,
|
|
7
|
+
start: 0,
|
|
8
|
+
seen: []
|
|
9
|
+
};
|
|
10
|
+
const parsed = JSON.parse(cursor);
|
|
11
|
+
const value = parsed?.value;
|
|
12
|
+
if (parsed?.type !== "cursor" || value == null || typeof value !== "object" || value.scope !== scope || typeof value.start !== "number" || !Number.isSafeInteger(value.start) || value.start <= 0 || !Array.isArray(value.seen) || !value.seen.every((id) => typeof id === "string")) throw new Error("Invalid Bitbucket Data Center discovery cursor for this connection or scope");
|
|
13
|
+
return {
|
|
14
|
+
scope,
|
|
15
|
+
start: value.start,
|
|
16
|
+
seen: value.seen
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function toInstallationUrl(baseUrl) {
|
|
20
|
+
return baseUrl.replace(/\/rest\/api\/1\.0$/, "");
|
|
21
|
+
}
|
|
22
|
+
/** The paths the web UI serves a project at; a personal project (`~user`) is also served under its owner. */
|
|
23
|
+
function getProjectPaths(key) {
|
|
24
|
+
return key.startsWith("~") ? [`/projects/${key}`, `/users/${key.slice(1)}`] : [`/projects/${key}`];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Keeps a link the server supplied only when it names one of `paths` on this connection's installation, then removes
|
|
28
|
+
* credentials, query and fragment. A response therefore cannot hand a consumer a remote on another host, or for a
|
|
29
|
+
* different repository than the entry it describes. Bitbucket serves SSH on its own port and without the context
|
|
30
|
+
* path, so an SSH link is held to the installation's hostname alone.
|
|
31
|
+
*/
|
|
32
|
+
function sanitizeLink(href, installationUrl, paths, ssh = false) {
|
|
33
|
+
if (href == null) return null;
|
|
34
|
+
try {
|
|
35
|
+
const url = new URL(href);
|
|
36
|
+
const installation = new URL(installationUrl);
|
|
37
|
+
if (ssh) {
|
|
38
|
+
if (url.protocol !== "ssh:" || url.hostname.toLowerCase() !== installation.hostname) return null;
|
|
39
|
+
} else if (url.protocol !== "http:" && url.protocol !== "https:" || url.origin !== installation.origin) return null;
|
|
40
|
+
const base = ssh ? "" : installation.pathname.replace(/\/+$/, "");
|
|
41
|
+
const path = url.pathname.toLowerCase();
|
|
42
|
+
if (!paths.some((expected) => path === `${base}${expected}`.toLowerCase())) return null;
|
|
43
|
+
if (!ssh) url.username = "";
|
|
44
|
+
url.password = "";
|
|
45
|
+
url.search = "";
|
|
46
|
+
url.hash = "";
|
|
47
|
+
return url.toString();
|
|
48
|
+
} catch {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async function requestPage(request, token, connectionId, endpoint, cursor, map) {
|
|
53
|
+
try {
|
|
54
|
+
const scope = await sha256(JSON.stringify([connectionId, endpoint]));
|
|
55
|
+
const { start, seen } = parseCursor(cursor, scope);
|
|
56
|
+
const url = new URL(endpoint);
|
|
57
|
+
url.searchParams.set("start", String(start));
|
|
58
|
+
url.searchParams.set("limit", "100");
|
|
59
|
+
const { body } = await request({
|
|
60
|
+
url: url.toString(),
|
|
61
|
+
headers: { Authorization: `Bearer ${token.accessToken}` }
|
|
62
|
+
});
|
|
63
|
+
if (body == null || !Array.isArray(body.values) || typeof body.isLastPage !== "boolean" || body.start !== start) throw new Error("Invalid Bitbucket Data Center discovery page");
|
|
64
|
+
const identities = new Set(seen);
|
|
65
|
+
const values = [];
|
|
66
|
+
for (const raw of body.values) {
|
|
67
|
+
const value = map(raw);
|
|
68
|
+
if (typeof value.id !== "string" || value.id.length === 0) throw new Error("Missing Bitbucket Data Center discovery identity");
|
|
69
|
+
if (identities.has(value.id)) continue;
|
|
70
|
+
identities.add(value.id);
|
|
71
|
+
values.push(value);
|
|
72
|
+
}
|
|
73
|
+
const next = body.nextPageStart;
|
|
74
|
+
const more = !body.isLastPage && next != null && Number.isSafeInteger(next) && next > start;
|
|
75
|
+
const truncated = !body.isLastPage && !more;
|
|
76
|
+
return {
|
|
77
|
+
values,
|
|
78
|
+
paging: {
|
|
79
|
+
more,
|
|
80
|
+
cursor: more ? JSON.stringify({
|
|
81
|
+
type: "cursor",
|
|
82
|
+
value: {
|
|
83
|
+
scope,
|
|
84
|
+
start: next,
|
|
85
|
+
seen: [...identities]
|
|
86
|
+
}
|
|
87
|
+
}) : "{}",
|
|
88
|
+
truncated: truncated || void 0
|
|
89
|
+
},
|
|
90
|
+
metadata: { completeness: truncated ? "partial" : "complete" }
|
|
91
|
+
};
|
|
92
|
+
} catch (ex) {
|
|
93
|
+
return throwProviderError(token, ex);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function requestBitbucketServerProjects(request, token, baseUrl, connectionId, cursor) {
|
|
97
|
+
const installationUrl = toInstallationUrl(baseUrl);
|
|
98
|
+
return requestPage(request, token, connectionId, `${baseUrl}/projects`, cursor, (project) => ({
|
|
99
|
+
id: project.key,
|
|
100
|
+
providerId: token.providerId,
|
|
101
|
+
name: project.key,
|
|
102
|
+
url: sanitizeLink(project.links?.self?.[0]?.href, installationUrl, getProjectPaths(project.key)) ?? `${installationUrl}/projects/${encodeURIComponent(project.key)}`
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
function requestBitbucketServerRepositories(request, token, baseUrl, connectionId, options) {
|
|
106
|
+
if (options?.project === "" || options?.project === "." || options?.project === "..") throw new Error("Invalid Bitbucket Data Center project key");
|
|
107
|
+
const endpoint = options?.project != null ? `${baseUrl}/projects/${encodeURIComponent(options.project)}/repos` : `${baseUrl}/repos`;
|
|
108
|
+
const installationUrl = toInstallationUrl(baseUrl);
|
|
109
|
+
return requestPage(request, token, connectionId, endpoint, options?.cursor, (repo) => {
|
|
110
|
+
const key = encodeURIComponent(repo.project.key);
|
|
111
|
+
const slug = encodeURIComponent(repo.slug);
|
|
112
|
+
const webPaths = getProjectPaths(repo.project.key).map((path) => `${path}/repos/${repo.slug}`);
|
|
113
|
+
return {
|
|
114
|
+
id: repo.id.toString(),
|
|
115
|
+
namespace: repo.project.key,
|
|
116
|
+
name: repo.slug,
|
|
117
|
+
webUrl: sanitizeLink(repo.links.self[0]?.href, installationUrl, [...webPaths, ...webPaths.map((path) => `${path}/browse`)]) ?? `${installationUrl}/projects/${key}/repos/${slug}/browse`,
|
|
118
|
+
httpsUrl: sanitizeLink(repo.links.clone.find((link) => link.name === "https" || link.name === "http")?.href, installationUrl, [`/scm/${repo.project.key}/${repo.slug}.git`]) ?? `${installationUrl}/scm/${key}/${slug}.git`,
|
|
119
|
+
sshUrl: sanitizeLink(repo.links.clone.find((link) => link.name === "ssh")?.href, installationUrl, [`/${repo.project.key}/${repo.slug}.git`], true),
|
|
120
|
+
defaultBranch: null,
|
|
121
|
+
permissions: null
|
|
122
|
+
};
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
//#endregion
|
|
126
|
+
export { requestBitbucketServerProjects, requestBitbucketServerRepositories };
|
|
127
|
+
|
|
128
|
+
//# sourceMappingURL=discovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discovery.js","names":[],"sources":["../../../../../../plus/integrations/src/providers/bitbucket-server/discovery.ts"],"sourcesContent":["import { sha256 } from '@gitlens/utils/crypto.js';\nimport type { TokenWithInfo } from '../../authentication/models.js';\nimport type { GitSelfManagedHostIntegrationId } from '../../constants.js';\nimport type {\n\tProviderApiPagedResult,\n\tProviderOrganization,\n\tProviderRepository,\n\tProviderRequestFunction,\n} from '../models.js';\nimport { throwProviderError } from '../providerErrors.js';\n\ntype ProjectResponse = {\n\tkey: string;\n\tlinks?: { self?: { href: string }[] };\n};\n\ntype RepositoryResponse = {\n\tid: number;\n\tslug: string;\n\tproject: ProjectResponse;\n\tlinks: {\n\t\tself: { href: string }[];\n\t\tclone: { name: string; href: string }[];\n\t};\n};\n\ntype DiscoveryCursor = { scope: string; start: number; seen: string[] };\n\nfunction parseCursor(cursor: string | undefined, scope: string): DiscoveryCursor {\n\tif (cursor == null) return { scope: scope, start: 0, seen: [] };\n\n\tconst parsed = JSON.parse(cursor) as { type?: unknown; value?: Partial<DiscoveryCursor> | number } | null;\n\tconst value = parsed?.value;\n\tif (\n\t\tparsed?.type !== 'cursor' ||\n\t\tvalue == null ||\n\t\ttypeof value !== 'object' ||\n\t\tvalue.scope !== scope ||\n\t\ttypeof value.start !== 'number' ||\n\t\t!Number.isSafeInteger(value.start) ||\n\t\tvalue.start <= 0 ||\n\t\t!Array.isArray(value.seen) ||\n\t\t!value.seen.every(id => typeof id === 'string')\n\t) {\n\t\tthrow new Error('Invalid Bitbucket Data Center discovery cursor for this connection or scope');\n\t}\n\n\treturn { scope: scope, start: value.start, seen: value.seen };\n}\n\nfunction toInstallationUrl(baseUrl: string): string {\n\treturn baseUrl.replace(/\\/rest\\/api\\/1\\.0$/, '');\n}\n\n/** The paths the web UI serves a project at; a personal project (`~user`) is also served under its owner. */\nfunction getProjectPaths(key: string): string[] {\n\treturn key.startsWith('~') ? [`/projects/${key}`, `/users/${key.slice(1)}`] : [`/projects/${key}`];\n}\n\n/**\n * Keeps a link the server supplied only when it names one of `paths` on this connection's installation, then removes\n * credentials, query and fragment. A response therefore cannot hand a consumer a remote on another host, or for a\n * different repository than the entry it describes. Bitbucket serves SSH on its own port and without the context\n * path, so an SSH link is held to the installation's hostname alone.\n */\nfunction sanitizeLink(href: string | undefined, installationUrl: string, paths: string[], ssh = false): string | null {\n\tif (href == null) return null;\n\n\ttry {\n\t\tconst url = new URL(href);\n\t\tconst installation = new URL(installationUrl);\n\t\tif (ssh) {\n\t\t\tif (url.protocol !== 'ssh:' || url.hostname.toLowerCase() !== installation.hostname) return null;\n\t\t} else if ((url.protocol !== 'http:' && url.protocol !== 'https:') || url.origin !== installation.origin) {\n\t\t\treturn null;\n\t\t}\n\n\t\t// Project keys and slugs resolve case-insensitively, and clone links spell the key in lower case.\n\t\tconst base = ssh ? '' : installation.pathname.replace(/\\/+$/, '');\n\t\tconst path = url.pathname.toLowerCase();\n\t\tif (!paths.some(expected => path === `${base}${expected}`.toLowerCase())) return null;\n\n\t\tif (!ssh) {\n\t\t\turl.username = '';\n\t\t}\n\t\turl.password = '';\n\t\turl.search = '';\n\t\turl.hash = '';\n\t\treturn url.toString();\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nasync function requestPage<T, R extends { id: string }>(\n\trequest: ProviderRequestFunction,\n\ttoken: TokenWithInfo<GitSelfManagedHostIntegrationId.BitbucketServer>,\n\tconnectionId: string,\n\tendpoint: string,\n\tcursor: string | undefined,\n\tmap: (value: T) => R,\n): Promise<ProviderApiPagedResult<R>> {\n\ttry {\n\t\tconst scope = await sha256(JSON.stringify([connectionId, endpoint]));\n\t\tconst { start, seen } = parseCursor(cursor, scope);\n\t\tconst url = new URL(endpoint);\n\t\turl.searchParams.set('start', String(start));\n\t\turl.searchParams.set('limit', '100');\n\t\tconst { body } = await request<{\n\t\t\tvalues: T[];\n\t\t\tstart: number;\n\t\t\tisLastPage: boolean;\n\t\t\tnextPageStart?: number;\n\t\t}>({ url: url.toString(), headers: { Authorization: `Bearer ${token.accessToken}` } });\n\t\tif (\n\t\t\tbody == null ||\n\t\t\t!Array.isArray(body.values) ||\n\t\t\ttypeof body.isLastPage !== 'boolean' ||\n\t\t\tbody.start !== start\n\t\t) {\n\t\t\tthrow new Error('Invalid Bitbucket Data Center discovery page');\n\t\t}\n\n\t\tconst identities = new Set(seen);\n\t\tconst values: R[] = [];\n\t\tfor (const raw of body.values) {\n\t\t\tconst value = map(raw);\n\t\t\tif (typeof value.id !== 'string' || value.id.length === 0) {\n\t\t\t\tthrow new Error('Missing Bitbucket Data Center discovery identity');\n\t\t\t}\n\t\t\tif (identities.has(value.id)) continue;\n\n\t\t\tidentities.add(value.id);\n\t\t\tvalues.push(value);\n\t\t}\n\n\t\tconst next = body.nextPageStart;\n\t\tconst more = !body.isLastPage && next != null && Number.isSafeInteger(next) && next > start;\n\t\tconst truncated = !body.isLastPage && !more;\n\t\treturn {\n\t\t\tvalues: values,\n\t\t\tpaging: {\n\t\t\t\tmore: more,\n\t\t\t\tcursor: more\n\t\t\t\t\t? JSON.stringify({ type: 'cursor', value: { scope: scope, start: next, seen: [...identities] } })\n\t\t\t\t\t: '{}',\n\t\t\t\ttruncated: truncated || undefined,\n\t\t\t},\n\t\t\tmetadata: { completeness: truncated ? 'partial' : 'complete' },\n\t\t};\n\t} catch (ex) {\n\t\treturn throwProviderError(token, ex);\n\t}\n}\n\nexport function requestBitbucketServerProjects(\n\trequest: ProviderRequestFunction,\n\ttoken: TokenWithInfo<GitSelfManagedHostIntegrationId.BitbucketServer>,\n\tbaseUrl: string,\n\tconnectionId: string,\n\tcursor?: string,\n): Promise<ProviderApiPagedResult<ProviderOrganization>> {\n\tconst installationUrl = toInstallationUrl(baseUrl);\n\treturn requestPage<ProjectResponse, ProviderOrganization>(\n\t\trequest,\n\t\ttoken,\n\t\tconnectionId,\n\t\t`${baseUrl}/projects`,\n\t\tcursor,\n\t\tproject => ({\n\t\t\tid: project.key,\n\t\t\tproviderId: token.providerId,\n\t\t\tname: project.key,\n\t\t\turl:\n\t\t\t\tsanitizeLink(project.links?.self?.[0]?.href, installationUrl, getProjectPaths(project.key)) ??\n\t\t\t\t`${installationUrl}/projects/${encodeURIComponent(project.key)}`,\n\t\t}),\n\t);\n}\n\nexport function requestBitbucketServerRepositories(\n\trequest: ProviderRequestFunction,\n\ttoken: TokenWithInfo<GitSelfManagedHostIntegrationId.BitbucketServer>,\n\tbaseUrl: string,\n\tconnectionId: string,\n\toptions?: { project?: string; cursor?: string },\n): Promise<ProviderApiPagedResult<ProviderRepository>> {\n\tif (options?.project === '' || options?.project === '.' || options?.project === '..') {\n\t\tthrow new Error('Invalid Bitbucket Data Center project key');\n\t}\n\n\tconst endpoint =\n\t\toptions?.project != null\n\t\t\t? `${baseUrl}/projects/${encodeURIComponent(options.project)}/repos`\n\t\t\t: `${baseUrl}/repos`;\n\tconst installationUrl = toInstallationUrl(baseUrl);\n\treturn requestPage<RepositoryResponse, ProviderRepository>(\n\t\trequest,\n\t\ttoken,\n\t\tconnectionId,\n\t\tendpoint,\n\t\toptions?.cursor,\n\t\trepo => {\n\t\t\tconst key = encodeURIComponent(repo.project.key);\n\t\t\tconst slug = encodeURIComponent(repo.slug);\n\t\t\tconst webPaths = getProjectPaths(repo.project.key).map(path => `${path}/repos/${repo.slug}`);\n\t\t\treturn {\n\t\t\t\tid: repo.id.toString(),\n\t\t\t\tnamespace: repo.project.key,\n\t\t\t\tname: repo.slug,\n\t\t\t\t// A link that fails validation (e.g. a server whose advertised base URL differs from the address the\n\t\t\t\t// connection is configured with) falls back to the canonical path on that address, like a project's.\n\t\t\t\twebUrl:\n\t\t\t\t\tsanitizeLink(repo.links.self[0]?.href, installationUrl, [\n\t\t\t\t\t\t...webPaths,\n\t\t\t\t\t\t...webPaths.map(path => `${path}/browse`),\n\t\t\t\t\t]) ?? `${installationUrl}/projects/${key}/repos/${slug}/browse`,\n\t\t\t\thttpsUrl:\n\t\t\t\t\tsanitizeLink(\n\t\t\t\t\t\trepo.links.clone.find(link => link.name === 'https' || link.name === 'http')?.href,\n\t\t\t\t\t\tinstallationUrl,\n\t\t\t\t\t\t[`/scm/${repo.project.key}/${repo.slug}.git`],\n\t\t\t\t\t) ?? `${installationUrl}/scm/${key}/${slug}.git`,\n\t\t\t\t// SSH has its own port (and possibly host) that the connection cannot know, so nothing to fall back to.\n\t\t\t\tsshUrl: sanitizeLink(\n\t\t\t\t\trepo.links.clone.find(link => link.name === 'ssh')?.href,\n\t\t\t\t\tinstallationUrl,\n\t\t\t\t\t[`/${repo.project.key}/${repo.slug}.git`],\n\t\t\t\t\ttrue,\n\t\t\t\t),\n\t\t\t\tdefaultBranch: null,\n\t\t\t\tpermissions: null,\n\t\t\t};\n\t\t},\n\t);\n}\n"],"mappings":";;;AA4BA,SAAS,YAAY,QAA4B,OAAgC;CAChF,IAAI,UAAU,MAAM,OAAO;EAAS;EAAO,OAAO;EAAG,MAAM,CAAC;CAAE;CAE9D,MAAM,SAAS,KAAK,MAAM,MAAM;CAChC,MAAM,QAAQ,QAAQ;CACtB,IACC,QAAQ,SAAS,YACjB,SAAS,QACT,OAAO,UAAU,YACjB,MAAM,UAAU,SAChB,OAAO,MAAM,UAAU,YACvB,CAAC,OAAO,cAAc,MAAM,K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AAI,GAAG,KAAK,KAAK,KAAK,CAC7C,KAAK,GAAG,gBAAgB,OAAO,IAAI,GAAG,KAAK;GAE5C,QAAQ,aACP,KAAK,MAAM,MAAM,MAAK,SAAQ,KAAK,SAAS,KAAK,CAAC,EAAE,MACpD,iBACA,CAAC,IAAI,KAAK,QAAQ,IAAI,GAAG,KAAK,KAAK,KAAK,GACxC,IACD;GACA,eAAe;GACf,aAAa;EACd;CACD,CACD;AACD"}
|
|
@@ -106,7 +106,16 @@ export interface BitbucketServerPullRequest {
|
|
|
106
106
|
version: number;
|
|
107
107
|
title: string;
|
|
108
108
|
description: string;
|
|
109
|
-
|
|
109
|
+
/**
|
|
110
|
+
* `SUPERSEDED` is not in the published schema, but a server can still report it for a pull request closed by a
|
|
111
|
+
* newer one (the Bitbucket SDK maps it too); it is a closed pull request, like `DECLINED`.
|
|
112
|
+
*/
|
|
113
|
+
state: 'OPEN' | 'MERGED' | 'DECLINED' | 'SUPERSEDED';
|
|
114
|
+
/**
|
|
115
|
+
* Drafts shipped in Bitbucket Data Center 8.18 (8.17 exposed the field experimentally); absent means the server
|
|
116
|
+
* has no drafts, so not a draft.
|
|
117
|
+
*/
|
|
118
|
+
draft?: boolean;
|
|
110
119
|
open: boolean;
|
|
111
120
|
closed: boolean;
|
|
112
121
|
createdDate: number;
|
|
@@ -33,7 +33,8 @@ const normalizeBitbucketServerPullRequest = (pr) => {
|
|
|
33
33
|
const bitbucketStateToGitState = {
|
|
34
34
|
OPEN: GitPullRequestState.Open,
|
|
35
35
|
MERGED: GitPullRequestState.Merged,
|
|
36
|
-
DECLINED: GitPullRequestState.Closed
|
|
36
|
+
DECLINED: GitPullRequestState.Closed,
|
|
37
|
+
SUPERSEDED: GitPullRequestState.Closed
|
|
37
38
|
};
|
|
38
39
|
const reviewerStatusToGitState = {
|
|
39
40
|
UNAPPROVED: GitPullRequestReviewState.ReviewRequested,
|
|
@@ -58,7 +59,7 @@ const normalizeBitbucketServerPullRequest = (pr) => {
|
|
|
58
59
|
url: pr.links.self[0].href,
|
|
59
60
|
state: bitbucketStateToGitState[pr.state],
|
|
60
61
|
isCrossRepository: pr.toRef.repository.id !== pr.fromRef.repository.id,
|
|
61
|
-
isDraft:
|
|
62
|
+
isDraft: pr.draft === true,
|
|
62
63
|
createdDate: new Date(pr.createdDate),
|
|
63
64
|
updatedDate: new Date(pr.updatedDate),
|
|
64
65
|
closedDate: pr.closedDate ? new Date(pr.closedDate) : null,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.js","names":[],"sources":["../../../../../../plus/integrations/src/providers/bitbucket-server/models.ts"],"sourcesContent":["import type {\n\tGitPullRequestMergeableState as GitPullRequestMergeableStateType,\n\tGitPullRequestReviewState as GitPullRequestReviewStateType,\n\tGitPullRequestState as GitPullRequestStateType,\n} from '@gitkraken/provider-apis';\nimport type { ProviderAccount, ProviderPullRequest } from '../models.js';\n\ntype GitPullRequestMergeableState = GitPullRequestMergeableStateType;\ntype GitPullRequestReviewState = GitPullRequestReviewStateType;\ntype GitPullRequestState = GitPullRequestStateType;\n\n// Local runtime copies of the `@gitkraken/provider-apis` PR string enums, duplicated for the same\n// CJS-from-ESM reason as the enums in `../models.ts`. Exported so the enum-parity test can guard them\n// against upstream drift. `GitPullRequestMergeableState` is an intentional subset: Bitbucket Server\n// only ever normalizes to `Unknown`, so the parity test asserts each local entry matches the SDK\n// rather than a full mirror.\nexport const GitPullRequestState = {\n\tOpen: 'OPEN' as GitPullRequestState,\n\tClosed: 'CLOSED' as GitPullRequestState,\n\tMerged: 'MERGED' as GitPullRequestState,\n} as const;\n\nexport const GitPullRequestReviewState = {\n\tApproved: 'APPROVED' as GitPullRequestReviewState,\n\tChangesRequested: 'CHANGES_REQUESTED' as GitPullRequestReviewState,\n\tCommented: 'COMMENTED' as GitPullRequestReviewState,\n\tReviewRequested: 'REVIEW_REQUESTED' as GitPullRequestReviewState,\n} as const;\n\nexport const GitPullRequestMergeableState = {\n\tUnknown: 'UNKNOWN' as GitPullRequestMergeableState,\n} as const;\n\nexport interface BitbucketServerLink {\n\thref: string;\n}\n\nexport interface NamedBitbucketServerLink<T extends string = string> extends BitbucketServerLink {\n\tname: T;\n}\n\nexport interface BitbucketServerPagedResponse<T> {\n\tvalues: T[];\n\tsize: number;\n\tlimit: number;\n\tisLastPage: boolean;\n\tnextPageStart: number;\n\tstart: number;\n}\n\nexport interface BitbucketServerPullRequestRef {\n\tid: string;\n\tdisplayId: string;\n\tlatestCommit: string;\n\ttype: string;\n\trepository: {\n\t\tslug: string;\n\t\tid: number;\n\t\tname: string;\n\t\thierarchyId: string;\n\t\tscmId: string;\n\t\tstate: string;\n\t\tstatusMessage: string;\n\t\tforkable: boolean;\n\t\tproject: {\n\t\t\tkey: string;\n\t\t\tid: number;\n\t\t\tname: string;\n\t\t\tpublic: boolean;\n\t\t\ttype: string;\n\t\t\tlinks: {\n\t\t\t\tself: BitbucketServerLink[];\n\t\t\t};\n\t\t};\n\t\tpublic: boolean;\n\t\tarchived: boolean;\n\t\tlinks: {\n\t\t\tclone: NamedBitbucketServerLink[];\n\t\t\tself: BitbucketServerLink[];\n\t\t};\n\t};\n}\n\nexport interface BitbucketAuthor {\n\tname: string;\n\temailAddress: string;\n\tid: undefined;\n}\n\nexport interface BitbucketServerUser {\n\tname: string;\n\temailAddress: string;\n\tactive: boolean;\n\tdisplayName: string;\n\tid: number;\n\tslug: string;\n\ttype: string;\n\tlinks: {\n\t\tself: BitbucketServerLink[];\n\t};\n\tavatarUrl?: string;\n}\n\nexport interface BitbucketServerPullRequestUser {\n\tuser: BitbucketServerUser;\n\tlastReviewedCommit?: string;\n\trole: 'REVIEWER' | 'AUTHOR' | 'PARTICIPANT';\n\tapproved: boolean;\n\tstatus: 'UNAPPROVED' | 'NEEDS_WORK' | 'APPROVED';\n}\n\nexport interface BitbucketServerBriefCommit {\n\tdisplayId: string;\n\tid: string;\n}\n\nexport interface BitbucketServerCommit extends BitbucketServerBriefCommit {\n\tauthor: BitbucketServerUser | BitbucketAuthor;\n\tauthorTimestamp: number;\n\tcommitter: BitbucketServerUser | BitbucketAuthor;\n\tcommitterTimestamp: number;\n\tmessage: string;\n\tparents: (BitbucketServerCommit | BitbucketServerBriefCommit)[];\n}\n\nexport interface BitbucketServerPullRequest {\n\tid: number;\n\tversion: number;\n\ttitle: string;\n\tdescription: string;\n\tstate: 'OPEN' | 'MERGED' | 'DECLINED';\n\topen: boolean;\n\tclosed: boolean;\n\tcreatedDate: number;\n\tupdatedDate: number;\n\tclosedDate: number | null;\n\tfromRef: BitbucketServerPullRequestRef;\n\ttoRef: BitbucketServerPullRequestRef;\n\tlocked: boolean;\n\tauthor: BitbucketServerPullRequestUser;\n\treviewers: BitbucketServerPullRequestUser[];\n\tparticipants: BitbucketServerPullRequestUser[];\n\tproperties: {\n\t\tmergeResult: {\n\t\t\toutcome: string;\n\t\t\tcurrent: boolean;\n\t\t};\n\t\tresolvedTaskCount: number;\n\t\tcommentCount: number;\n\t\topenTaskCount: number;\n\t};\n\tlinks: {\n\t\tself: BitbucketServerLink[];\n\t};\n}\n\nconst normalizeUser = (user: BitbucketServerUser): ProviderAccount => ({\n\tname: user.displayName,\n\temail: user.emailAddress,\n\tavatarUrl: user.avatarUrl ?? null,\n\tid: user.id.toString(),\n\tusername: user.name,\n\turl: user.links.self[0].href,\n});\n\nconst reviewDecisionWeightByReviewState = {\n\t[GitPullRequestReviewState.Approved]: 0,\n\t[GitPullRequestReviewState.Commented]: 1,\n\t[GitPullRequestReviewState.ReviewRequested]: 2,\n\t[GitPullRequestReviewState.ChangesRequested]: 3,\n};\n\nexport const summarizeReviewDecision = (\n\treviews: { state: GitPullRequestReviewState }[] | null,\n): GitPullRequestReviewState | null => {\n\tif (!reviews || reviews.length === 0) {\n\t\treturn null;\n\t}\n\n\treturn reviews.reduce(\n\t\t(prev: GitPullRequestReviewState, review) =>\n\t\t\treviewDecisionWeightByReviewState[review.state] > reviewDecisionWeightByReviewState[prev]\n\t\t\t\t? review.state\n\t\t\t\t: prev,\n\t\tGitPullRequestReviewState.Approved,\n\t);\n};\n\nexport const normalizeBitbucketServerPullRequest = (pr: BitbucketServerPullRequest): ProviderPullRequest => {\n\tconst bitbucketStateToGitState = {\n\t\tOPEN: GitPullRequestState.Open,\n\t\tMERGED: GitPullRequestState.Merged,\n\t\tDECLINED: GitPullRequestState.Closed,\n\t};\n\n\tconst reviewerStatusToGitState = {\n\t\tUNAPPROVED: GitPullRequestReviewState.ReviewRequested,\n\t\tNEEDS_WORK: GitPullRequestReviewState.ChangesRequested,\n\t\tAPPROVED: GitPullRequestReviewState.Approved,\n\t};\n\n\tconst reviews = pr.reviewers.map(reviewer => ({\n\t\treviewer: normalizeUser(reviewer.user),\n\t\tstate: reviewerStatusToGitState[reviewer.status],\n\t}));\n\n\tconst baseSSHUrl = pr.toRef.repository.links.clone.find(link => link.name === 'ssh')?.href ?? null;\n\tlet baseHTTPSUrl = pr.toRef.repository.links.clone.find(link => link.name === 'https')?.href ?? null;\n\tif (!baseHTTPSUrl) {\n\t\tbaseHTTPSUrl = pr.toRef.repository.links.clone.find(link => link.name === 'http')?.href ?? null;\n\t}\n\n\tconst headSSHUrl = pr.fromRef.repository.links.clone.find(link => link.name === 'ssh')?.href ?? null;\n\tlet headHTTPSUrl = pr.fromRef.repository.links.clone.find(link => link.name === 'https')?.href ?? null;\n\tif (!headHTTPSUrl) {\n\t\theadHTTPSUrl = pr.fromRef.repository.links.clone.find(link => link.name === 'http')?.href ?? null;\n\t}\n\n\treturn {\n\t\tid: pr.id.toString(),\n\t\tnumber: pr.id,\n\t\ttitle: pr.title,\n\t\tdescription: pr.description ?? null,\n\t\turl: pr.links.self[0].href,\n\t\tstate: bitbucketStateToGitState[pr.state],\n\t\tisCrossRepository: pr.toRef.repository.id !== pr.fromRef.repository.id,\n\t\tisDraft: false,\n\t\tcreatedDate: new Date(pr.createdDate),\n\t\tupdatedDate: new Date(pr.updatedDate),\n\t\tclosedDate: pr.closedDate ? new Date(pr.closedDate) : null,\n\t\tmergedDate: pr.state === 'MERGED' && pr.closedDate ? new Date(pr.closedDate) : null,\n\t\tbaseRef: {\n\t\t\tname: pr.toRef.displayId,\n\t\t\toid: pr.toRef.latestCommit,\n\t\t},\n\t\theadRef: {\n\t\t\tname: pr.fromRef.displayId,\n\t\t\toid: pr.fromRef.latestCommit,\n\t\t},\n\t\tcommentCount: pr.properties?.commentCount,\n\t\tupvoteCount: null,\n\t\tcommitCount: null,\n\t\tfileCount: null,\n\t\tadditions: null,\n\t\tdeletions: null,\n\t\tauthor: normalizeUser(pr.author.user),\n\t\tassignees: null,\n\t\treviews: reviews,\n\t\treviewDecision: summarizeReviewDecision(reviews),\n\t\trepository: {\n\t\t\tid: pr.toRef.repository.id.toString(),\n\t\t\tname: pr.toRef.repository.name,\n\t\t\towner: {\n\t\t\t\tlogin: pr.toRef.repository.project.key,\n\t\t\t},\n\t\t\tremoteInfo:\n\t\t\t\tbaseHTTPSUrl && baseSSHUrl\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tcloneUrlHTTPS: baseHTTPSUrl,\n\t\t\t\t\t\t\tcloneUrlSSH: baseSSHUrl,\n\t\t\t\t\t\t}\n\t\t\t\t\t: null,\n\t\t},\n\t\theadRepository: {\n\t\t\tid: pr.fromRef.repository.id.toString(),\n\t\t\tname: pr.fromRef.repository.name,\n\t\t\towner: {\n\t\t\t\tlogin: pr.fromRef.repository.project.key,\n\t\t\t},\n\t\t\tremoteInfo:\n\t\t\t\theadHTTPSUrl && headSSHUrl\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tcloneUrlHTTPS: headHTTPSUrl,\n\t\t\t\t\t\t\tcloneUrlSSH: headSSHUrl,\n\t\t\t\t\t\t}\n\t\t\t\t\t: null,\n\t\t},\n\t\theadCommit: null,\n\t\tmergeableState: GitPullRequestMergeableState.Unknown,\n\t\tpermissions: null,\n\t\tversion: pr.version,\n\t};\n};\n"],"mappings":";AAgBA,MAAa,sBAAsB;CAClC,MAAM;CACN,QAAQ;CACR,QA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;GACd,IACC;EACL;EACA,gBAAgB;GACf,IAAI,GAAG,QAAQ,WAAW,GAAG,SAAS;GACtC,MAAM,GAAG,QAAQ,WAAW;GAC5B,OAAO,EACN,OAAO,GAAG,QAAQ,WAAW,QAAQ,IACtC;GACA,YACC,gBAAgB,aACb;IACA,eAAe;IACf,aAAa;GACd,IACC;EACL;EACA,YAAY;EACZ,gBAAgB,6BAA6B;EAC7C,aAAa;EACb,SAAS,GAAG;CACb;AACD"}
|
|
1
|
+
{"version":3,"file":"models.js","names":[],"sources":["../../../../../../plus/integrations/src/providers/bitbucket-server/models.ts"],"sourcesContent":["import type {\n\tGitPullRequestMergeableState as GitPullRequestMergeableStateType,\n\tGitPullRequestReviewState as GitPullRequestReviewStateType,\n\tGitPullRequestState as GitPullRequestStateType,\n} from '@gitkraken/provider-apis';\nimport type { ProviderAccount, ProviderPullRequest } from '../models.js';\n\ntype GitPullRequestMergeableState = GitPullRequestMergeableStateType;\ntype GitPullRequestReviewState = GitPullRequestReviewStateType;\ntype GitPullRequestState = GitPullRequestStateType;\n\n// Local runtime copies of the `@gitkraken/provider-apis` PR string enums, duplicated for the same\n// CJS-from-ESM reason as the enums in `../models.ts`. Exported so the enum-parity test can guard them\n// against upstream drift. `GitPullRequestMergeableState` is an intentional subset: Bitbucket Server\n// only ever normalizes to `Unknown`, so the parity test asserts each local entry matches the SDK\n// rather than a full mirror.\nexport const GitPullRequestState = {\n\tOpen: 'OPEN' as GitPullRequestState,\n\tClosed: 'CLOSED' as GitPullRequestState,\n\tMerged: 'MERGED' as GitPullRequestState,\n} as const;\n\nexport const GitPullRequestReviewState = {\n\tApproved: 'APPROVED' as GitPullRequestReviewState,\n\tChangesRequested: 'CHANGES_REQUESTED' as GitPullRequestReviewState,\n\tCommented: 'COMMENTED' as GitPullRequestReviewState,\n\tReviewRequested: 'REVIEW_REQUESTED' as GitPullRequestReviewState,\n} as const;\n\nexport const GitPullRequestMergeableState = {\n\tUnknown: 'UNKNOWN' as GitPullRequestMergeableState,\n} as const;\n\nexport interface BitbucketServerLink {\n\thref: string;\n}\n\nexport interface NamedBitbucketServerLink<T extends string = string> extends BitbucketServerLink {\n\tname: T;\n}\n\nexport interface BitbucketServerPagedResponse<T> {\n\tvalues: T[];\n\tsize: number;\n\tlimit: number;\n\tisLastPage: boolean;\n\tnextPageStart: number;\n\tstart: number;\n}\n\nexport interface BitbucketServerPullRequestRef {\n\tid: string;\n\tdisplayId: string;\n\tlatestCommit: string;\n\ttype: string;\n\trepository: {\n\t\tslug: string;\n\t\tid: number;\n\t\tname: string;\n\t\thierarchyId: string;\n\t\tscmId: string;\n\t\tstate: string;\n\t\tstatusMessage: string;\n\t\tforkable: boolean;\n\t\tproject: {\n\t\t\tkey: string;\n\t\t\tid: number;\n\t\t\tname: string;\n\t\t\tpublic: boolean;\n\t\t\ttype: string;\n\t\t\tlinks: {\n\t\t\t\tself: BitbucketServerLink[];\n\t\t\t};\n\t\t};\n\t\tpublic: boolean;\n\t\tarchived: boolean;\n\t\tlinks: {\n\t\t\tclone: NamedBitbucketServerLink[];\n\t\t\tself: BitbucketServerLink[];\n\t\t};\n\t};\n}\n\nexport interface BitbucketAuthor {\n\tname: string;\n\temailAddress: string;\n\tid: undefined;\n}\n\nexport interface BitbucketServerUser {\n\tname: string;\n\temailAddress: string;\n\tactive: boolean;\n\tdisplayName: string;\n\tid: number;\n\tslug: string;\n\ttype: string;\n\tlinks: {\n\t\tself: BitbucketServerLink[];\n\t};\n\tavatarUrl?: string;\n}\n\nexport interface BitbucketServerPullRequestUser {\n\tuser: BitbucketServerUser;\n\tlastReviewedCommit?: string;\n\trole: 'REVIEWER' | 'AUTHOR' | 'PARTICIPANT';\n\tapproved: boolean;\n\tstatus: 'UNAPPROVED' | 'NEEDS_WORK' | 'APPROVED';\n}\n\nexport interface BitbucketServerBriefCommit {\n\tdisplayId: string;\n\tid: string;\n}\n\nexport interface BitbucketServerCommit extends BitbucketServerBriefCommit {\n\tauthor: BitbucketServerUser | BitbucketAuthor;\n\tauthorTimestamp: number;\n\tcommitter: BitbucketServerUser | BitbucketAuthor;\n\tcommitterTimestamp: number;\n\tmessage: string;\n\tparents: (BitbucketServerCommit | BitbucketServerBriefCommit)[];\n}\n\nexport interface BitbucketServerPullRequest {\n\tid: number;\n\tversion: number;\n\ttitle: string;\n\tdescription: string;\n\t/**\n\t * `SUPERSEDED` is not in the published schema, but a server can still report it for a pull request closed by a\n\t * newer one (the Bitbucket SDK maps it too); it is a closed pull request, like `DECLINED`.\n\t */\n\tstate: 'OPEN' | 'MERGED' | 'DECLINED' | 'SUPERSEDED';\n\t/**\n\t * Drafts shipped in Bitbucket Data Center 8.18 (8.17 exposed the field experimentally); absent means the server\n\t * has no drafts, so not a draft.\n\t */\n\tdraft?: boolean;\n\topen: boolean;\n\tclosed: boolean;\n\tcreatedDate: number;\n\tupdatedDate: number;\n\tclosedDate: number | null;\n\tfromRef: BitbucketServerPullRequestRef;\n\ttoRef: BitbucketServerPullRequestRef;\n\tlocked: boolean;\n\tauthor: BitbucketServerPullRequestUser;\n\treviewers: BitbucketServerPullRequestUser[];\n\tparticipants: BitbucketServerPullRequestUser[];\n\tproperties: {\n\t\tmergeResult: {\n\t\t\toutcome: string;\n\t\t\tcurrent: boolean;\n\t\t};\n\t\tresolvedTaskCount: number;\n\t\tcommentCount: number;\n\t\topenTaskCount: number;\n\t};\n\tlinks: {\n\t\tself: BitbucketServerLink[];\n\t};\n}\n\nconst normalizeUser = (user: BitbucketServerUser): ProviderAccount => ({\n\tname: user.displayName,\n\temail: user.emailAddress,\n\tavatarUrl: user.avatarUrl ?? null,\n\tid: user.id.toString(),\n\tusername: user.name,\n\turl: user.links.self[0].href,\n});\n\nconst reviewDecisionWeightByReviewState = {\n\t[GitPullRequestReviewState.Approved]: 0,\n\t[GitPullRequestReviewState.Commented]: 1,\n\t[GitPullRequestReviewState.ReviewRequested]: 2,\n\t[GitPullRequestReviewState.ChangesRequested]: 3,\n};\n\nexport const summarizeReviewDecision = (\n\treviews: { state: GitPullRequestReviewState }[] | null,\n): GitPullRequestReviewState | null => {\n\tif (!reviews || reviews.length === 0) {\n\t\treturn null;\n\t}\n\n\treturn reviews.reduce(\n\t\t(prev: GitPullRequestReviewState, review) =>\n\t\t\treviewDecisionWeightByReviewState[review.state] > reviewDecisionWeightByReviewState[prev]\n\t\t\t\t? review.state\n\t\t\t\t: prev,\n\t\tGitPullRequestReviewState.Approved,\n\t);\n};\n\nexport const normalizeBitbucketServerPullRequest = (pr: BitbucketServerPullRequest): ProviderPullRequest => {\n\tconst bitbucketStateToGitState = {\n\t\tOPEN: GitPullRequestState.Open,\n\t\tMERGED: GitPullRequestState.Merged,\n\t\tDECLINED: GitPullRequestState.Closed,\n\t\tSUPERSEDED: GitPullRequestState.Closed,\n\t};\n\n\tconst reviewerStatusToGitState = {\n\t\tUNAPPROVED: GitPullRequestReviewState.ReviewRequested,\n\t\tNEEDS_WORK: GitPullRequestReviewState.ChangesRequested,\n\t\tAPPROVED: GitPullRequestReviewState.Approved,\n\t};\n\n\tconst reviews = pr.reviewers.map(reviewer => ({\n\t\treviewer: normalizeUser(reviewer.user),\n\t\tstate: reviewerStatusToGitState[reviewer.status],\n\t}));\n\n\tconst baseSSHUrl = pr.toRef.repository.links.clone.find(link => link.name === 'ssh')?.href ?? null;\n\tlet baseHTTPSUrl = pr.toRef.repository.links.clone.find(link => link.name === 'https')?.href ?? null;\n\tif (!baseHTTPSUrl) {\n\t\tbaseHTTPSUrl = pr.toRef.repository.links.clone.find(link => link.name === 'http')?.href ?? null;\n\t}\n\n\tconst headSSHUrl = pr.fromRef.repository.links.clone.find(link => link.name === 'ssh')?.href ?? null;\n\tlet headHTTPSUrl = pr.fromRef.repository.links.clone.find(link => link.name === 'https')?.href ?? null;\n\tif (!headHTTPSUrl) {\n\t\theadHTTPSUrl = pr.fromRef.repository.links.clone.find(link => link.name === 'http')?.href ?? null;\n\t}\n\n\treturn {\n\t\tid: pr.id.toString(),\n\t\tnumber: pr.id,\n\t\ttitle: pr.title,\n\t\tdescription: pr.description ?? null,\n\t\turl: pr.links.self[0].href,\n\t\tstate: bitbucketStateToGitState[pr.state],\n\t\tisCrossRepository: pr.toRef.repository.id !== pr.fromRef.repository.id,\n\t\tisDraft: pr.draft === true,\n\t\tcreatedDate: new Date(pr.createdDate),\n\t\tupdatedDate: new Date(pr.updatedDate),\n\t\tclosedDate: pr.closedDate ? new Date(pr.closedDate) : null,\n\t\tmergedDate: pr.state === 'MERGED' && pr.closedDate ? new Date(pr.closedDate) : null,\n\t\tbaseRef: {\n\t\t\tname: pr.toRef.displayId,\n\t\t\toid: pr.toRef.latestCommit,\n\t\t},\n\t\theadRef: {\n\t\t\tname: pr.fromRef.displayId,\n\t\t\toid: pr.fromRef.latestCommit,\n\t\t},\n\t\tcommentCount: pr.properties?.commentCount,\n\t\tupvoteCount: null,\n\t\tcommitCount: null,\n\t\tfileCount: null,\n\t\tadditions: null,\n\t\tdeletions: null,\n\t\tauthor: normalizeUser(pr.author.user),\n\t\tassignees: null,\n\t\treviews: reviews,\n\t\treviewDecision: summarizeReviewDecision(reviews),\n\t\trepository: {\n\t\t\tid: pr.toRef.repository.id.toString(),\n\t\t\tname: pr.toRef.repository.name,\n\t\t\towner: {\n\t\t\t\tlogin: pr.toRef.repository.project.key,\n\t\t\t},\n\t\t\tremoteInfo:\n\t\t\t\tbaseHTTPSUrl && baseSSHUrl\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tcloneUrlHTTPS: baseHTTPSUrl,\n\t\t\t\t\t\t\tcloneUrlSSH: baseSSHUrl,\n\t\t\t\t\t\t}\n\t\t\t\t\t: null,\n\t\t},\n\t\theadRepository: {\n\t\t\tid: pr.fromRef.repository.id.toString(),\n\t\t\tname: pr.fromRef.repository.name,\n\t\t\towner: {\n\t\t\t\tlogin: pr.fromRef.repository.project.key,\n\t\t\t},\n\t\t\tremoteInfo:\n\t\t\t\theadHTTPSUrl && headSSHUrl\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tcloneUrlHTTPS: headHTTPSUrl,\n\t\t\t\t\t\t\tcloneUrlSSH: headSSHUrl,\n\t\t\t\t\t\t}\n\t\t\t\t\t: null,\n\t\t},\n\t\theadCommit: null,\n\t\tmergeableState: GitPullRequestMergeableState.Unknown,\n\t\tpermissions: null,\n\t\tversion: pr.version,\n\t};\n};\n"],"mappings":";AAgBA,MAAa,sBAAsB;CAClC,MAAM;CACN,QAAQ;CACR,QAAQ;AACT;AAEA,MAAa,4BAA4B;CACxC,UAAU;CACV,kBAAkB;CAClB,WAAW;CACX,iBAAiB;AAClB;AAEA,MAAa,+BAA+B,EAC3C,SAAS,UACV;AAsIA,MAAM,iBAAiB,UAAgD;CACtE,MAAM,KAAK;CACX,OAAO,KAAK;CACZ,WAAW,KAAK,aAAa;CAC7B,IAAI,KAAK,GAAG,SAAS;CACrB,UAAU,KAAK;CACf,KAAK,KAAK,MAAM,KAAK,EAAE,CAAC;AACzB;AAEA,MAAM,oCAAoC;EACxC,0BAA0B,WAAW;EACrC,0BAA0B,YAAY;EACtC,0BAA0B,kBAAkB;EAC5C,0BAA0B,mBAAmB;AAC/C;AAEA,MAAa,2BACZ,YACsC;CACtC,IAAI,CAAC,WAAW,QAAQ,WAAW,GAClC,OAAO;CAGR,OAAO,QAAQ,QACb,MAAiC,WACjC,kCAAkC,OAAO,SAAS,kCAAkC,QACjF,OAAO,QACP,MACJ,0BAA0B,QAC3B;AACD;AAEA,MAAa,uCAAuC,OAAwD;CAC3G,MAAM,2BAA2B;EAChC,MAAM,oBAAoB;EAC1B,QAAQ,oBAAoB;EAC5B,UAAU,oBAAoB;EAC9B,YAAY,oBAAoB;CACjC;CAEA,MAAM,2BAA2B;EAChC,YAAY,0BAA0B;EACtC,YAAY,0BAA0B;EACtC,UAAU,0BAA0B;CACrC;CAEA,MAAM,UAAU,GAAG,UAAU,KAAI,cAAa;EAC7C,UAAU,cAAc,SAAS,IAAI;EACrC,OAAO,yBAAyB,SAAS;CAC1C,EAAE;CAEF,MAAM,aAA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a;EACb,WAAW;EACX,WAAW;EACX,WAAW;EACX,QAAQ,cAAc,GAAG,OAAO,IAAI;EACpC,WAAW;EACF;EACT,gBAAgB,wBAAwB,OAAO;EAC/C,YAAY;GACX,IAAI,GAAG,MAAM,WAAW,GAAG,SAAS;GACpC,MAAM,GAAG,MAAM,WAAW;GAC1B,OAAO,EACN,OAAO,GAAG,MAAM,WAAW,QAAQ,IACpC;GACA,YACC,gBAAgB,aACb;IACA,eAAe;IACf,aAAa;GACd,IACC;EACL;EACA,gBAAgB;GACf,IAAI,GAAG,QAAQ,WAAW,GAAG,SAAS;GACtC,MAAM,GAAG,QAAQ,WAAW;GAC5B,OAAO,EACN,OAAO,GAAG,QAAQ,WAAW,QAAQ,IACtC;GACA,YACC,gBAAgB,aACb;IACA,eAAe;IACf,aAAa;GACd,IACC;EACL;EACA,YAAY;EACZ,gBAAgB,6BAA6B;EAC7C,aAAa;EACb,SAAS,GAAG;CACb;AACD"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Provider } from "../../../../git/models/remoteProvider.js";
|
|
2
|
+
import { PullRequestSearchCriteria } from "../../../../git/models/pullRequest.js";
|
|
3
|
+
import { TokenWithInfo } from "../../authentication/models.js";
|
|
4
|
+
import { GitSelfManagedHostIntegrationId } from "../../constants.js";
|
|
5
|
+
import { ProviderPullRequestCount, ProviderPullRequestSearchPage } from "../../models/pullRequestReads.js";
|
|
6
|
+
import { ProviderRepoInput, ProviderRequestFunction } from "../models.js";
|
|
7
|
+
//#region ../plus/integrations/src/providers/bitbucket-server/pullRequestSearch.d.ts
|
|
8
|
+
type Token = TokenWithInfo<GitSelfManagedHostIntegrationId.BitbucketServer>;
|
|
9
|
+
/** The current user, which both the server-side participant filters and their client-side re-check identify. */
|
|
10
|
+
export interface BitbucketServerSearchUser {
|
|
11
|
+
id: string;
|
|
12
|
+
username: string;
|
|
13
|
+
}
|
|
14
|
+
interface SearchOptions {
|
|
15
|
+
baseUrl: string;
|
|
16
|
+
repos?: ProviderRepoInput[];
|
|
17
|
+
/** Refused when set: Bitbucket Data Center has no project-wide pull-request list to scope it to. */
|
|
18
|
+
org?: string;
|
|
19
|
+
criteria?: PullRequestSearchCriteria;
|
|
20
|
+
/** Required when `criteria.relationships` is non-empty. */
|
|
21
|
+
currentUser?: BitbucketServerSearchUser;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Pull requests matching `criteria` over the requested repositories, or over the current user's relationships when
|
|
25
|
+
* none are given.
|
|
26
|
+
*
|
|
27
|
+
* Every facet reads its own page, and the merged page is re-ordered as a whole. Each facet keeps its own
|
|
28
|
+
* `nextPageStart` in the cursor, which is bound to this connection, installation and query: a cursor handed back
|
|
29
|
+
* under anything else is refused rather than read as page 1 of a different search. A pull request several
|
|
30
|
+
* relationships match is served by exactly one of them, the first in canonical order (see {@link ownsRow}), so facets
|
|
31
|
+
* that advance independently never serve it twice across pages and the cursor carries no history of what it emitted.
|
|
32
|
+
*
|
|
33
|
+
* Every criterion the server applies is applied again to the rows it returns, so a server that ignores a parameter
|
|
34
|
+
* (one older than 8.18, which shipped drafts, has no `draft`) narrows the page instead of silently widening it.
|
|
35
|
+
*
|
|
36
|
+
* A facet that fails is reported in `metadata` while its siblings still answer, and keeps its offset, so the next page
|
|
37
|
+
* retries the page it missed — a transient failure recovers the rows it cost. A facet that fails its retry too is
|
|
38
|
+
* dropped, and reported on every later page, which no longer reads it; one retry keeps a facet that will never answer
|
|
39
|
+
* from holding `hasMore` open forever. If every facet fails on the first page, the first failure is thrown instead.
|
|
40
|
+
*/
|
|
41
|
+
export declare function searchBitbucketServerPullRequestsPage(request: ProviderRequestFunction, token: Token, options: SearchOptions & {
|
|
42
|
+
connectionId: string;
|
|
43
|
+
provider: Provider;
|
|
44
|
+
cursor?: string;
|
|
45
|
+
pageSize?: number;
|
|
46
|
+
}, cancellation?: AbortSignal): Promise<ProviderPullRequestSearchPage>;
|
|
47
|
+
/**
|
|
48
|
+
* How many pull requests match `criteria`: the same facets, predicates and identity the search uses, so the count
|
|
49
|
+
* is the number of distinct rows the search would return — the union of the requested states, not the largest of
|
|
50
|
+
* them, since Bitbucket has no per-search ceiling for a maximum to stay under.
|
|
51
|
+
*
|
|
52
|
+
* Bitbucket Data Center has no count query and reports no total, so each facet reads one page of up to
|
|
53
|
+
* {@link maxPageSize} and the count is a floor (`lowerBound`) when any facet had more. Unlike the search, one failed
|
|
54
|
+
* facet fails the whole count: a count missing a facet is a wrong number rather than a partial one.
|
|
55
|
+
*/
|
|
56
|
+
export declare function countBitbucketServerPullRequests(request: ProviderRequestFunction, token: Token, options: SearchOptions, cancellation?: AbortSignal): Promise<ProviderPullRequestCount>;
|
|
57
|
+
//#endregion
|
|
58
|
+
//# sourceMappingURL=pullRequestSearch.d.ts.map
|