@gitkraken/core-gitlens 0.56.1 → 0.58.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/CHANGELOG.md +11 -1
  2. package/dist/git-cli/providers/config.js +2 -2
  3. package/dist/git-cli/providers/pausedOperations.js +2 -2
  4. package/dist/git-cli/providers/pausedOperations.js.map +1 -1
  5. package/dist/git-cli/providers/staging.js +1 -1
  6. package/dist/ipc/discovery.js +1 -1
  7. package/dist/plus/agents/providers/claudeCodeTranscript.js +6 -6
  8. package/dist/plus/agents/providers/claudeCodeTranscript.js.map +1 -1
  9. package/dist/plus/ai/providers/openAICompatibleProviderBase.js +1 -1
  10. package/dist/plus/integrations/authentication/configuredIntegrationService.d.ts +4 -0
  11. package/dist/plus/integrations/authentication/configuredIntegrationService.js +8 -2
  12. package/dist/plus/integrations/authentication/configuredIntegrationService.js.map +1 -1
  13. package/dist/plus/integrations/authentication/integrationAuthenticationService.d.ts +1 -1
  14. package/dist/plus/integrations/authentication/integrationAuthenticationService.js +2 -2
  15. package/dist/plus/integrations/authentication/integrationAuthenticationService.js.map +1 -1
  16. package/dist/plus/integrations/authentication/observedAuthenticationProvider.d.ts +2 -1
  17. package/dist/plus/integrations/authentication/observedAuthenticationProvider.js +16 -12
  18. package/dist/plus/integrations/authentication/observedAuthenticationProvider.js.map +1 -1
  19. package/dist/plus/integrations/index.d.ts +2 -1
  20. package/dist/plus/integrations/index.js.map +1 -1
  21. package/dist/plus/integrations/integrationService.d.ts +5 -0
  22. package/dist/plus/integrations/integrationService.js +54 -0
  23. package/dist/plus/integrations/integrationService.js.map +1 -1
  24. package/dist/plus/integrations/manager.d.ts +8 -0
  25. package/dist/plus/integrations/models/bitbucketServerPullRequestWrites.d.ts +142 -0
  26. package/dist/plus/integrations/models/bitbucketServerPullRequestWrites.js +0 -0
  27. package/dist/plus/integrations/models/integration.d.ts +6 -3
  28. package/dist/plus/integrations/models/integration.js +11 -10
  29. package/dist/plus/integrations/models/integration.js.map +1 -1
  30. package/dist/plus/integrations/providers/azure/azure.js +1 -1
  31. package/dist/plus/integrations/providers/bitbucket-server.d.ts +4 -1
  32. package/dist/plus/integrations/providers/bitbucket-server.js +23 -0
  33. package/dist/plus/integrations/providers/bitbucket-server.js.map +1 -1
  34. package/dist/plus/integrations/providers/bitbucketPullRequestWrites.js +2 -2
  35. package/dist/plus/integrations/providers/bitbucketPullRequestWrites.js.map +1 -1
  36. package/dist/plus/integrations/providers/bitbucketServerPullRequestWriteErrors.d.ts +22 -0
  37. package/dist/plus/integrations/providers/bitbucketServerPullRequestWriteErrors.js +94 -0
  38. package/dist/plus/integrations/providers/bitbucketServerPullRequestWriteErrors.js.map +1 -0
  39. package/dist/plus/integrations/providers/bitbucketServerPullRequestWrites.d.ts +51 -0
  40. package/dist/plus/integrations/providers/bitbucketServerPullRequestWrites.js +593 -0
  41. package/dist/plus/integrations/providers/bitbucketServerPullRequestWrites.js.map +1 -0
  42. package/dist/plus/integrations/providers/github.js +1 -1
  43. package/dist/plus/integrations/providers/providerApiClient.js +4 -3
  44. package/dist/plus/integrations/providers/providerApiClient.js.map +1 -1
  45. package/dist/plus/integrations/providers/providersApi.d.ts +10 -0
  46. package/dist/plus/integrations/providers/providersApi.js +45 -1
  47. package/dist/plus/integrations/providers/providersApi.js.map +1 -1
  48. package/dist/plus/integrations/providers/utils/writeInputs.d.ts +1 -0
  49. package/dist/plus/integrations/providers/utils/writeInputs.js +4 -1
  50. package/dist/plus/integrations/providers/utils/writeInputs.js.map +1 -1
  51. package/dist/utils/env/node/exec.js +2 -2
  52. package/docs/integrations.md +81 -0
  53. package/package.json +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bitbucketServerPullRequestWrites.js","names":[],"sources":["../../../../../plus/integrations/src/providers/bitbucketServerPullRequestWrites.ts"],"sourcesContent":["import { getAuthenticatedUser, getResponseHeader } from '../errors.js';\nimport type {\n\tBitbucketServerPullRequestActionCapability,\n\tBitbucketServerPullRequestCreateCapabilityResult,\n\tBitbucketServerPullRequestMergeCapability,\n\tBitbucketServerPullRequestRepository,\n\tBitbucketServerPullRequestWriteFailure,\n\tBitbucketServerPullRequestWriteOptions,\n\tBitbucketServerPullRequestWriteResult,\n\tBitbucketServerPullRequestWriteScope,\n\tBitbucketServerPullRequestWriteTargetResult,\n\tBitbucketServerWrittenPullRequest,\n} from '../models/bitbucketServerPullRequestWrites.js';\nimport {\n\tBitbucketServerPullRequestWriteError,\n\tgetBitbucketServerErrorDetail,\n\ttoBitbucketServerPullRequestWriteFailure,\n\ttoVetoes,\n} from './bitbucketServerPullRequestWriteErrors.js';\nimport type { ProviderRequestFunction } from './models.js';\nimport {\n\tisCommitSha,\n\tisGitBranchName,\n\tisPositiveInt32,\n\tisWriteIdentifier,\n\tsameIdentifier,\n} from './utils/writeInputs.js';\n\n// SEE: https://docs.atlassian.com/bitbucket-server/rest/5.1.0/bitbucket-rest.html (first to document DELETE)\nconst deleteSince = [5, 1] as const;\n// SEE: https://confluence.atlassian.com/bitbucketserver/bitbucket-data-center-8-18-release-notes-1333992708.html\nconst draftSince = [8, 18] as const;\nconst projectKeyPattern = /^~?[\\w.@+-]+$/;\nconst slugPattern = /^[\\w.-]+$/;\nconst accountIdPattern = /^\\d{1,19}$/;\nconst strategyIdPattern = /^[\\w-]{1,64}$/;\n\ntype FailureReason = BitbucketServerPullRequestWriteFailure['reason'];\ntype Failure = Extract<BitbucketServerPullRequestWriteResult, { ok: false }>;\ntype CreateOptions = Extract<BitbucketServerPullRequestWriteOptions, { action: 'create' }>;\ntype EditOptions = Extract<BitbucketServerPullRequestWriteOptions, { action: 'edit' }>;\ntype MergeOptions = Extract<BitbucketServerPullRequestWriteOptions, { action: 'merge' }>;\ntype ExistingOptions = Exclude<BitbucketServerPullRequestWriteOptions, CreateOptions>;\ntype Version = readonly [number, number];\n\ntype RawRepoRef = { id?: unknown; slug?: unknown; project?: { key?: unknown } | null };\ntype RawRef = {\n\tid?: unknown;\n\tlatestCommit?: unknown;\n\trepository?: RawRepoRef | null;\n};\n\ntype RawPullRequest = {\n\tid?: unknown;\n\tversion?: unknown;\n\ttitle?: unknown;\n\tdescription?: unknown;\n\tstate?: unknown;\n\tdraft?: unknown;\n\tauthor?: { user?: { id?: unknown } | null } | null;\n\treviewers?: unknown;\n\tfromRef?: RawRef | null;\n\ttoRef?: RawRef | null;\n};\n\ntype RawRepository = {\n\tid?: unknown;\n\tslug?: unknown;\n\tname?: unknown;\n\tproject?: { id?: unknown; key?: unknown } | null;\n};\n\ntype RawMergeability = { canMerge?: unknown; conflicted?: unknown; outcome?: unknown; vetoes?: unknown };\n\ntype PullRequestRead = {\n\tpullRequest: BitbucketServerWrittenPullRequest;\n\treviewers: unknown;\n\tsourceRepository: { projectKey: string; slug: string } | undefined;\n};\n\ntype MergeStrategies = { strategies: string[]; defaultStrategy?: string };\n\ntype ServerTransport = {\n\trequest: ProviderRequestFunction;\n\taccessToken: string;\n\tinstallationUrl: string;\n\tconnectionId: string;\n\tisSessionCurrent: () => Promise<boolean>;\n\tisConnectionCurrent: () => boolean;\n\tgetAccountId: (username: string) => Promise<string | undefined>;\n};\n\nfunction isProjectKey(value: unknown): value is string {\n\treturn typeof value === 'string' && projectKeyPattern.test(value) && !/^~?\\.{1,2}$/.test(value);\n}\n\nfunction isRepositorySlug(value: unknown): value is string {\n\treturn typeof value === 'string' && slugPattern.test(value) && !/^\\.\\.?$/.test(value);\n}\n\nfunction isVersionNumber(value: unknown): value is number {\n\treturn typeof value === 'number' && Number.isInteger(value) && value >= 0 && value <= 2147483647;\n}\n\nfunction isTitle(title: unknown): title is string {\n\treturn typeof title === 'string' && title.trim().length > 0;\n}\n\nfunction isBaseUrl(value: unknown): value is string {\n\tif (typeof value !== 'string' || !isWriteIdentifier(value)) return false;\n\n\tconst url = URL.parse(/^[a-z][a-z\\d+\\-.]*:\\/\\//i.test(value) ? value : `https://${value}`);\n\treturn (\n\t\t(url?.protocol === 'https:' || url?.protocol === 'http:') &&\n\t\t!url.username &&\n\t\t!url.password &&\n\t\t!url.search &&\n\t\t!url.hash\n\t);\n}\n\nfunction seg(value: string): string {\n\treturn encodeURIComponent(value);\n}\n\nfunction toBranchRef(branch: string): string {\n\treturn `refs/heads/${branch}`;\n}\n\nfunction parseVersion(value: unknown): Version | undefined {\n\tconst match = typeof value === 'string' ? /^(\\d+)\\.(\\d+)/.exec(value) : null;\n\treturn match == null ? undefined : [Number(match[1]), Number(match[2])];\n}\n\nfunction isAtLeast(version: Version, since: Version): boolean {\n\treturn version[0] > since[0] || (version[0] === since[0] && version[1] >= since[1]);\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\nexport function isBitbucketServerPullRequestScope(options: BitbucketServerPullRequestWriteScope): boolean {\n\treturn (\n\t\toptions.providerId === 'bitbucket-server' &&\n\t\tisWriteIdentifier(options.connectionId) &&\n\t\t(options.domain === undefined || isWriteIdentifier(options.domain)) &&\n\t\tisBaseUrl(options.baseUrl) &&\n\t\tisProjectKey(options.projectKey) &&\n\t\tisRepositorySlug(options.repositorySlug) &&\n\t\t(options.expectedAccountId === undefined ||\n\t\t\t(typeof options.expectedAccountId === 'string' && accountIdPattern.test(options.expectedAccountId)))\n\t);\n}\n\nexport function isBitbucketServerPullRequestWrite(options: BitbucketServerPullRequestWriteOptions): boolean {\n\tif (\n\t\t!isBitbucketServerPullRequestScope(options) ||\n\t\ttypeof options.expectedAccountId !== 'string' ||\n\t\t!isPositiveInt32(options.repositoryId)\n\t) {\n\t\treturn false;\n\t}\n\n\tif (options.action === 'create') {\n\t\treturn (\n\t\t\tisGitBranchName(options.sourceBranch) &&\n\t\t\tisGitBranchName(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\t(options.draft === undefined || typeof options.draft === 'boolean')\n\t\t);\n\t}\n\n\tif (!isPositiveInt32(options.number) || !isVersionNumber(options.expectedVersion)) 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\tcase 'reopen':\n\t\tcase 'delete':\n\t\t\treturn true;\n\t\tcase 'merge':\n\t\t\treturn (\n\t\t\t\t(options.strategy === undefined ||\n\t\t\t\t\t(typeof options.strategy === 'string' && strategyIdPattern.test(options.strategy))) &&\n\t\t\t\tisGitBranchName(options.expectedSourceBranch) &&\n\t\t\t\tisGitBranchName(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 class BitbucketServerPullRequestWriter {\n\tstatic async connect(\n\t\ttransport: ServerTransport,\n\t\toptions: BitbucketServerPullRequestWriteScope,\n\t): Promise<BitbucketServerPullRequestWriter> {\n\t\tconst apiUrl = `${transport.installationUrl}/rest/api/1.0`;\n\t\tconst headers = { Authorization: `Bearer ${transport.accessToken}` };\n\t\tconst [{ body: properties }, repoResponse] = await Promise.all([\n\t\t\ttransport.request<{ version?: unknown }>({\n\t\t\t\turl: `${apiUrl}/application-properties`,\n\t\t\t\theaders: headers,\n\t\t\t}),\n\t\t\ttransport.request<RawRepository>({\n\t\t\t\turl: `${apiUrl}/projects/${seg(options.projectKey)}/repos/${seg(options.repositorySlug)}`,\n\t\t\t\theaders: headers,\n\t\t\t}),\n\t\t]);\n\t\tconst serverVersion = typeof properties?.version === 'string' ? properties.version : undefined;\n\t\tconst version = parseVersion(serverVersion);\n\t\tif (serverVersion == null || version == null) throw new BitbucketServerPullRequestWriteError('unknown');\n\n\t\tconst username = getAuthenticatedUser(repoResponse.headers);\n\t\tconst accountId =\n\t\t\tgetResponseHeader(repoResponse.headers, 'x-auserid') ??\n\t\t\t(username != null && username !== 'anonymous'\n\t\t\t\t? await transport.getAccountId(decodeURIComponent(username))\n\t\t\t\t: undefined);\n\t\tif (\n\t\t\ttypeof accountId !== 'string' ||\n\t\t\t!accountIdPattern.test(accountId) ||\n\t\t\t(options.expectedAccountId !== undefined && accountId !== options.expectedAccountId)\n\t\t) {\n\t\t\tthrow new BitbucketServerPullRequestWriteError('no-connection');\n\t\t}\n\n\t\tconst repo = repoResponse.body;\n\t\tconst project = repo?.project;\n\t\tif (\n\t\t\t!isPositiveInt32(repo?.id) ||\n\t\t\t!isRepositorySlug(repo.slug) ||\n\t\t\ttypeof repo.name !== 'string' ||\n\t\t\t!isPositiveInt32(project?.id) ||\n\t\t\t!isProjectKey(project.key) ||\n\t\t\t!sameIdentifier(project.key, options.projectKey) ||\n\t\t\t!sameIdentifier(repo.slug, options.repositorySlug)\n\t\t) {\n\t\t\tthrow new BitbucketServerPullRequestWriteError('not-found');\n\t\t}\n\n\t\treturn new BitbucketServerPullRequestWriter(transport, apiUrl, headers, accountId, version, {\n\t\t\tproviderId: options.providerId,\n\t\t\tconnectionId: transport.connectionId,\n\t\t\tbaseUrl: transport.installationUrl,\n\t\t\tserverVersion: serverVersion,\n\t\t\tprojectId: project.id,\n\t\t\tprojectKey: project.key,\n\t\t\trepositoryId: repo.id,\n\t\t\trepositorySlug: repo.slug,\n\t\t\trepositoryName: repo.name,\n\t\t});\n\t}\n\n\tprivate readonly repoUrl: string;\n\n\tprivate constructor(\n\t\tprivate readonly transport: ServerTransport,\n\t\tprivate readonly apiUrl: string,\n\t\tprivate readonly headers: { Authorization: string },\n\t\tprivate readonly accountId: string,\n\t\tprivate readonly version: Version,\n\t\tprivate readonly repository: BitbucketServerPullRequestRepository,\n\t) {\n\t\tthis.repoUrl = `${apiUrl}/projects/${seg(repository.projectKey)}/repos/${seg(repository.repositorySlug)}`;\n\t}\n\n\tisConnectionCurrent(): boolean {\n\t\treturn this.transport.isConnectionCurrent();\n\t}\n\n\tasync getCreateCapability(): Promise<BitbucketServerPullRequestCreateCapabilityResult> {\n\t\tconst defaultBranch = await this.readDefaultBranch();\n\t\treturn {\n\t\t\tok: true,\n\t\t\taccountId: this.accountId,\n\t\t\trepository: this.repository,\n\t\t\t...(defaultBranch !== undefined && { defaultBranch: defaultBranch }),\n\t\t\tdraft: isAtLeast(this.version, draftSince),\n\t\t};\n\t}\n\n\tasync resolveTarget(number: number): Promise<BitbucketServerPullRequestWriteTargetResult> {\n\t\tif (!isPositiveInt32(number)) return { ok: false, reason: 'invalid-input' };\n\n\t\tconst read = await this.readPullRequest(number);\n\t\tconst { pullRequest } = read;\n\t\tconst open = pullRequest.state === 'open';\n\t\treturn {\n\t\t\tok: true,\n\t\t\taccountId: this.accountId,\n\t\t\tpullRequest: pullRequest,\n\t\t\tcapabilities: {\n\t\t\t\tedit: open && toReviewers(read.reviewers) != null,\n\t\t\t\tdecline: open,\n\t\t\t\treopen: pullRequest.state === 'declined',\n\t\t\t\tdelete: this.getDeleteCapability(pullRequest),\n\t\t\t\tmerge: await this.getMergeCapability(read),\n\t\t\t},\n\t\t};\n\t}\n\n\twrite(options: BitbucketServerPullRequestWriteOptions): Promise<BitbucketServerPullRequestWriteResult> {\n\t\tif (options.repositoryId !== this.repository.repositoryId) {\n\t\t\treturn Promise.resolve({ ok: false, reason: 'not-found' });\n\t\t}\n\t\tif (options.action === 'create') return this.create(options);\n\n\t\treturn this.writeExisting(options);\n\t}\n\n\tprivate async create(options: CreateOptions): Promise<BitbucketServerPullRequestWriteResult> {\n\t\tif (options.draft === true && !isAtLeast(this.version, draftSince)) return { ok: false, reason: 'unsupported' };\n\n\t\tconst [source, target] = await Promise.all([\n\t\t\tthis.readBranchTip(this.repoUrl, options.sourceBranch),\n\t\t\tthis.readBranchTip(this.repoUrl, options.targetBranch),\n\t\t]);\n\t\tif (source == null || target == null) return { ok: false, reason: 'not-found' };\n\n\t\tconst ref = (branch: string) => ({\n\t\t\tid: toBranchRef(branch),\n\t\t\trepository: { slug: this.repository.repositorySlug, project: { key: this.repository.projectKey } },\n\t\t});\n\t\tconst sent = await this.send(options, 'POST', `${this.repoUrl}/pull-requests`, {\n\t\t\ttitle: options.title,\n\t\t\t...(options.description !== undefined && { description: options.description }),\n\t\t\t...(options.draft === true && { draft: true }),\n\t\t\tfromRef: ref(options.sourceBranch),\n\t\t\ttoRef: ref(options.targetBranch),\n\t\t});\n\t\tif (!sent.ok) {\n\t\t\tconst { existing, ...failure } = sent;\n\t\t\treturn failure.reason === 'conflict'\n\t\t\t\t? { ...failure, ...(await this.findOpenPullRequest(options, existing)) }\n\t\t\t\t: failure;\n\t\t}\n\n\t\tconst read = this.toReadOrUndefined(sent.body);\n\t\tif (read == null) return { ok: false, reason: 'outcome-unknown' };\n\n\t\tconst { pullRequest } = read;\n\t\treturn sent.status === 201 &&\n\t\t\tpullRequest.state === 'open' &&\n\t\t\tpullRequest.draft === (options.draft === true) &&\n\t\t\tpullRequest.authorId === this.accountId &&\n\t\t\t!pullRequest.isCrossRepository &&\n\t\t\tpullRequest.sourceBranch === options.sourceBranch &&\n\t\t\tpullRequest.targetBranch === options.targetBranch &&\n\t\t\tsameText(pullRequest.title, options.title) &&\n\t\t\t(options.description === undefined || sameText(pullRequest.description, options.description))\n\t\t\t? { ok: true, status: 'created', pullRequest: pullRequest }\n\t\t\t: { ok: false, reason: 'outcome-unknown' };\n\t}\n\n\tprivate async findOpenPullRequest(\n\t\toptions: CreateOptions,\n\t\treported: unknown,\n\t): Promise<{ pullRequest?: BitbucketServerWrittenPullRequest }> {\n\t\tconst matches = (read: PullRequestRead | undefined): read is PullRequestRead =>\n\t\t\tread?.pullRequest.state === 'open' &&\n\t\t\t!read.pullRequest.isCrossRepository &&\n\t\t\tread.pullRequest.sourceBranch === options.sourceBranch &&\n\t\t\tread.pullRequest.targetBranch === options.targetBranch;\n\n\t\tconst existing = this.toReadOrUndefined(reported);\n\t\tif (matches(existing)) return { pullRequest: existing.pullRequest };\n\n\t\t// KEEP: the extra read only enriches a refusal already decided; failing it must not change the result.\n\t\ttry {\n\t\t\tconst query = new URLSearchParams({\n\t\t\t\tstate: 'OPEN',\n\t\t\t\tdirection: 'OUTGOING',\n\t\t\t\tat: toBranchRef(options.sourceBranch),\n\t\t\t\tlimit: '100',\n\t\t\t});\n\t\t\tconst found = await this.findOnPages(`${this.repoUrl}/pull-requests`, query, raw => {\n\t\t\t\tconst read = this.toReadOrUndefined(raw);\n\t\t\t\treturn matches(read) ? read.pullRequest : undefined;\n\t\t\t});\n\t\t\treturn found != null ? { pullRequest: found } : {};\n\t\t} catch {\n\t\t\treturn {};\n\t\t}\n\t}\n\n\tprivate async writeExisting(options: ExistingOptions): Promise<BitbucketServerPullRequestWriteResult> {\n\t\tconst read = await this.readPullRequest(options.number);\n\t\tconst { pullRequest } = read;\n\t\tif (pullRequest.version !== options.expectedVersion) return { ok: false, reason: 'stale-version' };\n\n\t\tconst url = this.pullRequestUrl(options.number);\n\t\tconst versioned = `?version=${options.expectedVersion}`;\n\t\tswitch (options.action) {\n\t\t\tcase 'edit':\n\t\t\t\tif (pullRequest.state !== 'open') return { ok: false, reason: 'conflict' };\n\n\t\t\t\treturn this.edit(options, read);\n\t\t\tcase 'decline':\n\t\t\t\tif (pullRequest.state !== 'open') return { ok: false, reason: 'conflict' };\n\n\t\t\t\treturn this.sendForReceipt(options, 'POST', `${url}/decline${versioned}`, {}, read =>\n\t\t\t\t\tread.pullRequest.state === 'declined' ? 'declined' : undefined,\n\t\t\t\t);\n\t\t\tcase 'reopen':\n\t\t\t\tif (pullRequest.state !== 'declined') return { ok: false, reason: 'conflict' };\n\n\t\t\t\treturn this.sendForReceipt(options, 'POST', `${url}/reopen${versioned}`, {}, read =>\n\t\t\t\t\tread.pullRequest.state === 'open' ? 'reopened' : undefined,\n\t\t\t\t);\n\t\t\tcase 'delete': {\n\t\t\t\tconst capability = this.getDeleteCapability(pullRequest);\n\t\t\t\tif (capability.kind === 'unavailable') return { ok: false, reason: capability.reason };\n\n\t\t\t\tconst sent = await this.send(options, 'DELETE', url, { version: options.expectedVersion });\n\t\t\t\tif (!sent.ok) return sent;\n\n\t\t\t\treturn sent.status === 204\n\t\t\t\t\t? { ok: true, status: 'deleted', number: options.number }\n\t\t\t\t\t: { ok: false, reason: 'outcome-unknown' };\n\t\t\t}\n\t\t\tcase 'merge':\n\t\t\t\treturn this.merge(options, read);\n\t\t}\n\t}\n\n\tprivate async edit(options: EditOptions, read: PullRequestRead): Promise<BitbucketServerPullRequestWriteResult> {\n\t\tconst reviewers = toReviewers(read.reviewers);\n\t\tif (reviewers == null) return { ok: false, reason: 'unknown' };\n\n\t\tconst { pullRequest } = read;\n\t\tconst title = options.title ?? pullRequest.title;\n\t\tconst description = options.description ?? pullRequest.description;\n\t\t// SEE: live DC 8.19.9, a PUT without `reviewers` removes every reviewer; omitted fields otherwise stay.\n\t\treturn this.sendForReceipt(\n\t\t\toptions,\n\t\t\t'PUT',\n\t\t\tthis.pullRequestUrl(options.number),\n\t\t\t{\n\t\t\t\tversion: options.expectedVersion,\n\t\t\t\ttitle: title,\n\t\t\t\tdescription: description,\n\t\t\t\treviewers: reviewers,\n\t\t\t},\n\t\t\treceipt =>\n\t\t\t\treceipt.pullRequest.state === 'open' &&\n\t\t\t\tsameText(receipt.pullRequest.title, title) &&\n\t\t\t\tsameText(receipt.pullRequest.description, description)\n\t\t\t\t\t? 'updated'\n\t\t\t\t\t: undefined,\n\t\t);\n\t}\n\n\tprivate async merge(options: MergeOptions, read: PullRequestRead): Promise<BitbucketServerPullRequestWriteResult> {\n\t\tconst { pullRequest } = read;\n\t\tconst stateFailure = getMergeStateFailure(pullRequest);\n\t\tif (stateFailure != null) return { ok: false, reason: stateFailure };\n\t\tif (pullRequest.sourceBranch !== options.expectedSourceBranch) return { ok: false, reason: 'source-changed' };\n\t\tif (pullRequest.targetBranch !== options.expectedTargetBranch) return { ok: false, reason: 'target-changed' };\n\t\tif (!sameIdentifier(pullRequest.sourceSha, options.expectedSourceSha)) {\n\t\t\treturn { ok: false, reason: 'source-changed' };\n\t\t}\n\t\tif (!sameIdentifier(pullRequest.targetSha, options.expectedTargetSha)) {\n\t\t\treturn { ok: false, reason: 'target-changed' };\n\t\t}\n\n\t\tconst sourceRepoUrl =\n\t\t\tread.sourceRepository == null\n\t\t\t\t? undefined\n\t\t\t\t: `${this.apiUrl}/projects/${seg(read.sourceRepository.projectKey)}/repos/${seg(read.sourceRepository.slug)}`;\n\t\tif (sourceRepoUrl == null) return { ok: false, reason: 'source-changed' };\n\n\t\tconst policy = await this.readMergePolicy(options.number);\n\t\tif ('ok' in policy) return policy;\n\t\tif (options.strategy !== undefined && !policy.strategies.includes(options.strategy)) {\n\t\t\treturn { ok: false, reason: 'policy-blocked' };\n\t\t}\n\n\t\tconst [source, target] = await Promise.all([\n\t\t\tthis.readBranchTip(sourceRepoUrl, pullRequest.sourceBranch),\n\t\t\tthis.readBranchTip(this.repoUrl, pullRequest.targetBranch),\n\t\t]);\n\t\tif (!sameIdentifier(source, options.expectedSourceSha)) return { ok: false, reason: 'source-changed' };\n\t\tif (!sameIdentifier(target, options.expectedTargetSha)) return { ok: false, reason: 'target-changed' };\n\n\t\treturn this.sendForReceipt(\n\t\t\toptions,\n\t\t\t'POST',\n\t\t\t`${this.pullRequestUrl(options.number)}/merge?version=${options.expectedVersion}`,\n\t\t\toptions.strategy !== undefined ? { strategyId: options.strategy } : {},\n\t\t\treceipt =>\n\t\t\t\treceipt.pullRequest.state === 'merged' &&\n\t\t\t\treceipt.pullRequest.sourceBranch === options.expectedSourceBranch &&\n\t\t\t\treceipt.pullRequest.targetBranch === options.expectedTargetBranch &&\n\t\t\t\tsameIdentifier(receipt.pullRequest.sourceSha, options.expectedSourceSha) &&\n\t\t\t\tsameIdentifier(receipt.pullRequest.targetSha, options.expectedTargetSha)\n\t\t\t\t\t? 'merged'\n\t\t\t\t\t: undefined,\n\t\t);\n\t}\n\n\tprivate getDeleteCapability(\n\t\tpullRequest: BitbucketServerWrittenPullRequest,\n\t): BitbucketServerPullRequestActionCapability {\n\t\tif (!isAtLeast(this.version, deleteSince)) return { kind: 'unavailable', reason: 'unsupported' };\n\t\tif (pullRequest.state === 'merged') return { kind: 'unavailable', reason: 'conflict' };\n\n\t\treturn { kind: 'available' };\n\t}\n\n\tprivate async getMergeCapability(read: PullRequestRead): Promise<BitbucketServerPullRequestMergeCapability> {\n\t\tconst stateFailure = getMergeStateFailure(read.pullRequest);\n\t\tif (stateFailure != null) return { kind: 'unavailable', reason: stateFailure };\n\n\t\ttry {\n\t\t\tconst policy = await this.readMergePolicy(read.pullRequest.number);\n\t\t\tif ('ok' in policy) {\n\t\t\t\treturn {\n\t\t\t\t\tkind: 'unavailable',\n\t\t\t\t\treason: policy.reason,\n\t\t\t\t\t...(policy.vetoes?.length && { vetoes: policy.vetoes }),\n\t\t\t\t};\n\t\t\t}\n\n\t\t\treturn { kind: 'available', ...policy };\n\t\t} catch (ex) {\n\t\t\tconst { reason } = toBitbucketServerPullRequestWriteFailure(ex);\n\t\t\tif (reason === 'no-connection') throw ex;\n\n\t\t\treturn { kind: 'unavailable', reason: reason };\n\t\t}\n\t}\n\n\tprivate async readMergePolicy(number: number): Promise<Failure | MergeStrategies> {\n\t\tconst [mergeability, strategies] = await Promise.all([\n\t\t\tthis.readMergeability(number),\n\t\t\tthis.readMergeStrategies(),\n\t\t]);\n\t\treturn getMergeabilityFailure(mergeability) ?? strategies;\n\t}\n\n\tprivate pullRequestUrl(number: number): string {\n\t\treturn `${this.repoUrl}/pull-requests/${number}`;\n\t}\n\n\tprivate async readPullRequest(number: number): Promise<PullRequestRead> {\n\t\tconst { body } = await this.transport.request<RawPullRequest>({\n\t\t\turl: this.pullRequestUrl(number),\n\t\t\theaders: this.headers,\n\t\t});\n\t\tconst read = this.toPullRequestRead(body, number);\n\t\tif (body.toRef?.repository?.id === undefined) {\n\t\t\tconst { body: repository } = await this.transport.request<RawRepository>({\n\t\t\t\turl: this.repoUrl,\n\t\t\t\theaders: this.headers,\n\t\t\t});\n\t\t\tif (repository?.id !== this.repository.repositoryId) {\n\t\t\t\tthrow new BitbucketServerPullRequestWriteError('not-found');\n\t\t\t}\n\t\t}\n\t\treturn read;\n\t}\n\n\tprivate toReadOrUndefined(raw: unknown, number?: number): PullRequestRead | undefined {\n\t\ttry {\n\t\t\treturn this.toPullRequestRead(raw as RawPullRequest, number);\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\tprivate toPullRequestRead(raw: RawPullRequest | undefined, number?: number): PullRequestRead {\n\t\tif (raw == null || !this.isSelectedRepository(raw.toRef?.repository)) {\n\t\t\tthrow new BitbucketServerPullRequestWriteError('not-found');\n\t\t}\n\n\t\tconst { id, version, title, description, fromRef, toRef } = raw;\n\t\tconst state = typeof raw.state === 'string' ? raw.state.toLowerCase() : undefined;\n\t\tconst sourceBranch = getBranchName(fromRef?.id);\n\t\tconst targetBranch = getBranchName(toRef?.id);\n\t\tif (\n\t\t\t!isPositiveInt32(id) ||\n\t\t\t(number !== undefined && id !== number) ||\n\t\t\t!isVersionNumber(version) ||\n\t\t\ttypeof title !== 'string' ||\n\t\t\t(description != null && typeof description !== 'string') ||\n\t\t\t(state !== 'open' && state !== 'declined' && state !== 'merged') ||\n\t\t\tsourceBranch == null ||\n\t\t\ttargetBranch == null\n\t\t) {\n\t\t\tthrow new BitbucketServerPullRequestWriteError('unknown');\n\t\t}\n\n\t\tconst sourceRepo = fromRef?.repository;\n\t\tconst sourceProjectKey = sourceRepo?.project?.key;\n\t\tconst authorId = raw.author?.user?.id;\n\t\tconst { projectKey, repositorySlug, baseUrl } = this.repository;\n\t\treturn {\n\t\t\tpullRequest: {\n\t\t\t\trepository: this.repository,\n\t\t\t\tnumber: id,\n\t\t\t\tversion: version,\n\t\t\t\turl: `${baseUrl}/projects/${seg(projectKey)}/repos/${seg(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\tisCrossRepository: !this.isSelectedRepository(sourceRepo),\n\t\t\t\t...(typeof authorId === 'number' && { authorId: String(authorId) }),\n\t\t\t\tsourceBranch: sourceBranch,\n\t\t\t\ttargetBranch: targetBranch,\n\t\t\t\t...(isCommitSha(fromRef?.latestCommit) && { sourceSha: fromRef.latestCommit.toLowerCase() }),\n\t\t\t\t...(isCommitSha(toRef?.latestCommit) && { targetSha: toRef.latestCommit.toLowerCase() }),\n\t\t\t},\n\t\t\treviewers: raw.reviewers,\n\t\t\tsourceRepository:\n\t\t\t\tisProjectKey(sourceProjectKey) && isRepositorySlug(sourceRepo?.slug)\n\t\t\t\t\t? { projectKey: sourceProjectKey, slug: sourceRepo.slug }\n\t\t\t\t\t: undefined,\n\t\t};\n\t}\n\n\tprivate isSelectedRepository(repo: RawRepoRef | null | undefined): boolean {\n\t\tif (repo?.id !== undefined) return repo.id === this.repository.repositoryId;\n\n\t\t// SEE: https://docs.atlassian.com/bitbucket-server/rest/5.1.0/bitbucket-rest.html (compact PR refs omit ids)\n\t\treturn (\n\t\t\tsameIdentifier(repo?.project?.key, this.repository.projectKey) &&\n\t\t\tsameIdentifier(repo?.slug, this.repository.repositorySlug)\n\t\t);\n\t}\n\n\tprivate async readBranchTip(repoUrl: string, branch: string): Promise<string | undefined> {\n\t\tconst query = new URLSearchParams({ filterText: branch, boostMatches: 'true', details: 'false', limit: '25' });\n\t\tconst ref = toBranchRef(branch);\n\t\treturn this.findOnPages(`${repoUrl}/branches`, query, value => {\n\t\t\tconst entry = value as { id?: unknown; latestCommit?: unknown } | null | undefined;\n\t\t\tif (entry?.id !== ref) return undefined;\n\t\t\tif (!isCommitSha(entry.latestCommit)) throw new BitbucketServerPullRequestWriteError('unknown');\n\n\t\t\treturn entry.latestCommit.toLowerCase();\n\t\t});\n\t}\n\n\tprivate async findOnPages<T>(\n\t\turl: string,\n\t\tquery: URLSearchParams,\n\t\tmatch: (value: unknown) => T | undefined,\n\t): Promise<T | undefined> {\n\t\tlet start = 0;\n\t\twhile (true) {\n\t\t\tquery.set('start', String(start));\n\t\t\tconst { body } = await this.transport.request<{\n\t\t\t\tvalues?: unknown;\n\t\t\t\tisLastPage?: unknown;\n\t\t\t\tnextPageStart?: unknown;\n\t\t\t}>({\n\t\t\t\turl: `${url}?${query.toString()}`,\n\t\t\t\theaders: this.headers,\n\t\t\t});\n\t\t\tif (!Array.isArray(body?.values)) throw new BitbucketServerPullRequestWriteError('unknown');\n\n\t\t\tfor (const value of body.values as unknown[]) {\n\t\t\t\tconst result = match(value);\n\t\t\t\tif (result !== undefined) return result;\n\t\t\t}\n\t\t\tif (body.isLastPage === true) return undefined;\n\n\t\t\tconst next = body.nextPageStart;\n\t\t\tif (typeof next !== 'number' || !Number.isSafeInteger(next) || next <= start) {\n\t\t\t\tthrow new BitbucketServerPullRequestWriteError('unknown');\n\t\t\t}\n\n\t\t\tstart = next;\n\t\t}\n\t}\n\n\tprivate async readDefaultBranch(): Promise<string | undefined> {\n\t\tfor (const path of ['default-branch', 'branches/default']) {\n\t\t\ttry {\n\t\t\t\tconst { body } = await this.transport.request<{ id?: unknown }>({\n\t\t\t\t\turl: `${this.repoUrl}/${path}`,\n\t\t\t\t\theaders: this.headers,\n\t\t\t\t});\n\t\t\t\treturn getBranchName(body?.id);\n\t\t\t} catch (ex) {\n\t\t\t\tconst { reason } = toBitbucketServerPullRequestWriteFailure(ex);\n\t\t\t\tif (reason === 'no-connection') throw ex;\n\t\t\t\tif (reason !== 'not-found') return undefined;\n\t\t\t}\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\tprivate async readMergeability(number: number): Promise<RawMergeability> {\n\t\tconst { body } = await this.transport.request<RawMergeability>({\n\t\t\turl: `${this.pullRequestUrl(number)}/merge`,\n\t\t\theaders: this.headers,\n\t\t});\n\t\tif (body == null || typeof body !== 'object') throw new BitbucketServerPullRequestWriteError('unknown');\n\n\t\treturn body;\n\t}\n\n\tprivate async readMergeStrategies(): Promise<MergeStrategies> {\n\t\tlet settings: { mergeConfig?: { defaultStrategy?: unknown; strategies?: unknown } | null } | undefined;\n\t\ttry {\n\t\t\t({ body: settings } = await this.transport.request<typeof settings>({\n\t\t\t\turl: `${this.repoUrl}/settings/pull-requests`,\n\t\t\t\theaders: this.headers,\n\t\t\t}));\n\t\t} catch (ex) {\n\t\t\tconst { reason } = toBitbucketServerPullRequestWriteFailure(ex);\n\t\t\tif (reason === 'forbidden' || reason === 'not-found') return { strategies: [] };\n\n\t\t\tthrow ex;\n\t\t}\n\n\t\tconst config = settings?.mergeConfig;\n\t\tconst strategies = Array.isArray(config?.strategies)\n\t\t\t? (config.strategies as { id?: unknown; enabled?: unknown }[]).flatMap(strategy =>\n\t\t\t\t\tstrategy?.enabled === true && typeof strategy.id === 'string' && strategyIdPattern.test(strategy.id)\n\t\t\t\t\t\t? [strategy.id]\n\t\t\t\t\t\t: [],\n\t\t\t\t)\n\t\t\t: [];\n\t\tconst defaultStrategy = (config?.defaultStrategy as { id?: unknown } | null | undefined)?.id;\n\t\treturn {\n\t\t\tstrategies: strategies,\n\t\t\t...(typeof defaultStrategy === 'string' &&\n\t\t\t\tstrategies.includes(defaultStrategy) && { defaultStrategy: defaultStrategy }),\n\t\t};\n\t}\n\n\tprivate async sendForReceipt(\n\t\toptions: ExistingOptions,\n\t\tmethod: 'POST' | 'PUT',\n\t\turl: string,\n\t\tbody: object,\n\t\tgetStatus: (receipt: PullRequestRead) => 'updated' | 'declined' | 'reopened' | 'merged' | undefined,\n\t): Promise<BitbucketServerPullRequestWriteResult> {\n\t\tconst sent = await this.send(options, method, url, body);\n\t\tif (!sent.ok) return sent;\n\n\t\tconst receipt = this.toReadOrUndefined(sent.body, options.number);\n\t\tif (receipt == null || receipt.pullRequest.version <= options.expectedVersion) {\n\t\t\treturn { ok: false, reason: 'outcome-unknown' };\n\t\t}\n\n\t\tconst status = getStatus(receipt);\n\t\treturn status === undefined\n\t\t\t? { ok: false, reason: 'outcome-unknown' }\n\t\t\t: { ok: true, status: status, pullRequest: receipt.pullRequest };\n\t}\n\n\tprivate async send(\n\t\toptions: BitbucketServerPullRequestWriteOptions,\n\t\tmethod: 'POST' | 'PUT' | 'DELETE',\n\t\turl: string,\n\t\tbody: object,\n\t): Promise<{ ok: true; status: number; body: unknown } | (Failure & { existing?: unknown })> {\n\t\tif (!(await this.transport.isSessionCurrent())) return { ok: false, reason: 'no-connection' };\n\n\t\ttry {\n\t\t\tconst response = await this.transport.request<unknown>({\n\t\t\t\turl: url,\n\t\t\t\tmethod: method,\n\t\t\t\theaders: { ...this.headers, 'Content-Type': 'application/json' },\n\t\t\t\tbody: JSON.stringify(body),\n\t\t\t});\n\t\t\treturn { ok: true, status: response.status, body: response.body };\n\t\t} catch (ex) {\n\t\t\tconst failure = toBitbucketServerPullRequestWriteFailure(ex, options.action);\n\t\t\tconst detail = getBitbucketServerErrorDetail(ex);\n\t\t\treturn {\n\t\t\t\t...failure,\n\t\t\t\t...(failure.reason === 'policy-blocked' && detail.vetoes.length && { vetoes: detail.vetoes }),\n\t\t\t\t...(options.action === 'create' &&\n\t\t\t\t\tfailure.reason === 'conflict' &&\n\t\t\t\t\tdetail.existingPullRequest != null && { existing: detail.existingPullRequest }),\n\t\t\t};\n\t\t}\n\t}\n}\n\nfunction getBranchName(refId: unknown): string | undefined {\n\tif (typeof refId !== 'string' || !refId.startsWith('refs/heads/')) return undefined;\n\n\tconst name = refId.slice('refs/heads/'.length);\n\treturn isGitBranchName(name) ? name : undefined;\n}\n\nfunction toReviewers(value: unknown): { user: { name: string } }[] | undefined {\n\tif (!Array.isArray(value)) return undefined;\n\n\tconst reviewers: { user: { name: string } }[] = [];\n\tfor (const reviewer of value as ({ user?: { name?: unknown } | null } | null | undefined)[]) {\n\t\tconst name = reviewer?.user?.name;\n\t\tif (!isWriteIdentifier(name)) return undefined;\n\n\t\treviewers.push({ user: { name: name } });\n\t}\n\treturn reviewers;\n}\n\nfunction getMergeStateFailure(pullRequest: BitbucketServerWrittenPullRequest): FailureReason | undefined {\n\tif (pullRequest.state !== 'open') return 'conflict';\n\tif (pullRequest.draft) return 'policy-blocked';\n\tif (pullRequest.sourceSha == null || pullRequest.targetSha == null) return 'unsupported';\n\n\treturn undefined;\n}\n\nfunction getMergeabilityFailure(mergeability: RawMergeability): Failure | undefined {\n\tif (mergeability.conflicted === true || mergeability.outcome === 'CONFLICTED') {\n\t\treturn { ok: false, reason: 'conflict' };\n\t}\n\n\tconst vetoes = toVetoes(mergeability.vetoes);\n\tif ((Array.isArray(mergeability.vetoes) && mergeability.vetoes.length > 0) || mergeability.canMerge === false) {\n\t\treturn { ok: false, reason: 'policy-blocked', ...(vetoes.length && { vetoes: vetoes }) };\n\t}\n\n\treturn mergeability.canMerge === true ? undefined : { ok: false, reason: 'unknown' };\n}\n"],"mappings":";;;;AA6BA,MAAM,cAAc,CAAC,GAAG,CAAC;AAEzB,MAAM,aAAa,CAAC,GAAG,EAAE;AACzB,MAAM,oBAAoB;AAC1B,MAAM,cAAc;AACpB,MAAM,mBAAmB;AACzB,MAAM,oBAAoB;AAyD1B,SAAS,aAAa,OAAiC;CACtD,OAAO,OAAO,UAAU,YAAY,kBAAkB,KAAK,KAAK,KAAK,CAAC,cAAc,KAAK,KAAK;AAC/F;AAEA,SAAS,iBAAiB,OAAiC;CAC1D,OAAO,OAAO,UAAU,YAAY,YAAY,KAAK,KAAK,KAAK,CAAC,UAAU,KAAK,KAAK;AACrF;AAEA,SAAS,gBAAgB,OAAiC;CACzD,OAAO,OAAO,UAAU,YAAY,OAAO,UAAU,KAAK,KAAK,SAAS,KAAK,SAAS;AACvF;AAEA,SAAS,QAAQ,OAAiC;CACjD,OAAO,OAAO,UAAU,YAAY,MAAM,KAAK,CAAC,CAAC,SAAS;AAC3D;AAEA,SAAS,UAAU,OAAiC;CACnD,IAAI,OAAO,UAAU,YAAY,CAAC,kBAAkB,KAAK,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YAAY,cAChE,OAAO;EAAE,IAAI;EAAO,QAAQ;CAAW;CAGxC,MAAM,SAAS,SAAS,aAAa,MAAM;CAC3C,IAAK,MAAM,QAAQ,aAAa,MAAM,KAAK,aAAa,OAAO,SAAS,KAAM,aAAa,aAAa,OACvG,OAAO;EAAE,IAAI;EAAO,QAAQ;EAAkB,GAAI,OAAO,UAAU,EAAU,OAAO;CAAG;CAGxF,OAAO,aAAa,aAAa,OAAO,KAAA,IAAY;EAAE,IAAI;EAAO,QAAQ;CAAU;AACpF"}
