@gitkraken/core-gitlens 0.57.0 → 0.58.0

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.
Files changed (53) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/git-cli/providers/config.js +2 -2
  3. package/dist/git-cli/providers/pausedOperations.js +2 -2
  4. package/dist/git-cli/providers/pausedOperations.js.map +1 -1
  5. package/dist/git-cli/providers/staging.js +1 -1
  6. package/dist/ipc/discovery.js +1 -1
  7. package/dist/plus/agents/providers/claudeCodeTranscript.js +6 -6
  8. package/dist/plus/agents/providers/claudeCodeTranscript.js.map +1 -1
  9. package/dist/plus/ai/providers/openAICompatibleProviderBase.js +1 -1
  10. package/dist/plus/integrations/authentication/configuredIntegrationService.d.ts +4 -0
  11. package/dist/plus/integrations/authentication/configuredIntegrationService.js +8 -2
  12. package/dist/plus/integrations/authentication/configuredIntegrationService.js.map +1 -1
  13. package/dist/plus/integrations/authentication/integrationAuthenticationService.d.ts +1 -1
  14. package/dist/plus/integrations/authentication/integrationAuthenticationService.js +2 -2
  15. package/dist/plus/integrations/authentication/integrationAuthenticationService.js.map +1 -1
  16. package/dist/plus/integrations/authentication/observedAuthenticationProvider.d.ts +2 -1
  17. package/dist/plus/integrations/authentication/observedAuthenticationProvider.js +16 -12
  18. package/dist/plus/integrations/authentication/observedAuthenticationProvider.js.map +1 -1
  19. package/dist/plus/integrations/index.d.ts +2 -1
  20. package/dist/plus/integrations/index.js.map +1 -1
  21. package/dist/plus/integrations/integrationService.d.ts +5 -0
  22. package/dist/plus/integrations/integrationService.js +54 -0
  23. package/dist/plus/integrations/integrationService.js.map +1 -1
  24. package/dist/plus/integrations/manager.d.ts +8 -0
  25. package/dist/plus/integrations/models/bitbucketServerPullRequestWrites.d.ts +142 -0
  26. package/dist/plus/integrations/models/bitbucketServerPullRequestWrites.js +0 -0
  27. package/dist/plus/integrations/models/integration.d.ts +6 -3
  28. package/dist/plus/integrations/models/integration.js +11 -10
  29. package/dist/plus/integrations/models/integration.js.map +1 -1
  30. package/dist/plus/integrations/providers/azure/azure.js +1 -1
  31. package/dist/plus/integrations/providers/bitbucket-server.d.ts +4 -1
  32. package/dist/plus/integrations/providers/bitbucket-server.js +23 -0
  33. package/dist/plus/integrations/providers/bitbucket-server.js.map +1 -1
  34. package/dist/plus/integrations/providers/bitbucketPullRequestWrites.js +2 -2
  35. package/dist/plus/integrations/providers/bitbucketPullRequestWrites.js.map +1 -1
  36. package/dist/plus/integrations/providers/bitbucketServerPullRequestWriteErrors.d.ts +22 -0
  37. package/dist/plus/integrations/providers/bitbucketServerPullRequestWriteErrors.js +94 -0
  38. package/dist/plus/integrations/providers/bitbucketServerPullRequestWriteErrors.js.map +1 -0
  39. package/dist/plus/integrations/providers/bitbucketServerPullRequestWrites.d.ts +51 -0
  40. package/dist/plus/integrations/providers/bitbucketServerPullRequestWrites.js +593 -0
  41. package/dist/plus/integrations/providers/bitbucketServerPullRequestWrites.js.map +1 -0
  42. package/dist/plus/integrations/providers/github.js +1 -1
  43. package/dist/plus/integrations/providers/providerApiClient.js +4 -3
  44. package/dist/plus/integrations/providers/providerApiClient.js.map +1 -1
  45. package/dist/plus/integrations/providers/providersApi.d.ts +10 -0
  46. package/dist/plus/integrations/providers/providersApi.js +45 -1
  47. package/dist/plus/integrations/providers/providersApi.js.map +1 -1
  48. package/dist/plus/integrations/providers/utils/writeInputs.d.ts +1 -0
  49. package/dist/plus/integrations/providers/utils/writeInputs.js +4 -1
  50. package/dist/plus/integrations/providers/utils/writeInputs.js.map +1 -1
  51. package/dist/utils/env/node/exec.js +2 -2
  52. package/docs/integrations.md +81 -0
  53. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"bitbucket-server.js","names":[],"sources":["../../../../../plus/integrations/src/providers/bitbucket-server.ts"],"sourcesContent":["import type { Account, UnidentifiedAuthor } from '@gitlens/git/models/author.js';\nimport type { DefaultBranch } from '@gitlens/git/models/defaultBranch.js';\nimport type { Issue, IssueShape } from '@gitlens/git/models/issue.js';\nimport type { IssueOrPullRequest, IssueOrPullRequestType } from '@gitlens/git/models/issueOrPullRequest.js';\nimport type {\n\tPullRequest,\n\tPullRequestMergeMethod,\n\tPullRequestSearchCriteria,\n\tPullRequestShape,\n\tPullRequestState,\n\tPullRequestStateFilter,\n} from '@gitlens/git/models/pullRequest.js';\nimport type { GitRemote } from '@gitlens/git/models/remote.js';\nimport type { RepositoryMetadata } from '@gitlens/git/models/repositoryMetadata.js';\nimport type { PullRequestUrlIdentity } from '@gitlens/git/utils/pullRequest.utils.js';\nimport { CancellationError, raceWithSignal } from '@gitlens/utils/cancellation.js';\nimport { md5 } from '@gitlens/utils/crypto.js';\nimport type { Emitter } from '@gitlens/utils/event.js';\nimport type { PagedResult } from '@gitlens/utils/paging.js';\nimport { mapSettledBounded, nonnullSettled } from '@gitlens/utils/promise.js';\nimport type { IntegrationAuthenticationProviderDescriptor } from '../authentication/integrationAuthenticationProvider.js';\nimport type { IntegrationAuthenticationService } from '../authentication/integrationAuthenticationService.js';\nimport type {\n\tAuthenticationSessionLike as AuthenticationSession,\n\tProviderAuthenticationSession,\n} from '../authentication/models.js';\nimport { toTokenWithInfo } from '../authentication/models.js';\nimport { GitSelfManagedHostIntegrationId } from '../constants.js';\nimport type { IntegrationServiceContext } from '../context.js';\nimport type { ResponseHeaders } from '../errors.js';\nimport { AuthenticationError, getAuthenticatedUser, IntegrationReadUnavailableError } from '../errors.js';\nimport type { IntegrationConnectionChangeEvent } from '../integrationService.js';\nimport { GitHostIntegration } from '../models/gitHostIntegration.js';\nimport type { ProviderPullRequestCount, ProviderPullRequestSearchPage } from '../models/integration.js';\nimport type {\n\tIntegrationKey,\n\tSearchMyPullRequestsOptions,\n\tSearchPullRequestsOptions,\n} from '../models/publicIntegration.js';\nimport type { BitbucketServerSearchUser } from './bitbucket-server/pullRequestSearch.js';\nimport { getBitbucketServerPullRequestIdentityFromMaybeUrl } from './bitbucket/bitbucket.utils.js';\nimport type { BitbucketRepositoryDescriptor } from './bitbucket/models.js';\nimport { providersMetadata } from './metadata.js';\nimport type {\n\tProviderHierarchyResult,\n\tProviderOrganization,\n\tProviderPullRequest,\n\tProviderRepoInput,\n\tProviderRepository,\n} from './models.js';\nimport {\n\tfromProviderPullRequest,\n\tproviderPullRequestMatchesSearch,\n\tProviderPullRequestReviewState,\n\tPullRequestFilter,\n\ttoProviderPullRequestStates,\n} from './models.js';\nimport type { ProvidersApi } from './providersApi.js';\nimport {\n\tcollectProviderPagedResult,\n\tflatSettledOrThrow,\n\tparsePageCursor,\n\tproviderFanOutConcurrency,\n\ttoPageCursor,\n} from './utils/providerPaging.js';\n\nconst metadata = providersMetadata[GitSelfManagedHostIntegrationId.BitbucketServer];\nconst authProvider = Object.freeze({ id: metadata.id, scopes: metadata.scopes });\n\nexport class BitbucketServerIntegration extends GitHostIntegration<\n\tGitSelfManagedHostIntegrationId.BitbucketServer,\n\tBitbucketRepositoryDescriptor\n> {\n\treadonly authProvider: IntegrationAuthenticationProviderDescriptor = authProvider;\n\treadonly id = GitSelfManagedHostIntegrationId.BitbucketServer;\n\tprotected readonly key =\n\t\t`${this.id}:${this.domain}` satisfies IntegrationKey<GitSelfManagedHostIntegrationId.BitbucketServer>;\n\treadonly name: string = 'Bitbucket Data Center';\n\n\tconstructor(\n\t\tctx: IntegrationServiceContext,\n\t\tauthenticationService: IntegrationAuthenticationService,\n\t\tgetProvidersApi: () => Promise<ProvidersApi>,\n\t\tdidChangeConnection: Emitter<IntegrationConnectionChangeEvent>,\n\t\tprivate readonly _domain: string,\n\t) {\n\t\tsuper(ctx, authenticationService, getProvidersApi, didChangeConnection);\n\t}\n\n\tget domain(): string {\n\t\treturn this._domain;\n\t}\n\n\tprotected apiBaseUrlFor(session: ProviderAuthenticationSession): string {\n\t\treturn this.getSelfManagedApiBaseUrl(session);\n\t}\n\n\tprotected override async mergeProviderPullRequest(\n\t\tsession: ProviderAuthenticationSession,\n\t\tpr: PullRequest,\n\t\toptions?: {\n\t\t\tmergeMethod?: PullRequestMergeMethod;\n\t\t},\n\t): Promise<boolean> {\n\t\tconst api = await this.getProvidersApi();\n\t\treturn api.mergePullRequest(toTokenWithInfo(this.id, session), pr, {\n\t\t\tmergeMethod: options?.mergeMethod,\n\t\t\tbaseUrl: this.apiBaseUrlFor(session),\n\t\t});\n\t}\n\n\tprotected override async getProviderAccountForCommit(\n\t\tsession: ProviderAuthenticationSession,\n\t\trepo: BitbucketRepositoryDescriptor,\n\t\trev: string,\n\t\toptions?: {\n\t\t\tavatarSize?: number;\n\t\t},\n\t): Promise<Account | UnidentifiedAuthor | undefined> {\n\t\treturn (await this.authenticationService.apis.bitbucket)?.getServerAccountForCommit(\n\t\t\tthis,\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\trepo.owner,\n\t\t\trepo.name,\n\t\t\trev,\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t\t{\n\t\t\t\tavatarSize: options?.avatarSize,\n\t\t\t},\n\t\t);\n\t}\n\n\tprotected override async getProviderAccountForEmail(\n\t\t_session: AuthenticationSession,\n\t\t_repo: BitbucketRepositoryDescriptor,\n\t\t_email: string,\n\t\t_options?: {\n\t\t\tavatarSize?: number;\n\t\t},\n\t): Promise<Account | undefined> {\n\t\treturn Promise.resolve(undefined);\n\t}\n\n\tprotected override async getProviderDefaultBranch(\n\t\t_session: AuthenticationSession,\n\t\t_repo: BitbucketRepositoryDescriptor,\n\t): Promise<DefaultBranch | undefined> {\n\t\treturn Promise.resolve(undefined);\n\t}\n\n\tprotected override async getProviderLinkedIssueOrPullRequest(\n\t\tsession: ProviderAuthenticationSession,\n\t\trepo: BitbucketRepositoryDescriptor,\n\t\t{ id }: { id: string; key: string },\n\t\ttype: undefined | IssueOrPullRequestType,\n\t): Promise<IssueOrPullRequest | undefined> {\n\t\tif (type === 'issue') {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn (await this.authenticationService.apis.bitbucket)?.getServerPullRequestById(\n\t\t\tthis,\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\trepo.owner,\n\t\t\trepo.name,\n\t\t\tid,\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t);\n\t}\n\n\t/**\n\t * One request per target, settled independently so one target's failure rejects only its own slot:\n\t * provider-apis has no single pull request read for Bitbucket, so this uses our own.\n\t */\n\tprotected override async getProviderPullRequestsBatch(\n\t\tsession: ProviderAuthenticationSession,\n\t\tcoordinates: readonly { owner: string; repo: string; number: number; project?: string }[],\n\t\toptions: { currentAccount?: { id: string; username?: string } } | undefined,\n\t\t_cancellation?: AbortSignal,\n\t): Promise<PromiseSettledResult<PullRequestShape | undefined>[] | undefined> {\n\t\tconst api = await this.authenticationService.apis.bitbucket;\n\t\tif (api == null) return undefined;\n\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\t\treturn mapSettledBounded(coordinates, providerFanOutConcurrency, c =>\n\t\t\tapi.getServerPullRequest(\n\t\t\t\tthis,\n\t\t\t\ttokenWithInfo,\n\t\t\t\tc.owner,\n\t\t\t\tc.repo,\n\t\t\t\tString(c.number),\n\t\t\t\tthis.apiBaseUrlFor(session),\n\t\t\t\t{\n\t\t\t\t\tcurrentAccount: options?.currentAccount,\n\t\t\t\t\tdeferFailure: true,\n\t\t\t\t\tprojection: 'batch',\n\t\t\t\t},\n\t\t\t),\n\t\t);\n\t}\n\n\t/**\n\t * One request per target, settled independently, through our own client: provider-apis' pull request list has\n\t * no source-branch filter. Serves only a branch in the base repository — the manager read refuses a `headOwner`\n\t * naming another owner here, since Bitbucket Data Center finds a branch's pull requests only through the\n\t * repository the branch lives in, and a fork's slug can't be derived from its owner.\n\t */\n\tprotected override async getProviderPullRequestsForBranches(\n\t\tsession: ProviderAuthenticationSession,\n\t\ttargets: readonly { owner: string; repo: string; project?: string; branch: string; headOwner?: string }[],\n\t\toptions: { currentAccount?: { id: string; username?: string }; limit: number },\n\t\t_cancellation?: AbortSignal,\n\t): Promise<PromiseSettledResult<{ pullRequests: PullRequestShape[]; truncated: boolean }>[] | undefined> {\n\t\tconst api = await this.authenticationService.apis.bitbucket;\n\t\tif (api == null) return undefined;\n\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\t\treturn mapSettledBounded(targets, providerFanOutConcurrency, async t => {\n\t\t\tif (t.headOwner != null) {\n\t\t\t\tthrow new Error(`Bitbucket Data Center can't find ${t.branch}'s pull requests in a fork by its owner`);\n\t\t\t}\n\n\t\t\treturn api.getServerPullRequestsForBranch(\n\t\t\t\tthis,\n\t\t\t\ttokenWithInfo,\n\t\t\t\tt.owner,\n\t\t\t\tt.repo,\n\t\t\t\tt.branch,\n\t\t\t\tthis.apiBaseUrlFor(session),\n\t\t\t\t{\n\t\t\t\t\tlimit: options.limit,\n\t\t\t\t\tcurrentAccount: options.currentAccount,\n\t\t\t\t\tdeferFailure: true,\n\t\t\t\t},\n\t\t\t);\n\t\t});\n\t}\n\n\tprotected override async getProviderIssue(\n\t\t_session: AuthenticationSession,\n\t\t_repo: BitbucketRepositoryDescriptor,\n\t\t_id: string,\n\t): Promise<Issue | undefined> {\n\t\treturn Promise.resolve(undefined);\n\t}\n\n\tprotected override async getProviderPullRequestForBranch(\n\t\tsession: ProviderAuthenticationSession,\n\t\trepo: BitbucketRepositoryDescriptor,\n\t\tbranch: string,\n\t\t_options?: {\n\t\t\tavatarSize?: number;\n\t\t\tinclude?: PullRequestState[];\n\t\t},\n\t): Promise<PullRequest | undefined> {\n\t\treturn (await this.authenticationService.apis.bitbucket)?.getServerPullRequestForBranch(\n\t\t\tthis,\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\trepo.owner,\n\t\t\trepo.name,\n\t\t\tbranch,\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t);\n\t}\n\n\tprotected override getProviderPullRequestForCommitInBatch(\n\t\tsession: ProviderAuthenticationSession,\n\t\trepo: BitbucketRepositoryDescriptor,\n\t\trev: string,\n\t\tcancellation?: AbortSignal,\n\t): Promise<PullRequest | undefined> {\n\t\treturn this.readPullRequestForCommit(session, repo, rev, true, cancellation);\n\t}\n\n\tprotected override getProviderPullRequestForCommit(\n\t\tsession: ProviderAuthenticationSession,\n\t\trepo: BitbucketRepositoryDescriptor,\n\t\trev: string,\n\t): Promise<PullRequest | undefined> {\n\t\treturn this.readPullRequestForCommit(session, repo, rev, false);\n\t}\n\n\tprivate async readPullRequestForCommit(\n\t\tsession: ProviderAuthenticationSession,\n\t\trepo: BitbucketRepositoryDescriptor,\n\t\trev: string,\n\t\tdeferFailure: boolean,\n\t\tcancellation?: AbortSignal,\n\t): Promise<PullRequest | undefined> {\n\t\tconst api = await this.authenticationService.apis.bitbucket;\n\t\tif (api == null) {\n\t\t\tthrow new IntegrationReadUnavailableError(this.name, 'no client to read the pull requests of a commit');\n\t\t}\n\n\t\treturn api.getServerPullRequestForCommit(\n\t\t\tthis,\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\trepo.owner,\n\t\t\trepo.name,\n\t\t\trev,\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t\t{ deferFailure: deferFailure },\n\t\t\tcancellation,\n\t\t);\n\t}\n\n\tprotected override async getProviderPullRequest(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresource: BitbucketRepositoryDescriptor,\n\t\tid: string,\n\t): Promise<PullRequest | undefined> {\n\t\treturn (await this.authenticationService.apis.bitbucket)?.getServerPullRequest(\n\t\t\tthis,\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\tresource.owner,\n\t\t\tresource.name,\n\t\t\tid,\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t\t{ projection: 'point' },\n\t\t);\n\t}\n\n\tprotected override getProviderPullRequestIdentityFromMaybeUrl(search: string): PullRequestUrlIdentity | undefined {\n\t\treturn getBitbucketServerPullRequestIdentityFromMaybeUrl(search, this.id);\n\t}\n\n\tpublic override async getRepoInfo(repo: {\n\t\towner: string;\n\t\tname: string;\n\t\tproject?: string;\n\t\tconnectionId?: string;\n\t}): Promise<ProviderRepository | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\t// `connectionId` targets a specific account (multi-account); omitted reads the primary.\n\t\tconst session = await this.resolveReadSessionOrThrow(repo.connectionId, undefined);\n\t\tif (session == null) return undefined;\n\n\t\treturn api.getRepo(toTokenWithInfo(this.id, session), repo.owner, repo.name, repo.project, {\n\t\t\tbaseUrl: this.apiBaseUrlFor(session),\n\t\t});\n\t}\n\n\tprotected override async getProviderRepositoryMetadata(\n\t\t_session: AuthenticationSession,\n\t\t_repo: BitbucketRepositoryDescriptor,\n\t\t_cancellation?: AbortSignal,\n\t): Promise<RepositoryMetadata | undefined> {\n\t\treturn Promise.resolve(undefined);\n\t}\n\n\t/**\n\t * Accounts by {@link getAccountKey}. One integration serves every installation on its host, and installations\n\t * mounted at different context paths are different servers whose users differ, even under the same token.\n\t */\n\tprivate _accounts: Map<string, Account | undefined> | undefined;\n\n\t/** The installation the session's reads address, plus the credential — what decides whose account it is. */\n\tprivate getAccountKey(session: ProviderAuthenticationSession): string {\n\t\treturn `${this.apiBaseUrlFor(session)}\\n${session.accessToken}`;\n\t}\n\n\t/**\n\t * The account request the account cache would otherwise answer; see `IntegrationBase.validateCredential`. Needed\n\t * without any discovery cache: a repo-scoped pull request read fans out across its repositories in the SDK with\n\t * no request to the connection first, so a dead token comes back as one refused repository per request.\n\t *\n\t * A project access token never confirms: its bot user authenticates, but `/users` does not list it, so the SDK\n\t * cannot find the current user and the check proves nothing.\n\t */\n\tprotected override async validateCredential(session: ProviderAuthenticationSession): Promise<void> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst user = await api\n\t\t\t.getCurrentUser(toTokenWithInfo(this.id, session), { baseUrl: this.apiBaseUrlFor(session) })\n\t\t\t.catch((ex: unknown) => {\n\t\t\t\tif (!(ex instanceof AuthenticationError)) throw ex;\n\n\t\t\t\t// Bitbucket Data Center names the user it authenticated in `X-AUSERNAME`, and answers a dead token\n\t\t\t\t// exactly as it answers no credential: the same 401 and body, without that header. So a refusal that\n\t\t\t\t// names a user other than `anonymous`, or says the user holds no license, came from a credential that\n\t\t\t\t// authenticated, and proves nothing about the scopes' refusals.\n\t\t\t\tconst response = (ex.original as { response?: { headers?: ResponseHeaders } } | undefined)?.response;\n\t\t\t\tconst user = getAuthenticatedUser(response?.headers);\n\t\t\t\tif (\n\t\t\t\t\t(user != null && user !== 'anonymous') ||\n\t\t\t\t\t/not (?:a|currently) licensed/i.test(ex.original?.message ?? '')\n\t\t\t\t) {\n\t\t\t\t\tthrow new Error('Bitbucket Data Center could not confirm the credential', { cause: ex });\n\t\t\t\t}\n\t\t\t\tthrow ex;\n\t\t\t});\n\t\tif (user == null) {\n\t\t\tthrow new Error('Bitbucket Data Center did not confirm the credential');\n\t\t}\n\t}\n\n\tprotected override async getProviderCurrentAccount(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<Account | undefined> {\n\t\tconst key = this.getAccountKey(session);\n\t\tthis._accounts ??= new Map<string, Account | undefined>();\n\n\t\tconst cachedAccount = this._accounts.get(key);\n\t\tif (cachedAccount == null) {\n\t\t\tconst api = await this.getProvidersApi();\n\t\t\tconst user = await api.getCurrentUser(toTokenWithInfo(this.id, session), {\n\t\t\t\tbaseUrl: this.apiBaseUrlFor(session),\n\t\t\t});\n\t\t\tthis._accounts.set(\n\t\t\t\tkey,\n\t\t\t\tuser\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tprovider: this,\n\t\t\t\t\t\t\tid: user.id,\n\t\t\t\t\t\t\tname: user.name ?? undefined,\n\t\t\t\t\t\t\temail: user.email ?? undefined,\n\t\t\t\t\t\t\tavatarUrl: user.avatarUrl ?? undefined,\n\t\t\t\t\t\t\tusername: user.username ?? undefined,\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined,\n\t\t\t);\n\t\t}\n\n\t\treturn this._accounts.get(key);\n\t}\n\n\tprotected override async getProviderOrganizationsForUser(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<ProviderHierarchyResult<ProviderOrganization>> {\n\t\tconst api = await this.getProvidersApi();\n\t\treturn api.getBitbucketServerProjects(\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t\tsession.id,\n\t\t);\n\t}\n\n\tprotected override async getProviderRepositoriesForOrg(\n\t\tsession: ProviderAuthenticationSession,\n\t\torg: string,\n\t\toptions?: { cursor?: string },\n\t): Promise<ProviderHierarchyResult<ProviderRepository>> {\n\t\tconst api = await this.getProvidersApi();\n\t\treturn api.getBitbucketServerRepositories(\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t\tsession.id,\n\t\t\t{\n\t\t\t\tproject: org,\n\t\t\t\tcursor: options?.cursor,\n\t\t\t},\n\t\t);\n\t}\n\n\tprotected override async getProviderRepositoriesForUser(\n\t\tsession: ProviderAuthenticationSession,\n\t\toptions?: { cursor?: string },\n\t): Promise<ProviderHierarchyResult<ProviderRepository>> {\n\t\tconst api = await this.getProvidersApi();\n\t\treturn api.getBitbucketServerRepositories(\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t\tsession.id,\n\t\t\toptions,\n\t\t);\n\t}\n\n\tprotected override async searchProviderMyPullRequests(\n\t\tsession: ProviderAuthenticationSession,\n\t\trepos?: BitbucketRepositoryDescriptor[],\n\t\t_cancellation?: AbortSignal,\n\t\toptions?: SearchMyPullRequestsOptions,\n\t): Promise<PullRequest[] | undefined> {\n\t\tif (repos != null) {\n\t\t\t// TODO: implement repos version\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst api = await this.getProvidersApi();\n\t\tif (!api) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst prs = await api.getBitbucketServerPullRequestsForCurrentUser(\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t\t{ states: toProviderPullRequestStates(options?.state) },\n\t\t);\n\t\treturn prs?.data.map(pr => fromProviderPullRequest(pr, this, { projection: 'search' }));\n\t}\n\n\tprotected override async getProviderMyPullRequestsForUser(\n\t\tsession: ProviderAuthenticationSession,\n\t\toptions?: { state?: PullRequestStateFilter[]; cursor?: string; filters?: PullRequestFilter[] },\n\t): Promise<PagedResult<ProviderPullRequest> | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst states = toProviderPullRequestStates(options?.state);\n\t\t// provider-apis translates the public 1-based `page` to Bitbucket Server's `start` offset and normalizes\n\t\t// `nextPageStart` back to the next page number. Thread that number inside our opaque cursor so the\n\t\t// ProviderBackend sweep drives the drain (bounded by its maxPages).\n\t\tconst page = parsePageCursor(options?.cursor);\n\t\tconst result = await api.getBitbucketServerPullRequestsForCurrentUser(\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t\t{ states: states, page: page },\n\t\t);\n\t\tif (result == null) return undefined;\n\n\t\tconst account = options?.filters?.length ? await this.getProviderCurrentAccount(session) : undefined;\n\t\tconst identifiers = new Set([account?.id, account?.username].filter((id): id is string => id != null));\n\t\tif (options?.filters?.length && identifiers.size === 0) {\n\t\t\tthrow new Error(\n\t\t\t\t'Unable to resolve the current Bitbucket Data Center account for the requested pull request filters.',\n\t\t\t);\n\t\t}\n\n\t\tconst values = options?.filters?.length\n\t\t\t? result.data.filter(pr => {\n\t\t\t\t\tconst isCurrentUser = (user: { id?: string | null; username?: string | null } | null | undefined) =>\n\t\t\t\t\t\tuser != null &&\n\t\t\t\t\t\t((user.id != null && identifiers.has(user.id)) ||\n\t\t\t\t\t\t\t(user.username != null && identifiers.has(user.username)));\n\t\t\t\t\tconst isAuthor = isCurrentUser(pr.author);\n\t\t\t\t\tconst isRequestedReviewer = pr.reviews?.some(\n\t\t\t\t\t\treview =>\n\t\t\t\t\t\t\tisCurrentUser(review.reviewer) &&\n\t\t\t\t\t\t\treview.state === ProviderPullRequestReviewState.ReviewRequested,\n\t\t\t\t\t);\n\t\t\t\t\treturn (\n\t\t\t\t\t\t(options.filters!.includes(PullRequestFilter.Author) && isAuthor) ||\n\t\t\t\t\t\t(options.filters!.includes(PullRequestFilter.ReviewRequested) && isRequestedReviewer)\n\t\t\t\t\t);\n\t\t\t\t})\n\t\t\t: result.data;\n\n\t\treturn {\n\t\t\tvalues: values,\n\t\t\tpaging: {\n\t\t\t\tmore: result.hasMore,\n\t\t\t\tcursor: result.hasMore && result.nextPage != null ? toPageCursor(result.nextPage) : '{}',\n\t\t\t},\n\t\t};\n\t}\n\n\tprotected override async searchProviderPullRequests(\n\t\tsession: ProviderAuthenticationSession,\n\t\tsearchQuery: string,\n\t\trepos?: BitbucketRepositoryDescriptor[],\n\t\tcancellation?: AbortSignal,\n\t\toptions?: SearchPullRequestsOptions,\n\t): Promise<PullRequest[] | undefined> {\n\t\tif (cancellation?.aborted) throw new CancellationError();\n\n\t\tconst api = await this.getProvidersApi();\n\t\tif (!api) return undefined;\n\n\t\tconst repoInputs =\n\t\t\trepos != null\n\t\t\t\t? repos.map(r => ({ name: r.name, namespace: r.owner }))\n\t\t\t\t: await this.getWorkspaceRepoInputs();\n\t\tif (cancellation?.aborted) throw new CancellationError();\n\t\t// An explicitly-empty `repos` means \"search these zero repos\" -> no results; reserve `undefined`\n\t\t// (\"scope couldn't be determined\") for when no repos were requested and none were discovered.\n\t\tif (repoInputs.length === 0) return repos != null ? [] : undefined;\n\n\t\tconst token = toTokenWithInfo(this.id, session);\n\t\tconst states = toProviderPullRequestStates(options?.include);\n\t\tconst providerPullRequests = await flatSettledOrThrow(\n\t\t\trepoInputs.map(async repo => {\n\t\t\t\tconst result = await collectProviderPagedResult(cursor => {\n\t\t\t\t\tif (cancellation?.aborted) throw new CancellationError();\n\n\t\t\t\t\treturn api.getPullRequestsForRepo(token, repo, {\n\t\t\t\t\t\tbaseUrl: this.apiBaseUrlFor(session),\n\t\t\t\t\t\tcursor: cursor,\n\t\t\t\t\t\tstates: states,\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t\treturn result.values;\n\t\t\t}),\n\t\t);\n\t\tif (cancellation?.aborted) throw new CancellationError();\n\n\t\treturn providerPullRequests\n\t\t\t.filter(pr => providerPullRequestMatchesSearch(pr, searchQuery))\n\t\t\t.map(pr => fromProviderPullRequest(pr, this, { projection: 'text-search' }));\n\t}\n\n\t/**\n\t * The filtered pull-request search, read by this module's own requests rather than the SDK's: the SDK's list\n\t * reads carry no text, draft or participant-status filter and no per-facet continuation. Every request goes to\n\t * the session's own address, context path included, so one connection's cursor can't be replayed on another.\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\tconst api = await this.getProvidersApi();\n\t\treturn api.searchBitbucketServerPullRequestsPage(\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\t{\n\t\t\t\tbaseUrl: this.apiBaseUrlFor(session),\n\t\t\t\tconnectionId: session.id,\n\t\t\t\tprovider: this,\n\t\t\t\trepos: options.repos,\n\t\t\t\torg: options.org,\n\t\t\t\tcriteria: options.criteria,\n\t\t\t\tcurrentUser: await this.getSearchUser(session, options.criteria, cancellation),\n\t\t\t\tcursor: options.cursor,\n\t\t\t\tpageSize: options.pageSize,\n\t\t\t\tprojection: options.summary ? 'search-summary' : 'search',\n\t\t\t},\n\t\t\tcancellation,\n\t\t);\n\t}\n\n\t/**\n\t * Counts each scope by reading it, since Bitbucket Data Center has neither a count query nor a total on its\n\t * pages. The facade hands over one scope per call and runs those calls concurrently (see `countPullRequests`),\n\t * so scopes here are counted one after another rather than multiplying that concurrency.\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[] | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst token = toTokenWithInfo(this.id, session);\n\t\tconst counts: ProviderPullRequestCount[] = [];\n\t\tfor (const scope of scopes) {\n\t\t\tcounts.push(\n\t\t\t\tawait api.countBitbucketServerPullRequests(\n\t\t\t\t\ttoken,\n\t\t\t\t\t{\n\t\t\t\t\t\tbaseUrl: this.apiBaseUrlFor(session),\n\t\t\t\t\t\trepos: scope.repos,\n\t\t\t\t\t\torg: scope.org,\n\t\t\t\t\t\tcriteria: scope.criteria,\n\t\t\t\t\t\tcurrentUser: await this.getSearchUser(session, scope.criteria, cancellation),\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\treturn counts;\n\t}\n\n\t/**\n\t * The session's own user, which a relationship facet filters by. Resolved per session rather than from the\n\t * primary connection, so a read pinned to one account never filters by another's identity; an account that\n\t * can't be resolved refuses the read instead of widening it to everyone's pull requests.\n\t *\n\t * The lookup is raced against `cancellation` so a cancelled read settles at once. The SDK's current-user read\n\t * takes no signal, so the request itself runs on; its answer still lands in the per-token account cache, so a\n\t * cold lookup a cancellation abandoned isn't wasted on the next read.\n\t */\n\tprivate async getSearchUser(\n\t\tsession: ProviderAuthenticationSession,\n\t\tcriteria: PullRequestSearchCriteria | undefined,\n\t\tcancellation: AbortSignal | undefined,\n\t): Promise<BitbucketServerSearchUser | undefined> {\n\t\tif (!criteria?.relationships?.length) return undefined;\n\n\t\tconst lookup = this.getProviderCurrentAccount(session);\n\t\tconst account = await (cancellation != null ? raceWithSignal(lookup, cancellation) : lookup);\n\t\tif (account?.id == null || account.username == null) {\n\t\t\tthrow new Error('Unable to resolve the current Bitbucket Data Center account for a relationship search.');\n\t\t}\n\n\t\treturn { id: account.id, username: account.username };\n\t}\n\n\tprivate async getWorkspaceRepoInputs(): Promise<{ name: string; namespace: string }[]> {\n\t\tconst remotes = await this.ctx.repositories.getOpenRemotes();\n\t\tconst inputs = await nonnullSettled(\n\t\t\tremotes.map(async (r: GitRemote) => {\n\t\t\t\tconst integration = await this.authenticationService.getByRemote(r);\n\t\t\t\tif (integration !== this) return undefined;\n\n\t\t\t\t// Use the remote provider's parsing so the Bitbucket Server `scm/<project>/<repo>` prefix is\n\t\t\t\t// stripped; a raw `path.split('/')` would yield namespace=`scm`, name=`<project>`.\n\t\t\t\tconst namespace = r.provider?.owner;\n\t\t\t\tconst name = r.provider?.repoName;\n\t\t\t\treturn namespace != null && name != null ? { name: name, namespace: namespace } : undefined;\n\t\t\t}),\n\t\t);\n\t\t// Dedupe: a repo with multiple remotes (e.g. `origin` + `upstream`) can map to the same input,\n\t\t// which would otherwise fetch and return the same PRs more than once.\n\t\treturn [...new Map(inputs.map(i => [`${i.namespace}/${i.name}`, i])).values()];\n\t}\n\n\tprotected override async searchProviderMyIssues(\n\t\t_session: AuthenticationSession,\n\t\t_repos?: BitbucketRepositoryDescriptor[],\n\t): Promise<IssueShape[] | undefined> {\n\t\treturn Promise.resolve(undefined);\n\t}\n\n\t/**\n\t * Bitbucket Data Center exposes no issue tracker at all (issues live in Jira), so — like Bitbucket Cloud,\n\t * whose own tracker is deprecated — it is not an issue provider on the ProviderBackend surface. Without this\n\t * the facade would take `supportsIssues`' default `true` and route the read to a provider that registers no\n\t * issue client: the repo-scoped path fails with the SDK's `does not support function: getIssuesForReposFn`\n\t * as an opaque `kind: 'other'` warning, and `broadenIssues` first drains every repo of the org before hitting\n\t * the same failure. Its metadata already declares no issue filters, so this keeps both halves of the\n\t * capability answer consistent.\n\t */\n\toverride get supportsIssues(): boolean {\n\t\treturn false;\n\t}\n\n\tprivate readonly storagePrefix = 'bitbucket-server';\n\tprotected override async providerOnConnect(): Promise<void> {\n\t\tif (this._session == null) return;\n\n\t\tconst accountKey = this.getAccountKey(this._session);\n\t\tconst accountStorageKey = md5(accountKey);\n\n\t\tconst storedAccount = this.ctx.storage.get(`${this.storagePrefix}:${accountStorageKey}:account`);\n\n\t\tlet account: Account | undefined = storedAccount?.data ? { ...storedAccount.data, provider: this } : undefined;\n\n\t\tif (storedAccount == null) {\n\t\t\taccount = await this.getProviderCurrentAccount(this._session);\n\t\t\tif (account != null) {\n\t\t\t\t// Clear all other stored workspaces and repositories and accounts when our session changes\n\t\t\t\tawait this.ctx.storage.deleteWithPrefix(this.storagePrefix);\n\t\t\t\tawait this.ctx.storage.store(`${this.storagePrefix}:${accountStorageKey}:account`, {\n\t\t\t\t\tv: 1,\n\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tid: account.id,\n\t\t\t\t\t\tname: account.name,\n\t\t\t\t\t\temail: account.email,\n\t\t\t\t\t\tavatarUrl: account.avatarUrl,\n\t\t\t\t\t\tusername: account.username,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tthis._accounts ??= new Map<string, Account | undefined>();\n\t\tthis._accounts.set(accountKey, account);\n\t}\n\n\tprotected override providerOnDisconnect(): void {\n\t\tthis._accounts = undefined;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;AAkEA,MAAM,WAAW,kBAAA;AACjB,MAAM,eAAe,OAAO,OAAO;CAAE,IAAI,SAAS;CAAI,QAAQ,SAAS;AAAO,CAAC;AAE/E,IAAa,6BAAb,cAAgD,mBAG9C;CAYiB;CAXlB,eAAqE;CACrE,KAAS;CACT,MACC,GAAG,KAAK,GAAG,GAAG,KAAK;CACpB,OAAwB;CAExB,YACC,KACA,uBACA,iBACA,qBACA,SACC;EACD,MAAM,KAAK,uBAAuB,iBAAiB,mBAAmB;EAFrD,KAAA,UAAA;CAGlB;CAEA,IAAI,SAAiB;EACpB,OAAO,KAAK;CACb;CAEA,cAAwB,SAAgD;EACvE,OAAO,KAAK,yBAAyB,OAAO;CAC7C;CAEA,MAAyB,yBACxB,SACA,IACA,SAGmB;EAEnB,QAAO,MADW,KAAK,gBA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C,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;CAC9E;CAEA,MAAyB,uBACxB,UACA,QACoC;EACpC,OAAO,QAAQ,QAAQ,KAAA,CAAS;CACjC;;;;;;;;;;CAWA,IAAa,iBAA0B;EACtC,OAAO;CACR;CAEA,gBAAiC;CACjC,MAAyB,oBAAmC;EAC3D,IAAI,KAAK,YAAY,MAAM;EAE3B,MAAM,aAAa,KAAK,cAAc,KAAK,QAAQ;EACnD,MAAM,oBAAoB,IAAI,UAAU;EAExC,MAAM,gBAAgB,KAAK,IAAI,QAAQ,IAAI,GAAG,KAAK,cAAc,GAAG,kBAAkB,SAAS;EAE/F,IAAI,UAA+B,eAAe,OAAO;GAAE,GAAG,cAAc;GAAM,UAAU;EAAK,IAAI,KAAA;EAErG,IAAI,iBAAiB,MAAM;GAC1B,UAAU,MAAM,KAAK,0BAA0B,KAAK,QAAQ;GAC5D,IAAI,WAAW,MAAM;IAEpB,MAAM,KAAK,IAAI,QAAQ,iBAAiB,KAAK,aAAa;IAC1D,MAAM,KAAK,IAAI,QAAQ,MAAM,GAAG,KAAK,cAAc,GAAG,kBAAkB,WAAW;KAClF,GAAG;KACH,WAAW,KAAK,IAAI;KACpB,MAAM;MACL,IAAI,QAAQ;MACZ,MAAM,QAAQ;MACd,OAAO,QAAQ;MACf,WAAW,QAAQ;MACnB,UAAU,QAAQ;KACnB;IACD,CAAC;GACF;EACD;EACA,KAAK,8BAAc,IAAI,IAAiC;EACxD,KAAK,UAAU,IAAI,YAAY,OAAO;CACvC;CAEA,uBAAgD;EAC/C,KAAK,YAAY,KAAA;CAClB;AACD"}
