@gitkraken/core-gitlens 0.57.0 → 0.59.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.
- package/CHANGELOG.md +20 -1
- package/dist/git/context.d.ts +1 -0
- package/dist/git/context.js.map +1 -1
- package/dist/git/features.d.ts +1 -1
- package/dist/git/features.js +1 -0
- package/dist/git/features.js.map +1 -1
- package/dist/git/models/graph.d.ts +2 -1
- package/dist/git/models/graph.js.map +1 -1
- package/dist/git/models/graphSession.d.ts +8 -0
- package/dist/git/models/graphSession.js.map +1 -1
- package/dist/git/parsers/diffParser.js +1 -1
- package/dist/git/utils/hiddenRefs.utils.d.ts +26 -0
- package/dist/git/utils/hiddenRefs.utils.js +89 -0
- package/dist/git/utils/hiddenRefs.utils.js.map +1 -0
- package/dist/git/utils/search.utils.d.ts +3 -1
- package/dist/git/utils/search.utils.js +3 -1
- package/dist/git/utils/search.utils.js.map +1 -1
- package/dist/git-cli/exec/git.js +2 -1
- package/dist/git-cli/exec/git.js.map +1 -1
- package/dist/git-cli/exec/locator.d.ts +2 -1
- package/dist/git-cli/exec/locator.js +11 -3
- package/dist/git-cli/exec/locator.js.map +1 -1
- package/dist/git-cli/parsers/blameParser.js +1 -1
- package/dist/git-cli/parsers/indexParser.js +1 -1
- package/dist/git-cli/parsers/statusParser.js +1 -1
- package/dist/git-cli/providers/branches.js +1 -1
- package/dist/git-cli/providers/commits.js +3 -2
- package/dist/git-cli/providers/commits.js.map +1 -1
- package/dist/git-cli/providers/graph.d.ts +11 -1
- package/dist/git-cli/providers/graph.js +156 -38
- package/dist/git-cli/providers/graph.js.map +1 -1
- package/dist/git-cli/providers/refs.js +1 -1
- package/dist/git-cli/providers/tags.js +1 -1
- package/dist/git-cli/service.js +1 -1
- package/dist/plus/integrations/authentication/configuredIntegrationService.d.ts +4 -0
- package/dist/plus/integrations/authentication/configuredIntegrationService.js +8 -2
- package/dist/plus/integrations/authentication/configuredIntegrationService.js.map +1 -1
- package/dist/plus/integrations/authentication/integrationAuthenticationService.d.ts +1 -1
- package/dist/plus/integrations/authentication/integrationAuthenticationService.js +2 -2
- package/dist/plus/integrations/authentication/integrationAuthenticationService.js.map +1 -1
- package/dist/plus/integrations/authentication/observedAuthenticationProvider.d.ts +2 -1
- package/dist/plus/integrations/authentication/observedAuthenticationProvider.js +16 -12
- package/dist/plus/integrations/authentication/observedAuthenticationProvider.js.map +1 -1
- package/dist/plus/integrations/index.d.ts +2 -1
- package/dist/plus/integrations/index.js.map +1 -1
- package/dist/plus/integrations/integrationService.d.ts +5 -0
- package/dist/plus/integrations/integrationService.js +89 -8
- package/dist/plus/integrations/integrationService.js.map +1 -1
- package/dist/plus/integrations/manager.d.ts +8 -0
- package/dist/plus/integrations/models/azurePullRequestWrites.d.ts +3 -1
- package/dist/plus/integrations/models/bitbucketServerPullRequestWrites.d.ts +142 -0
- package/dist/plus/integrations/models/bitbucketServerPullRequestWrites.js +0 -0
- package/dist/plus/integrations/models/integration.d.ts +7 -4
- package/dist/plus/integrations/models/integration.js +12 -11
- package/dist/plus/integrations/models/integration.js.map +1 -1
- package/dist/plus/integrations/models/issueTrackerWrites.d.ts +12 -3
- package/dist/plus/integrations/providers/azure/models.d.ts +1 -1
- package/dist/plus/integrations/providers/azure/models.js.map +1 -1
- package/dist/plus/integrations/providers/azurePullRequestWriteErrors.d.ts +6 -2
- package/dist/plus/integrations/providers/azurePullRequestWriteErrors.js +44 -10
- package/dist/plus/integrations/providers/azurePullRequestWriteErrors.js.map +1 -1
- package/dist/plus/integrations/providers/azurePullRequestWrites.d.ts +1 -0
- package/dist/plus/integrations/providers/azurePullRequestWrites.js +28 -13
- package/dist/plus/integrations/providers/azurePullRequestWrites.js.map +1 -1
- package/dist/plus/integrations/providers/bitbucket-server.d.ts +4 -1
- package/dist/plus/integrations/providers/bitbucket-server.js +23 -0
- package/dist/plus/integrations/providers/bitbucket-server.js.map +1 -1
- package/dist/plus/integrations/providers/bitbucketPullRequestWrites.js +2 -2
- package/dist/plus/integrations/providers/bitbucketPullRequestWrites.js.map +1 -1
- package/dist/plus/integrations/providers/bitbucketServerPullRequestWriteErrors.d.ts +22 -0
- package/dist/plus/integrations/providers/bitbucketServerPullRequestWriteErrors.js +94 -0
- package/dist/plus/integrations/providers/bitbucketServerPullRequestWriteErrors.js.map +1 -0
- package/dist/plus/integrations/providers/bitbucketServerPullRequestWrites.d.ts +51 -0
- package/dist/plus/integrations/providers/bitbucketServerPullRequestWrites.js +593 -0
- package/dist/plus/integrations/providers/bitbucketServerPullRequestWrites.js.map +1 -0
- package/dist/plus/integrations/providers/jira-server.d.ts +10 -0
- package/dist/plus/integrations/providers/jira-server.js +16 -1
- package/dist/plus/integrations/providers/jira-server.js.map +1 -1
- package/dist/plus/integrations/providers/jiraIssueWrites.d.ts +6 -0
- package/dist/plus/integrations/providers/jiraIssueWrites.js +60 -11
- package/dist/plus/integrations/providers/jiraIssueWrites.js.map +1 -1
- package/dist/plus/integrations/providers/providerApiClient.js +8 -3
- package/dist/plus/integrations/providers/providerApiClient.js.map +1 -1
- package/dist/plus/integrations/providers/providersApi.d.ts +13 -0
- package/dist/plus/integrations/providers/providersApi.js +58 -1
- package/dist/plus/integrations/providers/providersApi.js.map +1 -1
- package/dist/plus/integrations/providers/utils/writeInputs.d.ts +1 -0
- package/dist/plus/integrations/providers/utils/writeInputs.js +4 -1
- package/dist/plus/integrations/providers/utils/writeInputs.js.map +1 -1
- package/dist/plus/integrations/reads/currentAccount.d.ts +1 -1
- package/dist/plus/integrations/reads/currentAccount.js +1 -1
- package/dist/plus/integrations/reads/currentAccount.js.map +1 -1
- package/dist/plus/integrations/reads/issueTracker.js +4 -1
- package/dist/plus/integrations/reads/issueTracker.js.map +1 -1
- package/docs/integrations.md +121 -5
- package/docs/kepler-read-api-parity.md +2 -1
- package/package.json +1 -1
|
@@ -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,OAAuB;CACnC,OAAO,mBAAmB,KAAK;AAChC;AAEA,SAAS,qBACR,aACA,cACA,cACU;CACV,OACC,CAAC,YAAY,qBACb,YAAY,iBAAiB,iBAC5B,iBAAiB,KAAA,KAAa,Y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,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,MAAM,cAAc;AACpB,MAAM,cAAc;AACpB,MAAM,qBAAqB;AA6D3B,SAAS,gBAAgB,OAAiC;CACzD,OAAO,OAAO,UAAU,YAAY,YAAY,KAAK,KAAK;AAC3D;AA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,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
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { RequestRateLimitError } from "../../../git/errors.js";
|
|
2
|
+
import { getAuthenticatedUser, getResponseHeader, isRateLimitResponse } from "../errors.js";
|
|
3
|
+
import { AnonymousResponseError, UnexpectedHtmlResponseError, getProviderResponseBodyMessage } from "./providerErrors.js";
|
|
4
|
+
//#region ../plus/integrations/src/providers/bitbucketServerPullRequestWriteErrors.ts
|
|
5
|
+
var BitbucketServerPullRequestWriteError = class extends Error {
|
|
6
|
+
reason;
|
|
7
|
+
constructor(reason) {
|
|
8
|
+
super(reason);
|
|
9
|
+
this.reason = reason;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
function toBitbucketServerPullRequestWriteFailure(ex, dispatched) {
|
|
13
|
+
if (ex instanceof BitbucketServerPullRequestWriteError) return {
|
|
14
|
+
ok: false,
|
|
15
|
+
reason: ex.reason
|
|
16
|
+
};
|
|
17
|
+
if (RequestRateLimitError.is(ex)) return {
|
|
18
|
+
ok: false,
|
|
19
|
+
reason: "rate-limit"
|
|
20
|
+
};
|
|
21
|
+
if (UnexpectedHtmlResponseError.is(ex) || AnonymousResponseError.is(ex)) return {
|
|
22
|
+
ok: false,
|
|
23
|
+
reason: dispatched == null ? "no-connection" : "outcome-unknown"
|
|
24
|
+
};
|
|
25
|
+
return {
|
|
26
|
+
ok: false,
|
|
27
|
+
reason: getFailureReason(getBitbucketServerErrorDetail(ex), dispatched)
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function getFailureReason(detail, dispatched) {
|
|
31
|
+
const { status, message } = detail;
|
|
32
|
+
switch (status) {
|
|
33
|
+
case 400:
|
|
34
|
+
case 413:
|
|
35
|
+
case 422: return "invalid-input";
|
|
36
|
+
case 401: return detail.authenticated ? "forbidden" : "no-connection";
|
|
37
|
+
case 403: return detail.retryAfter || isRateLimitResponse({
|
|
38
|
+
status,
|
|
39
|
+
message
|
|
40
|
+
}) ? "rate-limit" : "forbidden";
|
|
41
|
+
case 404:
|
|
42
|
+
case 410: return "not-found";
|
|
43
|
+
case 409: return getConflictReason(detail);
|
|
44
|
+
case 429: return "rate-limit";
|
|
45
|
+
default: return dispatched == null ? "unknown" : "outcome-unknown";
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function getConflictReason(detail) {
|
|
49
|
+
const name = detail.exceptionName ?? "";
|
|
50
|
+
if (name.endsWith("OutOfDateException")) return "stale-version";
|
|
51
|
+
if (name.endsWith("MergeVetoedException") || detail.vetoes.length) return "policy-blocked";
|
|
52
|
+
if (/(?:EmptyPullRequest|PullRequestSameRef|InvalidPullRequestReviewers?|InvalidPullRequestTarget)/.test(name)) return "invalid-input";
|
|
53
|
+
return "conflict";
|
|
54
|
+
}
|
|
55
|
+
function getBitbucketServerErrorDetail(ex) {
|
|
56
|
+
const error = ex;
|
|
57
|
+
const response = error?.response;
|
|
58
|
+
let status;
|
|
59
|
+
if (typeof response?.status === "number") status = response.status;
|
|
60
|
+
else if (typeof error?.statusCode === "number") status = error.statusCode;
|
|
61
|
+
const first = getFirstError(response?.body);
|
|
62
|
+
return {
|
|
63
|
+
status,
|
|
64
|
+
exceptionName: typeof first?.exceptionName === "string" ? first.exceptionName : void 0,
|
|
65
|
+
message: (typeof first?.message === "string" ? first.message : getProviderResponseBodyMessage(response?.body)) ?? "",
|
|
66
|
+
vetoes: toVetoes(first?.vetoes),
|
|
67
|
+
existingPullRequest: first?.existingPullRequest,
|
|
68
|
+
authenticated: isAuthenticatedUser(getAuthenticatedUser(response?.headers)),
|
|
69
|
+
retryAfter: getResponseHeader(response?.headers, "retry-after") != null
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function toVetoes(value) {
|
|
73
|
+
if (!Array.isArray(value)) return [];
|
|
74
|
+
return value.flatMap((veto) => {
|
|
75
|
+
if (veto == null || typeof veto.summaryMessage !== "string") return [];
|
|
76
|
+
return [{
|
|
77
|
+
summary: veto.summaryMessage,
|
|
78
|
+
...typeof veto.detailedMessage === "string" && veto.detailedMessage.length > 0 && { detail: veto.detailedMessage }
|
|
79
|
+
}];
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function getFirstError(body) {
|
|
83
|
+
if (body == null || typeof body !== "object") return void 0;
|
|
84
|
+
const errors = body.errors;
|
|
85
|
+
const first = Array.isArray(errors) ? errors[0] : body;
|
|
86
|
+
return first != null && typeof first === "object" ? first : void 0;
|
|
87
|
+
}
|
|
88
|
+
function isAuthenticatedUser(user) {
|
|
89
|
+
return user != null && user !== "anonymous";
|
|
90
|
+
}
|
|
91
|
+
//#endregion
|
|
92
|
+
export { BitbucketServerPullRequestWriteError, getBitbucketServerErrorDetail, toBitbucketServerPullRequestWriteFailure, toVetoes };
|
|
93
|
+
|
|
94
|
+
//# sourceMappingURL=bitbucketServerPullRequestWriteErrors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitbucketServerPullRequestWriteErrors.js","names":[],"sources":["../../../../../plus/integrations/src/providers/bitbucketServerPullRequestWriteErrors.ts"],"sourcesContent":["import { getAuthenticatedUser, getResponseHeader, isRateLimitResponse, RequestRateLimitError } from '../errors.js';\nimport type {\n\tBitbucketServerPullRequestVeto,\n\tBitbucketServerPullRequestWriteFailure,\n} from '../models/bitbucketServerPullRequestWrites.js';\nimport {\n\tAnonymousResponseError,\n\tgetProviderResponseBodyMessage,\n\tUnexpectedHtmlResponseError,\n} from './providerErrors.js';\n\ntype FailureReason = BitbucketServerPullRequestWriteFailure['reason'];\ntype Action = 'create' | 'edit' | 'decline' | 'reopen' | 'merge' | 'delete';\n\nexport type BitbucketServerErrorDetail = {\n\tstatus: number | undefined;\n\texceptionName: string | undefined;\n\tmessage: string;\n\tvetoes: BitbucketServerPullRequestVeto[];\n\texistingPullRequest: unknown;\n\tauthenticated: boolean;\n\tretryAfter: boolean;\n};\n\nexport class BitbucketServerPullRequestWriteError extends Error {\n\tconstructor(readonly reason: FailureReason) {\n\t\tsuper(reason);\n\t}\n}\n\nexport function toBitbucketServerPullRequestWriteFailure(\n\tex: unknown,\n\tdispatched?: Action,\n): BitbucketServerPullRequestWriteFailure {\n\tif (ex instanceof BitbucketServerPullRequestWriteError) return { ok: false, reason: ex.reason };\n\tif (RequestRateLimitError.is(ex)) return { ok: false, reason: 'rate-limit' };\n\tif (UnexpectedHtmlResponseError.is(ex) || AnonymousResponseError.is(ex)) {\n\t\treturn { ok: false, reason: dispatched == null ? 'no-connection' : 'outcome-unknown' };\n\t}\n\n\treturn { ok: false, reason: getFailureReason(getBitbucketServerErrorDetail(ex), dispatched) };\n}\n\nfunction getFailureReason(detail: BitbucketServerErrorDetail, dispatched: Action | undefined): FailureReason {\n\tconst { status, message } = detail;\n\tswitch (status) {\n\t\tcase 400:\n\t\tcase 413:\n\t\tcase 422:\n\t\t\treturn 'invalid-input';\n\t\tcase 401:\n\t\t\treturn detail.authenticated ? 'forbidden' : 'no-connection';\n\t\tcase 403:\n\t\t\treturn detail.retryAfter || isRateLimitResponse({ status: status, message: message })\n\t\t\t\t? 'rate-limit'\n\t\t\t\t: 'forbidden';\n\t\tcase 404:\n\t\tcase 410:\n\t\t\treturn 'not-found';\n\t\tcase 409:\n\t\t\treturn getConflictReason(detail);\n\t\tcase 429:\n\t\t\treturn 'rate-limit';\n\t\tdefault:\n\t\t\treturn dispatched == null ? 'unknown' : 'outcome-unknown';\n\t}\n}\n\nfunction getConflictReason(detail: BitbucketServerErrorDetail): FailureReason {\n\tconst name = detail.exceptionName ?? '';\n\tif (name.endsWith('OutOfDateException')) return 'stale-version';\n\tif (name.endsWith('MergeVetoedException') || detail.vetoes.length) return 'policy-blocked';\n\tif (/(?:EmptyPullRequest|PullRequestSameRef|InvalidPullRequestReviewers?|InvalidPullRequestTarget)/.test(name)) {\n\t\treturn 'invalid-input';\n\t}\n\n\treturn 'conflict';\n}\n\nexport function getBitbucketServerErrorDetail(ex: unknown): BitbucketServerErrorDetail {\n\tconst error = ex as\n\t\t| { statusCode?: unknown; response?: { status?: unknown; body?: unknown; headers?: Record<string, unknown> } }\n\t\t| undefined;\n\tconst response = error?.response;\n\tlet status: number | undefined;\n\tif (typeof response?.status === 'number') {\n\t\tstatus = response.status;\n\t} else if (typeof error?.statusCode === 'number') {\n\t\tstatus = error.statusCode;\n\t}\n\n\tconst first = getFirstError(response?.body);\n\treturn {\n\t\tstatus: status,\n\t\texceptionName: typeof first?.exceptionName === 'string' ? first.exceptionName : undefined,\n\t\tmessage:\n\t\t\t(typeof first?.message === 'string' ? first.message : getProviderResponseBodyMessage(response?.body)) ?? '',\n\t\tvetoes: toVetoes(first?.vetoes),\n\t\texistingPullRequest: first?.existingPullRequest,\n\t\tauthenticated: isAuthenticatedUser(getAuthenticatedUser(response?.headers)),\n\t\tretryAfter: getResponseHeader(response?.headers, 'retry-after') != null,\n\t};\n}\n\nexport function toVetoes(value: unknown): BitbucketServerPullRequestVeto[] {\n\tif (!Array.isArray(value)) return [];\n\n\treturn value.flatMap((veto: { summaryMessage?: unknown; detailedMessage?: unknown } | null) => {\n\t\tif (veto == null || typeof veto.summaryMessage !== 'string') return [];\n\n\t\treturn [\n\t\t\t{\n\t\t\t\tsummary: veto.summaryMessage,\n\t\t\t\t...(typeof veto.detailedMessage === 'string' &&\n\t\t\t\t\tveto.detailedMessage.length > 0 && { detail: veto.detailedMessage }),\n\t\t\t},\n\t\t];\n\t});\n}\n\nfunction getFirstError(\n\tbody: unknown,\n): { message?: unknown; exceptionName?: unknown; vetoes?: unknown; existingPullRequest?: unknown } | undefined {\n\tif (body == null || typeof body !== 'object') return undefined;\n\n\tconst errors = (body as { errors?: unknown }).errors;\n\tconst first: unknown = Array.isArray(errors) ? errors[0] : body;\n\treturn first != null && typeof first === 'object' ? first : undefined;\n}\n\nfunction isAuthenticatedUser(user: string | undefined): boolean {\n\treturn user != null && user !== 'anonymous';\n}\n"],"mappings":";;;;AAwBA,IAAa,uCAAb,cAA0D,MAAM;CAC1C;CAArB,YAAY,QAAgC;EAC3C,MAAM,MAAM;EADQ,KAAA,SAAA;CAErB;AACD;AAEA,SAAgB,yCACf,IACA,YACyC;CACzC,IAAI,cAAc,sCAAsC,OAAO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AAW,MAAM,gBAAgB,KAAA;EAChF,UACE,OAAO,OAAO,YAAY,WAAW,MAAM,UAAU,+BAA+B,UAAU,IAAI,MAAM;EAC1G,QAAQ,SAAS,OAAO,MAAM;EAC9B,qBAAqB,OAAO;EAC5B,eAAe,oBAAoB,qBAAqB,UAAU,OAAO,CAAC;EAC1E,YAAY,kBAAkB,UAAU,SAAS,aAAa,KAAK;CACpE;AACD;AAEA,SAAgB,SAAS,OAAkD;CAC1E,IAAI,CAAC,MAAM,QAAQ,KAAK,GAAG,OAAO,CAAC;CAEnC,OAAO,MAAM,SAAS,SAAyE;EAC9F,IAAI,QAAQ,QAAQ,OAAO,KAAK,mBAAmB,UAAU,OAAO,CAAC;EAErE,OAAO,CACN;GACC,SAAS,KAAK;GACd,GAAI,OAAO,KAAK,oBAAoB,YACnC,KAAK,gBAAgB,SAAS,KAAK,EAAE,QAAQ,KAAK,gBAAgB;EACpE,CACD;CACD,CAAC;AACF;AAEA,SAAS,cACR,MAC8G;CAC9G,IAAI,QAAQ,QAAQ,OAAO,SAAS,UAAU,OAAO,KAAA;CAErD,MAAM,SAAU,KAA8B;CAC9C,MAAM,QAAiB,MAAM,QAAQ,MAAM,IAAI,OAAO,KAAK;CAC3D,OAAO,SAAS,QAAQ,OAAO,UAAU,WAAW,QAAQ,KAAA;AAC7D;AAEA,SAAS,oBAAoB,MAAmC;CAC/D,OAAO,QAAQ,QAAQ,SAAS;AACjC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { BitbucketServerPullRequestCreateCapabilityResult, BitbucketServerPullRequestWriteOptions, BitbucketServerPullRequestWriteResult, BitbucketServerPullRequestWriteScope, BitbucketServerPullRequestWriteTargetResult } from "../models/bitbucketServerPullRequestWrites.js";
|
|
2
|
+
import { ProviderRequestFunction } from "./models.js";
|
|
3
|
+
//#region ../plus/integrations/src/providers/bitbucketServerPullRequestWrites.d.ts
|
|
4
|
+
type ServerTransport = {
|
|
5
|
+
request: ProviderRequestFunction;
|
|
6
|
+
accessToken: string;
|
|
7
|
+
installationUrl: string;
|
|
8
|
+
connectionId: string;
|
|
9
|
+
isSessionCurrent: () => Promise<boolean>;
|
|
10
|
+
isConnectionCurrent: () => boolean;
|
|
11
|
+
getAccountId: (username: string) => Promise<string | undefined>;
|
|
12
|
+
};
|
|
13
|
+
export declare function isBitbucketServerPullRequestScope(options: BitbucketServerPullRequestWriteScope): boolean;
|
|
14
|
+
export declare function isBitbucketServerPullRequestWrite(options: BitbucketServerPullRequestWriteOptions): boolean;
|
|
15
|
+
export declare class BitbucketServerPullRequestWriter {
|
|
16
|
+
private readonly transport;
|
|
17
|
+
private readonly apiUrl;
|
|
18
|
+
private readonly headers;
|
|
19
|
+
private readonly accountId;
|
|
20
|
+
private readonly version;
|
|
21
|
+
private readonly repository;
|
|
22
|
+
static connect(transport: ServerTransport, options: BitbucketServerPullRequestWriteScope): Promise<BitbucketServerPullRequestWriter>;
|
|
23
|
+
private readonly repoUrl;
|
|
24
|
+
private constructor();
|
|
25
|
+
isConnectionCurrent(): boolean;
|
|
26
|
+
getCreateCapability(): Promise<BitbucketServerPullRequestCreateCapabilityResult>;
|
|
27
|
+
resolveTarget(number: number): Promise<BitbucketServerPullRequestWriteTargetResult>;
|
|
28
|
+
write(options: BitbucketServerPullRequestWriteOptions): Promise<BitbucketServerPullRequestWriteResult>;
|
|
29
|
+
private create;
|
|
30
|
+
private findOpenPullRequest;
|
|
31
|
+
private writeExisting;
|
|
32
|
+
private edit;
|
|
33
|
+
private merge;
|
|
34
|
+
private getDeleteCapability;
|
|
35
|
+
private getMergeCapability;
|
|
36
|
+
private readMergePolicy;
|
|
37
|
+
private pullRequestUrl;
|
|
38
|
+
private readPullRequest;
|
|
39
|
+
private toReadOrUndefined;
|
|
40
|
+
private toPullRequestRead;
|
|
41
|
+
private isSelectedRepository;
|
|
42
|
+
private readBranchTip;
|
|
43
|
+
private findOnPages;
|
|
44
|
+
private readDefaultBranch;
|
|
45
|
+
private readMergeability;
|
|
46
|
+
private readMergeStrategies;
|
|
47
|
+
private sendForReceipt;
|
|
48
|
+
private send;
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
//# sourceMappingURL=bitbucketServerPullRequestWrites.d.ts.map
|