@@ -2,9 +2,9 @@ import { chunk } from "../../../utils/array.js";
2
2
  import { isCancellationError } from "../../../utils/cancellation.js";
3
3
  import { batch, mapBounded, mapSettledBounded } from "../../../utils/promise.js";
4
4
  import { AuthenticationError, RequestNotFoundError } from "../../../git/errors.js";
5
+ import { uuid } from "../../../utils/crypto.js";
5
6
  import { parseGitRemoteUrl } from "../../../git/utils/remote.utils.js";
6
7
  import { getGitHubNoReplyAddressParts } from "../../../git/remotes/github.js";
7
- import { uuid } from "../../../utils/crypto.js";
8
8
  import "../../../git/models/pullRequest.js";
9
9
  import { decodeGitHubCheckRunId, fromGitHubCheckContextState, fromGitHubIssueOrPullRequestState, fromGitHubMergeQueueEntryState, fromGitHubMergeQueueRemoval, fromGitHubPullRequestMergeableState, fromGitHubPullRequestReviewDecision, fromGitHubPullRequestStatusCheckRollupState, toGitHubCheckRunId } from "../../git-github/models.js";
10
10
  import { IntegrationReadUnavailableError } from "../errors.js";
@@ -54,12 +54,13 @@ async function parseFetchResponseForApi(response, sentCredential, requestUrl = r
54
54
  }
