@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
|
@@ -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,MAA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aAAa,QAAQ,YAAY,aAAa,MAAM,OAAO;AAG5E;AAEA,SAAS,uBAAuB,cAAoD;CACnF,IAAI,aAAa,eAAe,QAAQ,aAAa,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"}
|
|
@@ -7,8 +7,10 @@ import { Account } from "../../../git/models/author.js";
|
|
|
7
7
|
import { ProviderAuthenticationSession } from "../authentication/models.js";
|
|
8
8
|
import { IssuesSelfManagedHostIntegrationId } from "../constants.js";
|
|
9
9
|
import { IntegrationAuthenticationProviderDescriptor } from "../authentication/integrationAuthenticationProvider.js";
|
|
10
|
+
import { IssueTrackerWriteConnection } from "../models/issueTrackerWrites.js";
|
|
10
11
|
import { IntegrationKey } from "../models/publicIntegration.js";
|
|
11
12
|
import { IntegrationServiceContext } from "../context.js";
|
|
13
|
+
import { JiraIssueWriter } from "./jiraIssueWrites.js";
|
|
12
14
|
import { ProvidersApi } from "./providersApi.js";
|
|
13
15
|
import { AccountWideIssuesResult, IssuesForProjectOptions, ProjectIssuesDrain, ProjectIssuesRequest, SearchMyIssuesOptions } from "../models/issueReads.js";
|
|
14
16
|
import { IssuesIntegration } from "../models/issuesIntegration.js";
|
|
@@ -39,6 +41,13 @@ export declare class JiraServerIntegration extends IssuesIntegration<IssuesSelfM
|
|
|
39
41
|
readonly name: string;
|
|
40
42
|
constructor(ctx: IntegrationServiceContext, authenticationService: IntegrationAuthenticationService, getProvidersApi: () => Promise<ProvidersApi>, didChangeConnection: Emitter<IntegrationConnectionChangeEvent>, _domain: string);
|
|
41
43
|
get domain(): string;
|
|
44
|
+
protected getSessionFingerprint(session: ProviderAuthenticationSession): string;
|
|
45
|
+
getIssueWriter(options: Extract<IssueTrackerWriteConnection, {
|
|
46
|
+
providerId: IssuesSelfManagedHostIntegrationId.JiraServer;
|
|
47
|
+
}>, session: ProviderAuthenticationSession, isSelectionCurrent: () => boolean): Promise<{
|
|
48
|
+
writer: JiraIssueWriter;
|
|
49
|
+
isCurrent: () => boolean;
|
|
50
|
+
}>;
|
|
42
51
|
/**
|
|
43
52
|
* The URL every request for this connection is addressed to, built from the SESSION's domain rather than
|
|
44
53
|
* the integration's.
|
|
@@ -61,6 +70,7 @@ export declare class JiraServerIntegration extends IssuesIntegration<IssuesSelfM
|
|
|
61
70
|
autolinks(): Promise<AutolinkReference[]>;
|
|
62
71
|
private buildAutolinks;
|
|
63
72
|
private buildAutolinksCore;
|
|
73
|
+
protected getProviderCurrentAccount(session: ProviderAuthenticationSession): Promise<Account | undefined>;
|
|
64
74
|
protected getProviderAccountForResource(session: ProviderAuthenticationSession, _resource: JiraServerResourceDescriptor): Promise<Account | undefined>;
|
|
65
75
|
protected getProviderResourcesForUser(session: ProviderAuthenticationSession, _force?: boolean): Promise<JiraServerResourceDescriptor[] | undefined>;
|
|
66
76
|
/** Expires, and is dropped on a re-sync, so a project created or deleted mid-session is picked up (#5907). */
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Logger as _logger } from "../../../utils/logger.js";
|
|
2
|
+
import { fnv1aHash64 } from "../../../utils/hash.js";
|
|
2
3
|
import "../constants.js";
|
|
3
4
|
import { isJiraServerMissingProjectError } from "./providerErrors.js";
|
|
4
5
|
import { isIncompleteCollection, toCollectionScopeFailure } from "../collectionMetadata.js";
|
|
5
6
|
import { mergeCollectionMetadata } from "./utils/providerPaging.js";
|
|
6
7
|
import { providersMetadata } from "./metadata.js";
|
|
7
8
|
import { areDomainsOnSameHost, baseUrlFromDomain } from "../utils/domain.utils.js";
|
|
8
|
-
import { toTokenWithInfo } from "../authentication/models.js";
|
|
9
|
+
import { sessionExpiry, toTokenWithInfo } from "../authentication/models.js";
|
|
9
10
|
import { toAccount, toIssueShape, toProviderIssueStates } from "./models.js";
|
|
10
11
|
import { createIssueAutolinkReferences } from "./utils/issueAutolinks.js";
|
|
11
12
|
import { IssuesIntegration, groupProjectIssuesSearches, toProjectsCollection } from "../models/issuesIntegration.js";
|
|
@@ -60,6 +61,17 @@ var JiraServerIntegration = class extends IssuesIntegration {
|
|
|
60
61
|
get domain() {
|
|
61
62
|
return this._domain;
|
|
62
63
|
}
|
|
64
|
+
getSessionFingerprint(session) {
|
|
65
|
+
return fnv1aHash64(JSON.stringify([this.apiBaseUrlFor(session), session.accessToken]));
|
|
66
|
+
}
|
|
67
|
+
async getIssueWriter(options, session, isSelectionCurrent) {
|
|
68
|
+
const isSessionCurrent = this.authenticationService.trackStoredSession(this.id, session, true);
|
|
69
|
+
const isCurrent = () => isSelectionCurrent() && this.isIntegrationAccessEnabled() && !isSessionCurrent.isRetired() && sessionExpiry(session.expiresAt) > Date.now();
|
|
70
|
+
return {
|
|
71
|
+
writer: await (await this.getProvidersApi()).getJiraServerIssueWriter(options, session, isCurrent, isSessionCurrent, () => this.getIgnoreSSLErrors()),
|
|
72
|
+
isCurrent
|
|
73
|
+
};
|
|
74
|
+
}
|
|
63
75
|
/**
|
|
64
76
|
* The URL every request for this connection is addressed to, built from the SESSION's domain rather than
|
|
65
77
|
* the integration's.
|
|
@@ -136,6 +148,9 @@ var JiraServerIntegration = class extends IssuesIntegration {
|
|
|
136
148
|
return this._autolinks.get(cacheKey)?.autolinks ?? [];
|
|
137
149
|
}
|
|
138
150
|
}
|
|
151
|
+
getProviderCurrentAccount(session) {
|
|
152
|
+
return this.getProviderAccountForResource(session, this.resourceFor(session));
|
|
153
|
+
}
|
|
139
154
|
async getProviderAccountForResource(session, _resource) {
|
|
140
155
|
const user = await (await this.getProvidersApi()).getJiraServerCurrentUser(toTokenWithInfo(this.id, session), this.apiBaseUrlFor(session));
|
|
141
156
|
if (user == null) return void 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jira-server.js","names":[],"sources":["../../../../../plus/integrations/src/providers/jira-server.ts"],"sourcesContent":["import type { CollectionMetadata } from '@gitkraken/provider-apis';\nimport { JIRA_MAX_PROJECT_KEYS_PER_REQUEST } from '@gitkraken/provider-apis';\nimport type { Account } from '@gitlens/git/models/author.js';\nimport type { AutolinkReference } from '@gitlens/git/models/autolink.js';\nimport type { Issue, IssueProjection, IssueShape } from '@gitlens/git/models/issue.js';\nimport type { IssueOrPullRequest } from '@gitlens/git/models/issueOrPullRequest.js';\nimport type { IssueResourceDescriptor } from '@gitlens/git/models/resourceDescriptor.js';\nimport type { Emitter } from '@gitlens/utils/event.js';\nimport { Logger } from '@gitlens/utils/logger.js';\nimport type { IntegrationAuthenticationProviderDescriptor } from '../authentication/integrationAuthenticationProvider.js';\nimport type { IntegrationAuthenticationService } from '../authentication/integrationAuthenticationService.js';\nimport type { ProviderAuthenticationSession } from '../authentication/models.js';\nimport { toTokenWithInfo } from '../authentication/models.js';\nimport { isIncompleteCollection, toCollectionScopeFailure } from '../collectionMetadata.js';\nimport { IssuesSelfManagedHostIntegrationId } from '../constants.js';\nimport type { IntegrationServiceContext } from '../context.js';\nimport type { IntegrationConnectionChangeEvent } from '../integrationService.js';\nimport type {\n\tAccountWideIssuesResult,\n\tIssuesForProjectOptions,\n\tProjectIssuesDrain,\n\tProjectIssuesRequest,\n\tSearchMyIssuesOptions,\n} from '../models/issueReads.js';\nimport { groupProjectIssuesSearches, IssuesIntegration, toProjectsCollection } from '../models/issuesIntegration.js';\nimport type { IntegrationKey } from '../models/publicIntegration.js';\nimport { areDomainsOnSameHost, baseUrlFromDomain } from '../utils/domain.utils.js';\nimport { providersMetadata } from './metadata.js';\nimport type { ProviderApiCollectionResult } from './models.js';\nimport { toAccount, toIssueShape, toProviderIssueStates } from './models.js';\nimport { isJiraServerMissingProjectError } from './providerErrors.js';\nimport type { ProvidersApi } from './providersApi.js';\nimport { DiscoveryCache, discoveryCacheTtl } from './utils/discoveryCache.js';\nimport { createIssueAutolinkReferences } from './utils/issueAutolinks.js';\nimport type { JiraDrainOptions, JiraIssuePageFetcher } from './utils/jiraIssueDrains.js';\nimport {\n\tdrainJiraIssues,\n\treadUserScopedJiraIssues,\n\tsearchJiraProjectIssues,\n\tsummarizePageMetadata,\n\ttoUniqueJiraIssueShapes,\n\twithFailureScope,\n} from './utils/jiraIssueDrains.js';\nimport { mergeCollectionMetadata } from './utils/providerPaging.js';\n\nconst metadata = providersMetadata[IssuesSelfManagedHostIntegrationId.JiraServer];\nconst authProvider = Object.freeze({ id: metadata.id, scopes: metadata.scopes });\nconst maxPagesPerRequest = 10;\n\n/**\n * Every clause is scoped by the HANDLE, and `options.userId` is deliberately ignored here — the one\n * place this provider diverges from Jira Cloud's, which applies it to `assignee`/`creator` (#5857).\n *\n * The two are not interchangeable because `Account.id` means something different per deployment. On\n * Cloud it is the `accountId`, which JQL resolves, so scoping by it fixes the deactivated-account case\n * where the display name no longer resolves. On Server it is the user KEY (`JIRAUSER10224`), which JQL\n * does not resolve at all: measured against a live Jira Server 8.20.13 site, `assignee in\n * (\"JIRAUSER10224\")` returns 0 with `\"The value 'JIRAUSER10224' does not exist for the field\n * 'assignee'\"` — the identical warning a genuinely nonexistent user produces — while the username and\n * the display name both return the real 4.\n *\n * So applying `userId` here would silently empty the read rather than harden it. Do not \"fix\" this\n * asymmetry to match Cloud without re-measuring against a Server instance.\n *\n * The handle itself is already the right one: `provider-apis` 0.60.0 maps `Account.username` from the\n * Server payload's `name` (falling back to `displayName` when absent), so these clauses are scoped by the\n * real username rather than a display name (GKDEV-3629). That is what makes the `mention` clause work at\n * all — it is a free-text `comment ~ \"...\"` over comment bodies, and a Jira mention is stored as\n * `[~username]`, which a display name never matches.\n */\nfunction toUserIdentities(user: string): { userField: string; mention: string } {\n\treturn { userField: user, mention: user };\n}\n\n/**\n * The single resource a Jira Server connection has: the instance itself.\n *\n * Jira Cloud's account spans many sites, so its resources come from an API call that lists them. A\n * self-hosted instance IS the one site the connection addresses, so there is nothing to enumerate — this\n * descriptor is synthesized from the configured host. Modelling it as a resource anyway keeps the\n * resource → project contract of {@link IssuesIntegration} intact, so every tracker read (`listOrgs`,\n * `listProjects`, `listIssueTrackerIssuesPage`) works unchanged.\n */\nexport interface JiraServerResourceDescriptor extends IssueResourceDescriptor {\n\turl: string;\n}\n\nexport interface JiraServerProjectDescriptor extends IssueResourceDescriptor {\n\tresourceId: string;\n}\n\nexport class JiraServerIntegration extends IssuesIntegration<IssuesSelfManagedHostIntegrationId.JiraServer> {\n\treadonly authProvider: IntegrationAuthenticationProviderDescriptor = authProvider;\n\treadonly id = IssuesSelfManagedHostIntegrationId.JiraServer;\n\tprotected readonly key: IntegrationKey<IssuesSelfManagedHostIntegrationId.JiraServer>;\n\treadonly name: string = 'Jira Data Center';\n\n\tconstructor(\n\t\tctx: IntegrationServiceContext,\n\t\tauthenticationService: IntegrationAuthenticationService,\n\t\tgetProvidersApi: () => Promise<ProvidersApi>,\n\t\tdidChangeConnection: Emitter<IntegrationConnectionChangeEvent>,\n\t\tprivate readonly _domain: string,\n\t) {\n\t\tsuper(ctx, authenticationService, getProvidersApi, didChangeConnection);\n\t\tthis.key = `${this.id}:${this._domain}`;\n\t}\n\n\tget domain(): string {\n\t\treturn this._domain;\n\t}\n\n\t/**\n\t * The URL every request for this connection is addressed to, built from the SESSION's domain rather than\n\t * the integration's.\n\t *\n\t * `this.domain` is the host-keyed identity — `IntegrationService.get()` runs it through `hostFromDomain`\n\t * so one host can't build two instances — which means it has had any context path stripped, and so has\n\t * `session.domain`, which is stored as that same normalized host. Jira Data Center officially supports\n\t * being mounted below a context path (`https://jira.example.com/jira`), so the address comes from\n\t * {@link ProviderAuthenticationSession.baseUrl}, which carries the configured value verbatim; it falls\n\t * back to the host when the backend reported nothing more, which is the common case.\n\t *\n\t * Takes the session rather than reading `_session` so a per-connection (multi-account) read is addressed\n\t * to the host of the connection it resolved, not to whichever one happens to be current.\n\t */\n\tprotected apiBaseUrlFor(session: ProviderAuthenticationSession | undefined): string {\n\t\tconst configured = baseUrlFromDomain(session?.baseUrl, session?.protocol);\n\t\t// A `baseUrl` from another host is not this connection's address — refuse it rather than routing this\n\t\t// integration's reads somewhere its key never named.\n\t\tif (configured != null && areDomainsOnSameHost(session?.baseUrl, this.domain)) return configured;\n\n\t\treturn (\n\t\t\tbaseUrlFromDomain(session?.domain, session?.protocol) ??\n\t\t\tbaseUrlFromDomain(this.domain, session?.protocol) ??\n\t\t\t`${session?.protocol ?? 'https:'}//${this.domain}`\n\t\t);\n\t}\n\n\t/** The one resource this connection has — see {@link JiraServerResourceDescriptor}. */\n\tprivate resourceFor(session: ProviderAuthenticationSession | undefined): JiraServerResourceDescriptor {\n\t\treturn { id: this.domain, key: this.domain, name: this.domain, url: this.apiBaseUrlFor(session) };\n\t}\n\n\tprivate readonly _autolinks = new Map<string, { autolinks: AutolinkReference[]; builtAt: number }>();\n\tprivate readonly _autolinksBuilds = new Map<string, Promise<AutolinkReference[]>>();\n\n\toverride async autolinks(): Promise<AutolinkReference[]> {\n\t\tconst generation = this.discoveryGeneration;\n\t\tconst connected = this.maybeConnected ?? (await this.isConnected());\n\t\tif (!connected || this._session == null) return [];\n\t\tif (!this.isResolvedSessionCurrent(this._session, generation)) return [];\n\n\t\tconst session = this._session;\n\t\tconst cacheKey = this.projectsCacheKey(session);\n\t\tconst cached = this._autolinks.get(cacheKey);\n\t\tif (this.connectionExpired === true) return cached?.autolinks ?? [];\n\t\tif (cached == null) return this.buildAutolinks(session);\n\n\t\tif (Date.now() - cached.builtAt >= discoveryCacheTtl) {\n\t\t\tvoid this.buildAutolinks(session);\n\t\t}\n\t\treturn cached.autolinks;\n\t}\n\n\tprivate buildAutolinks(session: ProviderAuthenticationSession): Promise<AutolinkReference[]> {\n\t\tconst cacheKey = this.projectsCacheKey(session);\n\t\tlet build = this._autolinksBuilds.get(cacheKey);\n\t\tif (build == null) {\n\t\t\tbuild = this.buildAutolinksCore(session).finally(() => {\n\t\t\t\tif (this._autolinksBuilds.get(cacheKey) === build) {\n\t\t\t\t\tthis._autolinksBuilds.delete(cacheKey);\n\t\t\t\t}\n\t\t\t});\n\t\t\tthis._autolinksBuilds.set(cacheKey, build);\n\t\t}\n\t\treturn build;\n\t}\n\n\tprivate async buildAutolinksCore(session: ProviderAuthenticationSession): Promise<AutolinkReference[]> {\n\t\tconst cacheKey = this.projectsCacheKey(session);\n\t\tconst generation = this._projects.generation;\n\t\ttry {\n\t\t\tconst resource = this.resourceFor(session);\n\t\t\tconst result = await this.getProjectsForResourcesWithMetadataResult([resource]);\n\t\t\tif (this._projects.generation !== generation) return [];\n\t\t\tif (result?.value == null || result.error != null || isIncompleteCollection(result.value.metadata)) {\n\t\t\t\treturn this._autolinks.get(cacheKey)?.autolinks ?? [];\n\t\t\t}\n\n\t\t\tconst autolinks: AutolinkReference[] = [];\n\t\t\tfor (const project of result.value.values) {\n\t\t\t\tif (project.key === project.id) continue;\n\n\t\t\t\tautolinks.push(\n\t\t\t\t\t...createIssueAutolinkReferences(\n\t\t\t\t\t\tproject.key,\n\t\t\t\t\t\t`${resource.url}/browse/${project.key}-<num>`,\n\t\t\t\t\t\tresource,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis._autolinks.set(cacheKey, { autolinks: autolinks, builtAt: Date.now() });\n\t\t\treturn autolinks;\n\t\t} catch (ex) {\n\t\t\tLogger.error(ex, 'JiraServerIntegration.autolinks');\n\t\t\treturn this._autolinks.get(cacheKey)?.autolinks ?? [];\n\t\t}\n\t}\n\n\tprotected override async getProviderAccountForResource(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resource: JiraServerResourceDescriptor,\n\t): Promise<Account | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst user = await api.getJiraServerCurrentUser(toTokenWithInfo(this.id, session), this.apiBaseUrlFor(session));\n\n\t\tif (user == null) return undefined;\n\t\treturn toAccount(user, this);\n\t}\n\n\tprotected override getProviderResourcesForUser(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_force?: boolean,\n\t): Promise<JiraServerResourceDescriptor[] | undefined> {\n\t\t// Synthesized from the configured host rather than fetched, so there is nothing to cache or force.\n\t\treturn Promise.resolve([this.resourceFor(session)]);\n\t}\n\n\t/** Expires, and is dropped on a re-sync, so a project created or deleted mid-session is picked up (#5907). */\n\tprivate readonly _projects = new DiscoveryCache<JiraServerProjectDescriptor[]>();\n\tprivate readonly _projectReads = new Map<string, Promise<JiraServerProjectDescriptor[] | undefined>>();\n\tprotected override getProviderProjectsForResources(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresources: JiraServerResourceDescriptor[],\n\t): Promise<JiraServerProjectDescriptor[] | undefined> {\n\t\t// Every resource here is this instance (see `getProviderResourcesForUser`), so one read serves them\n\t\t// all; a caller that passes none is asking for nothing.\n\t\tif (resources.length === 0) return Promise.resolve([]);\n\n\t\tconst cacheKey = this.projectsCacheKey(session);\n\t\tconst cached = this._projects.get(cacheKey);\n\t\tif (cached != null) return Promise.resolve(cached);\n\n\t\tlet read = this._projectReads.get(cacheKey);\n\t\tif (read == null) {\n\t\t\tread = this.readProjectsCached(session, cacheKey).finally(() => {\n\t\t\t\tif (this._projectReads.get(cacheKey) === read) {\n\t\t\t\t\tthis._projectReads.delete(cacheKey);\n\t\t\t\t}\n\t\t\t});\n\t\t\tthis._projectReads.set(cacheKey, read);\n\t\t}\n\t\treturn read;\n\t}\n\n\tprivate async readProjectsCached(\n\t\tsession: ProviderAuthenticationSession,\n\t\tcacheKey: string,\n\t): Promise<JiraServerProjectDescriptor[] | undefined> {\n\t\tconst generation = this._projects.generation;\n\t\tconst descriptors = await this.readProjects(session);\n\t\tif (descriptors == null) return undefined;\n\n\t\tif (this._projects.set(cacheKey, descriptors, { generation: generation }) !== false) {\n\t\t\tthis._autolinks.delete(cacheKey);\n\t\t}\n\n\t\treturn descriptors;\n\t}\n\n\tprotected override async getProviderUncachedProjectsForResourcesWithMetadata(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresources: JiraServerResourceDescriptor[],\n\t): Promise<ProviderApiCollectionResult<JiraServerProjectDescriptor>> {\n\t\tif (resources.length === 0) return { values: [] };\n\n\t\treturn toProjectsCollection(await this.readProjects(session));\n\t}\n\n\tprivate async readProjects(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<JiraServerProjectDescriptor[] | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst projects = await api.getJiraServerProjects(\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t);\n\t\tif (projects == null) return undefined;\n\t\tif (projects.length === 0) {\n\t\t\t// Jira can serve anonymous empty projects after rejection without an identifying response header.\n\t\t\tconst account = await this.getProviderAccountForResource(session, this.resourceFor(session));\n\t\t\tif ((account?.username ?? account?.name) == null) return undefined;\n\t\t}\n\n\t\tconst resourceId = this.resourceFor(session).id;\n\t\treturn projects.map<JiraServerProjectDescriptor>(p => ({\n\t\t\tid: p.id,\n\t\t\t// The project key, which selects the project (`listProjects`' `name`) and is what an issue key starts\n\t\t\t// with. The SDK does not validate it, so a missing or blank one falls back to the numeric id, never to the\n\t\t\t// display name, which can equal another project's key. The reads below still address the project by\n\t\t\t// `id`, which no other project can share.\n\t\t\tkey: p.key?.trim() || p.id,\n\t\t\tname: p.name,\n\t\t\tresourceId: resourceId,\n\t\t}));\n\t}\n\n\tprotected override async getProviderIssuesForProject(\n\t\tsession: ProviderAuthenticationSession,\n\t\tproject: JiraServerProjectDescriptor,\n\t\toptions?: IssuesForProjectOptions,\n\t): Promise<IssueShape[] | undefined> {\n\t\treturn (await this.getProviderIssuesForProjectWithTruncation(session, project, options))?.values;\n\t}\n\n\tprotected override async getProviderIssuesForProjectWithTruncation(\n\t\tsession: ProviderAuthenticationSession,\n\t\tproject: JiraServerProjectDescriptor,\n\t\toptions?: IssuesForProjectOptions,\n\t): Promise<ProjectIssuesDrain | undefined> {\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\t\tconst api = await this.getProvidersApi();\n\t\tconst baseUrl = this.apiBaseUrlFor(session);\n\n\t\t// The same drain as Jira Cloud's (`jiraIssueDrains.ts`): page to a defensive backstop, and report `truncated`\n\t\t// plus a structured failure rather than discarding an already-fetched prefix.\n\t\tconst states = toProviderIssueStates(options?.state);\n\t\t// The numeric project id, not the name: JQL resolves `project = \"<value>\"` against key first, so a display\n\t\t// name that matches another project's key reads that project's issues instead. A Jira project key must begin\n\t\t// with a letter, so a purely numeric value can only be an id.\n\t\tconst fetchPage: JiraIssuePageFetcher = (scope, cursor) =>\n\t\t\tapi.getJiraServerIssuesForProjectPaged(tokenWithInfo, baseUrl, project.id, {\n\t\t\t\t...scope,\n\t\t\t\tcursor: cursor,\n\t\t\t\tstates: states,\n\t\t\t\tsort: options?.sort,\n\t\t\t});\n\t\tconst drainOptions: JiraDrainOptions = {\n\t\t\tmaxPages: maxPagesPerRequest,\n\t\t\t// Scoped by key, as on Jira Cloud: the id addresses the read, the key is how a consumer names the project.\n\t\t\tfailureScope: { providerId: this.id, resourceId: project.resourceId, projectId: project.key },\n\t\t\tproviderName: 'Jira Server',\n\t\t\t// A project this connection can no longer see (deleted, or its browse permission removed) holds\n\t\t\t// no issues for it, and the project list that named it is stale: drop that list so the next read\n\t\t\t// re-reads it, instead of failing the whole provider on every read until a restart (#5907).\n\t\t\tisEmptyFailure: ex => {\n\t\t\t\tif (!isJiraServerMissingProjectError(ex)) return false;\n\n\t\t\t\tLogger.warn(`Jira Server project '${project.name}' (${project.id}) no longer exists or is not visible`);\n\t\t\t\tthis.invalidateDiscoveryCaches();\n\t\t\t\treturn true;\n\t\t\t},\n\t\t};\n\n\t\tif (options?.user != null) {\n\t\t\tconst read = await readUserScopedJiraIssues(\n\t\t\t\tfetchPage,\n\t\t\t\toptions.filters,\n\t\t\t\ttoUserIdentities(options.user),\n\t\t\t\tdrainOptions,\n\t\t\t);\n\t\t\tconst values = toUniqueJiraIssueShapes(read.issues, this);\n\t\t\tconst drain = { values: values, metadata: read.metadata, scope: drainOptions.failureScope };\n\t\t\t// `recovery: 'none'` for the whole set: the filter branches merge here, so even a pure backstop in one\n\t\t\t// branch is not fixable by narrowing this read's scope.\n\t\t\treturn read.truncated ? { ...drain, truncated: true, recovery: 'none' } : { ...drain, truncated: false };\n\t\t}\n\n\t\tconst unscoped = await drainJiraIssues(fetchPage, {}, drainOptions);\n\t\tconst values = unscoped.issues\n\t\t\t.map(issue => toIssueShape(issue, this, { projection: 'project' }))\n\t\t\t.filter((result): result is IssueShape => result !== undefined);\n\t\tconst drain = { values: values, metadata: unscoped.metadata, scope: drainOptions.failureScope };\n\t\treturn unscoped.status !== 'complete'\n\t\t\t? { ...drain, truncated: true, recovery: unscoped.status === 'backstop' ? 'narrow-scope' : 'none' }\n\t\t\t: { ...drain, truncated: false };\n\t}\n\n\t/**\n\t * Searches the instance's projects together for a user-scoped read, as Jira Cloud does per site: one JQL names\n\t * up to {@link JIRA_MAX_PROJECT_KEYS_PER_REQUEST} projects of one user scope. An unscoped read stays per project,\n\t * since its backstop is reported as `narrow-scope` per project.\n\t */\n\tprotected override getProjectIssuesSearches(\n\t\trequests: readonly ProjectIssuesRequest<JiraServerProjectDescriptor>[],\n\t): number[][] | undefined {\n\t\treturn groupProjectIssuesSearches(\n\t\t\trequests,\n\t\t\t({ options }) =>\n\t\t\t\toptions.user != null\n\t\t\t\t\t? [options.user, options.sort ?? '', options.state ?? '', options.filters?.join(',') ?? ''].join(\n\t\t\t\t\t\t\t'\\0',\n\t\t\t\t\t\t)\n\t\t\t\t\t: undefined,\n\t\t\tJIRA_MAX_PROJECT_KEYS_PER_REQUEST,\n\t\t);\n\t}\n\n\tprotected override async searchProviderProjectIssues(\n\t\tsession: ProviderAuthenticationSession,\n\t\trequests: readonly ProjectIssuesRequest<JiraServerProjectDescriptor>[],\n\t): Promise<IssueShape[][] | undefined> {\n\t\t// Every request of a search shares its user scope (see `getProjectIssuesSearches`).\n\t\tconst { options } = requests[0];\n\t\tif (options.user == null) return undefined;\n\t\t// One project's search is its own read, by the same numeric id, so it costs no more to read it as one. And it\n\t\t// reports what the search can't: a dropped issue's failure, which a search can only answer by being read again.\n\t\tif (requests.length === 1) return undefined;\n\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\t\tconst api = await this.getProvidersApi();\n\t\tconst baseUrl = this.apiBaseUrlFor(session);\n\t\t// By numeric id, as the per-project read names them (see there).\n\t\tconst projectIds = requests.map(request => request.project.id);\n\t\tconst states = toProviderIssueStates(options.state);\n\n\t\treturn searchJiraProjectIssues(\n\t\t\t(userScope, cursor) =>\n\t\t\t\tapi.getJiraServerIssuesForProjectsPaged(tokenWithInfo, baseUrl, projectIds, {\n\t\t\t\t\t...userScope,\n\t\t\t\t\tcursor: cursor,\n\t\t\t\t\tstates: states,\n\t\t\t\t\tsort: options.sort,\n\t\t\t\t}),\n\t\t\tprojectIds,\n\t\t\toptions.filters,\n\t\t\ttoUserIdentities(options.user),\n\t\t\t{ maxPages: maxPagesPerRequest, failureScope: { providerId: this.id }, providerName: 'Jira Server' },\n\t\t\tthis,\n\t\t);\n\t}\n\n\tprotected override async searchProviderMyIssues(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresources?: JiraServerResourceDescriptor[],\n\t\tcancellation?: AbortSignal,\n\t): Promise<IssueShape[] | undefined> {\n\t\treturn (await this.searchProviderMyIssuesWithTruncation(session, resources, cancellation))?.values;\n\t}\n\n\t/**\n\t * Account-wide \"my issues\" for this instance, drained to the backstop and reporting whether it got there.\n\t *\n\t * The override exists for the same reason the project drain reports `status`: the default\n\t * implementation wraps whatever the normalized read returned as `truncated: false`, so a run that stopped\n\t * at `maxPagesPerRequest` with pages left, or on a continuation the server never advanced, would be\n\t * published as a complete account. Cancellation is NOT truncation — the caller asked for the stop and\n\t * already knows the prefix is partial — so it breaks without setting the flag.\n\t */\n\tprotected override async searchProviderMyIssuesWithTruncation(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resources?: JiraServerResourceDescriptor[],\n\t\tcancellation?: AbortSignal,\n\t\toptions?: SearchMyIssuesOptions,\n\t): Promise<AccountWideIssuesResult | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst states = toProviderIssueStates(options?.state);\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\t\tconst baseUrl = this.apiBaseUrlFor(session);\n\n\t\t// Errors propagate, unlike Jira Cloud's sibling. Cloud swallows per resource because it loops over the\n\t\t// account's many sites and one bad site must not discard the others; this connection addresses exactly\n\t\t// one instance, so there is no sibling to protect and swallowing would turn every failure — an expired\n\t\t// token, an unreachable host — into an empty success. `searchMyIssuesWithTruncationResult` recovers the\n\t\t// throw into `{ error }`, which is what lets the caller warn instead of reporting \"no issues\".\n\t\t// Only the provider: the instance is this connection's single resource, so naming it would publish a\n\t\t// failure of the whole connection as one confined to a sub-scope (see `ProviderWarning.scope`).\n\t\tconst accountScope = { providerId: this.id };\n\t\tconst results: IssueShape[] = [];\n\t\tlet cursor: string | undefined;\n\t\tlet truncated = false;\n\t\tlet metadata: CollectionMetadata | undefined;\n\t\tconst pages: CollectionMetadata[] = [];\n\n\t\tconst stopIncomplete = (reason: string) => {\n\t\t\ttruncated = true;\n\t\t\tmetadata = mergeCollectionMetadata(metadata, {\n\t\t\t\tcompleteness: 'partial',\n\t\t\t\tfailures: [toCollectionScopeFailure(accountScope, new Error(reason))],\n\t\t\t});\n\t\t};\n\n\t\tfor (let i = 0; i < maxPagesPerRequest; i++) {\n\t\t\tif (cancellation?.aborted) break;\n\n\t\t\tconst page = await api.getJiraServerIssuesForCurrentUser(tokenWithInfo, baseUrl, {\n\t\t\t\tcursor: cursor,\n\t\t\t\tstates: states,\n\t\t\t});\n\t\t\tif (page == null) {\n\t\t\t\t// Nothing fetched yet and no page is an empty account, not a failure; after a continuation it\n\t\t\t\t// means the server dropped the drain mid-way.\n\t\t\t\tif (cursor != null) {\n\t\t\t\t\tstopIncomplete('Jira Server returned no page after advertising a continuation');\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tresults.push(\n\t\t\t\t...page.data\n\t\t\t\t\t.map(issue => toIssueShape(issue, this, { projection: 'account' }))\n\t\t\t\t\t.filter((r): r is IssueShape => r != null),\n\t\t\t);\n\t\t\t// An issue the page dropped because it could not be read arrives here, not as a missing row; recorded under\n\t\t\t// the same scope as this read's other failures.\n\t\t\tif (page.metadata != null) {\n\t\t\t\t// Truncated too, as Jira Cloud's read is through `getPagedResult`: the account is missing that issue.\n\t\t\t\ttruncated ||= isIncompleteCollection(page.metadata);\n\t\t\t\tpages.push(withFailureScope(page.metadata, accountScope));\n\t\t\t}\n\n\t\t\tif (!page.hasMore) break;\n\n\t\t\t// More pages are claimed but no advancing cursor came back: the drain can't continue, so flag it\n\t\t\t// rather than stopping silently.\n\t\t\tif (page.nextCursor == null || page.nextCursor === cursor) {\n\t\t\t\tstopIncomplete('Jira Server returned no advancing issue continuation');\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcursor = page.nextCursor;\n\t\t\t// Pages remain but this was the last allowed iteration: the backstop stopped the drain.\n\t\t\tif (i === maxPagesPerRequest - 1) {\n\t\t\t\tstopIncomplete(\n\t\t\t\t\t`Jira Server account-wide issue drain stopped at the ${maxPagesPerRequest}-page backstop`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tvalues: results,\n\t\t\ttruncated: truncated,\n\t\t\tmetadata: mergeCollectionMetadata(summarizePageMetadata(pages), metadata),\n\t\t};\n\t}\n\n\tprotected override async getProviderLinkedIssueOrPullRequest(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resource: JiraServerResourceDescriptor,\n\t\t{ key }: { id: string; key: string },\n\t): Promise<IssueOrPullRequest | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst issue = await api.getJiraServerIssue(toTokenWithInfo(this.id, session), this.apiBaseUrlFor(session), key);\n\t\treturn issue != null ? toIssueShape(issue, this, { projection: 'point' }) : undefined;\n\t}\n\n\tprotected override async getProviderIssue(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resource: JiraServerResourceDescriptor,\n\t\tid: string,\n\t): Promise<Issue | undefined> {\n\t\treturn this.readIssue(session, id, 'point');\n\t}\n\n\tprivate async readIssue(\n\t\tsession: ProviderAuthenticationSession,\n\t\tid: string,\n\t\tprojection: IssueProjection,\n\t): Promise<Issue | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst apiResult = await api.getJiraServerIssue(\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t\tid,\n\t\t);\n\t\tconst issue = apiResult != null ? toIssueShape(apiResult, this, { projection: projection }) : undefined;\n\t\treturn issue != null ? { ...issue, type: 'issue' } : undefined;\n\t}\n\n\t/**\n\t * The point read behind `getIssuesBatch`'s tracker targets (#5872). `resourceId` is this connection's single\n\t * synthetic resource — the host itself, see {@link JiraServerResourceDescriptor} — so it selects nothing further\n\t * here: the host was chosen upstream by `domain` (or the connection's configured domain) and the request is\n\t * addressed to the SESSION's base URL like every other read. No `resourceUrl` is needed either, unlike Jira\n\t * Cloud: its REST `self` link is an API endpoint, whereas `getJiraServerIssue` builds the browser link from\n\t * the base URL it was addressed to. A key that names no issue resolves to `undefined`, a proven absence.\n\t */\n\tprotected override getProviderIssueByResourceId(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resourceId: string,\n\t\tid: string,\n\t\t_resourceUrl: string | undefined,\n\t): Promise<Issue | undefined> {\n\t\treturn this.readIssue(session, id, 'batch');\n\t}\n\n\t/**\n\t * Caches are keyed by the ADDRESS the read was made against as well as the token: one integration instance\n\t * exists per configured host and two hosts can hold the same token, so a token-only key would serve one\n\t * host's projects for the other — and the host alone is not enough either, because a connection re-pointed\n\t * to another context path on the same host keeps its token and would otherwise be served the old path's\n\t * projects.\n\t */\n\tprivate projectsCacheKey(session: ProviderAuthenticationSession): string {\n\t\treturn `${this.apiBaseUrlFor(session)}:${session.accessToken}`;\n\t}\n\n\tprotected override clearDiscoveryCaches(): void {\n\t\tthis._projects.clear();\n\t\tthis._projectReads.clear();\n\t\tthis._autolinks.clear();\n\t\tthis._autolinksBuilds.clear();\n\t}\n\n\tprotected override providerOnDisconnect(): void {\n\t\tthis.invalidateDiscoveryCaches();\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;AA6CA,MAAM,WAAW,kBAAA;AACjB,MAAM,eAAe,OAAO,OAAO;CAAE,IAAI,SAAS;CAAI,QAAQ,SAAS;AAAO,CAAC;AAC/E,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;AAuB3B,SAAS,iBAAiB,MAAsD;CAC/E,OAAO;EAAE,WAAW;EAAM,SAAS;CAAK;AACzC;AAmBA,IAAa,wBAAb,cAA2C,kBAAiE;CAWzF;CAVlB,eAAqE;CACrE,KAAS;CACT;CACA,OAAwB;CAExB,YACC,KACA,uBACA,iBACA,qBACA,SACC;EACD,MAAM,KAAK,uBAAuB,iBAAiB,mBAAmB;EAFrD,KAAA,UAAA;EAGjB,KAAK,MAAM,GAAG,KAAK,GAAG,GAAG,KAAK;CAC/B;CAEA,IAAI,SAAiB;EACpB,OAAO,KAAK;CACb;;;;;;;;;;;;;;;CAgBA,cAAwB,SAA4D;EACnF,MAAM,aAAa,kBAAkB,SAAS,SAAS,SAAS,QAAQ;EAGxE,IAAI,cAAc,QAAQ,qBAAqB,SAAS,SAAS,KAAK,MAAM,GAAG,OAAO;EAEtF,OACC,kBAAkB,SAAS,QAAQ,SAAS,QAAQ,KACpD,kBAAkB,KAAK,QAAQ,SAAS,QAAQ,KAChD,GAAG,SAAS,YAAY,SAAS,IAAI,KAAK;CAE5C;;CAGA,YAAoB,SAAkF;EACrG,OAAO;GAAE,IAAI,KAAK;GAAQ,KAAK,KAAK;GAAQ,MAAM,KAAK;GAAQ,KAAK,KAAK,cAAc,OAAO;EAAE;CACjG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,YAAY,QAAQ,CAAC,IAAI,KAAA;CAC7E;CAEA,MAAyB,iBACxB,SACA,WACA,IAC6B;EAC7B,OAAO,KAAK,UAAU,SAAS,IAAI,OAAO;CAC3C;CAEA,MAAc,UACb,SACA,IACA,YAC6B;EAE7B,MAAM,YAAY,OAAM,MADN,KAAK,gBAAgB,EAAA,CACX,mBAC3B,gBAAgB,KAAK,IAAI,OAAO,GAChC,KAAK,cAAc,OAAO,GAC1B,EACD;EACA,MAAM,QAAQ,aAAa,OAAO,aAAa,WAAW,MAAM,EAAc,WAAW,CAAC,IAAI,KAAA;EAC9F,OAAO,SAAS,OAAO;GAAE,GAAG;GAAO,MAAM;EAAQ,IAAI,KAAA;CACtD;;;;;;;;;CAUA,6BACC,SACA,aACA,IACA,cAC6B;EAC7B,OAAO,KAAK,UAAU,SAAS,IAAI,OAAO;CAC3C;;;;;;;;CASA,iBAAyB,SAAgD;EACxE,OAAO,GAAG,KAAK,cAAc,OAAO,EAAE,GAAG,QAAQ;CAClD;CAEA,uBAAgD;EAC/C,KAAK,UAAU,MAAM;EACrB,KAAK,cAAc,MAAM;EACzB,KAAK,WAAW,MAAM;EACtB,KAAK,iBAAiB,MAAM;CAC7B;CAEA,uBAAgD;EAC/C,KAAK,0BAA0B;CAChC;AACD"}
|
|
1
|
+
{"version":3,"file":"jira-server.js","names":[],"sources":["../../../../../plus/integrations/src/providers/jira-server.ts"],"sourcesContent":["import type { CollectionMetadata } from '@gitkraken/provider-apis';\nimport { JIRA_MAX_PROJECT_KEYS_PER_REQUEST } from '@gitkraken/provider-apis';\nimport type { Account } from '@gitlens/git/models/author.js';\nimport type { AutolinkReference } from '@gitlens/git/models/autolink.js';\nimport type { Issue, IssueProjection, IssueShape } from '@gitlens/git/models/issue.js';\nimport type { IssueOrPullRequest } from '@gitlens/git/models/issueOrPullRequest.js';\nimport type { IssueResourceDescriptor } from '@gitlens/git/models/resourceDescriptor.js';\nimport type { Emitter } from '@gitlens/utils/event.js';\nimport { fnv1aHash64 } from '@gitlens/utils/hash.js';\nimport { Logger } from '@gitlens/utils/logger.js';\nimport type { IntegrationAuthenticationProviderDescriptor } from '../authentication/integrationAuthenticationProvider.js';\nimport type { IntegrationAuthenticationService } from '../authentication/integrationAuthenticationService.js';\nimport type { ProviderAuthenticationSession } from '../authentication/models.js';\nimport { sessionExpiry, toTokenWithInfo } from '../authentication/models.js';\nimport { isIncompleteCollection, toCollectionScopeFailure } from '../collectionMetadata.js';\nimport { IssuesSelfManagedHostIntegrationId } from '../constants.js';\nimport type { IntegrationServiceContext } from '../context.js';\nimport type { IntegrationConnectionChangeEvent } from '../integrationService.js';\nimport type {\n\tAccountWideIssuesResult,\n\tIssuesForProjectOptions,\n\tProjectIssuesDrain,\n\tProjectIssuesRequest,\n\tSearchMyIssuesOptions,\n} from '../models/issueReads.js';\nimport { groupProjectIssuesSearches, IssuesIntegration, toProjectsCollection } from '../models/issuesIntegration.js';\nimport type { IssueTrackerWriteConnection } from '../models/issueTrackerWrites.js';\nimport type { IntegrationKey } from '../models/publicIntegration.js';\nimport { areDomainsOnSameHost, baseUrlFromDomain } from '../utils/domain.utils.js';\nimport type { JiraIssueWriter } from './jiraIssueWrites.js';\nimport { providersMetadata } from './metadata.js';\nimport type { ProviderApiCollectionResult } from './models.js';\nimport { toAccount, toIssueShape, toProviderIssueStates } from './models.js';\nimport { isJiraServerMissingProjectError } from './providerErrors.js';\nimport type { ProvidersApi } from './providersApi.js';\nimport { DiscoveryCache, discoveryCacheTtl } from './utils/discoveryCache.js';\nimport { createIssueAutolinkReferences } from './utils/issueAutolinks.js';\nimport type { JiraDrainOptions, JiraIssuePageFetcher } from './utils/jiraIssueDrains.js';\nimport {\n\tdrainJiraIssues,\n\treadUserScopedJiraIssues,\n\tsearchJiraProjectIssues,\n\tsummarizePageMetadata,\n\ttoUniqueJiraIssueShapes,\n\twithFailureScope,\n} from './utils/jiraIssueDrains.js';\nimport { mergeCollectionMetadata } from './utils/providerPaging.js';\n\nconst metadata = providersMetadata[IssuesSelfManagedHostIntegrationId.JiraServer];\nconst authProvider = Object.freeze({ id: metadata.id, scopes: metadata.scopes });\nconst maxPagesPerRequest = 10;\n\n/**\n * Every clause is scoped by the HANDLE, and `options.userId` is deliberately ignored here — the one\n * place this provider diverges from Jira Cloud's, which applies it to `assignee`/`creator` (#5857).\n *\n * The two are not interchangeable because `Account.id` means something different per deployment. On\n * Cloud it is the `accountId`, which JQL resolves, so scoping by it fixes the deactivated-account case\n * where the display name no longer resolves. On Server it is the user KEY (`JIRAUSER10224`), which JQL\n * does not resolve at all: measured against a live Jira Server 8.20.13 site, `assignee in\n * (\"JIRAUSER10224\")` returns 0 with `\"The value 'JIRAUSER10224' does not exist for the field\n * 'assignee'\"` — the identical warning a genuinely nonexistent user produces — while the username and\n * the display name both return the real 4.\n *\n * So applying `userId` here would silently empty the read rather than harden it. Do not \"fix\" this\n * asymmetry to match Cloud without re-measuring against a Server instance.\n *\n * The handle itself is already the right one: `provider-apis` 0.60.0 maps `Account.username` from the\n * Server payload's `name` (falling back to `displayName` when absent), so these clauses are scoped by the\n * real username rather than a display name (GKDEV-3629). That is what makes the `mention` clause work at\n * all — it is a free-text `comment ~ \"...\"` over comment bodies, and a Jira mention is stored as\n * `[~username]`, which a display name never matches.\n */\nfunction toUserIdentities(user: string): { userField: string; mention: string } {\n\treturn { userField: user, mention: user };\n}\n\n/**\n * The single resource a Jira Server connection has: the instance itself.\n *\n * Jira Cloud's account spans many sites, so its resources come from an API call that lists them. A\n * self-hosted instance IS the one site the connection addresses, so there is nothing to enumerate — this\n * descriptor is synthesized from the configured host. Modelling it as a resource anyway keeps the\n * resource → project contract of {@link IssuesIntegration} intact, so every tracker read (`listOrgs`,\n * `listProjects`, `listIssueTrackerIssuesPage`) works unchanged.\n */\nexport interface JiraServerResourceDescriptor extends IssueResourceDescriptor {\n\turl: string;\n}\n\nexport interface JiraServerProjectDescriptor extends IssueResourceDescriptor {\n\tresourceId: string;\n}\n\nexport class JiraServerIntegration extends IssuesIntegration<IssuesSelfManagedHostIntegrationId.JiraServer> {\n\treadonly authProvider: IntegrationAuthenticationProviderDescriptor = authProvider;\n\treadonly id = IssuesSelfManagedHostIntegrationId.JiraServer;\n\tprotected readonly key: IntegrationKey<IssuesSelfManagedHostIntegrationId.JiraServer>;\n\treadonly name: string = 'Jira Data Center';\n\n\tconstructor(\n\t\tctx: IntegrationServiceContext,\n\t\tauthenticationService: IntegrationAuthenticationService,\n\t\tgetProvidersApi: () => Promise<ProvidersApi>,\n\t\tdidChangeConnection: Emitter<IntegrationConnectionChangeEvent>,\n\t\tprivate readonly _domain: string,\n\t) {\n\t\tsuper(ctx, authenticationService, getProvidersApi, didChangeConnection);\n\t\tthis.key = `${this.id}:${this._domain}`;\n\t}\n\n\tget domain(): string {\n\t\treturn this._domain;\n\t}\n\n\tprotected override getSessionFingerprint(session: ProviderAuthenticationSession): string {\n\t\treturn fnv1aHash64(JSON.stringify([this.apiBaseUrlFor(session), session.accessToken]));\n\t}\n\n\tasync getIssueWriter(\n\t\toptions: Extract<IssueTrackerWriteConnection, { providerId: IssuesSelfManagedHostIntegrationId.JiraServer }>,\n\t\tsession: ProviderAuthenticationSession,\n\t\tisSelectionCurrent: () => boolean,\n\t): Promise<{ writer: JiraIssueWriter; isCurrent: () => boolean }> {\n\t\tconst isSessionCurrent = this.authenticationService.trackStoredSession(this.id, session, true);\n\t\tconst isCurrent = () =>\n\t\t\tisSelectionCurrent() &&\n\t\t\tthis.isIntegrationAccessEnabled() &&\n\t\t\t!isSessionCurrent.isRetired() &&\n\t\t\tsessionExpiry(session.expiresAt) > Date.now();\n\t\tconst api = await this.getProvidersApi();\n\t\tconst writer = await api.getJiraServerIssueWriter(options, session, isCurrent, isSessionCurrent, () =>\n\t\t\tthis.getIgnoreSSLErrors(),\n\t\t);\n\t\treturn { writer: writer, isCurrent: isCurrent };\n\t}\n\n\t/**\n\t * The URL every request for this connection is addressed to, built from the SESSION's domain rather than\n\t * the integration's.\n\t *\n\t * `this.domain` is the host-keyed identity — `IntegrationService.get()` runs it through `hostFromDomain`\n\t * so one host can't build two instances — which means it has had any context path stripped, and so has\n\t * `session.domain`, which is stored as that same normalized host. Jira Data Center officially supports\n\t * being mounted below a context path (`https://jira.example.com/jira`), so the address comes from\n\t * {@link ProviderAuthenticationSession.baseUrl}, which carries the configured value verbatim; it falls\n\t * back to the host when the backend reported nothing more, which is the common case.\n\t *\n\t * Takes the session rather than reading `_session` so a per-connection (multi-account) read is addressed\n\t * to the host of the connection it resolved, not to whichever one happens to be current.\n\t */\n\tprotected apiBaseUrlFor(session: ProviderAuthenticationSession | undefined): string {\n\t\tconst configured = baseUrlFromDomain(session?.baseUrl, session?.protocol);\n\t\t// A `baseUrl` from another host is not this connection's address — refuse it rather than routing this\n\t\t// integration's reads somewhere its key never named.\n\t\tif (configured != null && areDomainsOnSameHost(session?.baseUrl, this.domain)) return configured;\n\n\t\treturn (\n\t\t\tbaseUrlFromDomain(session?.domain, session?.protocol) ??\n\t\t\tbaseUrlFromDomain(this.domain, session?.protocol) ??\n\t\t\t`${session?.protocol ?? 'https:'}//${this.domain}`\n\t\t);\n\t}\n\n\t/** The one resource this connection has — see {@link JiraServerResourceDescriptor}. */\n\tprivate resourceFor(session: ProviderAuthenticationSession | undefined): JiraServerResourceDescriptor {\n\t\treturn { id: this.domain, key: this.domain, name: this.domain, url: this.apiBaseUrlFor(session) };\n\t}\n\n\tprivate readonly _autolinks = new Map<string, { autolinks: AutolinkReference[]; builtAt: number }>();\n\tprivate readonly _autolinksBuilds = new Map<string, Promise<AutolinkReference[]>>();\n\n\toverride async autolinks(): Promise<AutolinkReference[]> {\n\t\tconst generation = this.discoveryGeneration;\n\t\tconst connected = this.maybeConnected ?? (await this.isConnected());\n\t\tif (!connected || this._session == null) return [];\n\t\tif (!this.isResolvedSessionCurrent(this._session, generation)) return [];\n\n\t\tconst session = this._session;\n\t\tconst cacheKey = this.projectsCacheKey(session);\n\t\tconst cached = this._autolinks.get(cacheKey);\n\t\tif (this.connectionExpired === true) return cached?.autolinks ?? [];\n\t\tif (cached == null) return this.buildAutolinks(session);\n\n\t\tif (Date.now() - cached.builtAt >= discoveryCacheTtl) {\n\t\t\tvoid this.buildAutolinks(session);\n\t\t}\n\t\treturn cached.autolinks;\n\t}\n\n\tprivate buildAutolinks(session: ProviderAuthenticationSession): Promise<AutolinkReference[]> {\n\t\tconst cacheKey = this.projectsCacheKey(session);\n\t\tlet build = this._autolinksBuilds.get(cacheKey);\n\t\tif (build == null) {\n\t\t\tbuild = this.buildAutolinksCore(session).finally(() => {\n\t\t\t\tif (this._autolinksBuilds.get(cacheKey) === build) {\n\t\t\t\t\tthis._autolinksBuilds.delete(cacheKey);\n\t\t\t\t}\n\t\t\t});\n\t\t\tthis._autolinksBuilds.set(cacheKey, build);\n\t\t}\n\t\treturn build;\n\t}\n\n\tprivate async buildAutolinksCore(session: ProviderAuthenticationSession): Promise<AutolinkReference[]> {\n\t\tconst cacheKey = this.projectsCacheKey(session);\n\t\tconst generation = this._projects.generation;\n\t\ttry {\n\t\t\tconst resource = this.resourceFor(session);\n\t\t\tconst result = await this.getProjectsForResourcesWithMetadataResult([resource]);\n\t\t\tif (this._projects.generation !== generation) return [];\n\t\t\tif (result?.value == null || result.error != null || isIncompleteCollection(result.value.metadata)) {\n\t\t\t\treturn this._autolinks.get(cacheKey)?.autolinks ?? [];\n\t\t\t}\n\n\t\t\tconst autolinks: AutolinkReference[] = [];\n\t\t\tfor (const project of result.value.values) {\n\t\t\t\tif (project.key === project.id) continue;\n\n\t\t\t\tautolinks.push(\n\t\t\t\t\t...createIssueAutolinkReferences(\n\t\t\t\t\t\tproject.key,\n\t\t\t\t\t\t`${resource.url}/browse/${project.key}-<num>`,\n\t\t\t\t\t\tresource,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis._autolinks.set(cacheKey, { autolinks: autolinks, builtAt: Date.now() });\n\t\t\treturn autolinks;\n\t\t} catch (ex) {\n\t\t\tLogger.error(ex, 'JiraServerIntegration.autolinks');\n\t\t\treturn this._autolinks.get(cacheKey)?.autolinks ?? [];\n\t\t}\n\t}\n\n\tprotected override getProviderCurrentAccount(session: ProviderAuthenticationSession): Promise<Account | undefined> {\n\t\treturn this.getProviderAccountForResource(session, this.resourceFor(session));\n\t}\n\n\tprotected override async getProviderAccountForResource(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resource: JiraServerResourceDescriptor,\n\t): Promise<Account | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst user = await api.getJiraServerCurrentUser(toTokenWithInfo(this.id, session), this.apiBaseUrlFor(session));\n\n\t\tif (user == null) return undefined;\n\t\treturn toAccount(user, this);\n\t}\n\n\tprotected override getProviderResourcesForUser(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_force?: boolean,\n\t): Promise<JiraServerResourceDescriptor[] | undefined> {\n\t\t// Synthesized from the configured host rather than fetched, so there is nothing to cache or force.\n\t\treturn Promise.resolve([this.resourceFor(session)]);\n\t}\n\n\t/** Expires, and is dropped on a re-sync, so a project created or deleted mid-session is picked up (#5907). */\n\tprivate readonly _projects = new DiscoveryCache<JiraServerProjectDescriptor[]>();\n\tprivate readonly _projectReads = new Map<string, Promise<JiraServerProjectDescriptor[] | undefined>>();\n\tprotected override getProviderProjectsForResources(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresources: JiraServerResourceDescriptor[],\n\t): Promise<JiraServerProjectDescriptor[] | undefined> {\n\t\t// Every resource here is this instance (see `getProviderResourcesForUser`), so one read serves them\n\t\t// all; a caller that passes none is asking for nothing.\n\t\tif (resources.length === 0) return Promise.resolve([]);\n\n\t\tconst cacheKey = this.projectsCacheKey(session);\n\t\tconst cached = this._projects.get(cacheKey);\n\t\tif (cached != null) return Promise.resolve(cached);\n\n\t\tlet read = this._projectReads.get(cacheKey);\n\t\tif (read == null) {\n\t\t\tread = this.readProjectsCached(session, cacheKey).finally(() => {\n\t\t\t\tif (this._projectReads.get(cacheKey) === read) {\n\t\t\t\t\tthis._projectReads.delete(cacheKey);\n\t\t\t\t}\n\t\t\t});\n\t\t\tthis._projectReads.set(cacheKey, read);\n\t\t}\n\t\treturn read;\n\t}\n\n\tprivate async readProjectsCached(\n\t\tsession: ProviderAuthenticationSession,\n\t\tcacheKey: string,\n\t): Promise<JiraServerProjectDescriptor[] | undefined> {\n\t\tconst generation = this._projects.generation;\n\t\tconst descriptors = await this.readProjects(session);\n\t\tif (descriptors == null) return undefined;\n\n\t\tif (this._projects.set(cacheKey, descriptors, { generation: generation }) !== false) {\n\t\t\tthis._autolinks.delete(cacheKey);\n\t\t}\n\n\t\treturn descriptors;\n\t}\n\n\tprotected override async getProviderUncachedProjectsForResourcesWithMetadata(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresources: JiraServerResourceDescriptor[],\n\t): Promise<ProviderApiCollectionResult<JiraServerProjectDescriptor>> {\n\t\tif (resources.length === 0) return { values: [] };\n\n\t\treturn toProjectsCollection(await this.readProjects(session));\n\t}\n\n\tprivate async readProjects(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<JiraServerProjectDescriptor[] | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst projects = await api.getJiraServerProjects(\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t);\n\t\tif (projects == null) return undefined;\n\t\tif (projects.length === 0) {\n\t\t\t// Jira can serve anonymous empty projects after rejection without an identifying response header.\n\t\t\tconst account = await this.getProviderAccountForResource(session, this.resourceFor(session));\n\t\t\tif ((account?.username ?? account?.name) == null) return undefined;\n\t\t}\n\n\t\tconst resourceId = this.resourceFor(session).id;\n\t\treturn projects.map<JiraServerProjectDescriptor>(p => ({\n\t\t\tid: p.id,\n\t\t\t// The project key, which selects the project (`listProjects`' `name`) and is what an issue key starts\n\t\t\t// with. The SDK does not validate it, so a missing or blank one falls back to the numeric id, never to the\n\t\t\t// display name, which can equal another project's key. The reads below still address the project by\n\t\t\t// `id`, which no other project can share.\n\t\t\tkey: p.key?.trim() || p.id,\n\t\t\tname: p.name,\n\t\t\tresourceId: resourceId,\n\t\t}));\n\t}\n\n\tprotected override async getProviderIssuesForProject(\n\t\tsession: ProviderAuthenticationSession,\n\t\tproject: JiraServerProjectDescriptor,\n\t\toptions?: IssuesForProjectOptions,\n\t): Promise<IssueShape[] | undefined> {\n\t\treturn (await this.getProviderIssuesForProjectWithTruncation(session, project, options))?.values;\n\t}\n\n\tprotected override async getProviderIssuesForProjectWithTruncation(\n\t\tsession: ProviderAuthenticationSession,\n\t\tproject: JiraServerProjectDescriptor,\n\t\toptions?: IssuesForProjectOptions,\n\t): Promise<ProjectIssuesDrain | undefined> {\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\t\tconst api = await this.getProvidersApi();\n\t\tconst baseUrl = this.apiBaseUrlFor(session);\n\n\t\t// The same drain as Jira Cloud's (`jiraIssueDrains.ts`): page to a defensive backstop, and report `truncated`\n\t\t// plus a structured failure rather than discarding an already-fetched prefix.\n\t\tconst states = toProviderIssueStates(options?.state);\n\t\t// The numeric project id, not the name: JQL resolves `project = \"<value>\"` against key first, so a display\n\t\t// name that matches another project's key reads that project's issues instead. A Jira project key must begin\n\t\t// with a letter, so a purely numeric value can only be an id.\n\t\tconst fetchPage: JiraIssuePageFetcher = (scope, cursor) =>\n\t\t\tapi.getJiraServerIssuesForProjectPaged(tokenWithInfo, baseUrl, project.id, {\n\t\t\t\t...scope,\n\t\t\t\tcursor: cursor,\n\t\t\t\tstates: states,\n\t\t\t\tsort: options?.sort,\n\t\t\t});\n\t\tconst drainOptions: JiraDrainOptions = {\n\t\t\tmaxPages: maxPagesPerRequest,\n\t\t\t// Scoped by key, as on Jira Cloud: the id addresses the read, the key is how a consumer names the project.\n\t\t\tfailureScope: { providerId: this.id, resourceId: project.resourceId, projectId: project.key },\n\t\t\tproviderName: 'Jira Server',\n\t\t\t// A project this connection can no longer see (deleted, or its browse permission removed) holds\n\t\t\t// no issues for it, and the project list that named it is stale: drop that list so the next read\n\t\t\t// re-reads it, instead of failing the whole provider on every read until a restart (#5907).\n\t\t\tisEmptyFailure: ex => {\n\t\t\t\tif (!isJiraServerMissingProjectError(ex)) return false;\n\n\t\t\t\tLogger.warn(`Jira Server project '${project.name}' (${project.id}) no longer exists or is not visible`);\n\t\t\t\tthis.invalidateDiscoveryCaches();\n\t\t\t\treturn true;\n\t\t\t},\n\t\t};\n\n\t\tif (options?.user != null) {\n\t\t\tconst read = await readUserScopedJiraIssues(\n\t\t\t\tfetchPage,\n\t\t\t\toptions.filters,\n\t\t\t\ttoUserIdentities(options.user),\n\t\t\t\tdrainOptions,\n\t\t\t);\n\t\t\tconst values = toUniqueJiraIssueShapes(read.issues, this);\n\t\t\tconst drain = { values: values, metadata: read.metadata, scope: drainOptions.failureScope };\n\t\t\t// `recovery: 'none'` for the whole set: the filter branches merge here, so even a pure backstop in one\n\t\t\t// branch is not fixable by narrowing this read's scope.\n\t\t\treturn read.truncated ? { ...drain, truncated: true, recovery: 'none' } : { ...drain, truncated: false };\n\t\t}\n\n\t\tconst unscoped = await drainJiraIssues(fetchPage, {}, drainOptions);\n\t\tconst values = unscoped.issues\n\t\t\t.map(issue => toIssueShape(issue, this, { projection: 'project' }))\n\t\t\t.filter((result): result is IssueShape => result !== undefined);\n\t\tconst drain = { values: values, metadata: unscoped.metadata, scope: drainOptions.failureScope };\n\t\treturn unscoped.status !== 'complete'\n\t\t\t? { ...drain, truncated: true, recovery: unscoped.status === 'backstop' ? 'narrow-scope' : 'none' }\n\t\t\t: { ...drain, truncated: false };\n\t}\n\n\t/**\n\t * Searches the instance's projects together for a user-scoped read, as Jira Cloud does per site: one JQL names\n\t * up to {@link JIRA_MAX_PROJECT_KEYS_PER_REQUEST} projects of one user scope. An unscoped read stays per project,\n\t * since its backstop is reported as `narrow-scope` per project.\n\t */\n\tprotected override getProjectIssuesSearches(\n\t\trequests: readonly ProjectIssuesRequest<JiraServerProjectDescriptor>[],\n\t): number[][] | undefined {\n\t\treturn groupProjectIssuesSearches(\n\t\t\trequests,\n\t\t\t({ options }) =>\n\t\t\t\toptions.user != null\n\t\t\t\t\t? [options.user, options.sort ?? '', options.state ?? '', options.filters?.join(',') ?? ''].join(\n\t\t\t\t\t\t\t'\\0',\n\t\t\t\t\t\t)\n\t\t\t\t\t: undefined,\n\t\t\tJIRA_MAX_PROJECT_KEYS_PER_REQUEST,\n\t\t);\n\t}\n\n\tprotected override async searchProviderProjectIssues(\n\t\tsession: ProviderAuthenticationSession,\n\t\trequests: readonly ProjectIssuesRequest<JiraServerProjectDescriptor>[],\n\t): Promise<IssueShape[][] | undefined> {\n\t\t// Every request of a search shares its user scope (see `getProjectIssuesSearches`).\n\t\tconst { options } = requests[0];\n\t\tif (options.user == null) return undefined;\n\t\t// One project's search is its own read, by the same numeric id, so it costs no more to read it as one. And it\n\t\t// reports what the search can't: a dropped issue's failure, which a search can only answer by being read again.\n\t\tif (requests.length === 1) return undefined;\n\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\t\tconst api = await this.getProvidersApi();\n\t\tconst baseUrl = this.apiBaseUrlFor(session);\n\t\t// By numeric id, as the per-project read names them (see there).\n\t\tconst projectIds = requests.map(request => request.project.id);\n\t\tconst states = toProviderIssueStates(options.state);\n\n\t\treturn searchJiraProjectIssues(\n\t\t\t(userScope, cursor) =>\n\t\t\t\tapi.getJiraServerIssuesForProjectsPaged(tokenWithInfo, baseUrl, projectIds, {\n\t\t\t\t\t...userScope,\n\t\t\t\t\tcursor: cursor,\n\t\t\t\t\tstates: states,\n\t\t\t\t\tsort: options.sort,\n\t\t\t\t}),\n\t\t\tprojectIds,\n\t\t\toptions.filters,\n\t\t\ttoUserIdentities(options.user),\n\t\t\t{ maxPages: maxPagesPerRequest, failureScope: { providerId: this.id }, providerName: 'Jira Server' },\n\t\t\tthis,\n\t\t);\n\t}\n\n\tprotected override async searchProviderMyIssues(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresources?: JiraServerResourceDescriptor[],\n\t\tcancellation?: AbortSignal,\n\t): Promise<IssueShape[] | undefined> {\n\t\treturn (await this.searchProviderMyIssuesWithTruncation(session, resources, cancellation))?.values;\n\t}\n\n\t/**\n\t * Account-wide \"my issues\" for this instance, drained to the backstop and reporting whether it got there.\n\t *\n\t * The override exists for the same reason the project drain reports `status`: the default\n\t * implementation wraps whatever the normalized read returned as `truncated: false`, so a run that stopped\n\t * at `maxPagesPerRequest` with pages left, or on a continuation the server never advanced, would be\n\t * published as a complete account. Cancellation is NOT truncation — the caller asked for the stop and\n\t * already knows the prefix is partial — so it breaks without setting the flag.\n\t */\n\tprotected override async searchProviderMyIssuesWithTruncation(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resources?: JiraServerResourceDescriptor[],\n\t\tcancellation?: AbortSignal,\n\t\toptions?: SearchMyIssuesOptions,\n\t): Promise<AccountWideIssuesResult | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst states = toProviderIssueStates(options?.state);\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\t\tconst baseUrl = this.apiBaseUrlFor(session);\n\n\t\t// Errors propagate, unlike Jira Cloud's sibling. Cloud swallows per resource because it loops over the\n\t\t// account's many sites and one bad site must not discard the others; this connection addresses exactly\n\t\t// one instance, so there is no sibling to protect and swallowing would turn every failure — an expired\n\t\t// token, an unreachable host — into an empty success. `searchMyIssuesWithTruncationResult` recovers the\n\t\t// throw into `{ error }`, which is what lets the caller warn instead of reporting \"no issues\".\n\t\t// Only the provider: the instance is this connection's single resource, so naming it would publish a\n\t\t// failure of the whole connection as one confined to a sub-scope (see `ProviderWarning.scope`).\n\t\tconst accountScope = { providerId: this.id };\n\t\tconst results: IssueShape[] = [];\n\t\tlet cursor: string | undefined;\n\t\tlet truncated = false;\n\t\tlet metadata: CollectionMetadata | undefined;\n\t\tconst pages: CollectionMetadata[] = [];\n\n\t\tconst stopIncomplete = (reason: string) => {\n\t\t\ttruncated = true;\n\t\t\tmetadata = mergeCollectionMetadata(metadata, {\n\t\t\t\tcompleteness: 'partial',\n\t\t\t\tfailures: [toCollectionScopeFailure(accountScope, new Error(reason))],\n\t\t\t});\n\t\t};\n\n\t\tfor (let i = 0; i < maxPagesPerRequest; i++) {\n\t\t\tif (cancellation?.aborted) break;\n\n\t\t\tconst page = await api.getJiraServerIssuesForCurrentUser(tokenWithInfo, baseUrl, {\n\t\t\t\tcursor: cursor,\n\t\t\t\tstates: states,\n\t\t\t});\n\t\t\tif (page == null) {\n\t\t\t\t// Nothing fetched yet and no page is an empty account, not a failure; after a continuation it\n\t\t\t\t// means the server dropped the drain mid-way.\n\t\t\t\tif (cursor != null) {\n\t\t\t\t\tstopIncomplete('Jira Server returned no page after advertising a continuation');\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tresults.push(\n\t\t\t\t...page.data\n\t\t\t\t\t.map(issue => toIssueShape(issue, this, { projection: 'account' }))\n\t\t\t\t\t.filter((r): r is IssueShape => r != null),\n\t\t\t);\n\t\t\t// An issue the page dropped because it could not be read arrives here, not as a missing row; recorded under\n\t\t\t// the same scope as this read's other failures.\n\t\t\tif (page.metadata != null) {\n\t\t\t\t// Truncated too, as Jira Cloud's read is through `getPagedResult`: the account is missing that issue.\n\t\t\t\ttruncated ||= isIncompleteCollection(page.metadata);\n\t\t\t\tpages.push(withFailureScope(page.metadata, accountScope));\n\t\t\t}\n\n\t\t\tif (!page.hasMore) break;\n\n\t\t\t// More pages are claimed but no advancing cursor came back: the drain can't continue, so flag it\n\t\t\t// rather than stopping silently.\n\t\t\tif (page.nextCursor == null || page.nextCursor === cursor) {\n\t\t\t\tstopIncomplete('Jira Server returned no advancing issue continuation');\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcursor = page.nextCursor;\n\t\t\t// Pages remain but this was the last allowed iteration: the backstop stopped the drain.\n\t\t\tif (i === maxPagesPerRequest - 1) {\n\t\t\t\tstopIncomplete(\n\t\t\t\t\t`Jira Server account-wide issue drain stopped at the ${maxPagesPerRequest}-page backstop`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tvalues: results,\n\t\t\ttruncated: truncated,\n\t\t\tmetadata: mergeCollectionMetadata(summarizePageMetadata(pages), metadata),\n\t\t};\n\t}\n\n\tprotected override async getProviderLinkedIssueOrPullRequest(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resource: JiraServerResourceDescriptor,\n\t\t{ key }: { id: string; key: string },\n\t): Promise<IssueOrPullRequest | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst issue = await api.getJiraServerIssue(toTokenWithInfo(this.id, session), this.apiBaseUrlFor(session), key);\n\t\treturn issue != null ? toIssueShape(issue, this, { projection: 'point' }) : undefined;\n\t}\n\n\tprotected override async getProviderIssue(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resource: JiraServerResourceDescriptor,\n\t\tid: string,\n\t): Promise<Issue | undefined> {\n\t\treturn this.readIssue(session, id, 'point');\n\t}\n\n\tprivate async readIssue(\n\t\tsession: ProviderAuthenticationSession,\n\t\tid: string,\n\t\tprojection: IssueProjection,\n\t): Promise<Issue | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst apiResult = await api.getJiraServerIssue(\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t\tid,\n\t\t);\n\t\tconst issue = apiResult != null ? toIssueShape(apiResult, this, { projection: projection }) : undefined;\n\t\treturn issue != null ? { ...issue, type: 'issue' } : undefined;\n\t}\n\n\t/**\n\t * The point read behind `getIssuesBatch`'s tracker targets (#5872). `resourceId` is this connection's single\n\t * synthetic resource — the host itself, see {@link JiraServerResourceDescriptor} — so it selects nothing further\n\t * here: the host was chosen upstream by `domain` (or the connection's configured domain) and the request is\n\t * addressed to the SESSION's base URL like every other read. No `resourceUrl` is needed either, unlike Jira\n\t * Cloud: its REST `self` link is an API endpoint, whereas `getJiraServerIssue` builds the browser link from\n\t * the base URL it was addressed to. A key that names no issue resolves to `undefined`, a proven absence.\n\t */\n\tprotected override getProviderIssueByResourceId(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resourceId: string,\n\t\tid: string,\n\t\t_resourceUrl: string | undefined,\n\t): Promise<Issue | undefined> {\n\t\treturn this.readIssue(session, id, 'batch');\n\t}\n\n\t/**\n\t * Caches are keyed by the ADDRESS the read was made against as well as the token: one integration instance\n\t * exists per configured host and two hosts can hold the same token, so a token-only key would serve one\n\t * host's projects for the other — and the host alone is not enough either, because a connection re-pointed\n\t * to another context path on the same host keeps its token and would otherwise be served the old path's\n\t * projects.\n\t */\n\tprivate projectsCacheKey(session: ProviderAuthenticationSession): string {\n\t\treturn `${this.apiBaseUrlFor(session)}:${session.accessToken}`;\n\t}\n\n\tprotected override clearDiscoveryCaches(): void {\n\t\tthis._projects.clear();\n\t\tthis._projectReads.clear();\n\t\tthis._autolinks.clear();\n\t\tthis._autolinksBuilds.clear();\n\t}\n\n\tprotected override providerOnDisconnect(): void {\n\t\tthis.invalidateDiscoveryCaches();\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgDA,MAAM,WAAW,kBAAA;AACjB,MAAM,eAAe,OAAO,OAAO;CAAE,IAAI,SAAS;CAAI,QAAQ,SAAS;AAAO,CAAC;AAC/E,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;AAuB3B,SAAS,iBAAiB,MAAsD;CAC/E,OAAO;EAAE,WAAW;EAAM,SAAS;CAAK;AACzC;AAmBA,IAAa,wBAAb,cAA2C,kBAAiE;CAWzF;CAVlB,eAAqE;CACrE,KAAS;CACT;CACA,OAAwB;CAExB,YACC,KACA,uBACA,iBACA,qBACA,SACC;EACD,MAAM,KAAK,uBAAuB,iBAAiB,mBAAmB;EAFrD,KAAA,UAAA;EAGjB,KAAK,MAAM,GAAG,KAAK,GAAG,GAAG,KAAK;CAC/B;CAEA,IAAI,SAAiB;EACpB,OAAO,KAAK;CACb;CAEA,sBAAyC,SAAgD;EACxF,OAAO,YAAY,K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;EACA,MAAM,QAAQ,aAAa,OAAO,aAAa,WAAW,MAAM,EAAc,WAAW,CAAC,IAAI,KAAA;EAC9F,OAAO,SAAS,OAAO;GAAE,GAAG;GAAO,MAAM;EAAQ,IAAI,KAAA;CACtD;;;;;;;;;CAUA,6BACC,SACA,aACA,IACA,cAC6B;EAC7B,OAAO,KAAK,UAAU,SAAS,IAAI,OAAO;CAC3C;;;;;;;;CASA,iBAAyB,SAAgD;EACxE,OAAO,GAAG,KAAK,cAAc,OAAO,EAAE,GAAG,QAAQ;CAClD;CAEA,uBAAgD;EAC/C,KAAK,UAAU,MAAM;EACrB,KAAK,cAAc,MAAM;EACzB,KAAK,WAAW,MAAM;EACtB,KAAK,iBAAiB,MAAM;CAC7B;CAEA,uBAAgD;EAC/C,KAAK,0BAA0B;CAChC;AACD"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ProviderAuthenticationSession } from "../authentication/models.js";
|
|
2
|
+
import { IssuesSelfManagedHostIntegrationId } from "../constants.js";
|
|
1
3
|
import { IssueTrackerCreateOptions, IssueTrackerCreateOptionsResult, IssueTrackerDeleteOptions, IssueTrackerIssueWriteOptions, IssueTrackerIssueWriteOptionsResult, IssueTrackerWriteConnection, IssueTrackerWriteOptions, IssueTrackerWriteResult, IssueTrackerWriteTargetOptions, IssueTrackerWriteTargetResult } from "../models/issueTrackerWrites.js";
|
|
2
4
|
import { ProviderRequestFunction } from "./models.js";
|
|
3
5
|
//#region ../plus/integrations/src/providers/jiraIssueWrites.d.ts
|
|
@@ -8,6 +10,9 @@ export declare class JiraIssueWriter {
|
|
|
8
10
|
private readonly site;
|
|
9
11
|
private readonly isSessionCurrent;
|
|
10
12
|
static connect(request: ProviderRequestFunction, accessToken: string, options: IssueTrackerWriteConnection, isSessionCurrent: () => Promise<boolean>): Promise<JiraIssueWriter>;
|
|
13
|
+
static connectServer(request: ProviderRequestFunction, session: ProviderAuthenticationSession, options: Extract<IssueTrackerWriteConnection, {
|
|
14
|
+
providerId: IssuesSelfManagedHostIntegrationId.JiraServer;
|
|
15
|
+
}>, isSessionCurrent: () => Promise<boolean>): Promise<JiraIssueWriter>;
|
|
11
16
|
private accountId;
|
|
12
17
|
private constructor();
|
|
13
18
|
getCreateOptions(options: IssueTrackerCreateOptions): Promise<IssueTrackerCreateOptionsResult>;
|
|
@@ -18,6 +23,7 @@ export declare class JiraIssueWriter {
|
|
|
18
23
|
private createIssue;
|
|
19
24
|
private updateIssue;
|
|
20
25
|
private editableFields;
|
|
26
|
+
private resolveMutationIssue;
|
|
21
27
|
private resolveIssue;
|
|
22
28
|
private readIssue;
|
|
23
29
|
private readCreateProject;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { baseUrlFromDomain, hostFromDomain, matchesInstallationOrigin } from "../utils/domain.utils.js";
|
|
1
2
|
import { JiraIssueWriteError, toJiraIssueWriteFailure } from "./jiraIssueWriteErrors.js";
|
|
2
3
|
import { toIssueWebUrl, toStatusCategory } from "./jiraIssueByKey.js";
|
|
3
4
|
//#region ../plus/integrations/src/providers/jiraIssueWrites.ts
|
|
@@ -73,13 +74,34 @@ var JiraIssueWriter = class JiraIssueWriter {
|
|
|
73
74
|
if (site == null) throw new JiraIssueWriteError("not-found");
|
|
74
75
|
const resourceUrl = new URL(site.url);
|
|
75
76
|
if (resourceUrl.protocol !== "https:" || resourceUrl.username || resourceUrl.password) throw new JiraIssueWriteError("unknown");
|
|
76
|
-
const
|
|
77
|
+
const { id, url, scopes } = site;
|
|
78
|
+
const writer = new JiraIssueWriter(request, accessToken, {
|
|
79
|
+
id,
|
|
80
|
+
url,
|
|
81
|
+
scopes
|
|
82
|
+
}, isSessionCurrent);
|
|
77
83
|
const { accountId } = await writer.read("/myself");
|
|
78
84
|
if (typeof accountId !== "string" || !accountId) throw new JiraIssueWriteError("unknown");
|
|
79
85
|
if (options.expectedAccountId !== void 0 && options.expectedAccountId !== accountId) throw new JiraIssueWriteError("forbidden");
|
|
80
86
|
writer.accountId = accountId;
|
|
81
87
|
return writer;
|
|
82
88
|
}
|
|
89
|
+
static async connectServer(request, session, options, isSessionCurrent) {
|
|
90
|
+
const siteUrl = normalizeJiraServerSiteUrl(session.baseUrl ?? session.domain, session.protocol);
|
|
91
|
+
if (normalizeJiraServerSiteUrl(options.siteUrl) !== siteUrl || options.siteUrl !== siteUrl) throw new JiraIssueWriteError("conflict");
|
|
92
|
+
if (hostFromDomain(session.domain) !== options.resourceId || !matchesInstallationOrigin(session.domain, siteUrl)) throw new JiraIssueWriteError("conflict");
|
|
93
|
+
const writer = new JiraIssueWriter(request, session.accessToken, {
|
|
94
|
+
id: options.resourceId,
|
|
95
|
+
url: siteUrl,
|
|
96
|
+
scopes: [],
|
|
97
|
+
server: true
|
|
98
|
+
}, isSessionCurrent);
|
|
99
|
+
const { key } = await writer.read("/myself");
|
|
100
|
+
if (!isJiraWriteIdentifier(key)) throw new JiraIssueWriteError("unknown");
|
|
101
|
+
if (options.expectedAccountId !== void 0 && options.expectedAccountId !== key) throw new JiraIssueWriteError("forbidden");
|
|
102
|
+
writer.accountId = key;
|
|
103
|
+
return writer;
|
|
104
|
+
}
|
|
83
105
|
accountId = "";
|
|
84
106
|
constructor(request, accessToken, site, isSessionCurrent) {
|
|
85
107
|
this.request = request;
|
|
@@ -97,7 +119,7 @@ var JiraIssueWriter = class JiraIssueWriter {
|
|
|
97
119
|
project
|
|
98
120
|
};
|
|
99
121
|
if (options.issueTypeId === void 0) {
|
|
100
|
-
const { values, truncated } = await this.readPages(this.createMetadataPath(project.id), (page) => page.issueTypes);
|
|
122
|
+
const { values, truncated } = await this.readPages(this.createMetadataPath(project.id), (page) => this.site.server ? page.values : page.issueTypes);
|
|
101
123
|
return {
|
|
102
124
|
...result,
|
|
103
125
|
issueTypes: values.map(({ id, name }) => ({
|
|
@@ -153,8 +175,11 @@ var JiraIssueWriter = class JiraIssueWriter {
|
|
|
153
175
|
}
|
|
154
176
|
async delete(options) {
|
|
155
177
|
if (!isJiraWriteIdentifier(options.expectedAccountId) || !isNumericId(options.expectedIssueId)) throw new JiraIssueWriteError("invalid-input");
|
|
156
|
-
const
|
|
157
|
-
await this.ensureDeletable(
|
|
178
|
+
const resolved = await this.resolveMutationIssue(options);
|
|
179
|
+
await this.ensureDeletable(resolved);
|
|
180
|
+
const issue = this.site.server ? await this.resolveMutationIssue(options) : resolved;
|
|
181
|
+
const reason = this.getDeleteRefusal(true, issue);
|
|
182
|
+
if (reason !== void 0) throw new JiraIssueWriteError(reason);
|
|
158
183
|
const receipt = this.toReceipt(issue);
|
|
159
184
|
return this.dispatch("DELETE", `/issue/${issue.id}?deleteSubtasks=false`, 204, () => receipt);
|
|
160
185
|
}
|
|
@@ -176,7 +201,7 @@ var JiraIssueWriter = class JiraIssueWriter {
|
|
|
176
201
|
}
|
|
177
202
|
async updateIssue(options) {
|
|
178
203
|
if (!isNumericId(options.expectedIssueId)) throw new JiraIssueWriteError("invalid-input");
|
|
179
|
-
const issue = await this.
|
|
204
|
+
const issue = await this.resolveMutationIssue(options);
|
|
180
205
|
const path = `/issue/${issue.id}`;
|
|
181
206
|
const readReceipt = async () => this.toReceipt(await this.readIssue(issue.id));
|
|
182
207
|
const permissions = await this.readPermissions(issue.id);
|
|
@@ -184,6 +209,7 @@ var JiraIssueWriter = class JiraIssueWriter {
|
|
|
184
209
|
if (!permissions.edit) throw new JiraIssueWriteError("forbidden");
|
|
185
210
|
const fields = validateFields(options.fields, this.editableFields(options), await this.readEditFields(issue.id));
|
|
186
211
|
if (Object.keys(fields).length === 0) throw new JiraIssueWriteError("invalid-input");
|
|
212
|
+
if (this.site.server) await this.resolveMutationIssue(options);
|
|
187
213
|
return this.dispatch("PUT", path, 204, readReceipt, { fields });
|
|
188
214
|
}
|
|
189
215
|
if (!isNumericId(options.transitionId)) throw new JiraIssueWriteError("invalid-input");
|
|
@@ -191,6 +217,7 @@ var JiraIssueWriter = class JiraIssueWriter {
|
|
|
191
217
|
const transition = (await this.readTransitions(issue.id)).find((item) => item.id === options.transitionId);
|
|
192
218
|
if (transition?.isAvailable !== true) throw new JiraIssueWriteError("transition-unavailable");
|
|
193
219
|
const fields = validateFields(options.fields, this.editableFields(options), transition.hasScreen ? transition.fields : []);
|
|
220
|
+
if (this.site.server) await this.resolveMutationIssue(options);
|
|
194
221
|
return this.dispatch("POST", `${path}/transitions`, 204, readReceipt, {
|
|
195
222
|
transition: { id: transition.id },
|
|
196
223
|
fields
|
|
@@ -204,6 +231,13 @@ var JiraIssueWriter = class JiraIssueWriter {
|
|
|
204
231
|
...description !== void 0 && { description }
|
|
205
232
|
};
|
|
206
233
|
}
|
|
234
|
+
async resolveMutationIssue(options) {
|
|
235
|
+
const expectedProjectId = "expectedProjectId" in options ? options.expectedProjectId : void 0;
|
|
236
|
+
if (this.site.server && !isNumericId(expectedProjectId)) throw new JiraIssueWriteError("invalid-input");
|
|
237
|
+
const issue = await this.resolveIssue(options);
|
|
238
|
+
if (this.site.server && expectedProjectId !== issue.fields.project.id) throw new JiraIssueWriteError("conflict");
|
|
239
|
+
return issue;
|
|
240
|
+
}
|
|
207
241
|
async resolveIssue(options) {
|
|
208
242
|
if (!isJiraWriteIdentifier(options.issue) || options.expectedIssueId !== void 0 && !isNumericId(options.expectedIssueId)) throw new JiraIssueWriteError("invalid-input");
|
|
209
243
|
const issue = await this.readIssue(options.issue);
|
|
@@ -241,8 +275,9 @@ var JiraIssueWriter = class JiraIssueWriter {
|
|
|
241
275
|
}
|
|
242
276
|
async readPermissionsFor(params) {
|
|
243
277
|
const query = new URLSearchParams(params);
|
|
278
|
+
if (this.site.server) query.delete("permissions");
|
|
244
279
|
const { permissions } = await this.read(`/mypermissions?${query.toString()}`);
|
|
245
|
-
return permissions;
|
|
280
|
+
return this.site.server ? Object.fromEntries(Object.entries(permissions).map(([key, permission]) => [permission.key ?? key, permission])) : permissions;
|
|
246
281
|
}
|
|
247
282
|
async readTransitions(issueId) {
|
|
248
283
|
const { transitions } = await this.read(`/issue/${issueId}/transitions?expand=transitions.fields`);
|
|
@@ -250,7 +285,7 @@ var JiraIssueWriter = class JiraIssueWriter {
|
|
|
250
285
|
id: transition.id,
|
|
251
286
|
name: transition.name,
|
|
252
287
|
to: toStatus(transition.to),
|
|
253
|
-
hasScreen: transition.hasScreen === true,
|
|
288
|
+
hasScreen: transition.hasScreen === true || this.site.server === true && Object.keys(transition.fields ?? {}).length > 0,
|
|
254
289
|
isAvailable: transition.isAvailable !== false,
|
|
255
290
|
isConditional: transition.isConditional === true,
|
|
256
291
|
fields: toFields(transition.fields ?? {})
|
|
@@ -262,7 +297,7 @@ var JiraIssueWriter = class JiraIssueWriter {
|
|
|
262
297
|
}
|
|
263
298
|
async readCreateFields(projectId, issueTypeId) {
|
|
264
299
|
if (!isNumericId(issueTypeId)) throw new JiraIssueWriteError("invalid-input");
|
|
265
|
-
const { values, truncated } = await this.readPages(`${this.createMetadataPath(projectId)}/${issueTypeId}`, (page) => page.fields ?? page.results);
|
|
300
|
+
const { values, truncated } = await this.readPages(`${this.createMetadataPath(projectId)}/${issueTypeId}`, (page) => this.site.server ? page.values : page.fields ?? page.results);
|
|
266
301
|
return {
|
|
267
302
|
values: values.map((field) => {
|
|
268
303
|
const id = field.fieldId ?? field.key;
|
|
@@ -281,9 +316,9 @@ var JiraIssueWriter = class JiraIssueWriter {
|
|
|
281
316
|
const startAt = values.length;
|
|
282
317
|
const page = await this.read(`${path}?startAt=${startAt}&maxResults=${pageSize}`);
|
|
283
318
|
const rows = items(page);
|
|
284
|
-
if (!Array.isArray(rows) || !Number.isSafeInteger(page.total) || page.total < 0 || page.startAt !== startAt) throw new Error("Jira returned invalid create metadata pagination");
|
|
319
|
+
if (!Array.isArray(rows) || (this.site.server ? typeof (page.last ?? page.isLast) !== "boolean" : !Number.isSafeInteger(page.total) || (page.total ?? -1) < 0) || (this.site.server ? page.start ?? page.startAt : page.startAt) !== startAt) throw new Error("Jira returned invalid create metadata pagination");
|
|
285
320
|
values.push(...rows);
|
|
286
|
-
if (values.length >= page.total) return {
|
|
321
|
+
if (this.site.server ? page.last ?? page.isLast : values.length >= page.total) return {
|
|
287
322
|
values,
|
|
288
323
|
truncated: false
|
|
289
324
|
};
|
|
@@ -296,7 +331,7 @@ var JiraIssueWriter = class JiraIssueWriter {
|
|
|
296
331
|
}
|
|
297
332
|
getDeleteRefusal(allowed, issue) {
|
|
298
333
|
if (!allowed) return "forbidden";
|
|
299
|
-
if (!this.site.scopes?.some((scope) => scope === "delete:issue:jira" || scope === "write:jira-work")) return "insufficient-scope";
|
|
334
|
+
if (!this.site.server && !this.site.scopes?.some((scope) => scope === "delete:issue:jira" || scope === "write:jira-work")) return "insufficient-scope";
|
|
300
335
|
if (!Array.isArray(issue.fields.subtasks) || issue.fields.subtasks.length !== 0) return "invalid-input";
|
|
301
336
|
}
|
|
302
337
|
async ensureDeletable(issue) {
|
|
@@ -382,6 +417,7 @@ var JiraIssueWriter = class JiraIssueWriter {
|
|
|
382
417
|
}
|
|
383
418
|
}
|
|
384
419
|
url(path) {
|
|
420
|
+
if (this.site.server) return `${this.site.url}/rest/api/2${path}`;
|
|
385
421
|
return `https://api.atlassian.com/ex/jira/${encodeURIComponent(this.site.id)}/rest/api/2${path}`;
|
|
386
422
|
}
|
|
387
423
|
headers() {
|
|
@@ -391,6 +427,19 @@ var JiraIssueWriter = class JiraIssueWriter {
|
|
|
391
427
|
};
|
|
392
428
|
}
|
|
393
429
|
};
|
|
430
|
+
function normalizeJiraServerSiteUrl(value, protocol = "https:") {
|
|
431
|
+
if (typeof value !== "string" || value.trim() !== value || /[\\?#]/.test(value)) throw new JiraIssueWriteError("invalid-input");
|
|
432
|
+
let url;
|
|
433
|
+
try {
|
|
434
|
+
url = new URL(/^[a-z][a-z\d+.-]*:\/\//i.test(value) ? value : `${protocol}//${value}`);
|
|
435
|
+
} catch {
|
|
436
|
+
throw new JiraIssueWriteError("invalid-input");
|
|
437
|
+
}
|
|
438
|
+
if (!["https:", "http:"].includes(url.protocol) || url.username || url.password || /%|(?:^|\/)\.\.?(?:\/|$)/.test(value.replace(/^[a-z]+:\/\/[^/]+/i, ""))) throw new JiraIssueWriteError("invalid-input");
|
|
439
|
+
const normalized = baseUrlFromDomain(value, protocol);
|
|
440
|
+
if (normalized == null) throw new JiraIssueWriteError("invalid-input");
|
|
441
|
+
return normalized;
|
|
442
|
+
}
|
|
394
443
|
//#endregion
|
|
395
444
|
export { JiraIssueWriter, isJiraWriteIdentifier };
|
|
396
445
|
|