1
+ {"version":3,"file":"bitbucket-server.js","names":[],"sources":["../../../../../plus/integrations/src/providers/bitbucket-server.ts"],"sourcesContent":["import type { Account, UnidentifiedAuthor } from '@gitlens/git/models/author.js';\nimport type { DefaultBranch } from '@gitlens/git/models/defaultBranch.js';\nimport type { Issue, IssueShape } from '@gitlens/git/models/issue.js';\nimport type { IssueOrPullRequest, IssueOrPullRequestType } from '@gitlens/git/models/issueOrPullRequest.js';\nimport type {\n\tPullRequest,\n\tPullRequestMergeMethod,\n\tPullRequestSearchCriteria,\n\tPullRequestShape,\n\tPullRequestState,\n\tPullRequestStateFilter,\n} from '@gitlens/git/models/pullRequest.js';\nimport type { GitRemote } from '@gitlens/git/models/remote.js';\nimport type { RepositoryMetadata } from '@gitlens/git/models/repositoryMetadata.js';\nimport type { PullRequestUrlIdentity } from '@gitlens/git/utils/pullRequest.utils.js';\nimport { CancellationError, raceWithSignal } from '@gitlens/utils/cancellation.js';\nimport { md5 } from '@gitlens/utils/crypto.js';\nimport type { Emitter } from '@gitlens/utils/event.js';\nimport type { PagedResult } from '@gitlens/utils/paging.js';\nimport { mapSettledBounded, nonnullSettled } from '@gitlens/utils/promise.js';\nimport type { IntegrationAuthenticationProviderDescriptor } from '../authentication/integrationAuthenticationProvider.js';\nimport type { IntegrationAuthenticationService } from '../authentication/integrationAuthenticationService.js';\nimport type {\n\tAuthenticationSessionLike as AuthenticationSession,\n\tConfiguredIntegrationDescriptor,\n\tProviderAuthenticationSession,\n} from '../authentication/models.js';\nimport { toTokenWithInfo } from '../authentication/models.js';\nimport { GitSelfManagedHostIntegrationId } from '../constants.js';\nimport type { IntegrationServiceContext } from '../context.js';\nimport type { ResponseHeaders } from '../errors.js';\nimport { AuthenticationError, getAuthenticatedUser, IntegrationReadUnavailableError } from '../errors.js';\nimport type { IntegrationConnectionChangeEvent } from '../integrationService.js';\nimport type { BitbucketServerPullRequestWriteScope } from '../models/bitbucketServerPullRequestWrites.js';\nimport { GitHostIntegration } from '../models/gitHostIntegration.js';\nimport type { ProviderPullRequestCount, ProviderPullRequestSearchPage } from '../models/integration.js';\nimport type {\n\tIntegrationKey,\n\tSearchMyPullRequestsOptions,\n\tSearchPullRequestsOptions,\n} from '../models/publicIntegration.js';\nimport { getSelfManagedBaseUrl } from '../utils/integration.utils.js';\nimport type { BitbucketServerSearchUser } from './bitbucket-server/pullRequestSearch.js';\nimport { getBitbucketServerPullRequestIdentityFromMaybeUrl } from './bitbucket/bitbucket.utils.js';\nimport type { BitbucketRepositoryDescriptor } from './bitbucket/models.js';\nimport { BitbucketServerPullRequestWriteError } from './bitbucketServerPullRequestWriteErrors.js';\nimport type { BitbucketServerPullRequestWriter } from './bitbucketServerPullRequestWrites.js';\nimport { providersMetadata } from './metadata.js';\nimport type {\n\tProviderHierarchyResult,\n\tProviderOrganization,\n\tProviderPullRequest,\n\tProviderRepoInput,\n\tProviderRepository,\n} from './models.js';\nimport {\n\tfromProviderPullRequest,\n\tproviderPullRequestMatchesSearch,\n\tProviderPullRequestReviewState,\n\tPullRequestFilter,\n\ttoProviderPullRequestStates,\n} from './models.js';\nimport type { ProvidersApi } from './providersApi.js';\nimport {\n\tcollectProviderPagedResult,\n\tflatSettledOrThrow,\n\tparsePageCursor,\n\tproviderFanOutConcurrency,\n\ttoPageCursor,\n} from './utils/providerPaging.js';\n\nconst metadata = providersMetadata[GitSelfManagedHostIntegrationId.BitbucketServer];\nconst authProvider = Object.freeze({ id: metadata.id, scopes: metadata.scopes });\n\nexport class BitbucketServerIntegration extends GitHostIntegration<\n\tGitSelfManagedHostIntegrationId.BitbucketServer,\n\tBitbucketRepositoryDescriptor\n> {\n\treadonly authProvider: IntegrationAuthenticationProviderDescriptor = authProvider;\n\treadonly id = GitSelfManagedHostIntegrationId.BitbucketServer;\n\tprotected readonly key =\n\t\t`${this.id}:${this.domain}` satisfies IntegrationKey<GitSelfManagedHostIntegrationId.BitbucketServer>;\n\treadonly name: string = 'Bitbucket Data Center';\n\n\tconstructor(\n\t\tctx: IntegrationServiceContext,\n\t\tauthenticationService: IntegrationAuthenticationService,\n\t\tgetProvidersApi: () => Promise<ProvidersApi>,\n\t\tdidChangeConnection: Emitter<IntegrationConnectionChangeEvent>,\n\t\tprivate readonly _domain: string,\n\t) {\n\t\tsuper(ctx, authenticationService, getProvidersApi, didChangeConnection);\n\t}\n\n\tget domain(): string {\n\t\treturn this._domain;\n\t}\n\n\tprotected apiBaseUrlFor(session: ProviderAuthenticationSession): string {\n\t\treturn this.getSelfManagedApiBaseUrl(session);\n\t}\n\n\tprotected override async mergeProviderPullRequest(\n\t\tsession: ProviderAuthenticationSession,\n\t\tpr: PullRequest,\n\t\toptions?: {\n\t\t\tmergeMethod?: PullRequestMergeMethod;\n\t\t},\n\t): Promise<boolean> {\n\t\tconst api = await this.getProvidersApi();\n\t\treturn api.mergePullRequest(toTokenWithInfo(this.id, session), pr, {\n\t\t\tmergeMethod: options?.mergeMethod,\n\t\t\tbaseUrl: this.apiBaseUrlFor(session),\n\t\t});\n\t}\n\n\tasync getPullRequestWriter(\n\t\toptions: BitbucketServerPullRequestWriteScope,\n\t\tconnection: ConfiguredIntegrationDescriptor,\n\t\tisSelectionCurrent: () => boolean,\n\t): Promise<BitbucketServerPullRequestWriter | undefined> {\n\t\tif (!isSelectionCurrent()) return undefined;\n\n\t\tconst session = await this.resolveReadSessionOrThrow(options.connectionId, undefined, connection.cloud);\n\t\tif (session?.id !== options.connectionId || !session.accessToken) return undefined;\n\t\tif (session.cloud != null && session.cloud !== connection.cloud) return undefined;\n\n\t\tconst installationUrl = this.getSelfManagedInstallationUrl(session);\n\t\tconst { protocol } = new URL(installationUrl);\n\t\tconst configuredAddress = connection.baseUrl ?? connection.domain ?? options.domain;\n\t\tif (\n\t\t\tgetSelfManagedBaseUrl(this.id, options.baseUrl, protocol) !== installationUrl ||\n\t\t\tgetSelfManagedBaseUrl(this.id, configuredAddress, protocol) !== installationUrl\n\t\t) {\n\t\t\tthrow new BitbucketServerPullRequestWriteError('not-found');\n\t\t}\n\n\t\tconst isSessionCurrent = this.trackWriteSession(session, { cloud: connection.cloud, observeHostChanges: true });\n\t\treturn (await this.getProvidersApi()).getBitbucketServerPullRequestWriter(options, {\n\t\t\tsession: session,\n\t\t\tinstallationUrl: installationUrl,\n\t\t\tgetIgnoreSSLErrors: () => this.getIgnoreSSLErrors(),\n\t\t\tisAccessEnabled: () => isSelectionCurrent() && this.isIntegrationAccessEnabled(),\n\t\t\tisSessionCurrent: isSessionCurrent,\n\t\t});\n\t}\n\n\tprotected override async getProviderAccountForCommit(\n\t\tsession: ProviderAuthenticationSession,\n\t\trepo: BitbucketRepositoryDescriptor,\n\t\trev: string,\n\t\toptions?: {\n\t\t\tavatarSize?: number;\n\t\t},\n\t): Promise<Account | UnidentifiedAuthor | undefined> {\n\t\treturn (await this.authenticationService.apis.bitbucket)?.getServerAccountForCommit(\n\t\t\tthis,\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\trepo.owner,\n\t\t\trepo.name,\n\t\t\trev,\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t\t{\n\t\t\t\tavatarSize: options?.avatarSize,\n\t\t\t},\n\t\t);\n\t}\n\n\tprotected override async getProviderAccountForEmail(\n\t\t_session: AuthenticationSession,\n\t\t_repo: BitbucketRepositoryDescriptor,\n\t\t_email: string,\n\t\t_options?: {\n\t\t\tavatarSize?: number;\n\t\t},\n\t): Promise<Account | undefined> {\n\t\treturn Promise.resolve(undefined);\n\t}\n\n\tprotected override async getProviderDefaultBranch(\n\t\t_session: AuthenticationSession,\n\t\t_repo: BitbucketRepositoryDescriptor,\n\t): Promise<DefaultBranch | undefined> {\n\t\treturn Promise.resolve(undefined);\n\t}\n\n\tprotected override async getProviderLinkedIssueOrPullRequest(\n\t\tsession: ProviderAuthenticationSession,\n\t\trepo: BitbucketRepositoryDescriptor,\n\t\t{ id }: { id: string; key: string },\n\t\ttype: undefined | IssueOrPullRequestType,\n\t): Promise<IssueOrPullRequest | undefined> {\n\t\tif (type === 'issue') {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn (await this.authenticationService.apis.bitbucket)?.getServerPullRequestById(\n\t\t\tthis,\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\trepo.owner,\n\t\t\trepo.name,\n\t\t\tid,\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t);\n\t}\n\n\t/**\n\t * One request per target, settled independently so one target's failure rejects only its own slot:\n\t * provider-apis has no single pull request read for Bitbucket, so this uses our own.\n\t */\n\tprotected override async getProviderPullRequestsBatch(\n\t\tsession: ProviderAuthenticationSession,\n\t\tcoordinates: readonly { owner: string; repo: string; number: number; project?: string }[],\n\t\toptions: { currentAccount?: { id: string; username?: string } } | undefined,\n\t\t_cancellation?: AbortSignal,\n\t): Promise<PromiseSettledResult<PullRequestShape | undefined>[] | undefined> {\n\t\tconst api = await this.authenticationService.apis.bitbucket;\n\t\tif (api == null) return undefined;\n\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\t\treturn mapSettledBounded(coordinates, providerFanOutConcurrency, c =>\n\t\t\tapi.getServerPullRequest(\n\t\t\t\tthis,\n\t\t\t\ttokenWithInfo,\n\t\t\t\tc.owner,\n\t\t\t\tc.repo,\n\t\t\t\tString(c.number),\n\t\t\t\tthis.apiBaseUrlFor(session),\n\t\t\t\t{\n\t\t\t\t\tcurrentAccount: options?.currentAccount,\n\t\t\t\t\tdeferFailure: true,\n\t\t\t\t\tprojection: 'batch',\n\t\t\t\t},\n\t\t\t),\n\t\t);\n\t}\n\n\t/**\n\t * One request per target, settled independently, through our own client: provider-apis' pull request list has\n\t * no source-branch filter. Serves only a branch in the base repository — the manager read refuses a `headOwner`\n\t * naming another owner here, since Bitbucket Data Center finds a branch's pull requests only through the\n\t * repository the branch lives in, and a fork's slug can't be derived from its owner.\n\t */\n\tprotected override async getProviderPullRequestsForBranches(\n\t\tsession: ProviderAuthenticationSession,\n\t\ttargets: readonly { owner: string; repo: string; project?: string; branch: string; headOwner?: string }[],\n\t\toptions: { currentAccount?: { id: string; username?: string }; limit: number },\n\t\t_cancellation?: AbortSignal,\n\t): Promise<PromiseSettledResult<{ pullRequests: PullRequestShape[]; truncated: boolean }>[] | undefined> {\n\t\tconst api = await this.authenticationService.apis.bitbucket;\n\t\tif (api == null) return undefined;\n\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\t\treturn mapSettledBounded(targets, providerFanOutConcurrency, async t => {\n\t\t\tif (t.headOwner != null) {\n\t\t\t\tthrow new Error(`Bitbucket Data Center can't find ${t.branch}'s pull requests in a fork by its owner`);\n\t\t\t}\n\n\t\t\treturn api.getServerPullRequestsForBranch(\n\t\t\t\tthis,\n\t\t\t\ttokenWithInfo,\n\t\t\t\tt.owner,\n\t\t\t\tt.repo,\n\t\t\t\tt.branch,\n\t\t\t\tthis.apiBaseUrlFor(session),\n\t\t\t\t{\n\t\t\t\t\tlimit: options.limit,\n\t\t\t\t\tcurrentAccount: options.currentAccount,\n\t\t\t\t\tdeferFailure: true,\n\t\t\t\t},\n\t\t\t);\n\t\t});\n\t}\n\n\tprotected override async getProviderIssue(\n\t\t_session: AuthenticationSession,\n\t\t_repo: BitbucketRepositoryDescriptor,\n\t\t_id: string,\n\t): Promise<Issue | undefined> {\n\t\treturn Promise.resolve(undefined);\n\t}\n\n\tprotected override async getProviderPullRequestForBranch(\n\t\tsession: ProviderAuthenticationSession,\n\t\trepo: BitbucketRepositoryDescriptor,\n\t\tbranch: string,\n\t\t_options?: {\n\t\t\tavatarSize?: number;\n\t\t\tinclude?: PullRequestState[];\n\t\t},\n\t): Promise<PullRequest | undefined> {\n\t\treturn (await this.authenticationService.apis.bitbucket)?.getServerPullRequestForBranch(\n\t\t\tthis,\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\trepo.owner,\n\t\t\trepo.name,\n\t\t\tbranch,\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t);\n\t}\n\n\tprotected override getProviderPullRequestForCommitInBatch(\n\t\tsession: ProviderAuthenticationSession,\n\t\trepo: BitbucketRepositoryDescriptor,\n\t\trev: string,\n\t\tcancellation?: AbortSignal,\n\t): Promise<PullRequest | undefined> {\n\t\treturn this.readPullRequestForCommit(session, repo, rev, true, cancellation);\n\t}\n\n\tprotected override getProviderPullRequestForCommit(\n\t\tsession: ProviderAuthenticationSession,\n\t\trepo: BitbucketRepositoryDescriptor,\n\t\trev: string,\n\t): Promise<PullRequest | undefined> {\n\t\treturn this.readPullRequestForCommit(session, repo, rev, false);\n\t}\n\n\tprivate async readPullRequestForCommit(\n\t\tsession: ProviderAuthenticationSession,\n\t\trepo: BitbucketRepositoryDescriptor,\n\t\trev: string,\n\t\tdeferFailure: boolean,\n\t\tcancellation?: AbortSignal,\n\t): Promise<PullRequest | undefined> {\n\t\tconst api = await this.authenticationService.apis.bitbucket;\n\t\tif (api == null) {\n\t\t\tthrow new IntegrationReadUnavailableError(this.name, 'no client to read the pull requests of a commit');\n\t\t}\n\n\t\treturn api.getServerPullRequestForCommit(\n\t\t\tthis,\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\trepo.owner,\n\t\t\trepo.name,\n\t\t\trev,\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t\t{ deferFailure: deferFailure },\n\t\t\tcancellation,\n\t\t);\n\t}\n\n\tprotected override async getProviderPullRequest(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresource: BitbucketRepositoryDescriptor,\n\t\tid: string,\n\t): Promise<PullRequest | undefined> {\n\t\treturn (await this.authenticationService.apis.bitbucket)?.getServerPullRequest(\n\t\t\tthis,\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\tresource.owner,\n\t\t\tresource.name,\n\t\t\tid,\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t\t{ projection: 'point' },\n\t\t);\n\t}\n\n\tprotected override getProviderPullRequestIdentityFromMaybeUrl(search: string): PullRequestUrlIdentity | undefined {\n\t\treturn getBitbucketServerPullRequestIdentityFromMaybeUrl(search, this.id);\n\t}\n\n\tpublic override async getRepoInfo(repo: {\n\t\towner: string;\n\t\tname: string;\n\t\tproject?: string;\n\t\tconnectionId?: string;\n\t}): Promise<ProviderRepository | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\t// `connectionId` targets a specific account (multi-account); omitted reads the primary.\n\t\tconst session = await this.resolveReadSessionOrThrow(repo.connectionId, undefined);\n\t\tif (session == null) return undefined;\n\n\t\treturn api.getRepo(toTokenWithInfo(this.id, session), repo.owner, repo.name, repo.project, {\n\t\t\tbaseUrl: this.apiBaseUrlFor(session),\n\t\t});\n\t}\n\n\tprotected override async getProviderRepositoryMetadata(\n\t\t_session: AuthenticationSession,\n\t\t_repo: BitbucketRepositoryDescriptor,\n\t\t_cancellation?: AbortSignal,\n\t): Promise<RepositoryMetadata | undefined> {\n\t\treturn Promise.resolve(undefined);\n\t}\n\n\t/**\n\t * Accounts by {@link getAccountKey}. One integration serves every installation on its host, and installations\n\t * mounted at different context paths are different servers whose users differ, even under the same token.\n\t */\n\tprivate _accounts: Map<string, Account | undefined> | undefined;\n\n\t/** The installation the session's reads address, plus the credential — what decides whose account it is. */\n\tprivate getAccountKey(session: ProviderAuthenticationSession): string {\n\t\treturn `${this.apiBaseUrlFor(session)}\\n${session.accessToken}`;\n\t}\n\n\t/**\n\t * The account request the account cache would otherwise answer; see `IntegrationBase.validateCredential`. Needed\n\t * without any discovery cache: a repo-scoped pull request read fans out across its repositories in the SDK with\n\t * no request to the connection first, so a dead token comes back as one refused repository per request.\n\t *\n\t * A project access token never confirms: its bot user authenticates, but `/users` does not list it, so the SDK\n\t * cannot find the current user and the check proves nothing.\n\t */\n\tprotected override async validateCredential(session: ProviderAuthenticationSession): Promise<void> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst user = await api\n\t\t\t.getCurrentUser(toTokenWithInfo(this.id, session), { baseUrl: this.apiBaseUrlFor(session) })\n\t\t\t.catch((ex: unknown) => {\n\t\t\t\tif (!(ex instanceof AuthenticationError)) throw ex;\n\n\t\t\t\t// Bitbucket Data Center names the user it authenticated in `X-AUSERNAME`, and answers a dead token\n\t\t\t\t// exactly as it answers no credential: the same 401 and body, without that header. So a refusal that\n\t\t\t\t// names a user other than `anonymous`, or says the user holds no license, came from a credential that\n\t\t\t\t// authenticated, and proves nothing about the scopes' refusals.\n\t\t\t\tconst response = (ex.original as { response?: { headers?: ResponseHeaders } } | undefined)?.response;\n\t\t\t\tconst user = getAuthenticatedUser(response?.headers);\n\t\t\t\tif (\n\t\t\t\t\t(user != null && user !== 'anonymous') ||\n\t\t\t\t\t/not (?:a|currently) licensed/i.test(ex.original?.message ?? '')\n\t\t\t\t) {\n\t\t\t\t\tthrow new Error('Bitbucket Data Center could not confirm the credential', { cause: ex });\n\t\t\t\t}\n\t\t\t\tthrow ex;\n\t\t\t});\n\t\tif (user == null) {\n\t\t\tthrow new Error('Bitbucket Data Center did not confirm the credential');\n\t\t}\n\t}\n\n\tprotected override async getProviderCurrentAccount(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<Account | undefined> {\n\t\tconst key = this.getAccountKey(session);\n\t\tthis._accounts ??= new Map<string, Account | undefined>();\n\n\t\tconst cachedAccount = this._accounts.get(key);\n\t\tif (cachedAccount == null) {\n\t\t\tconst api = await this.getProvidersApi();\n\t\t\tconst user = await api.getCurrentUser(toTokenWithInfo(this.id, session), {\n\t\t\t\tbaseUrl: this.apiBaseUrlFor(session),\n\t\t\t});\n\t\t\tthis._accounts.set(\n\t\t\t\tkey,\n\t\t\t\tuser\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tprovider: this,\n\t\t\t\t\t\t\tid: user.id,\n\t\t\t\t\t\t\tname: user.name ?? undefined,\n\t\t\t\t\t\t\temail: user.email ?? undefined,\n\t\t\t\t\t\t\tavatarUrl: user.avatarUrl ?? undefined,\n\t\t\t\t\t\t\tusername: user.username ?? undefined,\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined,\n\t\t\t);\n\t\t}\n\n\t\treturn this._accounts.get(key);\n\t}\n\n\tprotected override async getProviderOrganizationsForUser(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<ProviderHierarchyResult<ProviderOrganization>> {\n\t\tconst api = await this.getProvidersApi();\n\t\treturn api.getBitbucketServerProjects(\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t\tsession.id,\n\t\t);\n\t}\n\n\tprotected override async getProviderRepositoriesForOrg(\n\t\tsession: ProviderAuthenticationSession,\n\t\torg: string,\n\t\toptions?: { cursor?: string },\n\t): Promise<ProviderHierarchyResult<ProviderRepository>> {\n\t\tconst api = await this.getProvidersApi();\n\t\treturn api.getBitbucketServerRepositories(\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t\tsession.id,\n\t\t\t{\n\t\t\t\tproject: org,\n\t\t\t\tcursor: options?.cursor,\n\t\t\t},\n\t\t);\n\t}\n\n\tprotected override async getProviderRepositoriesForUser(\n\t\tsession: ProviderAuthenticationSession,\n\t\toptions?: { cursor?: string },\n\t): Promise<ProviderHierarchyResult<ProviderRepository>> {\n\t\tconst api = await this.getProvidersApi();\n\t\treturn api.getBitbucketServerRepositories(\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t\tsession.id,\n\t\t\toptions,\n\t\t);\n\t}\n\n\tprotected override async searchProviderMyPullRequests(\n\t\tsession: ProviderAuthenticationSession,\n\t\trepos?: BitbucketRepositoryDescriptor[],\n\t\t_cancellation?: AbortSignal,\n\t\toptions?: SearchMyPullRequestsOptions,\n\t): Promise<PullRequest[] | undefined> {\n\t\tif (repos != null) {\n\t\t\t// TODO: implement repos version\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst api = await this.getProvidersApi();\n\t\tif (!api) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst prs = await api.getBitbucketServerPullRequestsForCurrentUser(\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t\t{ states: toProviderPullRequestStates(options?.state) },\n\t\t);\n\t\treturn prs?.data.map(pr => fromProviderPullRequest(pr, this, { projection: 'search' }));\n\t}\n\n\tprotected override async getProviderMyPullRequestsForUser(\n\t\tsession: ProviderAuthenticationSession,\n\t\toptions?: { state?: PullRequestStateFilter[]; cursor?: string; filters?: PullRequestFilter[] },\n\t): Promise<PagedResult<ProviderPullRequest> | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst states = toProviderPullRequestStates(options?.state);\n\t\t// provider-apis translates the public 1-based `page` to Bitbucket Server's `start` offset and normalizes\n\t\t// `nextPageStart` back to the next page number. Thread that number inside our opaque cursor so the\n\t\t// ProviderBackend sweep drives the drain (bounded by its maxPages).\n\t\tconst page = parsePageCursor(options?.cursor);\n\t\tconst result = await api.getBitbucketServerPullRequestsForCurrentUser(\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t\t{ states: states, page: page },\n\t\t);\n\t\tif (result == null) return undefined;\n\n\t\tconst account = options?.filters?.length ? await this.getProviderCurrentAccount(session) : undefined;\n\t\tconst identifiers = new Set([account?.id, account?.username].filter((id): id is string => id != null));\n\t\tif (options?.filters?.length && identifiers.size === 0) {\n\t\t\tthrow new Error(\n\t\t\t\t'Unable to resolve the current Bitbucket Data Center account for the requested pull request filters.',\n\t\t\t);\n\t\t}\n\n\t\tconst values = options?.filters?.length\n\t\t\t? result.data.filter(pr => {\n\t\t\t\t\tconst isCurrentUser = (user: { id?: string | null; username?: string | null } | null | undefined) =>\n\t\t\t\t\t\tuser != null &&\n\t\t\t\t\t\t((user.id != null && identifiers.has(user.id)) ||\n\t\t\t\t\t\t\t(user.username != null && identifiers.has(user.username)));\n\t\t\t\t\tconst isAuthor = isCurrentUser(pr.author);\n\t\t\t\t\tconst isRequestedReviewer = pr.reviews?.some(\n\t\t\t\t\t\treview =>\n\t\t\t\t\t\t\tisCurrentUser(review.reviewer) &&\n\t\t\t\t\t\t\treview.state === ProviderPullRequestReviewState.ReviewRequested,\n\t\t\t\t\t);\n\t\t\t\t\treturn (\n\t\t\t\t\t\t(options.filters!.includes(PullRequestFilter.Author) && isAuthor) ||\n\t\t\t\t\t\t(options.filters!.includes(PullRequestFilter.ReviewRequested) && isRequestedReviewer)\n\t\t\t\t\t);\n\t\t\t\t})\n\t\t\t: result.data;\n\n\t\treturn {\n\t\t\tvalues: values,\n\t\t\tpaging: {\n\t\t\t\tmore: result.hasMore,\n\t\t\t\tcursor: result.hasMore && result.nextPage != null ? toPageCursor(result.nextPage) : '{}',\n\t\t\t},\n\t\t};\n\t}\n\n\tprotected override async searchProviderPullRequests(\n\t\tsession: ProviderAuthenticationSession,\n\t\tsearchQuery: string,\n\t\trepos?: BitbucketRepositoryDescriptor[],\n\t\tcancellation?: AbortSignal,\n\t\toptions?: SearchPullRequestsOptions,\n\t): Promise<PullRequest[] | undefined> {\n\t\tif (cancellation?.aborted) throw new CancellationError();\n\n\t\tconst api = await this.getProvidersApi();\n\t\tif (!api) return undefined;\n\n\t\tconst repoInputs =\n\t\t\trepos != null\n\t\t\t\t? repos.map(r => ({ name: r.name, namespace: r.owner }))\n\t\t\t\t: await this.getWorkspaceRepoInputs();\n\t\tif (cancellation?.aborted) throw new CancellationError();\n\t\t// An explicitly-empty `repos` means \"search these zero repos\" -> no results; reserve `undefined`\n\t\t// (\"scope couldn't be determined\") for when no repos were requested and none were discovered.\n\t\tif (repoInputs.length === 0) return repos != null ? [] : undefined;\n\n\t\tconst token = toTokenWithInfo(this.id, session);\n\t\tconst states = toProviderPullRequestStates(options?.include);\n\t\tconst providerPullRequests = await flatSettledOrThrow(\n\t\t\trepoInputs.map(async repo => {\n\t\t\t\tconst result = await collectProviderPagedResult(cursor => {\n\t\t\t\t\tif (cancellation?.aborted) throw new CancellationError();\n\n\t\t\t\t\treturn api.getPullRequestsForRepo(token, repo, {\n\t\t\t\t\t\tbaseUrl: this.apiBaseUrlFor(session),\n\t\t\t\t\t\tcursor: cursor,\n\t\t\t\t\t\tstates: states,\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t\treturn result.values;\n\t\t\t}),\n\t\t);\n\t\tif (cancellation?.aborted) throw new CancellationError();\n\n\t\treturn providerPullRequests\n\t\t\t.filter(pr => providerPullRequestMatchesSearch(pr, searchQuery))\n\t\t\t.map(pr => fromProviderPullRequest(pr, this, { projection: 'text-search' }));\n\t}\n\n\t/**\n\t * The filtered pull-request search, read by this module's own requests rather than the SDK's: the SDK's list\n\t * reads carry no text, draft or participant-status filter and no per-facet continuation. Every request goes to\n\t * the session's own address, context path included, so one connection's cursor can't be replayed on another.\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\tconst api = await this.getProvidersApi();\n\t\treturn api.searchBitbucketServerPullRequestsPage(\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\t{\n\t\t\t\tbaseUrl: this.apiBaseUrlFor(session),\n\t\t\t\tconnectionId: session.id,\n\t\t\t\tprovider: this,\n\t\t\t\trepos: options.repos,\n\t\t\t\torg: options.org,\n\t\t\t\tcriteria: options.criteria,\n\t\t\t\tcurrentUser: await this.getSearchUser(session, options.criteria, cancellation),\n\t\t\t\tcursor: options.cursor,\n\t\t\t\tpageSize: options.pageSize,\n\t\t\t\tprojection: options.summary ? 'search-summary' : 'search',\n\t\t\t},\n\t\t\tcancellation,\n\t\t);\n\t}\n\n\t/**\n\t * Counts each scope by reading it, since Bitbucket Data Center has neither a count query nor a total on its\n\t * pages. The facade hands over one scope per call and runs those calls concurrently (see `countPullRequests`),\n\t * so scopes here are counted one after another rather than multiplying that concurrency.\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[] | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst token = toTokenWithInfo(this.id, session);\n\t\tconst counts: ProviderPullRequestCount[] = [];\n\t\tfor (const scope of scopes) {\n\t\t\tcounts.push(\n\t\t\t\tawait api.countBitbucketServerPullRequests(\n\t\t\t\t\ttoken,\n\t\t\t\t\t{\n\t\t\t\t\t\tbaseUrl: this.apiBaseUrlFor(session),\n\t\t\t\t\t\trepos: scope.repos,\n\t\t\t\t\t\torg: scope.org,\n\t\t\t\t\t\tcriteria: scope.criteria,\n\t\t\t\t\t\tcurrentUser: await this.getSearchUser(session, scope.criteria, cancellation),\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\treturn counts;\n\t}\n\n\t/**\n\t * The session's own user, which a relationship facet filters by. Resolved per session rather than from the\n\t * primary connection, so a read pinned to one account never filters by another's identity; an account that\n\t * can't be resolved refuses the read instead of widening it to everyone's pull requests.\n\t *\n\t * The lookup is raced against `cancellation` so a cancelled read settles at once. The SDK's current-user read\n\t * takes no signal, so the request itself runs on; its answer still lands in the per-token account cache, so a\n\t * cold lookup a cancellation abandoned isn't wasted on the next read.\n\t */\n\tprivate async getSearchUser(\n\t\tsession: ProviderAuthenticationSession,\n\t\tcriteria: PullRequestSearchCriteria | undefined,\n\t\tcancellation: AbortSignal | undefined,\n\t): Promise<BitbucketServerSearchUser | undefined> {\n\t\tif (!criteria?.relationships?.length) return undefined;\n\n\t\tconst lookup = this.getProviderCurrentAccount(session);\n\t\tconst account = await (cancellation != null ? raceWithSignal(lookup, cancellation) : lookup);\n\t\tif (account?.id == null || account.username == null) {\n\t\t\tthrow new Error('Unable to resolve the current Bitbucket Data Center account for a relationship search.');\n\t\t}\n\n\t\treturn { id: account.id, username: account.username };\n\t}\n\n\tprivate async getWorkspaceRepoInputs(): Promise<{ name: string; namespace: string }[]> {\n\t\tconst remotes = await this.ctx.repositories.getOpenRemotes();\n\t\tconst inputs = await nonnullSettled(\n\t\t\tremotes.map(async (r: GitRemote) => {\n\t\t\t\tconst integration = await this.authenticationService.getByRemote(r);\n\t\t\t\tif (integration !== this) return undefined;\n\n\t\t\t\t// Use the remote provider's parsing so the Bitbucket Server `scm/<project>/<repo>` prefix is\n\t\t\t\t// stripped; a raw `path.split('/')` would yield namespace=`scm`, name=`<project>`.\n\t\t\t\tconst namespace = r.provider?.owner;\n\t\t\t\tconst name = r.provider?.repoName;\n\t\t\t\treturn namespace != null && name != null ? { name: name, namespace: namespace } : undefined;\n\t\t\t}),\n\t\t);\n\t\t// Dedupe: a repo with multiple remotes (e.g. `origin` + `upstream`) can map to the same input,\n\t\t// which would otherwise fetch and return the same PRs more than once.\n\t\treturn [...new Map(inputs.map(i => [`${i.namespace}/${i.name}`, i])).values()];\n\t}\n\n\tprotected override async searchProviderMyIssues(\n\t\t_session: AuthenticationSession,\n\t\t_repos?: BitbucketRepositoryDescriptor[],\n\t): Promise<IssueShape[] | undefined> {\n\t\treturn Promise.resolve(undefined);\n\t}\n\n\t/**\n\t * Bitbucket Data Center exposes no issue tracker at all (issues live in Jira), so — like Bitbucket Cloud,\n\t * whose own tracker is deprecated — it is not an issue provider on the ProviderBackend surface. Without this\n\t * the facade would take `supportsIssues`' default `true` and route the read to a provider that registers no\n\t * issue client: the repo-scoped path fails with the SDK's `does not support function: getIssuesForReposFn`\n\t * as an opaque `kind: 'other'` warning, and `broadenIssues` first drains every repo of the org before hitting\n\t * the same failure. Its metadata already declares no issue filters, so this keeps both halves of the\n\t * capability answer consistent.\n\t */\n\toverride get supportsIssues(): boolean {\n\t\treturn false;\n\t}\n\n\tprivate readonly storagePrefix = 'bitbucket-server';\n\tprotected override async providerOnConnect(): Promise<void> {\n\t\tif (this._session == null) return;\n\n\t\tconst accountKey = this.getAccountKey(this._session);\n\t\tconst accountStorageKey = md5(accountKey);\n\n\t\tconst storedAccount = this.ctx.storage.get(`${this.storagePrefix}:${accountStorageKey}:account`);\n\n\t\tlet account: Account | undefined = storedAccount?.data ? { ...storedAccount.data, provider: this } : undefined;\n\n\t\tif (storedAccount == null) {\n\t\t\taccount = await this.getProviderCurrentAccount(this._session);\n\t\t\tif (account != null) {\n\t\t\t\t// Clear all other stored workspaces and repositories and accounts when our session changes\n\t\t\t\tawait this.ctx.storage.deleteWithPrefix(this.storagePrefix);\n\t\t\t\tawait this.ctx.storage.store(`${this.storagePrefix}:${accountStorageKey}:account`, {\n\t\t\t\t\tv: 1,\n\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tid: account.id,\n\t\t\t\t\t\tname: account.name,\n\t\t\t\t\t\temail: account.email,\n\t\t\t\t\t\tavatarUrl: account.avatarUrl,\n\t\t\t\t\t\tusername: account.username,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tthis._accounts ??= new Map<string, Account | undefined>();\n\t\tthis._accounts.set(accountKey, account);\n\t}\n\n\tprotected override providerOnDisconnect(): void {\n\t\tthis._accounts = undefined;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAuEA,MAAM,WAAW,kBAAA;AACjB,MAAM,eAAe,OAAO,OAAO;CAAE,IAAI,SAAS;CAAI,QAAQ,SAAS;AAAO,CAAC;AAE/E,IAAa,6BAAb,cAAgD,mBAG9C;CAYiB;CAXlB,eAAqE;CACrE,KAAS;CACT,MACC,GAAG,KAAK,GAAG,GAAG,KAAK;CACpB,OAAwB;CAExB,YACC,KACA,uBACA,iBACA,qBACA,SACC;EACD,MAAM,KAAK,uBAAuB,iBAAiB,mBAAmB;EAFrD,KAAA,UAAA;CAGlB;CAEA,IAAI,SAAiB;EACpB,OAAO,KAAK;CACb;CAEA,cAAwB,SAAgD;EACvE,OAAO,KAAK,yBAAyB,OAAO;CAC7C;CAEA,MAAyB,yBACxB,SACA,IACA,SAGmB;EAEnB,QAAO,MADW,KAAK,gBAAgB,EAAA,CAC5B,iBAAiB,gBAAgB,KAAK,IAAI,OAAO,GAAG,IAAI;GAClE,aAAa,SAAS;GACtB,SAAS,KAAK,cAAc,OAAO;EACpC,CAAC;CACF;CAEA,MA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,KAAK,QAAQ;GAC5D,IAAI,WAAW,MAAM;IAEpB,MAAM,KAAK,IAAI,QAAQ,iBAAiB,KAAK,aAAa;IAC1D,MAAM,KAAK,IAAI,QAAQ,MAAM,GAAG,KAAK,cAAc,GAAG,kBAAkB,WAAW;KAClF,GAAG;KACH,WAAW,KAAK,IAAI;KACpB,MAAM;MACL,IAAI,QAAQ;MACZ,MAAM,QAAQ;MACd,OAAO,QAAQ;MACf,WAAW,QAAQ;MACnB,UAAU,QAAQ;KACnB;IACD,CAAC;GACF;EACD;EACA,KAAK,8BAAc,IAAI,IAAiC;EACxD,KAAK,UAAU,IAAI,YAAY,OAAO;CACvC;CAEA,uBAAgD;EAC/C,KAAK,YAAY,KAAA;CAClB;AACD"}
@@ -1,6 +1,6 @@
1
1
  import { uuid } from "../../../utils/crypto.js";
2
2
  import { getResponseHeader } from "../errors.js";
3
- import { isCommitSha, isPositiveInt32, isWriteIdentifier, sameIdentifier } from "./utils/writeInputs.js";
3
+ import { isCommitSha, isGitBranchName, isPositiveInt32, isWriteIdentifier, sameIdentifier } from "./utils/writeInputs.js";
4
4
  import { BitbucketPullRequestWriteError, getBitbucketMergeRefusal, toBitbucketPullRequestWriteFailure } from "./bitbucketPullRequestWriteErrors.js";
5
5
  //#region ../plus/integrations/src/providers/bitbucketPullRequestWrites.ts
6
6
  const apiUrl = "https://api.bitbucket.org/2.0";
@@ -28,7 +28,7 @@ function isSlugOrUuid(value) {
28
28
  return isBitbucketUuid(value) || typeof value === "string" && slugPattern.test(value) && !/^\.\.?$/.test(value);
29
29
  }
30
30
  function isBranchName(name) {
31
- return typeof name === "string" && name.length > 0 && !name.startsWith("refs/") && !name.startsWith("-") && ![...name].some((character) => character <= " " || "~^:?*[\\\"".includes(character)) && !name.includes("..") && !name.includes("@{") && name !== "@" && !name.endsWith(".") && name.split("/").every((part) => part.length > 0 && !part.startsWith(".") && !part.endsWith(".lock"));
31
+ return isGitBranchName(name) && name !== "@" && !name.startsWith("refs/") && !name.includes("\"");
32
32
  }
33
33
  function isTitle(title) {
34
34
  return typeof title === "string" && title.trim().length > 0;
@@ -1 +1 @@
1
- {"version":3,"file":"bitbucketPullRequestWrites.js","names":[],"sources":["../../../../../plus/integrations/src/providers/bitbucketPullRequestWrites.ts"],"sourcesContent":["import { uuid } from '@gitlens/utils/crypto.js';\nimport { getResponseHeader } from '../errors.js';\nimport type {\n\tBitbucketPullRequestCreateCapabilityOptions,\n\tBitbucketPullRequestCreateCapabilityResult,\n\tBitbucketPullRequestMergeCapability,\n\tBitbucketPullRequestMergeStatusOptions,\n\tBitbucketPullRequestMergeStatusResult,\n\tBitbucketPullRequestMergeStrategy,\n\tBitbucketPullRequestRepository,\n\tBitbucketPullRequestWriteFailure,\n\tBitbucketPullRequestWriteOptions,\n\tBitbucketPullRequestWriteReleaseOptions,\n\tBitbucketPullRequestWriteReleaseResult,\n\tBitbucketPullRequestWriteResult,\n\tBitbucketPullRequestWriteTargetResult,\n\tBitbucketUnsettledPullRequestWrite,\n\tBitbucketWrittenPullRequest,\n} from '../models/bitbucketPullRequestWrites.js';\nimport {\n\tBitbucketPullRequestWriteError,\n\tgetBitbucketMergeRefusal,\n\ttoBitbucketPullRequestWriteFailure,\n} from './bitbucketPullRequestWriteErrors.js';\nimport type { BitbucketPullRequestWriteLedger } from './bitbucketPullRequestWriteLedger.js';\nimport type { ProviderRequestFunction } from './models.js';\nimport { isCommitSha, isPositiveInt32, isWriteIdentifier, sameIdentifier } from './utils/writeInputs.js';\n\nconst apiUrl = 'https://api.bitbucket.org/2.0';\nconst webUrl = 'https://bitbucket.org';\nconst mergeStrategies: BitbucketPullRequestMergeStrategy[] = [\n\t'merge_commit',\n\t'squash',\n\t'fast_forward',\n\t'squash_fast_forward',\n\t'rebase_fast_forward',\n\t'rebase_merge',\n];\n// SEE: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pullrequests/#api-repositories-workspace-repo-slug-pullrequests-pull-request-id-merge-post\nconst queueStrategies: BitbucketPullRequestMergeStrategy[] = ['merge_commit', 'squash', 'rebase_merge'];\nconst uuidPattern = /^\\{[\\da-f]{8}-(?:[\\da-f]{4}-){3}[\\da-f]{12}\\}$/i;\nconst slugPattern = /^[\\w.-]+$/;\nconst mergeTaskIdPattern = /^(?!\\.{1,2}$)[\\w.:-]{1,256}$/;\n\ntype FailureReason = BitbucketPullRequestWriteFailure['reason'];\ntype MergeOptions = Extract<BitbucketPullRequestWriteOptions, { action: 'merge' }>;\ntype CreateOptions = Extract<BitbucketPullRequestWriteOptions, { action: 'create' }>;\ntype SendContext = {\n\tcreatedNotBefore?: number;\n\tonReceipt?: (pullRequest: BitbucketWrittenPullRequest) => void;\n};\ntype WriteStatus = Extract<BitbucketPullRequestWriteResult, { ok: true }>['status'];\ntype PendingResult = Extract<BitbucketPullRequestWriteResult, { status: 'pending' }>;\ntype SettledResult = Exclude<BitbucketPullRequestWriteResult, PendingResult>;\ntype SentResult = SettledResult | Omit<PendingResult, 'unsettled'>;\n\ntype RawRepository = {\n\tuuid?: unknown;\n\tslug?: unknown;\n\tfull_name?: unknown;\n\tworkspace?: { uuid?: unknown; slug?: unknown };\n\tmainbranch?: { name?: unknown } | null;\n};\n\ntype RawEndpoint = {\n\tbranch?: { name?: unknown };\n\tcommit?: { hash?: unknown } | null;\n\trepository?: { uuid?: unknown } | null;\n};\n\ntype RawPullRequest = {\n\tid?: unknown;\n\ttitle?: unknown;\n\tdescription?: unknown;\n\tstate?: unknown;\n\tdraft?: unknown;\n\tqueued?: unknown;\n\tauthor?: { uuid?: unknown } | null;\n\tcreated_on?: unknown;\n\tupdated_on?: unknown;\n\tsource?: RawEndpoint;\n\tdestination?: RawEndpoint;\n};\n\ntype RawBranch = {\n\tname?: unknown;\n\ttarget?: { hash?: unknown };\n\tmerge_strategies?: unknown;\n\tdefault_merge_strategy?: unknown;\n};\n\ntype RawMergeTask = {\n\ttask_status?: unknown;\n\tmerge_result?: RawPullRequest;\n\tqueued_pullrequest?: { type?: unknown; pullrequest?: RawPullRequest | null } | null;\n};\n\ntype RawMergeabilityCheck = { type?: unknown; blocking?: unknown; required?: unknown };\n\ntype PullRequestRead = { pullRequest: BitbucketWrittenPullRequest; sourceHash: string | undefined };\n\ntype TargetBranch = { sha: string; strategies: BitbucketPullRequestMergeStrategy[]; defaultStrategy?: string };\n\nfunction isBitbucketUuid(value: unknown): value is string {\n\treturn typeof value === 'string' && uuidPattern.test(value);\n}\n\nfunction isSlugOrUuid(value: unknown): value is string {\n\treturn isBitbucketUuid(value) || (typeof value === 'string' && slugPattern.test(value) && !/^\\.\\.?$/.test(value));\n}\n\nfunction isBranchName(name: unknown): name is string {\n\treturn (\n\t\ttypeof name === 'string' &&\n\t\tname.length > 0 &&\n\t\t!name.startsWith('refs/') &&\n\t\t!name.startsWith('-') &&\n\t\t![...name].some(character => character <= ' ' || '~^:?*[\\\\\"\\x7f'.includes(character)) &&\n\t\t!name.includes('..') &&\n\t\t!name.includes('@{') &&\n\t\tname !== '@' &&\n\t\t!name.endsWith('.') &&\n\t\tname.split('/').every(part => part.length > 0 && !part.startsWith('.') && !part.endsWith('.lock'))\n\t);\n}\n\nfunction isTitle(title: unknown): title is string {\n\treturn typeof title === 'string' && title.trim().length > 0;\n}\n\nfunction seg(value: string): string {\n\treturn encodeURIComponent(value);\n}\n\nfunction isAttemptPullRequest(\n\tpullRequest: BitbucketWrittenPullRequest,\n\tsourceBranch: string,\n\ttargetBranch: string | undefined,\n): boolean {\n\treturn (\n\t\t!pullRequest.isCrossRepository &&\n\t\tpullRequest.sourceBranch === sourceBranch &&\n\t\t(targetBranch === undefined || pullRequest.targetBranch === targetBranch)\n\t);\n}\n\nfunction getCreateKey(repositoryId: string, sourceBranch: string): string {\n\treturn `create\\n${repositoryId.toLowerCase()}\\n${sourceBranch}`;\n}\n\nfunction getMergeKey(repositoryId: string, number: number): string {\n\treturn `merge\\n${repositoryId.toLowerCase()}\\n${number}`;\n}\n\nfunction isBitbucketMergeTaskId(value: unknown): value is string {\n\treturn typeof value === 'string' && mergeTaskIdPattern.test(value);\n}\n\nexport function isBitbucketPullRequestMergeStatusRead(options: BitbucketPullRequestMergeStatusOptions): boolean {\n\treturn (\n\t\t(options.providerId === undefined || options.providerId === 'bitbucket') &&\n\t\tisWriteIdentifier(options.connectionId) &&\n\t\tisBitbucketUuid(options.workspaceId) &&\n\t\tisBitbucketUuid(options.repositoryId) &&\n\t\tisBitbucketUuid(options.expectedAccountId) &&\n\t\tisPositiveInt32(options.number) &&\n\t\tisBitbucketMergeTaskId(options.mergeTaskId) &&\n\t\tisBranchName(options.expectedSourceBranch) &&\n\t\tisBranchName(options.expectedTargetBranch) &&\n\t\toptions.expectedSourceBranch !== options.expectedTargetBranch &&\n\t\tisCommitSha(options.expectedSourceSha)\n\t);\n}\n\nexport function isBitbucketPullRequestScope(options: BitbucketPullRequestCreateCapabilityOptions): boolean {\n\treturn (\n\t\t(options.providerId === undefined || options.providerId === 'bitbucket') &&\n\t\tisWriteIdentifier(options.connectionId) &&\n\t\tisSlugOrUuid(options.workspace) &&\n\t\tisSlugOrUuid(options.repository) &&\n\t\t(options.expectedAccountId === undefined || isBitbucketUuid(options.expectedAccountId))\n\t);\n}\n\nexport function isBitbucketPullRequestWrite(options: BitbucketPullRequestWriteOptions): boolean {\n\tif (\n\t\t(options.providerId !== undefined && options.providerId !== 'bitbucket') ||\n\t\t!isWriteIdentifier(options.connectionId) ||\n\t\t!isBitbucketUuid(options.workspaceId) ||\n\t\t!isBitbucketUuid(options.repositoryId) ||\n\t\t!isBitbucketUuid(options.expectedAccountId)\n\t) {\n\t\treturn false;\n\t}\n\n\tif (options.action === 'create') {\n\t\treturn (\n\t\t\tisBranchName(options.sourceBranch) &&\n\t\t\tisBranchName(options.targetBranch) &&\n\t\t\toptions.sourceBranch !== options.targetBranch &&\n\t\t\tisTitle(options.title) &&\n\t\t\t(options.description === undefined || typeof options.description === 'string')\n\t\t);\n\t}\n\n\tif (!isPositiveInt32(options.number)) return false;\n\n\tswitch (options.action) {\n\t\tcase 'edit':\n\t\t\treturn (\n\t\t\t\t(options.title !== undefined || options.description !== undefined) &&\n\t\t\t\t(options.title === undefined || isTitle(options.title)) &&\n\t\t\t\t(options.description === undefined || typeof options.description === 'string')\n\t\t\t);\n\t\tcase 'decline':\n\t\t\treturn true;\n\t\tcase 'merge':\n\t\t\treturn (\n\t\t\t\tmergeStrategies.includes(options.strategy) &&\n\t\t\t\tisBranchName(options.expectedSourceBranch) &&\n\t\t\t\tisBranchName(options.expectedTargetBranch) &&\n\t\t\t\toptions.expectedSourceBranch !== options.expectedTargetBranch &&\n\t\t\t\tisCommitSha(options.expectedSourceSha) &&\n\t\t\t\tisCommitSha(options.expectedTargetSha)\n\t\t\t);\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nexport function isBitbucketPullRequestWriteRelease(options: BitbucketPullRequestWriteReleaseOptions): boolean {\n\treturn (\n\t\t(options.providerId === undefined || options.providerId === 'bitbucket') &&\n\t\tisWriteIdentifier(options.connectionId) &&\n\t\tisBitbucketUuid(options.workspaceId) &&\n\t\tisBitbucketUuid(options.repositoryId) &&\n\t\tisBitbucketUuid(options.expectedAccountId) &&\n\t\tisWriteIdentifier(options.attemptId) &&\n\t\t(options.action === 'create'\n\t\t\t? isBranchName(options.sourceBranch)\n\t\t\t: options.action === 'merge' &&\n\t\t\t\tisPositiveInt32(options.number) &&\n\t\t\t\t(options.mergeTaskId === undefined || isBitbucketMergeTaskId(options.mergeTaskId)))\n\t);\n}\n\nfunction toStrategies(value: unknown): BitbucketPullRequestMergeStrategy[] {\n\treturn Array.isArray(value) ? mergeStrategies.filter(strategy => value.includes(strategy)) : [];\n}\n\nfunction getBlockingCheckFailure(checks: RawMergeabilityCheck[]): FailureReason | undefined {\n\tconst blocking = new Set(checks.filter(check => check.blocking === true).map(check => check.type));\n\tif (blocking.size === 0) return undefined;\n\tif (blocking.has('pullrequest_state_check')) return 'conflict';\n\tif (blocking.has('current_user_permission_check')) return 'forbidden';\n\tif (blocking.has('git_mergeability_check')) return 'conflict';\n\n\treturn 'policy-blocked';\n}\n\nfunction getMergeStateFailure(pullRequest: BitbucketWrittenPullRequest): FailureReason | undefined {\n\tif (pullRequest.state !== 'open' || pullRequest.queued) return 'conflict';\n\tif (pullRequest.isCrossRepository) return 'unsupported';\n\tif (pullRequest.draft) return 'policy-blocked';\n\n\treturn undefined;\n}\n\nfunction getMergeRefFailure(options: MergeOptions, read: PullRequestRead): FailureReason | undefined {\n\tconst { pullRequest, sourceHash } = read;\n\tif (pullRequest.sourceBranch !== options.expectedSourceBranch) return 'source-changed';\n\tif (pullRequest.targetBranch !== options.expectedTargetBranch) return 'target-changed';\n\tif (sourceHash == null || !options.expectedSourceSha.toLowerCase().startsWith(sourceHash)) return 'source-changed';\n\n\treturn undefined;\n}\n\nexport class BitbucketPullRequestWriter {\n\tstatic async connect(\n\t\trequest: ProviderRequestFunction,\n\t\taccessToken: string,\n\t\toptions: BitbucketPullRequestCreateCapabilityOptions,\n\t\tisSessionCurrent: () => Promise<boolean>,\n\t\tledger: BitbucketPullRequestWriteLedger,\n\t): Promise<BitbucketPullRequestWriter> {\n\t\tconst headers = { Authorization: `Bearer ${accessToken}` };\n\t\tconst { body: user } = await request<{ uuid?: unknown }>({\n\t\t\turl: `${apiUrl}/user`,\n\t\t\theaders: headers,\n\t\t\tredirect: 'error',\n\t\t});\n\t\tconst accountId = user?.uuid;\n\t\tif (\n\t\t\t!isBitbucketUuid(accountId) ||\n\t\t\t(options.expectedAccountId !== undefined && !sameIdentifier(accountId, options.expectedAccountId))\n\t\t) {\n\t\t\tthrow new BitbucketPullRequestWriteError('no-connection');\n\t\t}\n\n\t\tconst { body: repo } = await request<RawRepository>({\n\t\t\turl: `${apiUrl}/repositories/${seg(options.workspace)}/${seg(options.repository)}`,\n\t\t\theaders: headers,\n\t\t\tredirect: 'error',\n\t\t});\n\t\tconst workspace = repo?.workspace;\n\t\tif (\n\t\t\t!isBitbucketUuid(repo?.uuid) ||\n\t\t\t!isBitbucketUuid(workspace?.uuid) ||\n\t\t\t!isSlugOrUuid(repo.slug) ||\n\t\t\t!isSlugOrUuid(workspace.slug) ||\n\t\t\ttypeof repo.full_name !== 'string' ||\n\t\t\t!sameIdentifier(isBitbucketUuid(options.workspace) ? workspace.uuid : workspace.slug, options.workspace) ||\n\t\t\t!sameIdentifier(isBitbucketUuid(options.repository) ? repo.uuid : repo.slug, options.repository)\n\t\t) {\n\t\t\tthrow new BitbucketPullRequestWriteError('not-found');\n\t\t}\n\n\t\tconst mainBranch = repo.mainbranch?.name;\n\t\treturn new BitbucketPullRequestWriter(\n\t\t\trequest,\n\t\t\theaders,\n\t\t\taccountId,\n\t\t\t{\n\t\t\t\tworkspaceId: workspace.uuid,\n\t\t\t\tworkspaceSlug: workspace.slug,\n\t\t\t\trepositoryId: repo.uuid,\n\t\t\t\trepositorySlug: repo.slug,\n\t\t\t\tfullName: repo.full_name,\n\t\t\t},\n\t\t\tisBranchName(mainBranch) ? mainBranch : undefined,\n\t\t\tisSessionCurrent,\n\t\t\tledger,\n\t\t);\n\t}\n\n\tprivate readonly repoUrl: string;\n\n\tprivate constructor(\n\t\tprivate readonly request: ProviderRequestFunction,\n\t\tprivate readonly headers: { Authorization: string },\n\t\tprivate readonly accountId: string,\n\t\tprivate readonly repository: BitbucketPullRequestRepository,\n\t\tprivate readonly defaultBranch: string | undefined,\n\t\tprivate readonly isSessionCurrent: () => Promise<boolean>,\n\t\tprivate readonly ledger: BitbucketPullRequestWriteLedger,\n\t) {\n\t\tthis.repoUrl = `${apiUrl}/repositories/${seg(repository.workspaceId)}/${seg(repository.repositoryId)}`;\n\t}\n\n\tgetCreateCapability(): BitbucketPullRequestCreateCapabilityResult {\n\t\treturn {\n\t\t\tok: true,\n\t\t\taccountId: this.accountId,\n\t\t\trepository: this.repository,\n\t\t\t...(this.defaultBranch !== undefined && { defaultBranch: this.defaultBranch }),\n\t\t};\n\t}\n\n\tasync resolveTarget(number: number): Promise<BitbucketPullRequestWriteTargetResult> {\n\t\tif (!isPositiveInt32(number)) return { ok: false, reason: 'invalid-input' };\n\n\t\tconst read = await this.readPullRequest(number);\n\t\tconst open = read.pullRequest.state === 'open';\n\t\tconst key = getMergeKey(this.repository.repositoryId, number);\n\t\tif (!open) {\n\t\t\tthis.ledger.settle(key);\n\t\t}\n\n\t\tconst target = await this.getMergeTarget(read);\n\t\tconst { pullRequest } = target;\n\t\tconst unsettled = open ? this.ledger.get(key) : undefined;\n\t\tlet merge: BitbucketPullRequestMergeCapability = target.merge;\n\t\tif (unsettled != null) {\n\t\t\tmerge =\n\t\t\t\tmerge.kind === 'available'\n\t\t\t\t\t? { kind: 'unavailable', reason: 'outcome-unknown', unsettled: unsettled }\n\t\t\t\t\t: { ...merge, unsettled: unsettled };\n\t\t}\n\t\treturn {\n\t\t\tok: true,\n\t\t\taccountId: this.accountId,\n\t\t\tpullRequest: pullRequest,\n\t\t\tcapabilities: { edit: open, decline: open, reopen: false, merge: merge },\n\t\t};\n\t}\n\n\tasync write(options: BitbucketPullRequestWriteOptions): Promise<BitbucketPullRequestWriteResult> {\n\t\tif (options.action === 'create') {\n\t\t\tconst key = getCreateKey(this.repository.repositoryId, options.sourceBranch);\n\t\t\treturn this.ledger.run(key, () => this.create(options, key));\n\t\t}\n\t\tif (options.action === 'merge') {\n\t\t\tconst key = getMergeKey(this.repository.repositoryId, options.number);\n\t\t\treturn this.ledger.run(key, () => this.merge(options, key));\n\t\t}\n\n\t\tconst current = await this.readPullRequest(options.number);\n\t\tswitch (options.action) {\n\t\t\tcase 'edit':\n\t\t\t\tif (current.pullRequest.state !== 'open') return { ok: false, reason: 'conflict' };\n\n\t\t\t\treturn this.send(options, 'PUT', this.pullRequestUrl(options.number), {\n\t\t\t\t\ttitle: options.title,\n\t\t\t\t\tdescription: options.description,\n\t\t\t\t});\n\t\t\tcase 'decline':\n\t\t\t\tif (current.pullRequest.state !== 'open') return { ok: false, reason: 'conflict' };\n\n\t\t\t\treturn this.send(options, 'POST', `${this.pullRequestUrl(options.number)}/decline`);\n\t\t}\n\t}\n\n\tprivate async create(options: CreateOptions, key: string): Promise<BitbucketPullRequestWriteResult> {\n\t\tconst [source, target] = await Promise.all([\n\t\t\tthis.readBranch(options.sourceBranch),\n\t\t\tthis.readBranch(options.targetBranch),\n\t\t]);\n\t\tif (source == null || target == null) return { ok: false, reason: 'not-found' };\n\n\t\tconst preflight = await this.readCreateEvidence(key, options.sourceBranch);\n\t\tif (preflight.open.length) return { ok: false, reason: 'conflict' };\n\t\tif (preflight.unsettled != null) {\n\t\t\treturn { ok: false, reason: 'outcome-unknown', unsettled: preflight.unsettled };\n\t\t}\n\n\t\tconst { serverTime } = preflight;\n\t\tconst dispatchedAt = Date.now();\n\t\tlet pullRequestNumber: number | undefined;\n\t\tconst result = await this.send(\n\t\t\toptions,\n\t\t\t'POST',\n\t\t\t`${this.repoUrl}/pullrequests`,\n\t\t\t{\n\t\t\t\ttitle: options.title,\n\t\t\t\tdescription: options.description,\n\t\t\t\tsource: { branch: { name: options.sourceBranch } },\n\t\t\t\tdestination: { branch: { name: options.targetBranch } },\n\t\t\t},\n\t\t\t{\n\t\t\t\tcreatedNotBefore: serverTime,\n\t\t\t\tonReceipt: pullRequest => {\n\t\t\t\t\tif (!pullRequest.isCrossRepository && pullRequest.sourceBranch === options.sourceBranch) {\n\t\t\t\t\t\tpullRequestNumber = pullRequest.number;\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\t\treturn this.recordUnsettled(key, result, {\n\t\t\tattemptId: uuid(),\n\t\t\taccountId: this.accountId,\n\t\t\tdispatchedAt: dispatchedAt,\n\t\t\taction: 'create',\n\t\t\tsourceBranch: options.sourceBranch,\n\t\t\ttargetBranch: options.targetBranch,\n\t\t\t...(pullRequestNumber !== undefined && { pullRequestNumber: pullRequestNumber }),\n\t\t});\n\t}\n\n\tprivate async readCreateEvidence(\n\t\tkey: string,\n\t\tbranch: string,\n\t): Promise<{\n\t\topen: number[];\n\t\tserverTime: number | undefined;\n\t\tlanded?: number;\n\t\tclosed?: BitbucketWrittenPullRequest;\n\t\tunsettled?: BitbucketUnsettledPullRequestWrite;\n\t}> {\n\t\tconst entry = this.ledger.get(key);\n\t\tconst receipt = entry?.action === 'create' ? entry.pullRequestNumber : undefined;\n\t\t// KEEP: Bitbucket updates an open pull request from the same source branch instead of creating one.\n\t\tconst open: number[] = [];\n\t\tconst serverTime = await this.scanPullRequests(this.getOpenPullRequestsFromQuery(branch), pr => {\n\t\t\tif (!sameIdentifier(pr?.source?.repository?.uuid, this.repository.repositoryId)) return false;\n\t\t\tif (pr.state === 'MERGED' || pr.state === 'DECLINED' || pr.state === 'SUPERSEDED') return false;\n\n\t\t\topen.push(isPositiveInt32(pr.id) ? pr.id : Number.NaN);\n\t\t\treturn receipt !== undefined ? pr.id === receipt : open.length > 1;\n\t\t});\n\t\tconst landed = receipt !== undefined && open.includes(receipt) ? receipt : undefined;\n\t\tconst closed = !open.length && receipt !== undefined ? await this.readClosed(receipt) : undefined;\n\t\tif (entry == null || landed !== undefined || closed != null) {\n\t\t\tthis.ledger.settle(key);\n\t\t\treturn { open: open, serverTime: serverTime, landed: landed, closed: closed };\n\t\t}\n\n\t\treturn { open: open, serverTime: serverTime, unsettled: entry };\n\t}\n\n\t// KEEP: another account may lack pull request read access, so it learns nothing about the attempt.\n\tprivate refuseRelease(\n\t\treason: 'conflict' | 'invalid-input',\n\t\theld: BitbucketUnsettledPullRequestWrite,\n\t): BitbucketPullRequestWriteReleaseResult {\n\t\treturn sameIdentifier(held.accountId, this.accountId)\n\t\t\t? { ok: false, reason: reason, unsettled: held }\n\t\t\t: { ok: false, reason: reason };\n\t}\n\n\tprivate async readShownPullRequest(\n\t\tnumber: number | undefined,\n\t\tsourceBranch: string,\n\t\ttargetBranch: string | undefined,\n\t): Promise<BitbucketWrittenPullRequest | undefined> {\n\t\tif (number === undefined) return undefined;\n\n\t\t// KEEP: the decision is made; a failed read of the pull request to show only leaves it out.\n\t\tconst pullRequest = await this.readPullRequest(number).then(\n\t\t\tread => read.pullRequest,\n\t\t\t() => undefined,\n\t\t);\n\t\treturn pullRequest?.state === 'open' && isAttemptPullRequest(pullRequest, sourceBranch, targetBranch)\n\t\t\t? pullRequest\n\t\t\t: undefined;\n\t}\n\n\tprivate async readClosed(number: number): Promise<BitbucketWrittenPullRequest | undefined> {\n\t\tconst pullRequest = await this.readPullRequest(number).then(\n\t\t\tread => read.pullRequest,\n\t\t\t(ex: unknown) => {\n\t\t\t\tif (toBitbucketPullRequestWriteFailure(ex).reason === 'not-found') return undefined;\n\n\t\t\t\tthrow ex;\n\t\t\t},\n\t\t);\n\t\treturn pullRequest != null && pullRequest.state !== 'open' ? pullRequest : undefined;\n\t}\n\n\tprivate recordUnsettled(\n\t\tkey: string,\n\t\tresult: SentResult,\n\t\twrite: BitbucketUnsettledPullRequestWrite,\n\t): BitbucketPullRequestWriteResult {\n\t\tif (result.ok ? result.status !== 'pending' : result.reason !== 'outcome-unknown') {\n\t\t\treturn result as SettledResult;\n\t\t}\n\n\t\tthis.ledger.record(key, write);\n\t\tconst unsettled = this.ledger.get(key)!;\n\t\treturn result.ok ? { ...result, status: 'pending', unsettled: unsettled } : { ...result, unsettled: unsettled };\n\t}\n\n\tprivate async merge(options: MergeOptions, key: string): Promise<BitbucketPullRequestWriteResult> {\n\t\tconst current = await this.readPullRequest(options.number);\n\t\tconst held = this.ledger.get(key);\n\t\tif (held != null) {\n\t\t\tif (current.pullRequest.state === 'open') return { ok: false, reason: 'outcome-unknown', unsettled: held };\n\n\t\t\tthis.ledger.settle(key);\n\t\t}\n\n\t\tconst failure = getMergeStateFailure(current.pullRequest) ?? getMergeRefFailure(options, current);\n\t\tif (failure != null) return { ok: false, reason: failure };\n\n\t\tconst checks = await this.readMergeabilityChecks(options.number);\n\t\tconst [latest, source, target] = await Promise.all([\n\t\t\tthis.readPullRequest(options.number),\n\t\t\tthis.readBranch(options.expectedSourceBranch),\n\t\t\tthis.readBranch(options.expectedTargetBranch),\n\t\t]);\n\t\tconst latestFailure = getMergeStateFailure(latest.pullRequest) ?? getMergeRefFailure(options, latest);\n\t\tif (latestFailure != null) return { ok: false, reason: latestFailure };\n\t\tif (!sameIdentifier(source?.sha, options.expectedSourceSha)) return { ok: false, reason: 'source-changed' };\n\t\tif (target == null || !sameIdentifier(target.sha, options.expectedTargetSha)) {\n\t\t\treturn { ok: false, reason: 'target-changed' };\n\t\t}\n\t\tif (!getAllowedStrategies(target, checks).includes(options.strategy)) {\n\t\t\treturn { ok: false, reason: 'policy-blocked' };\n\t\t}\n\n\t\tconst blocked = getBlockingCheckFailure(checks);\n\t\tif (blocked != null) return { ok: false, reason: blocked };\n\n\t\tconst dispatchedAt = Date.now();\n\t\tconst result = await this.send(\n\t\t\toptions,\n\t\t\t'POST',\n\t\t\t`${this.pullRequestUrl(options.number)}/merge?async=false`,\n\t\t\t{ type: 'pullrequest', merge_strategy: options.strategy },\n\t\t\t{ pending: latest.pullRequest },\n\t\t);\n\t\tconst mergeTaskId = result.ok && result.status === 'pending' ? result.mergeTaskId : undefined;\n\t\treturn this.recordUnsettled(key, result, {\n\t\t\tattemptId: uuid(),\n\t\t\taccountId: this.accountId,\n\t\t\tdispatchedAt: dispatchedAt,\n\t\t\taction: 'merge',\n\t\t\tnumber: options.number,\n\t\t\t...(mergeTaskId !== undefined && { mergeTaskId: mergeTaskId }),\n\t\t});\n\t}\n\n\trelease(options: BitbucketPullRequestWriteReleaseOptions): Promise<BitbucketPullRequestWriteReleaseResult> {\n\t\tif (options.action === 'create') {\n\t\t\tconst key = getCreateKey(this.repository.repositoryId, options.sourceBranch);\n\t\t\treturn this.ledger.run(key, async () => {\n\t\t\t\tconst held = this.ledger.get(key);\n\t\t\t\t// KEEP: an ok release must mean Core holds no attempt here, or a host could drop its own durable barrier.\n\t\t\t\tif (held != null && held.attemptId !== options.attemptId) {\n\t\t\t\t\treturn this.refuseRelease('conflict', held);\n\t\t\t\t}\n\n\t\t\t\tconst matches = held != null;\n\t\t\t\tconst target = held?.action === 'create' ? held.targetBranch : undefined;\n\t\t\t\tconst evidence = await this.readCreateEvidence(key, options.sourceBranch);\n\t\t\t\tconst only =\n\t\t\t\t\tevidence.open.length === 1 && isPositiveInt32(evidence.open[0]) ? evidence.open[0] : undefined;\n\t\t\t\tconst shown = evidence.landed ?? only;\n\t\t\t\t// KEEP: only the receipt's own PR is evidence; another open PR keeps the attempt, as it can still land once that PR closes.\n\t\t\t\tif (evidence.open.length && evidence.landed === undefined) {\n\t\t\t\t\tconst pullRequest = await this.readShownPullRequest(shown, options.sourceBranch, target);\n\t\t\t\t\treturn { ok: false, reason: 'conflict', pullRequest: pullRequest };\n\t\t\t\t}\n\n\t\t\t\tconst settled = matches && evidence.unsettled == null;\n\t\t\t\tconst released = settled || this.ledger.release(key, options.attemptId);\n\t\t\t\tif (evidence.landed !== undefined) {\n\t\t\t\t\tconst pullRequest = await this.readShownPullRequest(shown, options.sourceBranch, target);\n\t\t\t\t\treturn { ok: true, released: released, observed: 'pull-request-open', pullRequest: pullRequest };\n\t\t\t\t}\n\t\t\t\tif (evidence.closed != null && matches) {\n\t\t\t\t\tconst pullRequest = isAttemptPullRequest(evidence.closed, options.sourceBranch, target)\n\t\t\t\t\t\t? evidence.closed\n\t\t\t\t\t\t: undefined;\n\t\t\t\t\treturn { ok: true, released: released, observed: 'pull-request-closed', pullRequest: pullRequest };\n\t\t\t\t}\n\n\t\t\t\treturn { ok: true, released: released, observed: 'no-open-pull-request' };\n\t\t\t});\n\t\t}\n\n\t\tconst key = getMergeKey(this.repository.repositoryId, options.number);\n\t\treturn this.ledger.run(key, async () => {\n\t\t\tconst held = this.ledger.get(key);\n\t\t\t// KEEP: the held write's own task id is authoritative; the host's only stands in when Core holds none.\n\t\t\tconst heldTaskId = held?.action === 'merge' ? held.mergeTaskId : undefined;\n\t\t\tif (\n\t\t\t\theld != null &&\n\t\t\t\theldTaskId != null &&\n\t\t\t\toptions.mergeTaskId != null &&\n\t\t\t\toptions.mergeTaskId !== heldTaskId\n\t\t\t) {\n\t\t\t\treturn this.refuseRelease('invalid-input', held);\n\t\t\t}\n\t\t\tif (held != null && held.attemptId !== options.attemptId) {\n\t\t\t\treturn this.refuseRelease('conflict', held);\n\t\t\t}\n\n\t\t\tconst matches = held != null;\n\n\t\t\tconst { pullRequest } = await this.readPullRequest(options.number);\n\t\t\tif (pullRequest.state !== 'open') {\n\t\t\t\tthis.ledger.settle(key);\n\t\t\t\treturn { ok: true, released: matches, observed: 'pull-request-closed', pullRequest: pullRequest };\n\t\t\t}\n\t\t\tif (pullRequest.queued) return { ok: false, reason: 'conflict' };\n\n\t\t\tconst mergeTaskId = heldTaskId ?? options.mergeTaskId;\n\t\t\tif (mergeTaskId != null) {\n\t\t\t\tconst task = await this.readMergeTaskForRelease(options.number, mergeTaskId);\n\t\t\t\tif (task !== 'expired') return { ok: false, reason: task };\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tok: true,\n\t\t\t\treleased: this.ledger.release(key, options.attemptId),\n\t\t\t\tobserved: 'pull-request-open',\n\t\t\t\tpullRequest: pullRequest,\n\t\t\t};\n\t\t});\n\t}\n\n\t// KEEP: Bitbucket answers a bare PENDING for an unknown or expired task too, so only that one may release.\n\tprivate async readMergeTaskForRelease(\n\t\tnumber: number,\n\t\tmergeTaskId: string,\n\t): Promise<'expired' | 'conflict' | 'outcome-unknown'> {\n\t\tconst key = getMergeKey(this.repository.repositoryId, number);\n\t\tlet task: RawMergeTask | undefined;\n\t\ttry {\n\t\t\t({ body: task } = await this.request<RawMergeTask>({\n\t\t\t\turl: `${this.pullRequestUrl(number)}/merge/task-status/${seg(mergeTaskId)}`,\n\t\t\t\theaders: this.headers,\n\t\t\t\tredirect: 'error',\n\t\t\t}));\n\t\t} catch (ex) {\n\t\t\tconst refusal = getBitbucketMergeRefusal(ex);\n\t\t\tif (refusal == null) throw ex;\n\t\t\tif (refusal === 'invalid-input') throw new BitbucketPullRequestWriteError(refusal);\n\t\t\tif (refusal !== 'conflict' && refusal !== 'policy-blocked') return 'outcome-unknown';\n\n\t\t\tthis.ledger.settleMergeTask(key, mergeTaskId);\n\t\t\treturn 'conflict';\n\t\t}\n\n\t\tif (task == null || typeof task !== 'object') return 'outcome-unknown';\n\t\tif (task.task_status === 'SUCCESS') {\n\t\t\tthis.ledger.settleMergeTask(key, mergeTaskId);\n\t\t\treturn 'conflict';\n\t\t}\n\t\tif (task.task_status !== 'PENDING') return 'outcome-unknown';\n\t\tif (task.queued_pullrequest == null) return 'expired';\n\n\t\treturn this.isQueuedPullRequest(task.queued_pullrequest, number) ? 'conflict' : 'outcome-unknown';\n\t}\n\n\tasync readMergeStatus(\n\t\toptions: BitbucketPullRequestMergeStatusOptions,\n\t): Promise<BitbucketPullRequestMergeStatusResult> {\n\t\tconst key = getMergeKey(this.repository.repositoryId, options.number);\n\t\tlet task: RawMergeTask | undefined;\n\t\tlet refusal: FailureReason | undefined;\n\t\ttry {\n\t\t\t({ body: task } = await this.request<RawMergeTask>({\n\t\t\t\turl: `${this.pullRequestUrl(options.number)}/merge/task-status/${seg(options.mergeTaskId)}`,\n\t\t\t\theaders: this.headers,\n\t\t\t\tredirect: 'error',\n\t\t\t}));\n\t\t} catch (ex) {\n\t\t\trefusal = getBitbucketMergeRefusal(ex);\n\t\t\tif (refusal == null) throw ex;\n\t\t}\n\t\tif (refusal === 'invalid-input') return { ok: false, reason: refusal };\n\n\t\tif (refusal === 'conflict' || refusal === 'policy-blocked') {\n\t\t\tthis.ledger.settleMergeTask(key, options.mergeTaskId);\n\t\t\tconst snapshot = await this.readPullRequest(options.number).catch(() => undefined);\n\t\t\tif (snapshot != null && snapshot.pullRequest.state !== 'open') {\n\t\t\t\tthis.ledger.settle(key);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tok: true,\n\t\t\t\tstatus: 'failed',\n\t\t\t\treason: refusal,\n\t\t\t\t...(snapshot != null && { pullRequest: snapshot.pullRequest }),\n\t\t\t};\n\t\t}\n\t\tif (refusal != null) return { ok: false, reason: refusal };\n\n\t\tif (task?.task_status === 'SUCCESS') {\n\t\t\tconst merged = this.getApprovedMergeResult(task.merge_result, options);\n\t\t\tif (merged != null) {\n\t\t\t\tthis.ledger.settleMergeTask(key, options.mergeTaskId);\n\t\t\t\treturn { ok: true, status: 'merged', pullRequest: merged };\n\t\t\t}\n\t\t}\n\n\t\tconst { pullRequest } = await this.readPullRequest(options.number);\n\t\tif (pullRequest.state !== 'open') {\n\t\t\tthis.ledger.settle(key);\n\t\t}\n\n\t\t// SEE: unknown or expired task ids answer PENDING; only the task's own queued_pullrequest proves this one.\n\t\t// https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pullrequests/#api-repositories-workspace-repo-slug-pullrequests-pull-request-id-merge-task-status-task-id-get\n\t\treturn task?.task_status === 'PENDING' && this.isQueuedPullRequest(task.queued_pullrequest, options.number)\n\t\t\t? { ok: true, status: 'pending', pullRequest: pullRequest }\n\t\t\t: { ok: false, reason: 'outcome-unknown' };\n\t}\n\n\tprivate getApprovedMergeResult(\n\t\traw: RawPullRequest | undefined,\n\t\toptions: BitbucketPullRequestMergeStatusOptions,\n\t): BitbucketWrittenPullRequest | undefined {\n\t\tif (raw == null) return undefined;\n\n\t\tlet read: PullRequestRead;\n\t\ttry {\n\t\t\tread = this.toPullRequestRead(raw, options.number);\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst { pullRequest } = read;\n\t\treturn pullRequest.state === 'merged' &&\n\t\t\tpullRequest.sourceBranch === options.expectedSourceBranch &&\n\t\t\tpullRequest.targetBranch === options.expectedTargetBranch &&\n\t\t\tisApprovedSource(options.expectedSourceSha, read)\n\t\t\t? pullRequest\n\t\t\t: undefined;\n\t}\n\n\tprivate isQueuedPullRequest(queued: RawMergeTask['queued_pullrequest'], number: number): boolean {\n\t\tconst pullRequest = queued?.pullrequest;\n\t\tconst repositoryId = pullRequest?.destination?.repository?.uuid;\n\t\treturn (\n\t\t\tqueued?.type === 'queued_pullrequest' &&\n\t\t\tpullRequest?.id === number &&\n\t\t\t(repositoryId == null || sameIdentifier(repositoryId, this.repository.repositoryId))\n\t\t);\n\t}\n\n\tprivate async getMergeTarget(\n\t\tread: PullRequestRead,\n\t): Promise<{ merge: BitbucketPullRequestMergeCapability; pullRequest: BitbucketWrittenPullRequest }> {\n\t\tconst { pullRequest } = read;\n\t\tconst stateFailure = getMergeStateFailure(pullRequest);\n\t\tif (stateFailure != null) {\n\t\t\treturn { merge: { kind: 'unavailable', reason: stateFailure }, pullRequest: pullRequest };\n\t\t}\n\n\t\ttry {\n\t\t\tconst [source, target] = await Promise.all([\n\t\t\t\tthis.readBranch(pullRequest.sourceBranch),\n\t\t\t\tthis.readBranch(pullRequest.targetBranch),\n\t\t\t]);\n\t\t\tconst snapshot = {\n\t\t\t\t...pullRequest,\n\t\t\t\t...(source != null && { sourceSha: source.sha }),\n\t\t\t\t...(target != null && { targetSha: target.sha }),\n\t\t\t};\n\t\t\tif (source == null || read.sourceHash == null || !source.sha.toLowerCase().startsWith(read.sourceHash)) {\n\t\t\t\treturn { merge: { kind: 'unavailable', reason: 'source-changed' }, pullRequest: snapshot };\n\t\t\t}\n\t\t\tif (target == null) {\n\t\t\t\treturn { merge: { kind: 'unavailable', reason: 'target-changed' }, pullRequest: snapshot };\n\t\t\t}\n\n\t\t\tconst checks = await this.readMergeabilityChecks(pullRequest.number);\n\t\t\tconst strategies = getAllowedStrategies(target, checks);\n\t\t\tconst blocked = strategies.length ? getBlockingCheckFailure(checks) : 'policy-blocked';\n\t\t\tif (blocked != null) return { merge: { kind: 'unavailable', reason: blocked }, pullRequest: snapshot };\n\n\t\t\tconst defaultStrategy = strategies.find(strategy => strategy === target.defaultStrategy);\n\t\t\treturn {\n\t\t\t\tmerge: {\n\t\t\t\t\tkind: 'available',\n\t\t\t\t\tstrategies: strategies,\n\t\t\t\t\t...(defaultStrategy !== undefined && { defaultStrategy: defaultStrategy }),\n\t\t\t\t},\n\t\t\t\tpullRequest: snapshot,\n\t\t\t};\n\t\t} catch (ex) {\n\t\t\treturn {\n\t\t\t\tmerge: { kind: 'unavailable', reason: toBitbucketPullRequestWriteFailure(ex).reason },\n\t\t\t\tpullRequest: pullRequest,\n\t\t\t};\n\t\t}\n\t}\n\n\tprivate pullRequestUrl(number: number): string {\n\t\treturn `${this.repoUrl}/pullrequests/${number}`;\n\t}\n\n\tprivate async readPullRequest(number: number): Promise<PullRequestRead> {\n\t\tconst { body: raw } = await this.request<RawPullRequest>({\n\t\t\turl: this.pullRequestUrl(number),\n\t\t\theaders: this.headers,\n\t\t\tredirect: 'error',\n\t\t});\n\t\treturn this.toPullRequestRead(raw, number);\n\t}\n\n\tprivate toPullRequestRead(raw: RawPullRequest, number?: number): PullRequestRead {\n\t\tif (!sameIdentifier(raw?.destination?.repository?.uuid, this.repository.repositoryId)) {\n\t\t\tthrow new BitbucketPullRequestWriteError('not-found');\n\t\t}\n\n\t\tconst { id, title, description, source, destination } = raw;\n\t\tconst state = typeof raw.state === 'string' ? raw.state.toLowerCase() : undefined;\n\t\tconst sourceBranch = source?.branch?.name;\n\t\tconst targetBranch = destination?.branch?.name;\n\t\tconst sourceHash = source?.commit?.hash;\n\t\tif (\n\t\t\t!isPositiveInt32(id) ||\n\t\t\t(number !== undefined && id !== number) ||\n\t\t\ttypeof title !== 'string' ||\n\t\t\t(description != null && typeof description !== 'string') ||\n\t\t\t(state !== 'open' && state !== 'merged' && state !== 'declined' && state !== 'superseded') ||\n\t\t\ttypeof sourceBranch !== 'string' ||\n\t\t\tsourceBranch.length === 0 ||\n\t\t\ttypeof targetBranch !== 'string' ||\n\t\t\ttargetBranch.length === 0\n\t\t) {\n\t\t\tthrow new BitbucketPullRequestWriteError('unknown');\n\t\t}\n\n\t\tconst sourceRepository = source?.repository?.uuid;\n\t\treturn {\n\t\t\tsourceHash:\n\t\t\t\ttypeof sourceHash === 'string' && /^[\\da-f]{7,40}$/i.test(sourceHash)\n\t\t\t\t\t? sourceHash.toLowerCase()\n\t\t\t\t\t: undefined,\n\t\t\tpullRequest: {\n\t\t\t\trepository: this.repository,\n\t\t\t\tnumber: id,\n\t\t\t\turl: `${webUrl}/${seg(this.repository.workspaceSlug)}/${seg(this.repository.repositorySlug)}/pull-requests/${id}`,\n\t\t\t\ttitle: title,\n\t\t\t\tdescription: description ?? '',\n\t\t\t\tstate: state,\n\t\t\t\tdraft: raw.draft === true,\n\t\t\t\tqueued: raw.queued === true,\n\t\t\t\tisCrossRepository: !sameIdentifier(sourceRepository, this.repository.repositoryId),\n\t\t\t\tsourceBranch: sourceBranch,\n\t\t\t\ttargetBranch: targetBranch,\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate async readBranch(name: string): Promise<TargetBranch | undefined> {\n\t\tlet branch: RawBranch;\n\t\ttry {\n\t\t\t({ body: branch } = await this.request<RawBranch>({\n\t\t\t\turl: `${this.repoUrl}/refs/branches/${seg(name)}`,\n\t\t\t\theaders: this.headers,\n\t\t\t\tredirect: 'error',\n\t\t\t}));\n\t\t} catch (ex) {\n\t\t\tif (toBitbucketPullRequestWriteFailure(ex).reason === 'not-found') return undefined;\n\n\t\t\tthrow ex;\n\t\t}\n\n\t\tconst sha = branch?.target?.hash;\n\t\tif (branch?.name !== name || !isCommitSha(sha)) throw new BitbucketPullRequestWriteError('unknown');\n\n\t\treturn {\n\t\t\tsha: sha,\n\t\t\tstrategies: toStrategies(branch.merge_strategies),\n\t\t\tdefaultStrategy:\n\t\t\t\ttypeof branch.default_merge_strategy === 'string' ? branch.default_merge_strategy : undefined,\n\t\t};\n\t}\n\n\tprivate async readMergeabilityChecks(number: number): Promise<RawMergeabilityCheck[]> {\n\t\tconst { body } = await this.request<{ values?: unknown }>({\n\t\t\turl: `${this.pullRequestUrl(number)}/mergeability/checks`,\n\t\t\theaders: this.headers,\n\t\t\tredirect: 'error',\n\t\t});\n\t\tconst values = body?.values;\n\t\tif (!Array.isArray(values) || values.some(check => check == null || typeof check !== 'object')) {\n\t\t\tthrow new BitbucketPullRequestWriteError('unknown');\n\t\t}\n\n\t\treturn values as RawMergeabilityCheck[];\n\t}\n\n\tprivate getOpenPullRequestsFromQuery(branch: string): URLSearchParams {\n\t\t// SEE: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pullrequests/#api-repositories-workspace-repo-slug-pullrequests-get\n\t\tconst escapedBranch = branch.replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"');\n\t\t// SEE: live Bitbucket Cloud ignores the `state` parameter once `q` is set, so the state goes in `q`.\n\t\treturn new URLSearchParams({\n\t\t\tq: `source.branch.name=\"${escapedBranch}\" AND state=\"OPEN\"`,\n\t\t\tfields: 'next,values.id,values.state,values.source.repository.uuid',\n\t\t\tpagelen: '50',\n\t\t});\n\t}\n\n\tprivate async scanPullRequests(\n\t\tquery: URLSearchParams,\n\t\tvisit: (pr: RawPullRequest) => boolean,\n\t): Promise<number | undefined> {\n\t\tlet url = `${this.repoUrl}/pullrequests?${query.toString()}`;\n\t\tconst seen = new Set<string>();\n\t\tlet serverTime: number | undefined;\n\t\twhile (true) {\n\t\t\tseen.add(url);\n\t\t\tconst response = await this.request<{ values?: unknown; next?: unknown }>({\n\t\t\t\turl: url,\n\t\t\t\theaders: this.headers,\n\t\t\t\tredirect: 'error',\n\t\t\t});\n\t\t\tserverTime ??= getServerTime(response.headers);\n\t\t\tconst { values, next } = response.body ?? {};\n\t\t\tif (!Array.isArray(values)) throw new BitbucketPullRequestWriteError('unknown');\n\t\t\tif ((values as RawPullRequest[]).some(pr => visit(pr))) return serverTime;\n\t\t\tif (next == null) return serverTime;\n\t\t\tif (typeof next !== 'string' || !next.startsWith(`${apiUrl}/`) || seen.has(next)) {\n\t\t\t\tthrow new BitbucketPullRequestWriteError('unknown');\n\t\t\t}\n\n\t\t\turl = next;\n\t\t}\n\t}\n\n\tprivate getMergeTaskId(number: number, headers: Record<string, unknown>): string | undefined {\n\t\tconst location = getResponseHeader(headers, 'location');\n\t\tif (typeof location !== 'string' || !URL.canParse(location, apiUrl)) return undefined;\n\n\t\tconst url = new URL(location, apiUrl);\n\t\tconst match = /^\\/2\\.0\\/repositories\\/([^/]+)\\/([^/]+)\\/pullrequests\\/(\\d+)\\/merge\\/task-status\\/([^/]+)$/.exec(\n\t\t\turl.pathname,\n\t\t);\n\t\tif (url.origin !== new URL(apiUrl).origin || url.search !== '' || match == null) return undefined;\n\n\t\tconst [, workspace, repository, id, taskId] = match.map(part => safeDecode(part));\n\t\tconst { workspaceId, workspaceSlug, repositoryId, repositorySlug } = this.repository;\n\t\treturn Number(id) === number &&\n\t\t\t(sameIdentifier(workspace, workspaceId) || sameIdentifier(workspace, workspaceSlug)) &&\n\t\t\t(sameIdentifier(repository, repositoryId) || sameIdentifier(repository, repositorySlug)) &&\n\t\t\tisBitbucketMergeTaskId(taskId)\n\t\t\t? taskId\n\t\t\t: undefined;\n\t}\n\n\tprivate send(\n\t\toptions: BitbucketPullRequestWriteOptions,\n\t\tmethod: 'POST' | 'PUT',\n\t\turl: string,\n\t\tbody?: object,\n\t\tcontext?: SendContext & { pending?: undefined },\n\t): Promise<SettledResult>;\n\tprivate send(\n\t\toptions: BitbucketPullRequestWriteOptions,\n\t\tmethod: 'POST' | 'PUT',\n\t\turl: string,\n\t\tbody: object,\n\t\tcontext: SendContext & { pending: BitbucketWrittenPullRequest },\n\t): Promise<SentResult>;\n\tprivate async send(\n\t\toptions: BitbucketPullRequestWriteOptions,\n\t\tmethod: 'POST' | 'PUT',\n\t\turl: string,\n\t\tbody?: object,\n\t\tcontext?: SendContext & { pending?: BitbucketWrittenPullRequest },\n\t): Promise<SentResult> {\n\t\tconst pending = context?.pending;\n\t\tif (!(await this.isSessionCurrent())) return { ok: false, reason: 'no-connection' };\n\n\t\tlet response: { status: number; body: RawPullRequest; headers: Record<string, unknown> };\n\t\ttry {\n\t\t\tresponse = await this.request<RawPullRequest>({\n\t\t\t\turl: url,\n\t\t\t\tmethod: method,\n\t\t\t\theaders: body == null ? this.headers : { ...this.headers, 'Content-Type': 'application/json' },\n\t\t\t\tbody: body == null ? undefined : JSON.stringify(body),\n\t\t\t\tredirect: 'error',\n\t\t\t});\n\t\t} catch (ex) {\n\t\t\treturn toBitbucketPullRequestWriteFailure(ex, { action: options.action });\n\t\t}\n\n\t\tif (options.action === 'merge' && response.status === 202 && pending != null) {\n\t\t\tconst mergeTaskId = this.getMergeTaskId(options.number, response.headers);\n\t\t\treturn {\n\t\t\t\tok: true,\n\t\t\t\tstatus: 'pending',\n\t\t\t\tpullRequest: pending,\n\t\t\t\t...(mergeTaskId !== undefined && { mergeTaskId: mergeTaskId }),\n\t\t\t};\n\t\t}\n\n\t\tlet read: PullRequestRead;\n\t\ttry {\n\t\t\tread = this.toPullRequestRead(response.body, options.action === 'create' ? undefined : options.number);\n\t\t} catch {\n\t\t\treturn { ok: false, reason: 'outcome-unknown' };\n\t\t}\n\t\tcontext?.onReceipt?.(read.pullRequest);\n\n\t\tconst status = getReceiptStatus(options, response, read, this.accountId, context?.createdNotBefore);\n\t\treturn status === undefined\n\t\t\t? { ok: false, reason: 'outcome-unknown' }\n\t\t\t: { ok: true, status: status, pullRequest: read.pullRequest };\n\t}\n}\n\nfunction getAllowedStrategies(\n\ttarget: TargetBranch,\n\tchecks: RawMergeabilityCheck[],\n): BitbucketPullRequestMergeStrategy[] {\n\tconst queued = checks.some(check => check.type === 'merge_queue_check' && check.required === true);\n\treturn queued ? target.strategies.filter(strategy => queueStrategies.includes(strategy)) : target.strategies;\n}\n\nfunction safeDecode(value: string): string | undefined {\n\ttry {\n\t\treturn decodeURIComponent(value);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction isApprovedSource(expectedSourceSha: string, read: PullRequestRead): boolean {\n\treturn read.sourceHash != null && expectedSourceSha.toLowerCase().startsWith(read.sourceHash);\n}\n\nfunction sameText(actual: string, expected: string): boolean {\n\treturn actual.replaceAll('\\r\\n', '\\n').trim() === expected.replaceAll('\\r\\n', '\\n').trim();\n}\n\nfunction getServerTime(headers: Record<string, unknown> | undefined): number | undefined {\n\tconst date = getResponseHeader(headers, 'date');\n\tif (typeof date !== 'string') return undefined;\n\n\tconst time = Date.parse(date);\n\treturn Number.isNaN(time) ? undefined : Math.floor(time / 1000) * 1000;\n}\n\nfunction isCreatedSince(raw: RawPullRequest, accountId: string, notBefore: number | undefined): boolean {\n\tif (notBefore == null || !sameIdentifier(raw.author?.uuid, accountId)) return false;\n\tif (typeof raw.created_on !== 'string') return false;\n\n\tconst createdOn = Date.parse(raw.created_on);\n\treturn !Number.isNaN(createdOn) && createdOn >= notBefore;\n}\n\nfunction getReceiptStatus(\n\toptions: BitbucketPullRequestWriteOptions,\n\tresponse: { status: number; body: RawPullRequest },\n\tread: PullRequestRead,\n\taccountId: string,\n\tcreatedNotBefore: number | undefined,\n): WriteStatus | undefined {\n\tconst { pullRequest } = read;\n\tswitch (options.action) {\n\t\tcase 'create':\n\t\t\t// KEEP: Bitbucket upserts; an open PR from the branch made in the preflight's second or after it can still pass here.\n\t\t\treturn response.status === 201 &&\n\t\t\t\tisCreatedSince(response.body, accountId, createdNotBefore) &&\n\t\t\t\tpullRequest.state === 'open' &&\n\t\t\t\t!pullRequest.isCrossRepository &&\n\t\t\t\tpullRequest.sourceBranch === options.sourceBranch &&\n\t\t\t\tpullRequest.targetBranch === options.targetBranch &&\n\t\t\t\tsameText(pullRequest.title, options.title) &&\n\t\t\t\t(options.description === undefined || sameText(pullRequest.description, options.description))\n\t\t\t\t? 'created'\n\t\t\t\t: undefined;\n\t\tcase 'edit':\n\t\t\treturn pullRequest.state === 'open' &&\n\t\t\t\t(options.title === undefined || sameText(pullRequest.title, options.title)) &&\n\t\t\t\t(options.description === undefined || sameText(pullRequest.description, options.description))\n\t\t\t\t? 'updated'\n\t\t\t\t: undefined;\n\t\tcase 'decline':\n\t\t\treturn pullRequest.state === 'declined' ? 'declined' : undefined;\n\t\tcase 'merge':\n\t\t\tif (\n\t\t\t\tpullRequest.sourceBranch !== options.expectedSourceBranch ||\n\t\t\t\tpullRequest.targetBranch !== options.expectedTargetBranch\n\t\t\t) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tif (pullRequest.state === 'merged') {\n\t\t\t\t// KEEP: Bitbucket has no compare-and-swap, so a source pushed after the last read may be what merged.\n\t\t\t\treturn isApprovedSource(options.expectedSourceSha, read) ? 'merged' : undefined;\n\t\t\t}\n\n\t\t\treturn pullRequest.state === 'open' && pullRequest.queued ? 'pending' : undefined;\n\t}\n}\n"],"mappings":";;;;;AA4BA,MAAM,SAAS;AACf,MAAM,SAAS;AACf,MAAM,kBAAuD;CAC5D;CACA;CACA;CACA;CACA;CACA;AACD;AAEA,MAAM,kBAAuD;CAAC;CAAgB;CAAU;AAAc;AACtG,MAAM,cAAc;AACpB,MAAM,cAAc;AACpB,MAAM,qBAAqB;AA6D3B,SAAS,gBAAgB,OAAiC;CACzD,OAAO,OAAO,UAAU,YAAY,YAAY,KAAK,KAAK;AAC3D;AAEA,SAAS,aAAa,OAAiC;CACtD,OAAO,gBAAgB,KAAK,KAAM,OAAO,UAAU,YAAY,YAAY,KAAK,KAAK,KAAK,CAAC,UAAU,KAAK,KAAK;AAChH;AAEA,SAAS,aAAa,MAA+B;CACpD,OACC,OAAO,SAAS,YAChB,KAAK,SAAS,KACd,CAAC,KAAK,WAAW,OAAO,KACxB,CAAC,KAAK,WAAW,GAAG,KACpB,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,MAAK,cAAa,aAAa,OAAO,cAAgB,SAAS,SAAS,CAAC,KACpF,CAAC,KAAK,SAAS,IAAI,KACnB,CAAC,KAAK,SAAS,IAAI,KACnB,SAAS,OACT,CAAC,KAAK,SAAS,GAAG,KAClB,KAAK,MAAM,GAAG,CAAC,CAAC,OAAM,SAAQ,KAAK,SAAS,KAAK,CAAC,KAAK,WAAW,GAAG,KAAK,CAAC,KAAK,SAAS,OAAO,CAAC;AAEnG;AAEA,SAAS,QAAQ,OAAiC;CACjD,OAAO,OAAO,UAAU,YAAY,MAAM,KAAK,CAAC,CAAC,SAAS;AAC3D;AAEA,SAAS,IAAI,O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AAS,eAAe,KAAqB,WAAmB,WAAwC;CACvG,IAAI,aAAa,QAAQ,CAAC,eAAe,IAAI,QAAQ,MAAM,SAAS,GAAG,OAAO;CAC9E,IAAI,OAAO,IAAI,eAAe,UAAU,OAAO;CAE/C,MAAM,YAAY,KAAK,MAAM,IAAI,UAAU;CAC3C,OAAO,CAAC,OAAO,MAAM,SAAS,KAAK,aAAa;AACjD;AAEA,SAAS,iBACR,SACA,UACA,MACA,WACA,kBAC0B;CAC1B,MAAM,EAAE,gBAAgB;CACxB,QAAQ,QAAQ,QAAhB;EACC,KAAK,UAEJ,OAAO,SAAS,WAAW,OAC1B,eAAe,SAAS,MAAM,WAAW,gBAAgB,KACzD,YAAY,UAAU,UACtB,CAAC,YAAY,qBACb,YAAY,iBAAiB,QAAQ,gBACrC,YAAY,iBAAiB,QAAQ,gBACrC,SAAS,YAAY,OAAO,QAAQ,KAAK,MACxC,QAAQ,gBAAgB,KAAA,KAAa,SAAS,YAAY,aAAa,QAAQ,WAAW,KACzF,YACA,KAAA;EACJ,KAAK,QACJ,OAAO,YAAY,UAAU,WAC3B,QAAQ,UAAU,KAAA,KAAa,SAAS,YAAY,OAAO,QAAQ,KAAK,OACxE,QAAQ,gBAAgB,KAAA,KAAa,SAAS,YAAY,aAAa,QAAQ,WAAW,KACzF,YACA,KAAA;EACJ,KAAK,WACJ,OAAO,YAAY,UAAU,aAAa,aAAa,KAAA;EACxD,KAAK;GACJ,IACC,YAAY,iBAAiB,QAAQ,wBACrC,YAAY,iBAAiB,QAAQ,sBAErC;GAED,IAAI,YAAY,UAAU,UAEzB,OAAO,iBAAiB,QAAQ,mBAAmB,IAAI,IAAI,WAAW,KAAA;GAGvE,OAAO,YAAY,UAAU,UAAU,YAAY,SAAS,YAAY,KAAA;CAC1E;AACD"}
1
+ {"version":3,"file":"bitbucketPullRequestWrites.js","names":[],"sources":["../../../../../plus/integrations/src/providers/bitbucketPullRequestWrites.ts"],"sourcesContent":["import { uuid } from '@gitlens/utils/crypto.js';\nimport { getResponseHeader } from '../errors.js';\nimport type {\n\tBitbucketPullRequestCreateCapabilityOptions,\n\tBitbucketPullRequestCreateCapabilityResult,\n\tBitbucketPullRequestMergeCapability,\n\tBitbucketPullRequestMergeStatusOptions,\n\tBitbucketPullRequestMergeStatusResult,\n\tBitbucketPullRequestMergeStrategy,\n\tBitbucketPullRequestRepository,\n\tBitbucketPullRequestWriteFailure,\n\tBitbucketPullRequestWriteOptions,\n\tBitbucketPullRequestWriteReleaseOptions,\n\tBitbucketPullRequestWriteReleaseResult,\n\tBitbucketPullRequestWriteResult,\n\tBitbucketPullRequestWriteTargetResult,\n\tBitbucketUnsettledPullRequestWrite,\n\tBitbucketWrittenPullRequest,\n} from '../models/bitbucketPullRequestWrites.js';\nimport {\n\tBitbucketPullRequestWriteError,\n\tgetBitbucketMergeRefusal,\n\ttoBitbucketPullRequestWriteFailure,\n} from './bitbucketPullRequestWriteErrors.js';\nimport type { BitbucketPullRequestWriteLedger } from './bitbucketPullRequestWriteLedger.js';\nimport type { ProviderRequestFunction } from './models.js';\nimport {\n\tisCommitSha,\n\tisGitBranchName,\n\tisPositiveInt32,\n\tisWriteIdentifier,\n\tsameIdentifier,\n} from './utils/writeInputs.js';\n\nconst apiUrl = 'https://api.bitbucket.org/2.0';\nconst webUrl = 'https://bitbucket.org';\nconst mergeStrategies: BitbucketPullRequestMergeStrategy[] = [\n\t'merge_commit',\n\t'squash',\n\t'fast_forward',\n\t'squash_fast_forward',\n\t'rebase_fast_forward',\n\t'rebase_merge',\n];\n// SEE: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pullrequests/#api-repositories-workspace-repo-slug-pullrequests-pull-request-id-merge-post\nconst queueStrategies: BitbucketPullRequestMergeStrategy[] = ['merge_commit', 'squash', 'rebase_merge'];\nconst uuidPattern = /^\\{[\\da-f]{8}-(?:[\\da-f]{4}-){3}[\\da-f]{12}\\}$/i;\nconst slugPattern = /^[\\w.-]+$/;\nconst mergeTaskIdPattern = /^(?!\\.{1,2}$)[\\w.:-]{1,256}$/;\n\ntype FailureReason = BitbucketPullRequestWriteFailure['reason'];\ntype MergeOptions = Extract<BitbucketPullRequestWriteOptions, { action: 'merge' }>;\ntype CreateOptions = Extract<BitbucketPullRequestWriteOptions, { action: 'create' }>;\ntype SendContext = {\n\tcreatedNotBefore?: number;\n\tonReceipt?: (pullRequest: BitbucketWrittenPullRequest) => void;\n};\ntype WriteStatus = Extract<BitbucketPullRequestWriteResult, { ok: true }>['status'];\ntype PendingResult = Extract<BitbucketPullRequestWriteResult, { status: 'pending' }>;\ntype SettledResult = Exclude<BitbucketPullRequestWriteResult, PendingResult>;\ntype SentResult = SettledResult | Omit<PendingResult, 'unsettled'>;\n\ntype RawRepository = {\n\tuuid?: unknown;\n\tslug?: unknown;\n\tfull_name?: unknown;\n\tworkspace?: { uuid?: unknown; slug?: unknown };\n\tmainbranch?: { name?: unknown } | null;\n};\n\ntype RawEndpoint = {\n\tbranch?: { name?: unknown };\n\tcommit?: { hash?: unknown } | null;\n\trepository?: { uuid?: unknown } | null;\n};\n\ntype RawPullRequest = {\n\tid?: unknown;\n\ttitle?: unknown;\n\tdescription?: unknown;\n\tstate?: unknown;\n\tdraft?: unknown;\n\tqueued?: unknown;\n\tauthor?: { uuid?: unknown } | null;\n\tcreated_on?: unknown;\n\tupdated_on?: unknown;\n\tsource?: RawEndpoint;\n\tdestination?: RawEndpoint;\n};\n\ntype RawBranch = {\n\tname?: unknown;\n\ttarget?: { hash?: unknown };\n\tmerge_strategies?: unknown;\n\tdefault_merge_strategy?: unknown;\n};\n\ntype RawMergeTask = {\n\ttask_status?: unknown;\n\tmerge_result?: RawPullRequest;\n\tqueued_pullrequest?: { type?: unknown; pullrequest?: RawPullRequest | null } | null;\n};\n\ntype RawMergeabilityCheck = { type?: unknown; blocking?: unknown; required?: unknown };\n\ntype PullRequestRead = { pullRequest: BitbucketWrittenPullRequest; sourceHash: string | undefined };\n\ntype TargetBranch = { sha: string; strategies: BitbucketPullRequestMergeStrategy[]; defaultStrategy?: string };\n\nfunction isBitbucketUuid(value: unknown): value is string {\n\treturn typeof value === 'string' && uuidPattern.test(value);\n}\n\nfunction isSlugOrUuid(value: unknown): value is string {\n\treturn isBitbucketUuid(value) || (typeof value === 'string' && slugPattern.test(value) && !/^\\.\\.?$/.test(value));\n}\n\nfunction isBranchName(name: unknown): name is string {\n\treturn isGitBranchName(name) && name !== '@' && !name.startsWith('refs/') && !name.includes('\"');\n}\n\nfunction isTitle(title: unknown): title is string {\n\treturn typeof title === 'string' && title.trim().length > 0;\n}\n\nfunction seg(value: string): string {\n\treturn encodeURIComponent(value);\n}\n\nfunction isAttemptPullRequest(\n\tpullRequest: BitbucketWrittenPullRequest,\n\tsourceBranch: string,\n\ttargetBranch: string | undefined,\n): boolean {\n\treturn (\n\t\t!pullRequest.isCrossRepository &&\n\t\tpullRequest.sourceBranch === sourceBranch &&\n\t\t(targetBranch === undefined || pullRequest.targetBranch === targetBranch)\n\t);\n}\n\nfunction getCreateKey(repositoryId: string, sourceBranch: string): string {\n\treturn `create\\n${repositoryId.toLowerCase()}\\n${sourceBranch}`;\n}\n\nfunction getMergeKey(repositoryId: string, number: number): string {\n\treturn `merge\\n${repositoryId.toLowerCase()}\\n${number}`;\n}\n\nfunction isBitbucketMergeTaskId(value: unknown): value is string {\n\treturn typeof value === 'string' && mergeTaskIdPattern.test(value);\n}\n\nexport function isBitbucketPullRequestMergeStatusRead(options: BitbucketPullRequestMergeStatusOptions): boolean {\n\treturn (\n\t\t(options.providerId === undefined || options.providerId === 'bitbucket') &&\n\t\tisWriteIdentifier(options.connectionId) &&\n\t\tisBitbucketUuid(options.workspaceId) &&\n\t\tisBitbucketUuid(options.repositoryId) &&\n\t\tisBitbucketUuid(options.expectedAccountId) &&\n\t\tisPositiveInt32(options.number) &&\n\t\tisBitbucketMergeTaskId(options.mergeTaskId) &&\n\t\tisBranchName(options.expectedSourceBranch) &&\n\t\tisBranchName(options.expectedTargetBranch) &&\n\t\toptions.expectedSourceBranch !== options.expectedTargetBranch &&\n\t\tisCommitSha(options.expectedSourceSha)\n\t);\n}\n\nexport function isBitbucketPullRequestScope(options: BitbucketPullRequestCreateCapabilityOptions): boolean {\n\treturn (\n\t\t(options.providerId === undefined || options.providerId === 'bitbucket') &&\n\t\tisWriteIdentifier(options.connectionId) &&\n\t\tisSlugOrUuid(options.workspace) &&\n\t\tisSlugOrUuid(options.repository) &&\n\t\t(options.expectedAccountId === undefined || isBitbucketUuid(options.expectedAccountId))\n\t);\n}\n\nexport function isBitbucketPullRequestWrite(options: BitbucketPullRequestWriteOptions): boolean {\n\tif (\n\t\t(options.providerId !== undefined && options.providerId !== 'bitbucket') ||\n\t\t!isWriteIdentifier(options.connectionId) ||\n\t\t!isBitbucketUuid(options.workspaceId) ||\n\t\t!isBitbucketUuid(options.repositoryId) ||\n\t\t!isBitbucketUuid(options.expectedAccountId)\n\t) {\n\t\treturn false;\n\t}\n\n\tif (options.action === 'create') {\n\t\treturn (\n\t\t\tisBranchName(options.sourceBranch) &&\n\t\t\tisBranchName(options.targetBranch) &&\n\t\t\toptions.sourceBranch !== options.targetBranch &&\n\t\t\tisTitle(options.title) &&\n\t\t\t(options.description === undefined || typeof options.description === 'string')\n\t\t);\n\t}\n\n\tif (!isPositiveInt32(options.number)) return false;\n\n\tswitch (options.action) {\n\t\tcase 'edit':\n\t\t\treturn (\n\t\t\t\t(options.title !== undefined || options.description !== undefined) &&\n\t\t\t\t(options.title === undefined || isTitle(options.title)) &&\n\t\t\t\t(options.description === undefined || typeof options.description === 'string')\n\t\t\t);\n\t\tcase 'decline':\n\t\t\treturn true;\n\t\tcase 'merge':\n\t\t\treturn (\n\t\t\t\tmergeStrategies.includes(options.strategy) &&\n\t\t\t\tisBranchName(options.expectedSourceBranch) &&\n\t\t\t\tisBranchName(options.expectedTargetBranch) &&\n\t\t\t\toptions.expectedSourceBranch !== options.expectedTargetBranch &&\n\t\t\t\tisCommitSha(options.expectedSourceSha) &&\n\t\t\t\tisCommitSha(options.expectedTargetSha)\n\t\t\t);\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nexport function isBitbucketPullRequestWriteRelease(options: BitbucketPullRequestWriteReleaseOptions): boolean {\n\treturn (\n\t\t(options.providerId === undefined || options.providerId === 'bitbucket') &&\n\t\tisWriteIdentifier(options.connectionId) &&\n\t\tisBitbucketUuid(options.workspaceId) &&\n\t\tisBitbucketUuid(options.repositoryId) &&\n\t\tisBitbucketUuid(options.expectedAccountId) &&\n\t\tisWriteIdentifier(options.attemptId) &&\n\t\t(options.action === 'create'\n\t\t\t? isBranchName(options.sourceBranch)\n\t\t\t: options.action === 'merge' &&\n\t\t\t\tisPositiveInt32(options.number) &&\n\t\t\t\t(options.mergeTaskId === undefined || isBitbucketMergeTaskId(options.mergeTaskId)))\n\t);\n}\n\nfunction toStrategies(value: unknown): BitbucketPullRequestMergeStrategy[] {\n\treturn Array.isArray(value) ? mergeStrategies.filter(strategy => value.includes(strategy)) : [];\n}\n\nfunction getBlockingCheckFailure(checks: RawMergeabilityCheck[]): FailureReason | undefined {\n\tconst blocking = new Set(checks.filter(check => check.blocking === true).map(check => check.type));\n\tif (blocking.size === 0) return undefined;\n\tif (blocking.has('pullrequest_state_check')) return 'conflict';\n\tif (blocking.has('current_user_permission_check')) return 'forbidden';\n\tif (blocking.has('git_mergeability_check')) return 'conflict';\n\n\treturn 'policy-blocked';\n}\n\nfunction getMergeStateFailure(pullRequest: BitbucketWrittenPullRequest): FailureReason | undefined {\n\tif (pullRequest.state !== 'open' || pullRequest.queued) return 'conflict';\n\tif (pullRequest.isCrossRepository) return 'unsupported';\n\tif (pullRequest.draft) return 'policy-blocked';\n\n\treturn undefined;\n}\n\nfunction getMergeRefFailure(options: MergeOptions, read: PullRequestRead): FailureReason | undefined {\n\tconst { pullRequest, sourceHash } = read;\n\tif (pullRequest.sourceBranch !== options.expectedSourceBranch) return 'source-changed';\n\tif (pullRequest.targetBranch !== options.expectedTargetBranch) return 'target-changed';\n\tif (sourceHash == null || !options.expectedSourceSha.toLowerCase().startsWith(sourceHash)) return 'source-changed';\n\n\treturn undefined;\n}\n\nexport class BitbucketPullRequestWriter {\n\tstatic async connect(\n\t\trequest: ProviderRequestFunction,\n\t\taccessToken: string,\n\t\toptions: BitbucketPullRequestCreateCapabilityOptions,\n\t\tisSessionCurrent: () => Promise<boolean>,\n\t\tledger: BitbucketPullRequestWriteLedger,\n\t): Promise<BitbucketPullRequestWriter> {\n\t\tconst headers = { Authorization: `Bearer ${accessToken}` };\n\t\tconst { body: user } = await request<{ uuid?: unknown }>({\n\t\t\turl: `${apiUrl}/user`,\n\t\t\theaders: headers,\n\t\t\tredirect: 'error',\n\t\t});\n\t\tconst accountId = user?.uuid;\n\t\tif (\n\t\t\t!isBitbucketUuid(accountId) ||\n\t\t\t(options.expectedAccountId !== undefined && !sameIdentifier(accountId, options.expectedAccountId))\n\t\t) {\n\t\t\tthrow new BitbucketPullRequestWriteError('no-connection');\n\t\t}\n\n\t\tconst { body: repo } = await request<RawRepository>({\n\t\t\turl: `${apiUrl}/repositories/${seg(options.workspace)}/${seg(options.repository)}`,\n\t\t\theaders: headers,\n\t\t\tredirect: 'error',\n\t\t});\n\t\tconst workspace = repo?.workspace;\n\t\tif (\n\t\t\t!isBitbucketUuid(repo?.uuid) ||\n\t\t\t!isBitbucketUuid(workspace?.uuid) ||\n\t\t\t!isSlugOrUuid(repo.slug) ||\n\t\t\t!isSlugOrUuid(workspace.slug) ||\n\t\t\ttypeof repo.full_name !== 'string' ||\n\t\t\t!sameIdentifier(isBitbucketUuid(options.workspace) ? workspace.uuid : workspace.slug, options.workspace) ||\n\t\t\t!sameIdentifier(isBitbucketUuid(options.repository) ? repo.uuid : repo.slug, options.repository)\n\t\t) {\n\t\t\tthrow new BitbucketPullRequestWriteError('not-found');\n\t\t}\n\n\t\tconst mainBranch = repo.mainbranch?.name;\n\t\treturn new BitbucketPullRequestWriter(\n\t\t\trequest,\n\t\t\theaders,\n\t\t\taccountId,\n\t\t\t{\n\t\t\t\tworkspaceId: workspace.uuid,\n\t\t\t\tworkspaceSlug: workspace.slug,\n\t\t\t\trepositoryId: repo.uuid,\n\t\t\t\trepositorySlug: repo.slug,\n\t\t\t\tfullName: repo.full_name,\n\t\t\t},\n\t\t\tisBranchName(mainBranch) ? mainBranch : undefined,\n\t\t\tisSessionCurrent,\n\t\t\tledger,\n\t\t);\n\t}\n\n\tprivate readonly repoUrl: string;\n\n\tprivate constructor(\n\t\tprivate readonly request: ProviderRequestFunction,\n\t\tprivate readonly headers: { Authorization: string },\n\t\tprivate readonly accountId: string,\n\t\tprivate readonly repository: BitbucketPullRequestRepository,\n\t\tprivate readonly defaultBranch: string | undefined,\n\t\tprivate readonly isSessionCurrent: () => Promise<boolean>,\n\t\tprivate readonly ledger: BitbucketPullRequestWriteLedger,\n\t) {\n\t\tthis.repoUrl = `${apiUrl}/repositories/${seg(repository.workspaceId)}/${seg(repository.repositoryId)}`;\n\t}\n\n\tgetCreateCapability(): BitbucketPullRequestCreateCapabilityResult {\n\t\treturn {\n\t\t\tok: true,\n\t\t\taccountId: this.accountId,\n\t\t\trepository: this.repository,\n\t\t\t...(this.defaultBranch !== undefined && { defaultBranch: this.defaultBranch }),\n\t\t};\n\t}\n\n\tasync resolveTarget(number: number): Promise<BitbucketPullRequestWriteTargetResult> {\n\t\tif (!isPositiveInt32(number)) return { ok: false, reason: 'invalid-input' };\n\n\t\tconst read = await this.readPullRequest(number);\n\t\tconst open = read.pullRequest.state === 'open';\n\t\tconst key = getMergeKey(this.repository.repositoryId, number);\n\t\tif (!open) {\n\t\t\tthis.ledger.settle(key);\n\t\t}\n\n\t\tconst target = await this.getMergeTarget(read);\n\t\tconst { pullRequest } = target;\n\t\tconst unsettled = open ? this.ledger.get(key) : undefined;\n\t\tlet merge: BitbucketPullRequestMergeCapability = target.merge;\n\t\tif (unsettled != null) {\n\t\t\tmerge =\n\t\t\t\tmerge.kind === 'available'\n\t\t\t\t\t? { kind: 'unavailable', reason: 'outcome-unknown', unsettled: unsettled }\n\t\t\t\t\t: { ...merge, unsettled: unsettled };\n\t\t}\n\t\treturn {\n\t\t\tok: true,\n\t\t\taccountId: this.accountId,\n\t\t\tpullRequest: pullRequest,\n\t\t\tcapabilities: { edit: open, decline: open, reopen: false, merge: merge },\n\t\t};\n\t}\n\n\tasync write(options: BitbucketPullRequestWriteOptions): Promise<BitbucketPullRequestWriteResult> {\n\t\tif (options.action === 'create') {\n\t\t\tconst key = getCreateKey(this.repository.repositoryId, options.sourceBranch);\n\t\t\treturn this.ledger.run(key, () => this.create(options, key));\n\t\t}\n\t\tif (options.action === 'merge') {\n\t\t\tconst key = getMergeKey(this.repository.repositoryId, options.number);\n\t\t\treturn this.ledger.run(key, () => this.merge(options, key));\n\t\t}\n\n\t\tconst current = await this.readPullRequest(options.number);\n\t\tswitch (options.action) {\n\t\t\tcase 'edit':\n\t\t\t\tif (current.pullRequest.state !== 'open') return { ok: false, reason: 'conflict' };\n\n\t\t\t\treturn this.send(options, 'PUT', this.pullRequestUrl(options.number), {\n\t\t\t\t\ttitle: options.title,\n\t\t\t\t\tdescription: options.description,\n\t\t\t\t});\n\t\t\tcase 'decline':\n\t\t\t\tif (current.pullRequest.state !== 'open') return { ok: false, reason: 'conflict' };\n\n\t\t\t\treturn this.send(options, 'POST', `${this.pullRequestUrl(options.number)}/decline`);\n\t\t}\n\t}\n\n\tprivate async create(options: CreateOptions, key: string): Promise<BitbucketPullRequestWriteResult> {\n\t\tconst [source, target] = await Promise.all([\n\t\t\tthis.readBranch(options.sourceBranch),\n\t\t\tthis.readBranch(options.targetBranch),\n\t\t]);\n\t\tif (source == null || target == null) return { ok: false, reason: 'not-found' };\n\n\t\tconst preflight = await this.readCreateEvidence(key, options.sourceBranch);\n\t\tif (preflight.open.length) return { ok: false, reason: 'conflict' };\n\t\tif (preflight.unsettled != null) {\n\t\t\treturn { ok: false, reason: 'outcome-unknown', unsettled: preflight.unsettled };\n\t\t}\n\n\t\tconst { serverTime } = preflight;\n\t\tconst dispatchedAt = Date.now();\n\t\tlet pullRequestNumber: number | undefined;\n\t\tconst result = await this.send(\n\t\t\toptions,\n\t\t\t'POST',\n\t\t\t`${this.repoUrl}/pullrequests`,\n\t\t\t{\n\t\t\t\ttitle: options.title,\n\t\t\t\tdescription: options.description,\n\t\t\t\tsource: { branch: { name: options.sourceBranch } },\n\t\t\t\tdestination: { branch: { name: options.targetBranch } },\n\t\t\t},\n\t\t\t{\n\t\t\t\tcreatedNotBefore: serverTime,\n\t\t\t\tonReceipt: pullRequest => {\n\t\t\t\t\tif (!pullRequest.isCrossRepository && pullRequest.sourceBranch === options.sourceBranch) {\n\t\t\t\t\t\tpullRequestNumber = pullRequest.number;\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\t\treturn this.recordUnsettled(key, result, {\n\t\t\tattemptId: uuid(),\n\t\t\taccountId: this.accountId,\n\t\t\tdispatchedAt: dispatchedAt,\n\t\t\taction: 'create',\n\t\t\tsourceBranch: options.sourceBranch,\n\t\t\ttargetBranch: options.targetBranch,\n\t\t\t...(pullRequestNumber !== undefined && { pullRequestNumber: pullRequestNumber }),\n\t\t});\n\t}\n\n\tprivate async readCreateEvidence(\n\t\tkey: string,\n\t\tbranch: string,\n\t): Promise<{\n\t\topen: number[];\n\t\tserverTime: number | undefined;\n\t\tlanded?: number;\n\t\tclosed?: BitbucketWrittenPullRequest;\n\t\tunsettled?: BitbucketUnsettledPullRequestWrite;\n\t}> {\n\t\tconst entry = this.ledger.get(key);\n\t\tconst receipt = entry?.action === 'create' ? entry.pullRequestNumber : undefined;\n\t\t// KEEP: Bitbucket updates an open pull request from the same source branch instead of creating one.\n\t\tconst open: number[] = [];\n\t\tconst serverTime = await this.scanPullRequests(this.getOpenPullRequestsFromQuery(branch), pr => {\n\t\t\tif (!sameIdentifier(pr?.source?.repository?.uuid, this.repository.repositoryId)) return false;\n\t\t\tif (pr.state === 'MERGED' || pr.state === 'DECLINED' || pr.state === 'SUPERSEDED') return false;\n\n\t\t\topen.push(isPositiveInt32(pr.id) ? pr.id : Number.NaN);\n\t\t\treturn receipt !== undefined ? pr.id === receipt : open.length > 1;\n\t\t});\n\t\tconst landed = receipt !== undefined && open.includes(receipt) ? receipt : undefined;\n\t\tconst closed = !open.length && receipt !== undefined ? await this.readClosed(receipt) : undefined;\n\t\tif (entry == null || landed !== undefined || closed != null) {\n\t\t\tthis.ledger.settle(key);\n\t\t\treturn { open: open, serverTime: serverTime, landed: landed, closed: closed };\n\t\t}\n\n\t\treturn { open: open, serverTime: serverTime, unsettled: entry };\n\t}\n\n\t// KEEP: another account may lack pull request read access, so it learns nothing about the attempt.\n\tprivate refuseRelease(\n\t\treason: 'conflict' | 'invalid-input',\n\t\theld: BitbucketUnsettledPullRequestWrite,\n\t): BitbucketPullRequestWriteReleaseResult {\n\t\treturn sameIdentifier(held.accountId, this.accountId)\n\t\t\t? { ok: false, reason: reason, unsettled: held }\n\t\t\t: { ok: false, reason: reason };\n\t}\n\n\tprivate async readShownPullRequest(\n\t\tnumber: number | undefined,\n\t\tsourceBranch: string,\n\t\ttargetBranch: string | undefined,\n\t): Promise<BitbucketWrittenPullRequest | undefined> {\n\t\tif (number === undefined) return undefined;\n\n\t\t// KEEP: the decision is made; a failed read of the pull request to show only leaves it out.\n\t\tconst pullRequest = await this.readPullRequest(number).then(\n\t\t\tread => read.pullRequest,\n\t\t\t() => undefined,\n\t\t);\n\t\treturn pullRequest?.state === 'open' && isAttemptPullRequest(pullRequest, sourceBranch, targetBranch)\n\t\t\t? pullRequest\n\t\t\t: undefined;\n\t}\n\n\tprivate async readClosed(number: number): Promise<BitbucketWrittenPullRequest | undefined> {\n\t\tconst pullRequest = await this.readPullRequest(number).then(\n\t\t\tread => read.pullRequest,\n\t\t\t(ex: unknown) => {\n\t\t\t\tif (toBitbucketPullRequestWriteFailure(ex).reason === 'not-found') return undefined;\n\n\t\t\t\tthrow ex;\n\t\t\t},\n\t\t);\n\t\treturn pullRequest != null && pullRequest.state !== 'open' ? pullRequest : undefined;\n\t}\n\n\tprivate recordUnsettled(\n\t\tkey: string,\n\t\tresult: SentResult,\n\t\twrite: BitbucketUnsettledPullRequestWrite,\n\t): BitbucketPullRequestWriteResult {\n\t\tif (result.ok ? result.status !== 'pending' : result.reason !== 'outcome-unknown') {\n\t\t\treturn result as SettledResult;\n\t\t}\n\n\t\tthis.ledger.record(key, write);\n\t\tconst unsettled = this.ledger.get(key)!;\n\t\treturn result.ok ? { ...result, status: 'pending', unsettled: unsettled } : { ...result, unsettled: unsettled };\n\t}\n\n\tprivate async merge(options: MergeOptions, key: string): Promise<BitbucketPullRequestWriteResult> {\n\t\tconst current = await this.readPullRequest(options.number);\n\t\tconst held = this.ledger.get(key);\n\t\tif (held != null) {\n\t\t\tif (current.pullRequest.state === 'open') return { ok: false, reason: 'outcome-unknown', unsettled: held };\n\n\t\t\tthis.ledger.settle(key);\n\t\t}\n\n\t\tconst failure = getMergeStateFailure(current.pullRequest) ?? getMergeRefFailure(options, current);\n\t\tif (failure != null) return { ok: false, reason: failure };\n\n\t\tconst checks = await this.readMergeabilityChecks(options.number);\n\t\tconst [latest, source, target] = await Promise.all([\n\t\t\tthis.readPullRequest(options.number),\n\t\t\tthis.readBranch(options.expectedSourceBranch),\n\t\t\tthis.readBranch(options.expectedTargetBranch),\n\t\t]);\n\t\tconst latestFailure = getMergeStateFailure(latest.pullRequest) ?? getMergeRefFailure(options, latest);\n\t\tif (latestFailure != null) return { ok: false, reason: latestFailure };\n\t\tif (!sameIdentifier(source?.sha, options.expectedSourceSha)) return { ok: false, reason: 'source-changed' };\n\t\tif (target == null || !sameIdentifier(target.sha, options.expectedTargetSha)) {\n\t\t\treturn { ok: false, reason: 'target-changed' };\n\t\t}\n\t\tif (!getAllowedStrategies(target, checks).includes(options.strategy)) {\n\t\t\treturn { ok: false, reason: 'policy-blocked' };\n\t\t}\n\n\t\tconst blocked = getBlockingCheckFailure(checks);\n\t\tif (blocked != null) return { ok: false, reason: blocked };\n\n\t\tconst dispatchedAt = Date.now();\n\t\tconst result = await this.send(\n\t\t\toptions,\n\t\t\t'POST',\n\t\t\t`${this.pullRequestUrl(options.number)}/merge?async=false`,\n\t\t\t{ type: 'pullrequest', merge_strategy: options.strategy },\n\t\t\t{ pending: latest.pullRequest },\n\t\t);\n\t\tconst mergeTaskId = result.ok && result.status === 'pending' ? result.mergeTaskId : undefined;\n\t\treturn this.recordUnsettled(key, result, {\n\t\t\tattemptId: uuid(),\n\t\t\taccountId: this.accountId,\n\t\t\tdispatchedAt: dispatchedAt,\n\t\t\taction: 'merge',\n\t\t\tnumber: options.number,\n\t\t\t...(mergeTaskId !== undefined && { mergeTaskId: mergeTaskId }),\n\t\t});\n\t}\n\n\trelease(options: BitbucketPullRequestWriteReleaseOptions): Promise<BitbucketPullRequestWriteReleaseResult> {\n\t\tif (options.action === 'create') {\n\t\t\tconst key = getCreateKey(this.repository.repositoryId, options.sourceBranch);\n\t\t\treturn this.ledger.run(key, async () => {\n\t\t\t\tconst held = this.ledger.get(key);\n\t\t\t\t// KEEP: an ok release must mean Core holds no attempt here, or a host could drop its own durable barrier.\n\t\t\t\tif (held != null && held.attemptId !== options.attemptId) {\n\t\t\t\t\treturn this.refuseRelease('conflict', held);\n\t\t\t\t}\n\n\t\t\t\tconst matches = held != null;\n\t\t\t\tconst target = held?.action === 'create' ? held.targetBranch : undefined;\n\t\t\t\tconst evidence = await this.readCreateEvidence(key, options.sourceBranch);\n\t\t\t\tconst only =\n\t\t\t\t\tevidence.open.length === 1 && isPositiveInt32(evidence.open[0]) ? evidence.open[0] : undefined;\n\t\t\t\tconst shown = evidence.landed ?? only;\n\t\t\t\t// KEEP: only the receipt's own PR is evidence; another open PR keeps the attempt, as it can still land once that PR closes.\n\t\t\t\tif (evidence.open.length && evidence.landed === undefined) {\n\t\t\t\t\tconst pullRequest = await this.readShownPullRequest(shown, options.sourceBranch, target);\n\t\t\t\t\treturn { ok: false, reason: 'conflict', pullRequest: pullRequest };\n\t\t\t\t}\n\n\t\t\t\tconst settled = matches && evidence.unsettled == null;\n\t\t\t\tconst released = settled || this.ledger.release(key, options.attemptId);\n\t\t\t\tif (evidence.landed !== undefined) {\n\t\t\t\t\tconst pullRequest = await this.readShownPullRequest(shown, options.sourceBranch, target);\n\t\t\t\t\treturn { ok: true, released: released, observed: 'pull-request-open', pullRequest: pullRequest };\n\t\t\t\t}\n\t\t\t\tif (evidence.closed != null && matches) {\n\t\t\t\t\tconst pullRequest = isAttemptPullRequest(evidence.closed, options.sourceBranch, target)\n\t\t\t\t\t\t? evidence.closed\n\t\t\t\t\t\t: undefined;\n\t\t\t\t\treturn { ok: true, released: released, observed: 'pull-request-closed', pullRequest: pullRequest };\n\t\t\t\t}\n\n\t\t\t\treturn { ok: true, released: released, observed: 'no-open-pull-request' };\n\t\t\t});\n\t\t}\n\n\t\tconst key = getMergeKey(this.repository.repositoryId, options.number);\n\t\treturn this.ledger.run(key, async () => {\n\t\t\tconst held = this.ledger.get(key);\n\t\t\t// KEEP: the held write's own task id is authoritative; the host's only stands in when Core holds none.\n\t\t\tconst heldTaskId = held?.action === 'merge' ? held.mergeTaskId : undefined;\n\t\t\tif (\n\t\t\t\theld != null &&\n\t\t\t\theldTaskId != null &&\n\t\t\t\toptions.mergeTaskId != null &&\n\t\t\t\toptions.mergeTaskId !== heldTaskId\n\t\t\t) {\n\t\t\t\treturn this.refuseRelease('invalid-input', held);\n\t\t\t}\n\t\t\tif (held != null && held.attemptId !== options.attemptId) {\n\t\t\t\treturn this.refuseRelease('conflict', held);\n\t\t\t}\n\n\t\t\tconst matches = held != null;\n\n\t\t\tconst { pullRequest } = await this.readPullRequest(options.number);\n\t\t\tif (pullRequest.state !== 'open') {\n\t\t\t\tthis.ledger.settle(key);\n\t\t\t\treturn { ok: true, released: matches, observed: 'pull-request-closed', pullRequest: pullRequest };\n\t\t\t}\n\t\t\tif (pullRequest.queued) return { ok: false, reason: 'conflict' };\n\n\t\t\tconst mergeTaskId = heldTaskId ?? options.mergeTaskId;\n\t\t\tif (mergeTaskId != null) {\n\t\t\t\tconst task = await this.readMergeTaskForRelease(options.number, mergeTaskId);\n\t\t\t\tif (task !== 'expired') return { ok: false, reason: task };\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tok: true,\n\t\t\t\treleased: this.ledger.release(key, options.attemptId),\n\t\t\t\tobserved: 'pull-request-open',\n\t\t\t\tpullRequest: pullRequest,\n\t\t\t};\n\t\t});\n\t}\n\n\t// KEEP: Bitbucket answers a bare PENDING for an unknown or expired task too, so only that one may release.\n\tprivate async readMergeTaskForRelease(\n\t\tnumber: number,\n\t\tmergeTaskId: string,\n\t): Promise<'expired' | 'conflict' | 'outcome-unknown'> {\n\t\tconst key = getMergeKey(this.repository.repositoryId, number);\n\t\tlet task: RawMergeTask | undefined;\n\t\ttry {\n\t\t\t({ body: task } = await this.request<RawMergeTask>({\n\t\t\t\turl: `${this.pullRequestUrl(number)}/merge/task-status/${seg(mergeTaskId)}`,\n\t\t\t\theaders: this.headers,\n\t\t\t\tredirect: 'error',\n\t\t\t}));\n\t\t} catch (ex) {\n\t\t\tconst refusal = getBitbucketMergeRefusal(ex);\n\t\t\tif (refusal == null) throw ex;\n\t\t\tif (refusal === 'invalid-input') throw new BitbucketPullRequestWriteError(refusal);\n\t\t\tif (refusal !== 'conflict' && refusal !== 'policy-blocked') return 'outcome-unknown';\n\n\t\t\tthis.ledger.settleMergeTask(key, mergeTaskId);\n\t\t\treturn 'conflict';\n\t\t}\n\n\t\tif (task == null || typeof task !== 'object') return 'outcome-unknown';\n\t\tif (task.task_status === 'SUCCESS') {\n\t\t\tthis.ledger.settleMergeTask(key, mergeTaskId);\n\t\t\treturn 'conflict';\n\t\t}\n\t\tif (task.task_status !== 'PENDING') return 'outcome-unknown';\n\t\tif (task.queued_pullrequest == null) return 'expired';\n\n\t\treturn this.isQueuedPullRequest(task.queued_pullrequest, number) ? 'conflict' : 'outcome-unknown';\n\t}\n\n\tasync readMergeStatus(\n\t\toptions: BitbucketPullRequestMergeStatusOptions,\n\t): Promise<BitbucketPullRequestMergeStatusResult> {\n\t\tconst key = getMergeKey(this.repository.repositoryId, options.number);\n\t\tlet task: RawMergeTask | undefined;\n\t\tlet refusal: FailureReason | undefined;\n\t\ttry {\n\t\t\t({ body: task } = await this.request<RawMergeTask>({\n\t\t\t\turl: `${this.pullRequestUrl(options.number)}/merge/task-status/${seg(options.mergeTaskId)}`,\n\t\t\t\theaders: this.headers,\n\t\t\t\tredirect: 'error',\n\t\t\t}));\n\t\t} catch (ex) {\n\t\t\trefusal = getBitbucketMergeRefusal(ex);\n\t\t\tif (refusal == null) throw ex;\n\t\t}\n\t\tif (refusal === 'invalid-input') return { ok: false, reason: refusal };\n\n\t\tif (refusal === 'conflict' || refusal === 'policy-blocked') {\n\t\t\tthis.ledger.settleMergeTask(key, options.mergeTaskId);\n\t\t\tconst snapshot = await this.readPullRequest(options.number).catch(() => undefined);\n\t\t\tif (snapshot != null && snapshot.pullRequest.state !== 'open') {\n\t\t\t\tthis.ledger.settle(key);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tok: true,\n\t\t\t\tstatus: 'failed',\n\t\t\t\treason: refusal,\n\t\t\t\t...(snapshot != null && { pullRequest: snapshot.pullRequest }),\n\t\t\t};\n\t\t}\n\t\tif (refusal != null) return { ok: false, reason: refusal };\n\n\t\tif (task?.task_status === 'SUCCESS') {\n\t\t\tconst merged = this.getApprovedMergeResult(task.merge_result, options);\n\t\t\tif (merged != null) {\n\t\t\t\tthis.ledger.settleMergeTask(key, options.mergeTaskId);\n\t\t\t\treturn { ok: true, status: 'merged', pullRequest: merged };\n\t\t\t}\n\t\t}\n\n\t\tconst { pullRequest } = await this.readPullRequest(options.number);\n\t\tif (pullRequest.state !== 'open') {\n\t\t\tthis.ledger.settle(key);\n\t\t}\n\n\t\t// SEE: unknown or expired task ids answer PENDING; only the task's own queued_pullrequest proves this one.\n\t\t// https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pullrequests/#api-repositories-workspace-repo-slug-pullrequests-pull-request-id-merge-task-status-task-id-get\n\t\treturn task?.task_status === 'PENDING' && this.isQueuedPullRequest(task.queued_pullrequest, options.number)\n\t\t\t? { ok: true, status: 'pending', pullRequest: pullRequest }\n\t\t\t: { ok: false, reason: 'outcome-unknown' };\n\t}\n\n\tprivate getApprovedMergeResult(\n\t\traw: RawPullRequest | undefined,\n\t\toptions: BitbucketPullRequestMergeStatusOptions,\n\t): BitbucketWrittenPullRequest | undefined {\n\t\tif (raw == null) return undefined;\n\n\t\tlet read: PullRequestRead;\n\t\ttry {\n\t\t\tread = this.toPullRequestRead(raw, options.number);\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst { pullRequest } = read;\n\t\treturn pullRequest.state === 'merged' &&\n\t\t\tpullRequest.sourceBranch === options.expectedSourceBranch &&\n\t\t\tpullRequest.targetBranch === options.expectedTargetBranch &&\n\t\t\tisApprovedSource(options.expectedSourceSha, read)\n\t\t\t? pullRequest\n\t\t\t: undefined;\n\t}\n\n\tprivate isQueuedPullRequest(queued: RawMergeTask['queued_pullrequest'], number: number): boolean {\n\t\tconst pullRequest = queued?.pullrequest;\n\t\tconst repositoryId = pullRequest?.destination?.repository?.uuid;\n\t\treturn (\n\t\t\tqueued?.type === 'queued_pullrequest' &&\n\t\t\tpullRequest?.id === number &&\n\t\t\t(repositoryId == null || sameIdentifier(repositoryId, this.repository.repositoryId))\n\t\t);\n\t}\n\n\tprivate async getMergeTarget(\n\t\tread: PullRequestRead,\n\t): Promise<{ merge: BitbucketPullRequestMergeCapability; pullRequest: BitbucketWrittenPullRequest }> {\n\t\tconst { pullRequest } = read;\n\t\tconst stateFailure = getMergeStateFailure(pullRequest);\n\t\tif (stateFailure != null) {\n\t\t\treturn { merge: { kind: 'unavailable', reason: stateFailure }, pullRequest: pullRequest };\n\t\t}\n\n\t\ttry {\n\t\t\tconst [source, target] = await Promise.all([\n\t\t\t\tthis.readBranch(pullRequest.sourceBranch),\n\t\t\t\tthis.readBranch(pullRequest.targetBranch),\n\t\t\t]);\n\t\t\tconst snapshot = {\n\t\t\t\t...pullRequest,\n\t\t\t\t...(source != null && { sourceSha: source.sha }),\n\t\t\t\t...(target != null && { targetSha: target.sha }),\n\t\t\t};\n\t\t\tif (source == null || read.sourceHash == null || !source.sha.toLowerCase().startsWith(read.sourceHash)) {\n\t\t\t\treturn { merge: { kind: 'unavailable', reason: 'source-changed' }, pullRequest: snapshot };\n\t\t\t}\n\t\t\tif (target == null) {\n\t\t\t\treturn { merge: { kind: 'unavailable', reason: 'target-changed' }, pullRequest: snapshot };\n\t\t\t}\n\n\t\t\tconst checks = await this.readMergeabilityChecks(pullRequest.number);\n\t\t\tconst strategies = getAllowedStrategies(target, checks);\n\t\t\tconst blocked = strategies.length ? getBlockingCheckFailure(checks) : 'policy-blocked';\n\t\t\tif (blocked != null) return { merge: { kind: 'unavailable', reason: blocked }, pullRequest: snapshot };\n\n\t\t\tconst defaultStrategy = strategies.find(strategy => strategy === target.defaultStrategy);\n\t\t\treturn {\n\t\t\t\tmerge: {\n\t\t\t\t\tkind: 'available',\n\t\t\t\t\tstrategies: strategies,\n\t\t\t\t\t...(defaultStrategy !== undefined && { defaultStrategy: defaultStrategy }),\n\t\t\t\t},\n\t\t\t\tpullRequest: snapshot,\n\t\t\t};\n\t\t} catch (ex) {\n\t\t\treturn {\n\t\t\t\tmerge: { kind: 'unavailable', reason: toBitbucketPullRequestWriteFailure(ex).reason },\n\t\t\t\tpullRequest: pullRequest,\n\t\t\t};\n\t\t}\n\t}\n\n\tprivate pullRequestUrl(number: number): string {\n\t\treturn `${this.repoUrl}/pullrequests/${number}`;\n\t}\n\n\tprivate async readPullRequest(number: number): Promise<PullRequestRead> {\n\t\tconst { body: raw } = await this.request<RawPullRequest>({\n\t\t\turl: this.pullRequestUrl(number),\n\t\t\theaders: this.headers,\n\t\t\tredirect: 'error',\n\t\t});\n\t\treturn this.toPullRequestRead(raw, number);\n\t}\n\n\tprivate toPullRequestRead(raw: RawPullRequest, number?: number): PullRequestRead {\n\t\tif (!sameIdentifier(raw?.destination?.repository?.uuid, this.repository.repositoryId)) {\n\t\t\tthrow new BitbucketPullRequestWriteError('not-found');\n\t\t}\n\n\t\tconst { id, title, description, source, destination } = raw;\n\t\tconst state = typeof raw.state === 'string' ? raw.state.toLowerCase() : undefined;\n\t\tconst sourceBranch = source?.branch?.name;\n\t\tconst targetBranch = destination?.branch?.name;\n\t\tconst sourceHash = source?.commit?.hash;\n\t\tif (\n\t\t\t!isPositiveInt32(id) ||\n\t\t\t(number !== undefined && id !== number) ||\n\t\t\ttypeof title !== 'string' ||\n\t\t\t(description != null && typeof description !== 'string') ||\n\t\t\t(state !== 'open' && state !== 'merged' && state !== 'declined' && state !== 'superseded') ||\n\t\t\ttypeof sourceBranch !== 'string' ||\n\t\t\tsourceBranch.length === 0 ||\n\t\t\ttypeof targetBranch !== 'string' ||\n\t\t\ttargetBranch.length === 0\n\t\t) {\n\t\t\tthrow new BitbucketPullRequestWriteError('unknown');\n\t\t}\n\n\t\tconst sourceRepository = source?.repository?.uuid;\n\t\treturn {\n\t\t\tsourceHash:\n\t\t\t\ttypeof sourceHash === 'string' && /^[\\da-f]{7,40}$/i.test(sourceHash)\n\t\t\t\t\t? sourceHash.toLowerCase()\n\t\t\t\t\t: undefined,\n\t\t\tpullRequest: {\n\t\t\t\trepository: this.repository,\n\t\t\t\tnumber: id,\n\t\t\t\turl: `${webUrl}/${seg(this.repository.workspaceSlug)}/${seg(this.repository.repositorySlug)}/pull-requests/${id}`,\n\t\t\t\ttitle: title,\n\t\t\t\tdescription: description ?? '',\n\t\t\t\tstate: state,\n\t\t\t\tdraft: raw.draft === true,\n\t\t\t\tqueued: raw.queued === true,\n\t\t\t\tisCrossRepository: !sameIdentifier(sourceRepository, this.repository.repositoryId),\n\t\t\t\tsourceBranch: sourceBranch,\n\t\t\t\ttargetBranch: targetBranch,\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate async readBranch(name: string): Promise<TargetBranch | undefined> {\n\t\tlet branch: RawBranch;\n\t\ttry {\n\t\t\t({ body: branch } = await this.request<RawBranch>({\n\t\t\t\turl: `${this.repoUrl}/refs/branches/${seg(name)}`,\n\t\t\t\theaders: this.headers,\n\t\t\t\tredirect: 'error',\n\t\t\t}));\n\t\t} catch (ex) {\n\t\t\tif (toBitbucketPullRequestWriteFailure(ex).reason === 'not-found') return undefined;\n\n\t\t\tthrow ex;\n\t\t}\n\n\t\tconst sha = branch?.target?.hash;\n\t\tif (branch?.name !== name || !isCommitSha(sha)) throw new BitbucketPullRequestWriteError('unknown');\n\n\t\treturn {\n\t\t\tsha: sha,\n\t\t\tstrategies: toStrategies(branch.merge_strategies),\n\t\t\tdefaultStrategy:\n\t\t\t\ttypeof branch.default_merge_strategy === 'string' ? branch.default_merge_strategy : undefined,\n\t\t};\n\t}\n\n\tprivate async readMergeabilityChecks(number: number): Promise<RawMergeabilityCheck[]> {\n\t\tconst { body } = await this.request<{ values?: unknown }>({\n\t\t\turl: `${this.pullRequestUrl(number)}/mergeability/checks`,\n\t\t\theaders: this.headers,\n\t\t\tredirect: 'error',\n\t\t});\n\t\tconst values = body?.values;\n\t\tif (!Array.isArray(values) || values.some(check => check == null || typeof check !== 'object')) {\n\t\t\tthrow new BitbucketPullRequestWriteError('unknown');\n\t\t}\n\n\t\treturn values as RawMergeabilityCheck[];\n\t}\n\n\tprivate getOpenPullRequestsFromQuery(branch: string): URLSearchParams {\n\t\t// SEE: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pullrequests/#api-repositories-workspace-repo-slug-pullrequests-get\n\t\tconst escapedBranch = branch.replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"');\n\t\t// SEE: live Bitbucket Cloud ignores the `state` parameter once `q` is set, so the state goes in `q`.\n\t\treturn new URLSearchParams({\n\t\t\tq: `source.branch.name=\"${escapedBranch}\" AND state=\"OPEN\"`,\n\t\t\tfields: 'next,values.id,values.state,values.source.repository.uuid',\n\t\t\tpagelen: '50',\n\t\t});\n\t}\n\n\tprivate async scanPullRequests(\n\t\tquery: URLSearchParams,\n\t\tvisit: (pr: RawPullRequest) => boolean,\n\t): Promise<number | undefined> {\n\t\tlet url = `${this.repoUrl}/pullrequests?${query.toString()}`;\n\t\tconst seen = new Set<string>();\n\t\tlet serverTime: number | undefined;\n\t\twhile (true) {\n\t\t\tseen.add(url);\n\t\t\tconst response = await this.request<{ values?: unknown; next?: unknown }>({\n\t\t\t\turl: url,\n\t\t\t\theaders: this.headers,\n\t\t\t\tredirect: 'error',\n\t\t\t});\n\t\t\tserverTime ??= getServerTime(response.headers);\n\t\t\tconst { values, next } = response.body ?? {};\n\t\t\tif (!Array.isArray(values)) throw new BitbucketPullRequestWriteError('unknown');\n\t\t\tif ((values as RawPullRequest[]).some(pr => visit(pr))) return serverTime;\n\t\t\tif (next == null) return serverTime;\n\t\t\tif (typeof next !== 'string' || !next.startsWith(`${apiUrl}/`) || seen.has(next)) {\n\t\t\t\tthrow new BitbucketPullRequestWriteError('unknown');\n\t\t\t}\n\n\t\t\turl = next;\n\t\t}\n\t}\n\n\tprivate getMergeTaskId(number: number, headers: Record<string, unknown>): string | undefined {\n\t\tconst location = getResponseHeader(headers, 'location');\n\t\tif (typeof location !== 'string' || !URL.canParse(location, apiUrl)) return undefined;\n\n\t\tconst url = new URL(location, apiUrl);\n\t\tconst match = /^\\/2\\.0\\/repositories\\/([^/]+)\\/([^/]+)\\/pullrequests\\/(\\d+)\\/merge\\/task-status\\/([^/]+)$/.exec(\n\t\t\turl.pathname,\n\t\t);\n\t\tif (url.origin !== new URL(apiUrl).origin || url.search !== '' || match == null) return undefined;\n\n\t\tconst [, workspace, repository, id, taskId] = match.map(part => safeDecode(part));\n\t\tconst { workspaceId, workspaceSlug, repositoryId, repositorySlug } = this.repository;\n\t\treturn Number(id) === number &&\n\t\t\t(sameIdentifier(workspace, workspaceId) || sameIdentifier(workspace, workspaceSlug)) &&\n\t\t\t(sameIdentifier(repository, repositoryId) || sameIdentifier(repository, repositorySlug)) &&\n\t\t\tisBitbucketMergeTaskId(taskId)\n\t\t\t? taskId\n\t\t\t: undefined;\n\t}\n\n\tprivate send(\n\t\toptions: BitbucketPullRequestWriteOptions,\n\t\tmethod: 'POST' | 'PUT',\n\t\turl: string,\n\t\tbody?: object,\n\t\tcontext?: SendContext & { pending?: undefined },\n\t): Promise<SettledResult>;\n\tprivate send(\n\t\toptions: BitbucketPullRequestWriteOptions,\n\t\tmethod: 'POST' | 'PUT',\n\t\turl: string,\n\t\tbody: object,\n\t\tcontext: SendContext & { pending: BitbucketWrittenPullRequest },\n\t): Promise<SentResult>;\n\tprivate async send(\n\t\toptions: BitbucketPullRequestWriteOptions,\n\t\tmethod: 'POST' | 'PUT',\n\t\turl: string,\n\t\tbody?: object,\n\t\tcontext?: SendContext & { pending?: BitbucketWrittenPullRequest },\n\t): Promise<SentResult> {\n\t\tconst pending = context?.pending;\n\t\tif (!(await this.isSessionCurrent())) return { ok: false, reason: 'no-connection' };\n\n\t\tlet response: { status: number; body: RawPullRequest; headers: Record<string, unknown> };\n\t\ttry {\n\t\t\tresponse = await this.request<RawPullRequest>({\n\t\t\t\turl: url,\n\t\t\t\tmethod: method,\n\t\t\t\theaders: body == null ? this.headers : { ...this.headers, 'Content-Type': 'application/json' },\n\t\t\t\tbody: body == null ? undefined : JSON.stringify(body),\n\t\t\t\tredirect: 'error',\n\t\t\t});\n\t\t} catch (ex) {\n\t\t\treturn toBitbucketPullRequestWriteFailure(ex, { action: options.action });\n\t\t}\n\n\t\tif (options.action === 'merge' && response.status === 202 && pending != null) {\n\t\t\tconst mergeTaskId = this.getMergeTaskId(options.number, response.headers);\n\t\t\treturn {\n\t\t\t\tok: true,\n\t\t\t\tstatus: 'pending',\n\t\t\t\tpullRequest: pending,\n\t\t\t\t...(mergeTaskId !== undefined && { mergeTaskId: mergeTaskId }),\n\t\t\t};\n\t\t}\n\n\t\tlet read: PullRequestRead;\n\t\ttry {\n\t\t\tread = this.toPullRequestRead(response.body, options.action === 'create' ? undefined : options.number);\n\t\t} catch {\n\t\t\treturn { ok: false, reason: 'outcome-unknown' };\n\t\t}\n\t\tcontext?.onReceipt?.(read.pullRequest);\n\n\t\tconst status = getReceiptStatus(options, response, read, this.accountId, context?.createdNotBefore);\n\t\treturn status === undefined\n\t\t\t? { ok: false, reason: 'outcome-unknown' }\n\t\t\t: { ok: true, status: status, pullRequest: read.pullRequest };\n\t}\n}\n\nfunction getAllowedStrategies(\n\ttarget: TargetBranch,\n\tchecks: RawMergeabilityCheck[],\n): BitbucketPullRequestMergeStrategy[] {\n\tconst queued = checks.some(check => check.type === 'merge_queue_check' && check.required === true);\n\treturn queued ? target.strategies.filter(strategy => queueStrategies.includes(strategy)) : target.strategies;\n}\n\nfunction safeDecode(value: string): string | undefined {\n\ttry {\n\t\treturn decodeURIComponent(value);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction isApprovedSource(expectedSourceSha: string, read: PullRequestRead): boolean {\n\treturn read.sourceHash != null && expectedSourceSha.toLowerCase().startsWith(read.sourceHash);\n}\n\nfunction sameText(actual: string, expected: string): boolean {\n\treturn actual.replaceAll('\\r\\n', '\\n').trim() === expected.replaceAll('\\r\\n', '\\n').trim();\n}\n\nfunction getServerTime(headers: Record<string, unknown> | undefined): number | undefined {\n\tconst date = getResponseHeader(headers, 'date');\n\tif (typeof date !== 'string') return undefined;\n\n\tconst time = Date.parse(date);\n\treturn Number.isNaN(time) ? undefined : Math.floor(time / 1000) * 1000;\n}\n\nfunction isCreatedSince(raw: RawPullRequest, accountId: string, notBefore: number | undefined): boolean {\n\tif (notBefore == null || !sameIdentifier(raw.author?.uuid, accountId)) return false;\n\tif (typeof raw.created_on !== 'string') return false;\n\n\tconst createdOn = Date.parse(raw.created_on);\n\treturn !Number.isNaN(createdOn) && createdOn >= notBefore;\n}\n\nfunction getReceiptStatus(\n\toptions: BitbucketPullRequestWriteOptions,\n\tresponse: { status: number; body: RawPullRequest },\n\tread: PullRequestRead,\n\taccountId: string,\n\tcreatedNotBefore: number | undefined,\n): WriteStatus | undefined {\n\tconst { pullRequest } = read;\n\tswitch (options.action) {\n\t\tcase 'create':\n\t\t\t// KEEP: Bitbucket upserts; an open PR from the branch made in the preflight's second or after it can still pass here.\n\t\t\treturn response.status === 201 &&\n\t\t\t\tisCreatedSince(response.body, accountId, createdNotBefore) &&\n\t\t\t\tpullRequest.state === 'open' &&\n\t\t\t\t!pullRequest.isCrossRepository &&\n\t\t\t\tpullRequest.sourceBranch === options.sourceBranch &&\n\t\t\t\tpullRequest.targetBranch === options.targetBranch &&\n\t\t\t\tsameText(pullRequest.title, options.title) &&\n\t\t\t\t(options.description === undefined || sameText(pullRequest.description, options.description))\n\t\t\t\t? 'created'\n\t\t\t\t: undefined;\n\t\tcase 'edit':\n\t\t\treturn pullRequest.state === 'open' &&\n\t\t\t\t(options.title === undefined || sameText(pullRequest.title, options.title)) &&\n\t\t\t\t(options.description === undefined || sameText(pullRequest.description, options.description))\n\t\t\t\t? 'updated'\n\t\t\t\t: undefined;\n\t\tcase 'decline':\n\t\t\treturn pullRequest.state === 'declined' ? 'declined' : undefined;\n\t\tcase 'merge':\n\t\t\tif (\n\t\t\t\tpullRequest.sourceBranch !== options.expectedSourceBranch ||\n\t\t\t\tpullRequest.targetBranch !== options.expectedTargetBranch\n\t\t\t) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tif (pullRequest.state === 'merged') {\n\t\t\t\t// KEEP: Bitbucket has no compare-and-swap, so a source pushed after the last read may be what merged.\n\t\t\t\treturn isApprovedSource(options.expectedSourceSha, read) ? 'merged' : undefined;\n\t\t\t}\n\n\t\t\treturn pullRequest.state === 'open' && pullRequest.queued ? 'pending' : undefined;\n\t}\n}\n"],"mappings":";;;;;AAkCA,MAAM,SAAS;AACf,MAAM,SAAS;AACf,MAAM,kBAAuD;CAC5D;CACA;CACA;CACA;CACA;CACA;AACD;AAEA,MAAM,kBAAuD;CAAC;CAAgB;CAAU;AAAc;AACtG,MA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QAAQ,KAAK,OACxE,QAAQ,gBAAgB,KAAA,KAAa,SAAS,YAAY,aAAa,QAAQ,WAAW,KACzF,YACA,KAAA;EACJ,KAAK,WACJ,OAAO,YAAY,UAAU,aAAa,aAAa,KAAA;EACxD,KAAK;GACJ,IACC,YAAY,iBAAiB,QAAQ,wBACrC,YAAY,iBAAiB,QAAQ,sBAErC;GAED,IAAI,YAAY,UAAU,UAEzB,OAAO,iBAAiB,QAAQ,mBAAmB,IAAI,IAAI,WAAW,KAAA;GAGvE,OAAO,YAAY,UAAU,UAAU,YAAY,SAAS,YAAY,KAAA;CAC1E;AACD"}
@@ -0,0 +1,22 @@
1
+ import { BitbucketServerPullRequestVeto, BitbucketServerPullRequestWriteFailure } from "../models/bitbucketServerPullRequestWrites.js";
2
+ //#region ../plus/integrations/src/providers/bitbucketServerPullRequestWriteErrors.d.ts
3
+ type FailureReason = BitbucketServerPullRequestWriteFailure['reason'];
4
+ type Action = 'create' | 'edit' | 'decline' | 'reopen' | 'merge' | 'delete';
5
+ export type BitbucketServerErrorDetail = {
6
+ status: number | undefined;
7
+ exceptionName: string | undefined;
8
+ message: string;
9
+ vetoes: BitbucketServerPullRequestVeto[];
10
+ existingPullRequest: unknown;
11
+ authenticated: boolean;
12
+ retryAfter: boolean;
13
+ };
14
+ export declare class BitbucketServerPullRequestWriteError extends Error {
15
+ readonly reason: FailureReason;
16
+ constructor(reason: FailureReason);
17
+ }
18
+ export declare function toBitbucketServerPullRequestWriteFailure(ex: unknown, dispatched?: Action): BitbucketServerPullRequestWriteFailure;
19
+ export declare function getBitbucketServerErrorDetail(ex: unknown): BitbucketServerErrorDetail;
20
+ export declare function toVetoes(value: unknown): BitbucketServerPullRequestVeto[];
21
+ //#endregion
22
+ //# sourceMappingURL=bitbucketServerPullRequestWriteErrors.d.ts.map