55
55
  } catch (ex) {
56
56
  if (response.ok) throw ex;
57
- const retryAfter = response.status === 403 ? response.headers.get("retry-after") : null;
57
+ const header = response.status === 401 ? "x-ausername" : "retry-after";
58
+ const value = response.status === 401 || response.status === 403 ? response.headers.get(header) : null;
58
59
  throw Object.assign(/* @__PURE__ */ new Error(`(${response.status}) Unable to decode the provider response.`), {
59
60
  statusCode: response.status,
60
- ...retryAfter != null && { response: {
61
+ ...value != null && { response: {
61
62
  status: response.status,
62
- headers: { "retry-after": retryAfter }
63
+ headers: { [header]: value }
63
64
  } }
64
65
  });
65
66
  }
@@ -1 +1 @@
1
- {"version":3,"file":"providerApiClient.js","names":[],"sources":["../../../../../plus/integrations/src/providers/providerApiClient.ts"],"sourcesContent":["import { captureProviderRead } from '@gitkraken/provider-apis/read-provenance';\nimport { getAuthenticatedUser } from '../errors.js';\nimport type { ProviderRequestFunction, ProviderRequestOptions, ProviderRequestResponse } from './models.js';\nimport {\n\tAnonymousResponseError,\n\tgetProviderResponseBodyMessage,\n\tmarkRequestError,\n\tUnexpectedHtmlResponseError,\n} from './providerErrors.js';\n\nexport function createProviderApiRequest(\n\tfetch: (input: string | URL, init?: RequestInit) => Promise<Response>,\n\tuserAgent?: string,\n): ProviderRequestFunction {\n\treturn async <T>({ url, ...options }: ProviderRequestOptions): Promise<ProviderRequestResponse<T>> => {\n\t\ttry {\n\t\t\treturn await captureProviderRead(async () => {\n\t\t\t\tconst response = await fetch(url, {\n\t\t\t\t\t...options,\n\t\t\t\t\theaders: { ...(userAgent != null ? { 'User-Agent': userAgent } : {}), ...options.headers },\n\t\t\t\t});\n\t\t\t\treturn parseFetchResponseForApi<T>(response, () => hasAuthorization(options.headers), url);\n\t\t\t});\n\t\t} catch (ex) {\n\t\t\tthrow markRequestError(ex, { url: url, method: options.method });\n\t\t}\n\t};\n}\n\nexport async function parseFetchResponseForApi<T>(\n\tresponse: Response,\n\tsentCredential?: () => boolean,\n\trequestUrl = response.url,\n): Promise<ProviderRequestResponse<T>> {\n\tconst contentType = (response.headers.get('content-type') || '').toLowerCase();\n\n\tif (\n\t\tresponse.status !== 401 &&\n\t\tresponse.status !== 429 &&\n\t\tresponse.status < 500 &&\n\t\tgetAuthenticatedUser(response.headers) === 'anonymous' &&\n\t\tsentCredential?.() === true\n\t) {\n\t\tvoid response.body?.cancel().catch(() => undefined);\n\t\tthrow new AnonymousResponseError(response.status, {\n\t\t\theaders: Object.fromEntries(response.headers.entries()),\n\t\t\tstatus: response.status,\n\t\t});\n\t}\n\n\tlet body;\n\tlet servedHtml = false;\n\n\tconst headers = Object.fromEntries(response.headers.entries());\n\ttry {\n\t\tif (!response.ok && requestUrl === 'https://api.github.com/graphql') {\n\t\t\t// KEEP: GraphQL execution evidence can arrive with a missing or incorrect media type.\n\t\t\tbody = await response.json();\n\t\t\tif (body == null || typeof body !== 'object' || Array.isArray(body)) {\n\t\t\t\tthrow new Error('Expected a GitHub GraphQL response object.');\n\t\t\t}\n\t\t} else if (contentType.startsWith('application/json')) {\n\t\t\tconst text = await response.text();\n\t\t\tif (text.trimStart().startsWith('<')) {\n\t\t\t\tservedHtml = true;\n\t\t\t\tbody = text;\n\t\t\t} else {\n\t\t\t\tbody = text.trim().length > 0 ? JSON.parse(text) : null;\n\t\t\t}\n\t\t} else if (contentType.startsWith('text/') || contentType === '') {\n\t\t\tbody = await response.text();\n\t\t\tservedHtml = contentType.startsWith('text/html') && body.trim().length > 0;\n\t\t} else if (contentType.startsWith('application/vnd.github.raw+json')) {\n\t\t\tbody = await response.arrayBuffer();\n\t\t} else {\n\t\t\tvoid response.body?.cancel().catch(() => undefined);\n\t\t\tthrow new Error(`Unsupported content-type: ${contentType}`);\n\t\t}\n\t} catch (ex) {\n\t\tif (response.ok) throw ex;\n\n\t\tconst retryAfter = response.status === 403 ? response.headers.get('retry-after') : null;\n\t\tthrow Object.assign(new Error(`(${response.status}) Unable to decode the provider response.`), {\n\t\t\tstatusCode: response.status,\n\t\t\t...(retryAfter != null && {\n\t\t\t\tresponse: { status: response.status, headers: { 'retry-after': retryAfter } },\n\t\t\t}),\n\t\t});\n\t}\n\n\tconst result = {\n\t\tbody: body,\n\t\theaders: headers,\n\t\tstatus: response.status,\n\t\tstatusText: response.statusText,\n\t};\n\n\tif (response.ok && servedHtml) {\n\t\tthrow new UnexpectedHtmlResponseError(response.status, contentType, result);\n\t}\n\n\tif (!response.ok) {\n\t\tconst status = `(${response.status})${response.statusText ? ` ${response.statusText}` : ''}.`;\n\t\tconst detail = getProviderResponseBodyMessage(body);\n\t\tconst error = new Error(detail != null ? `${status} ${detail}` : status);\n\t\tObject.assign(error, { response: result });\n\t\tthrow error;\n\t}\n\n\treturn result;\n}\n\nfunction hasAuthorization(headers: ProviderRequestOptions['headers']): boolean {\n\tif (headers == null) return false;\n\n\treturn Object.entries(headers).some(([name, value]) => name.toLowerCase() === 'authorization' && Boolean(value));\n}\n"],"mappings":";;;;AAUA,SAAgB,yBACf,OACA,WAC0B;CAC1B,OAAO,OAAU,EAAE,KAAK,GAAG,cAA2E;EACrG,IAAI;GACH,OAAO,MAAM,oBAAoB,YAAY;IAK5C,OAAO,yBAA4B,MAJZ,MAAM,KAAK;KACjC,GAAG;KACH,SAAS;MAAE,GAAI,aAAa,OAAO,EAAE,cAAc,UAAU,IAAI,CAAC;MAAI,GAAG,QAAQ;KAAQ;IAC1F,CAAC,SACkD,iBAAiB,QAAQ,OAAO,GAAG,GAAG;GAC1F,CAAC;EACF,SAAS,IAAI;GACZ,MAAM,iBAAiB,IAAI;IAAO;IAAK,QAAQ,QAAQ;GAAO,CAAC;EAChE;CACD;AACD;AAEA,eAAsB,yBACrB,UACA,gBACA,aAAa,SAAS,KACgB;CACtC,MAAM,eAAe,SAAS,QAAQ,IAAI,cAAc,KAAK,GAAA,CAAI,YAAY;CAE7E,IACC,SAAS,WAAW,OACpB,SAAS,WAAW,OACpB,SAAS,SAAS,OAClB,qBAAqB,SAAS,OAAO,MAAM,eAC3C,iBAAiB,MAAM,MACtB;EACD,SAAc,MAAM,OAAO,CAAC,CAAC,YAAY,KAAA,CAAS;EAClD,MAAM,IAAI,uBAAuB,SAAS,QAAQ;GACjD,SAAS,OAAO,YAAY,SAAS,QAAQ,QAAQ,CAAC;GACtD,QAAQ,SAAS;EAClB,CAAC;CACF;CAEA,IAAI;CACJ,IAAI,aAAa;CAEjB,MAAM,UAAU,OAAO,YAAY,SAAS,QAAQ,QAAQ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AAI,CAAC,SAAS,IAAI;EACjB,MAAM,SAAS,IAAI,SAAS,OAAO,GAAG,SAAS,aAAa,IAAI,SAAS,eAAe,GAAG;EAC3F,MAAM,SAAS,+BAA+B,IAAI;EAClD,MAAM,QAAQ,IAAI,MAAM,UAAU,OAAO,GAAG,OAAO,GAAG,WAAW,MAAM;EACvE,OAAO,OAAO,OAAO,EAAE,UAAU,OAAO,CAAC;EACzC,MAAM;CACP;CAEA,OAAO;AACR;AAEA,SAAS,iBAAiB,SAAqD;CAC9E,IAAI,WAAW,MAAM,OAAO;CAE5B,OAAO,OAAO,QAAQ,OAAO,CAAC,CAAC,MAAM,CAAC,MAAM,WAAW,KAAK,YAAY,MAAM,mBAAmB,QAAQ,KAAK,CAAC;AAChH"}
1
+ {"version":3,"file":"providerApiClient.js","names":[],"sources":["../../../../../plus/integrations/src/providers/providerApiClient.ts"],"sourcesContent":["import { captureProviderRead } from '@gitkraken/provider-apis/read-provenance';\nimport { getAuthenticatedUser } from '../errors.js';\nimport type { ProviderRequestFunction, ProviderRequestOptions, ProviderRequestResponse } from './models.js';\nimport {\n\tAnonymousResponseError,\n\tgetProviderResponseBodyMessage,\n\tmarkRequestError,\n\tUnexpectedHtmlResponseError,\n} from './providerErrors.js';\n\nexport function createProviderApiRequest(\n\tfetch: (input: string | URL, init?: RequestInit) => Promise<Response>,\n\tuserAgent?: string,\n): ProviderRequestFunction {\n\treturn async <T>({ url, ...options }: ProviderRequestOptions): Promise<ProviderRequestResponse<T>> => {\n\t\ttry {\n\t\t\treturn await captureProviderRead(async () => {\n\t\t\t\tconst response = await fetch(url, {\n\t\t\t\t\t...options,\n\t\t\t\t\theaders: { ...(userAgent != null ? { 'User-Agent': userAgent } : {}), ...options.headers },\n\t\t\t\t});\n\t\t\t\treturn parseFetchResponseForApi<T>(response, () => hasAuthorization(options.headers), url);\n\t\t\t});\n\t\t} catch (ex) {\n\t\t\tthrow markRequestError(ex, { url: url, method: options.method });\n\t\t}\n\t};\n}\n\nexport async function parseFetchResponseForApi<T>(\n\tresponse: Response,\n\tsentCredential?: () => boolean,\n\trequestUrl = response.url,\n): Promise<ProviderRequestResponse<T>> {\n\tconst contentType = (response.headers.get('content-type') || '').toLowerCase();\n\n\tif (\n\t\tresponse.status !== 401 &&\n\t\tresponse.status !== 429 &&\n\t\tresponse.status < 500 &&\n\t\tgetAuthenticatedUser(response.headers) === 'anonymous' &&\n\t\tsentCredential?.() === true\n\t) {\n\t\tvoid response.body?.cancel().catch(() => undefined);\n\t\tthrow new AnonymousResponseError(response.status, {\n\t\t\theaders: Object.fromEntries(response.headers.entries()),\n\t\t\tstatus: response.status,\n\t\t});\n\t}\n\n\tlet body;\n\tlet servedHtml = false;\n\n\tconst headers = Object.fromEntries(response.headers.entries());\n\ttry {\n\t\tif (!response.ok && requestUrl === 'https://api.github.com/graphql') {\n\t\t\t// KEEP: GraphQL execution evidence can arrive with a missing or incorrect media type.\n\t\t\tbody = await response.json();\n\t\t\tif (body == null || typeof body !== 'object' || Array.isArray(body)) {\n\t\t\t\tthrow new Error('Expected a GitHub GraphQL response object.');\n\t\t\t}\n\t\t} else if (contentType.startsWith('application/json')) {\n\t\t\tconst text = await response.text();\n\t\t\tif (text.trimStart().startsWith('<')) {\n\t\t\t\tservedHtml = true;\n\t\t\t\tbody = text;\n\t\t\t} else {\n\t\t\t\tbody = text.trim().length > 0 ? JSON.parse(text) : null;\n\t\t\t}\n\t\t} else if (contentType.startsWith('text/') || contentType === '') {\n\t\t\tbody = await response.text();\n\t\t\tservedHtml = contentType.startsWith('text/html') && body.trim().length > 0;\n\t\t} else if (contentType.startsWith('application/vnd.github.raw+json')) {\n\t\t\tbody = await response.arrayBuffer();\n\t\t} else {\n\t\t\tvoid response.body?.cancel().catch(() => undefined);\n\t\t\tthrow new Error(`Unsupported content-type: ${contentType}`);\n\t\t}\n\t} catch (ex) {\n\t\tif (response.ok) throw ex;\n\n\t\tconst header = response.status === 401 ? 'x-ausername' : 'retry-after';\n\t\tconst value = response.status === 401 || response.status === 403 ? response.headers.get(header) : null;\n\t\tthrow Object.assign(new Error(`(${response.status}) Unable to decode the provider response.`), {\n\t\t\tstatusCode: response.status,\n\t\t\t...(value != null && { response: { status: response.status, headers: { [header]: value } } }),\n\t\t});\n\t}\n\n\tconst result = {\n\t\tbody: body,\n\t\theaders: headers,\n\t\tstatus: response.status,\n\t\tstatusText: response.statusText,\n\t};\n\n\tif (response.ok && servedHtml) {\n\t\tthrow new UnexpectedHtmlResponseError(response.status, contentType, result);\n\t}\n\n\tif (!response.ok) {\n\t\tconst status = `(${response.status})${response.statusText ? ` ${response.statusText}` : ''}.`;\n\t\tconst detail = getProviderResponseBodyMessage(body);\n\t\tconst error = new Error(detail != null ? `${status} ${detail}` : status);\n\t\tObject.assign(error, { response: result });\n\t\tthrow error;\n\t}\n\n\treturn result;\n}\n\nfunction hasAuthorization(headers: ProviderRequestOptions['headers']): boolean {\n\tif (headers == null) return false;\n\n\treturn Object.entries(headers).some(([name, value]) => name.toLowerCase() === 'authorization' && Boolean(value));\n}\n"],"mappings":";;;;AAUA,SAAgB,yBACf,OACA,WAC0B;CAC1B,OAAO,OAAU,EAAE,KAAK,GAAG,cAA2E;EACrG,IAAI;GACH,OAAO,MAAM,oBAAoB,YAAY;IAK5C,OAAO,yBAA4B,MAJZ,MAAM,KAAK;KACjC,GAAG;KACH,SAAS;MAAE,GAAI,aAAa,OAAO,EAAE,cAAc,UAAU,IAAI,CAAC;MAAI,GAAG,QAAQ;KAAQ;IAC1F,CAAC,SACkD,iBAAiB,QAAQ,OAAO,GAAG,GAAG;GAC1F,CAAC;EACF,SAAS,IAAI;GACZ,MAAM,iBAAiB,IAAI;IAAO;IAAK,QAAQ,QAAQ;GAAO,CAAC;EAChE;CACD;AACD;AAEA,eAAsB,yBACrB,UACA,gBACA,aAAa,SAAS,KACgB;CACtC,MAAM,eAAe,SAAS,QAAQ,IAAI,cAAc,KAAK,GAAA,CAAI,YAAY;CAE7E,IACC,SAAS,WAAW,OACpB,S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AO,SAAS,WAAW,MAAM,SAAS,QAAQ,IAAI,MAAM,IAAI;EAClG,MAAM,OAAO,uBAAO,IAAI,MAAM,IAAI,SAAS,OAAO,0CAA0C,GAAG;GAC9F,YAAY,SAAS;GACrB,GAAI,SAAS,QAAQ,EAAE,UAAU;IAAE,QAAQ,SAAS;IAAQ,SAAS,GAAG,SAAS,MAAM;GAAE,EAAE;EAC5F,CAAC;CACF;CAEA,MAAM,SAAS;EACR;EACG;EACT,QAAQ,SAAS;EACjB,YAAY,SAAS;CACtB;CAEA,IAAI,SAAS,MAAM,YAClB,MAAM,IAAI,4BAA4B,SAAS,QAAQ,aAAa,MAAM;CAG3E,IAAI,CAAC,SAAS,IAAI;EACjB,MAAM,SAAS,IAAI,SAAS,OAAO,GAAG,SAAS,aAAa,IAAI,SAAS,eAAe,GAAG;EAC3F,MAAM,SAAS,+BAA+B,IAAI;EAClD,MAAM,QAAQ,IAAI,MAAM,UAAU,OAAO,GAAG,OAAO,GAAG,WAAW,MAAM;EACvE,OAAO,OAAO,OAAO,EAAE,UAAU,OAAO,CAAC;EACzC,MAAM;CACP;CAEA,OAAO;AACR;AAEA,SAAS,iBAAiB,SAAqD;CAC9E,IAAI,WAAW,MAAM,OAAO;CAE5B,OAAO,OAAO,QAAQ,OAAO,CAAC,CAAC,MAAM,CAAC,MAAM,WAAW,KAAK,YAAY,MAAM,mBAAmB,QAAQ,KAAK,CAAC;AAChH"}
@@ -8,6 +8,7 @@ import { IssueTrackerWriteConnection } from "../models/issueTrackerWrites.js";
8
8
  import { AzureServerWorkItemWriteScope, AzureServicesWorkItemWriteScope } from "../models/workItemWrites.js";
9
9
  import { AzurePullRequestCreateCapabilityOptions, AzureServerPullRequestWriteScope } from "../models/azurePullRequestWrites.js";
10
10
  import { BitbucketPullRequestCreateCapabilityOptions } from "../models/bitbucketPullRequestWrites.js";
11
+ import { BitbucketServerPullRequestWriteScope } from "../models/bitbucketServerPullRequestWrites.js";
11
12
  import { IssueFilter } from "../providerFilters.js";
12
13
  import { ProviderOrganization } from "../results.js";
13
14
  import { ProviderPullRequestCount, ProviderPullRequestSearchPage } from "../models/pullRequestReads.js";
@@ -19,6 +20,7 @@ import { AzureWorkItemWriter } from "./azureWorkItemWrites.js";
19
20
  import { countBitbucketServerPullRequests, searchBitbucketServerPullRequestsPage } from "./bitbucket-server/pullRequestSearch.js";
20
21
  import { BitbucketPullRequestWriteLedger } from "./bitbucketPullRequestWriteLedger.js";
21
22
  import { BitbucketPullRequestWriter } from "./bitbucketPullRequestWrites.js";
23
+ import { BitbucketServerPullRequestWriter } from "./bitbucketServerPullRequestWrites.js";
22
24
  import { JiraIssueEtagResponse } from "./jiraIssueByKey.js";
23
25
  import { JiraIssueWriter } from "./jiraIssueWrites.js";
24
26
  import { LinearIssueEtagNode } from "./linearIssuesEtag.js";
@@ -35,6 +37,13 @@ export interface AsanaTaskPageOptions {
35
37
  /** See {@link GetIssuesOptions.sort}. Asana can order by nothing, so any sort is refused by the SDK. */
36
38
  sort?: IssueSorting;
37
39
  }
40
+ export type BitbucketServerWriteConnection = {
41
+ session: ProviderAuthenticationSession;
42
+ installationUrl: string;
43
+ getIgnoreSSLErrors: () => boolean | 'force';
44
+ isAccessEnabled: () => boolean;
45
+ isSessionCurrent: TrackedSession;
46
+ };
38
47
  export type AzureServerWriteConnection = {
39
48
  session: ProviderAuthenticationSession;
40
49
  route: {
@@ -188,6 +197,7 @@ export declare class ProvidersApi implements Disposable {
188
197
  baseUrl?: string;
189
198
  }): Promise<ProviderAccount | undefined>;
190
199
  getBitbucketPullRequestWriter(options: BitbucketPullRequestCreateCapabilityOptions, session: ProviderAuthenticationSession, isSessionCurrent: TrackedSession, ledger: BitbucketPullRequestWriteLedger): Promise<BitbucketPullRequestWriter>;
200
+ getBitbucketServerPullRequestWriter(options: BitbucketServerPullRequestWriteScope, connection: BitbucketServerWriteConnection): Promise<BitbucketServerPullRequestWriter>;
191
201
  getAzurePullRequestWriter(options: AzurePullRequestCreateCapabilityOptions, session: ProviderAuthenticationSession, isSessionCurrent: () => Promise<boolean>): Promise<AzurePullRequestWriter>;
192
202
  getAzureServerPullRequestWriter(options: AzureServerPullRequestWriteScope, connection: AzureServerWriteConnection): Promise<AzurePullRequestWriter>;
193
203
  getAzureWorkItemWriter(options: AzureServicesWorkItemWriteScope, session: ProviderAuthenticationSession, isSessionCurrent: () => Promise<boolean>): Promise<AzureWorkItemWriter>;
@@ -14,10 +14,13 @@ import { azureIssueStateCategory, azureWorkItemEtagFieldNames, encodeAzurePathSe
14
14
  import { AzureWorkItemDescriptionsCache } from "./azure/workItemDescriptions.js";
15
15
  import { AzureWorkItemStatesCache, getAzureWorkItemTypeStatesUrl, getAzureWorkItemTypesUrl, requireAzureWorkItemStateCategories, resolveAzureWorkItemStateCategory } from "./azure/workItemStateCategories.js";
16
16
  import { AzurePullRequestWriteError } from "./azurePullRequestWriteErrors.js";
17
+ import { sameIdentifier } from "./utils/writeInputs.js";
17
18
  import { WorkItemWriteNotDispatchedError } from "./azureWorkItemWriteErrors.js";
18
19
  import { AzurePullRequestWriter } from "./azurePullRequestWrites.js";
19
20
  import { BitbucketPullRequestWriteError } from "./bitbucketPullRequestWriteErrors.js";
20
21
  import { BitbucketPullRequestWriter } from "./bitbucketPullRequestWrites.js";
22
+ import { BitbucketServerPullRequestWriteError } from "./bitbucketServerPullRequestWriteErrors.js";
23
+ import { BitbucketServerPullRequestWriter } from "./bitbucketServerPullRequestWrites.js";
21
24
  import { requestJiraIssueByKey, requestJiraIssuesEtagFields } from "./jiraIssueByKey.js";
22
25
  import { JiraIssueWriter } from "./jiraIssueWrites.js";
23
26
  import { createProviderApiRequest } from "./providerApiClient.js";
@@ -26,7 +29,7 @@ import { requestLinearIssuesEtagFields } from "./linearIssuesEtag.js";
26
29
  import { requestBitbucketServerProjects, requestBitbucketServerRepositories } from "./bitbucket-server/discovery.js";
27
30
  import { countBitbucketServerPullRequests, searchBitbucketServerPullRequestsPage } from "./bitbucket-server/pullRequestSearch.js";
28
31
  import { copyReadProvenance } from "@gitkraken/provider-apis/read-provenance";
29
- import { AzureDevOps, GitIssueState, makeProviderAPIs } from "@gitkraken/provider-apis";
32
+ import { AzureDevOps, BitbucketServer, GitIssueState, makeProviderAPIs } from "@gitkraken/provider-apis";
30
33
  //#region ../plus/integrations/src/providers/providersApi.ts
31
34
  const repoNotFoundMessage = /^Repository .+ not found$/i;
32
35
  function isGraphQLErrors(ex) {
@@ -804,6 +807,47 @@ var ProvidersApi = class {
804
807
  getBitbucketPullRequestWriter(options, session, isSessionCurrent, ledger) {
805
808
  return BitbucketPullRequestWriter.connect((o) => o.method != null && o.method !== "GET" && isSessionCurrent.isRetired() ? Promise.reject(new BitbucketPullRequestWriteError("no-connection")) : this.request(o), session.accessToken, options, isSessionCurrent, ledger);
806
809
  }
810
+ async getBitbucketServerPullRequestWriter(options, connection) {
811
+ const http = this.authenticationService.ctx.http;
812
+ const canRequest = () => connection.isAccessEnabled() && !connection.isSessionCurrent.isRetired();
813
+ if (!await connection.isSessionCurrent() || !canRequest()) throw new BitbucketServerPullRequestWriteError("no-connection");
814
+ const request = async (o) => {
815
+ const ignoreSSL = connection.getIgnoreSSLErrors();
816
+ const verifyRead = () => {
817
+ if ((o.method == null || o.method === "GET") && !canRequest()) throw new BitbucketServerPullRequestWriteError("no-connection");
818
+ };
819
+ let response;
820
+ try {
821
+ response = await http.wrapForForcedInsecureSSL(ignoreSSL, () => {
822
+ if (!canRequest() || ignoreSSL !== connection.getIgnoreSSLErrors()) throw new BitbucketServerPullRequestWriteError("no-connection");
823
+ return this.request({
824
+ ...o,
825
+ redirect: "error"
826
+ });
827
+ });
828
+ } catch (ex) {
829
+ verifyRead();
830
+ throw ex;
831
+ }
832
+ verifyRead();
833
+ return response;
834
+ };
835
+ return BitbucketServerPullRequestWriter.connect({
836
+ request,
837
+ accessToken: connection.session.accessToken,
838
+ installationUrl: connection.installationUrl,
839
+ connectionId: connection.session.id,
840
+ isSessionCurrent: connection.isSessionCurrent,
841
+ isConnectionCurrent: canRequest,
842
+ getAccountId: async (username) => {
843
+ const { data: user } = await new BitbucketServer({ request }).getCurrentUser({}, {
844
+ token: connection.session.accessToken,
845
+ baseUrl: `${connection.installationUrl}/rest/api/1.0`
846
+ });
847
+ return user != null && sameIdentifier(user.username, username) ? user.id : void 0;
848
+ }
849
+ }, options);
850
+ }
807
851
  getAzurePullRequestWriter(options, session, isSessionCurrent) {
808
852
  return AzurePullRequestWriter.connect(this.request, {
809
853
  accessToken: session.accessToken,