@gitkraken/core-gitlens 0.37.1 → 0.38.1
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 +69 -1
- package/dist/git/cache.d.ts +128 -8
- package/dist/git/cache.js +425 -46
- package/dist/git/cache.js.map +1 -1
- package/dist/git/features.d.ts +1 -1
- package/dist/git/features.js +3 -0
- package/dist/git/features.js.map +1 -1
- package/dist/git/providers/branches.d.ts +42 -1
- package/dist/git/providers/diff.d.ts +17 -0
- package/dist/git/providers/provider.d.ts +7 -0
- package/dist/git/providers/shared/remotes.js +8 -4
- package/dist/git/providers/shared/remotes.js.map +1 -1
- package/dist/git/remotes/matcher.js +2 -2
- package/dist/git/remotes/matcher.js.map +1 -1
- package/dist/git/repositoryService.d.ts +16 -1
- package/dist/git/repositoryService.js +51 -3
- package/dist/git/repositoryService.js.map +1 -1
- package/dist/git/run.types.d.ts +1 -0
- package/dist/git/service.js +6 -2
- package/dist/git/service.js.map +1 -1
- package/dist/git/utils/fileStatus.utils.d.ts +5 -0
- package/dist/git/utils/fileStatus.utils.js +18 -1
- package/dist/git/utils/fileStatus.utils.js.map +1 -1
- package/dist/git/watching/changeEvent.d.ts +13 -3
- package/dist/git/watching/changeEvent.js +15 -4
- package/dist/git/watching/changeEvent.js.map +1 -1
- package/dist/git/watching/changeOrdinal.d.ts +9 -0
- package/dist/git/watching/changeOrdinal.js +14 -0
- package/dist/git/watching/changeOrdinal.js.map +1 -0
- package/dist/git/watching/unwatchedCacheValidator.d.ts +38 -5
- package/dist/git/watching/unwatchedCacheValidator.js +180 -36
- package/dist/git/watching/unwatchedCacheValidator.js.map +1 -1
- package/dist/git/watching/watchGroup.d.ts +63 -14
- package/dist/git/watching/watchGroup.js +213 -74
- package/dist/git/watching/watchGroup.js.map +1 -1
- package/dist/git/watching/watchService.js +4 -3
- package/dist/git/watching/watchService.js.map +1 -1
- package/dist/git/watching/watchSession.d.ts +10 -2
- package/dist/git/watching/watchSession.js +18 -4
- package/dist/git/watching/watchSession.js.map +1 -1
- package/dist/git/watching/watcherPatterns.d.ts +18 -4
- package/dist/git/watching/watcherPatterns.js +39 -8
- package/dist/git/watching/watcherPatterns.js.map +1 -1
- package/dist/git/watching/worktreeSummary.d.ts +23 -12
- package/dist/git/watching/worktreeSummary.js +164 -41
- package/dist/git/watching/worktreeSummary.js.map +1 -1
- package/dist/git-cli/cliGitProvider.d.ts +1 -0
- package/dist/git-cli/cliGitProvider.js +11 -2
- package/dist/git-cli/cliGitProvider.js.map +1 -1
- package/dist/git-cli/exec/git.d.ts +7 -2
- package/dist/git-cli/exec/git.js +46 -10
- package/dist/git-cli/exec/git.js.map +1 -1
- package/dist/git-cli/exec/headState.d.ts +24 -0
- package/dist/git-cli/exec/headState.js +46 -6
- package/dist/git-cli/exec/headState.js.map +1 -1
- package/dist/git-cli/parsers/logParser.js +6 -3
- package/dist/git-cli/parsers/logParser.js.map +1 -1
- package/dist/git-cli/providers/branches.d.ts +135 -10
- package/dist/git-cli/providers/branches.js +622 -80
- package/dist/git-cli/providers/branches.js.map +1 -1
- package/dist/git-cli/providers/commits.d.ts +16 -0
- package/dist/git-cli/providers/commits.js +80 -28
- package/dist/git-cli/providers/commits.js.map +1 -1
- package/dist/git-cli/providers/config.d.ts +10 -0
- package/dist/git-cli/providers/config.js +50 -12
- package/dist/git-cli/providers/config.js.map +1 -1
- package/dist/git-cli/providers/contributors.js +11 -7
- package/dist/git-cli/providers/contributors.js.map +1 -1
- package/dist/git-cli/providers/diff.d.ts +12 -0
- package/dist/git-cli/providers/diff.js +107 -15
- package/dist/git-cli/providers/diff.js.map +1 -1
- package/dist/git-cli/providers/graph.js +32 -25
- package/dist/git-cli/providers/graph.js.map +1 -1
- package/dist/git-cli/providers/operations.d.ts +37 -3
- package/dist/git-cli/providers/operations.js +124 -46
- package/dist/git-cli/providers/operations.js.map +1 -1
- package/dist/git-cli/providers/patch.js +1 -1
- package/dist/git-cli/providers/patch.js.map +1 -1
- package/dist/git-cli/providers/refs.d.ts +1 -1
- package/dist/git-cli/providers/refs.js +10 -11
- package/dist/git-cli/providers/refs.js.map +1 -1
- package/dist/git-cli/providers/status.d.ts +4 -5
- package/dist/git-cli/providers/status.js +36 -33
- package/dist/git-cli/providers/status.js.map +1 -1
- package/dist/git-cli/providers/tags.d.ts +8 -0
- package/dist/git-cli/providers/tags.js +53 -34
- package/dist/git-cli/providers/tags.js.map +1 -1
- package/dist/git-cli/service.d.ts +15 -0
- package/dist/git-cli/service.js +19 -1
- package/dist/git-cli/service.js.map +1 -1
- package/dist/plus/git-github/providers/github/diff.d.ts +1 -0
- package/dist/plus/git-github/providers/github/diff.js +6 -1
- package/dist/plus/git-github/providers/github/diff.js.map +1 -1
- package/dist/plus/integrations/integrationService.js +9 -0
- package/dist/plus/integrations/integrationService.js.map +1 -1
- package/dist/plus/integrations/providers/jira-server.js +1 -1
- package/dist/plus/integrations/providers/jira-server.js.map +1 -1
- package/dist/plus/integrations/providers/jira.d.ts +20 -9
- package/dist/plus/integrations/providers/jira.js +114 -99
- package/dist/plus/integrations/providers/jira.js.map +1 -1
- package/dist/plus/integrations/providers/linear.d.ts +11 -4
- package/dist/plus/integrations/providers/linear.js +75 -32
- package/dist/plus/integrations/providers/linear.js.map +1 -1
- package/dist/plus/integrations/providers/utils/discoveryCache.d.ts +35 -4
- package/dist/plus/integrations/providers/utils/discoveryCache.js +45 -11
- package/dist/plus/integrations/providers/utils/discoveryCache.js.map +1 -1
- package/dist/utils/env/node/exec.d.ts +8 -4
- package/dist/utils/env/node/exec.js +115 -9
- package/dist/utils/env/node/exec.js.map +1 -1
- package/dist/utils/holdOffMap.d.ts +23 -0
- package/dist/utils/holdOffMap.js +43 -0
- package/dist/utils/holdOffMap.js.map +1 -0
- package/dist/utils/promiseCache.d.ts +15 -2
- package/dist/utils/promiseCache.js +34 -4
- package/dist/utils/promiseCache.js.map +1 -1
- package/package.json +1 -1
|
@@ -164,7 +164,7 @@ var JiraServerIntegration = class extends IssuesIntegration {
|
|
|
164
164
|
const generation = this._projects.generation;
|
|
165
165
|
const descriptors = await this.readProjects(session);
|
|
166
166
|
if (descriptors == null) return void 0;
|
|
167
|
-
if (this._projects.set(cacheKey, descriptors, { generation })) this._autolinks.delete(cacheKey);
|
|
167
|
+
if (this._projects.set(cacheKey, descriptors, { generation }) !== false) this._autolinks.delete(cacheKey);
|
|
168
168
|
return descriptors;
|
|
169
169
|
}
|
|
170
170
|
async getProviderUncachedProjectsForResourcesWithMetadata(session, resources) {
|
|
@@ -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 { IntegrationKey } from '../models/integration.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 { areDomainsOnSameHost, baseUrlFromDomain } from '../utils/domain.utils.js';\nimport type { ProviderApiCollectionResult } from './models.js';\nimport { providersMetadata, 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 })) {\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":";;;;;;;;;;;;;;AA4CA,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;EAE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B,sBAAsB,KAAK,GAAG,QAAQ;EACzE;CACD;CAEA,MAAyB,oCACxB,SACA,WACA,EAAE,OACwC;EAE1C,MAAM,QAAQ,OAAM,MADF,KAAK,gBAAgB,EAAA,CACf,mBAAmB,gBAAgB,KAAK,IAAI,OAAO,GAAG,KAAK,cAAc,OAAO,GAAG,GAAG;EAC9G,OAAO,SAAS,OAAO,aAAa,OAAO,MAAM,EAAE,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 { 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 { IntegrationKey } from '../models/integration.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 { areDomainsOnSameHost, baseUrlFromDomain } from '../utils/domain.utils.js';\nimport type { ProviderApiCollectionResult } from './models.js';\nimport { providersMetadata, 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}\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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"}
|
|
@@ -29,16 +29,29 @@ export declare class JiraIntegration extends IssuesIntegration<IssuesCloudHostIn
|
|
|
29
29
|
protected get apiBaseUrl(): string;
|
|
30
30
|
/**
|
|
31
31
|
* Built from the sites and their projects, so it follows them: rebuilt when a site's project list changes or the
|
|
32
|
-
* caches are dropped, and once
|
|
33
|
-
*
|
|
34
|
-
*
|
|
32
|
+
* caches are dropped, and once {@link isAutolinkSetExpired}: older than the TTL, or than a shorter retry delay when
|
|
33
|
+
* the sites or a site's projects couldn't be read whole. An expired set is still served while it is rebuilt in the
|
|
34
|
+
* background, because autolinks are read on every render of a commit message and must not wait on the network,
|
|
35
|
+
* nor go empty just because nothing read the projects for a while (#5907, #6183).
|
|
35
36
|
*/
|
|
36
37
|
private readonly _autolinks;
|
|
37
38
|
private readonly _autolinksBuilds;
|
|
39
|
+
/**
|
|
40
|
+
* Moves, by token, on every missing-project eviction, which drops one site's list without clearing the caches: a
|
|
41
|
+
* build or project read that started before it puts neither the list it read back in `_projects` nor what it built
|
|
42
|
+
* from it in `_autolinks` (#6176). Cleared with `_projects`, whose generation then refuses those same writes.
|
|
43
|
+
*/
|
|
44
|
+
private readonly _projectEvictions;
|
|
38
45
|
autolinks(): Promise<(AutolinkReference | DynamicAutolinkReference)[]>;
|
|
39
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* One build per token at a time: concurrent renders share it rather than each re-reading sites and projects. A
|
|
48
|
+
* drop, a missing-project eviction or a change to a site's project list retires it, so a render after one doesn't
|
|
49
|
+
* join a build reading the lists as they were before (#6170, #6176, #6184).
|
|
50
|
+
*/
|
|
40
51
|
private buildAutolinks;
|
|
41
52
|
private buildAutolinksCore;
|
|
53
|
+
private deriveAutolinks;
|
|
54
|
+
private onDiscoveryStored;
|
|
42
55
|
protected getProviderAccountForResource(session: ProviderAuthenticationSession, resource: JiraOrganizationDescriptor): Promise<Account | undefined>;
|
|
43
56
|
/** Atlassian's account id is the same on every site, so the first site answers for all of them. */
|
|
44
57
|
protected getProviderCurrentAccount(session: ProviderAuthenticationSession): Promise<Account | undefined>;
|
|
@@ -56,17 +69,15 @@ export declare class JiraIntegration extends IssuesIntegration<IssuesCloudHostIn
|
|
|
56
69
|
*/
|
|
57
70
|
private readonly _organizations;
|
|
58
71
|
private readonly _projects;
|
|
59
|
-
|
|
60
|
-
private _discoveryInvalidatedAt;
|
|
61
|
-
protected getProviderResourcesForUser(session: ProviderAuthenticationSession, force?: boolean): Promise<JiraOrganizationDescriptor[] | undefined>;
|
|
72
|
+
protected getProviderResourcesForUser(session: ProviderAuthenticationSession, force?: boolean, reader?: () => Promise<unknown> | undefined): Promise<JiraOrganizationDescriptor[] | undefined>;
|
|
62
73
|
protected getProviderUncachedResourcesForUser(session: ProviderAuthenticationSession): Promise<JiraOrganizationDescriptor[] | undefined>;
|
|
63
74
|
private readOrganizations;
|
|
64
75
|
protected getProviderProjectsForResources(session: ProviderAuthenticationSession, resources: JiraOrganizationDescriptor[], force?: boolean): Promise<JiraProjectDescriptor[] | undefined>;
|
|
65
|
-
protected getProviderProjectsForResourcesWithMetadata(session: ProviderAuthenticationSession, resources: JiraOrganizationDescriptor[], force?: boolean): Promise<ProviderApiCollectionResult<JiraProjectDescriptor>>;
|
|
76
|
+
protected getProviderProjectsForResourcesWithMetadata(session: ProviderAuthenticationSession, resources: JiraOrganizationDescriptor[], force?: boolean, reader?: () => Promise<unknown> | undefined): Promise<ProviderApiCollectionResult<JiraProjectDescriptor>>;
|
|
66
77
|
protected getProviderUncachedProjectsForResourcesWithMetadata(session: ProviderAuthenticationSession, resources: JiraOrganizationDescriptor[]): Promise<ProviderApiCollectionResult<JiraProjectDescriptor>>;
|
|
67
78
|
/**
|
|
68
79
|
* Reads the projects of each resource from the provider, apart by whether a resource's list came back complete:
|
|
69
|
-
*
|
|
80
|
+
* incomplete lists remain available for decoration but cannot satisfy a fresh discovery read.
|
|
70
81
|
*/
|
|
71
82
|
private readProjects;
|
|
72
83
|
protected getProviderIssuesForProject(session: ProviderAuthenticationSession, project: JiraProjectDescriptor, options?: IssuesForProjectOptions): Promise<IssueShape[] | undefined>;
|
|
@@ -9,7 +9,7 @@ import { providersMetadata, toAccount, toIssueShape, toProviderIssueStates } fro
|
|
|
9
9
|
import { toTokenWithInfo } from "../authentication/models.js";
|
|
10
10
|
import { IssuesIntegration, groupProjectIssuesSearches } from "../models/issuesIntegration.js";
|
|
11
11
|
import { createIssueAutolinkReferences } from "./utils/issueAutolinks.js";
|
|
12
|
-
import { DiscoveryCache } from "./utils/discoveryCache.js";
|
|
12
|
+
import { DiscoveryCache, isAutolinkSetExpired } from "./utils/discoveryCache.js";
|
|
13
13
|
import { drainJiraIssues, readUserScopedJiraIssues, searchJiraProjectIssues, summarizePageMetadata, toUniqueJiraIssueShapes } from "./utils/jiraIssueDrains.js";
|
|
14
14
|
import { toJiraIssueEtagFields } from "./jiraIssueByKey.js";
|
|
15
15
|
import { JIRA_MAX_PROJECT_KEYS_PER_REQUEST } from "@gitkraken/provider-apis";
|
|
@@ -52,53 +52,78 @@ var JiraIntegration = class extends IssuesIntegration {
|
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
54
|
* Built from the sites and their projects, so it follows them: rebuilt when a site's project list changes or the
|
|
55
|
-
* caches are dropped, and once
|
|
56
|
-
*
|
|
57
|
-
*
|
|
55
|
+
* caches are dropped, and once {@link isAutolinkSetExpired}: older than the TTL, or than a shorter retry delay when
|
|
56
|
+
* the sites or a site's projects couldn't be read whole. An expired set is still served while it is rebuilt in the
|
|
57
|
+
* background, because autolinks are read on every render of a commit message and must not wait on the network,
|
|
58
|
+
* nor go empty just because nothing read the projects for a while (#5907, #6183).
|
|
58
59
|
*/
|
|
59
60
|
_autolinks = /* @__PURE__ */ new Map();
|
|
60
61
|
_autolinksBuilds = /* @__PURE__ */ new Map();
|
|
62
|
+
/**
|
|
63
|
+
* Moves, by token, on every missing-project eviction, which drops one site's list without clearing the caches: a
|
|
64
|
+
* build or project read that started before it puts neither the list it read back in `_projects` nor what it built
|
|
65
|
+
* from it in `_autolinks` (#6176). Cleared with `_projects`, whose generation then refuses those same writes.
|
|
66
|
+
*/
|
|
67
|
+
_projectEvictions = /* @__PURE__ */ new Map();
|
|
61
68
|
async autolinks() {
|
|
62
69
|
if (!(this.maybeConnected ?? await this.isConnected()) || this._session == null) return [];
|
|
63
70
|
const session = this._session;
|
|
64
71
|
const cached = this._autolinks.get(session.accessToken);
|
|
65
72
|
if (this.connectionExpired === true) return cached?.autolinks ?? [];
|
|
66
|
-
if (cached == null) return this.buildAutolinks(session);
|
|
67
|
-
if (
|
|
73
|
+
if (cached == null || cached.builtAt === 0 && !cached.complete && cached.autolinks.length === 0) return this.buildAutolinks(session);
|
|
74
|
+
if (cached.builtAt === 0 || isAutolinkSetExpired(cached)) this.buildAutolinks(session);
|
|
68
75
|
return cached.autolinks;
|
|
69
76
|
}
|
|
70
|
-
/**
|
|
77
|
+
/**
|
|
78
|
+
* One build per token at a time: concurrent renders share it rather than each re-reading sites and projects. A
|
|
79
|
+
* drop, a missing-project eviction or a change to a site's project list retires it, so a render after one doesn't
|
|
80
|
+
* join a build reading the lists as they were before (#6170, #6176, #6184).
|
|
81
|
+
*/
|
|
71
82
|
buildAutolinks(session) {
|
|
72
83
|
const { accessToken } = session;
|
|
73
84
|
let build = this._autolinksBuilds.get(accessToken);
|
|
74
85
|
if (build == null) {
|
|
75
|
-
build = this.buildAutolinksCore(session).finally(() =>
|
|
86
|
+
build = this.buildAutolinksCore(session, () => build).finally(() => {
|
|
87
|
+
if (this._autolinksBuilds.get(accessToken) === build) this._autolinksBuilds.delete(accessToken);
|
|
88
|
+
});
|
|
76
89
|
this._autolinksBuilds.set(accessToken, build);
|
|
77
90
|
}
|
|
78
91
|
return build;
|
|
79
92
|
}
|
|
80
|
-
async buildAutolinksCore(session) {
|
|
93
|
+
async buildAutolinksCore(session, reader) {
|
|
81
94
|
const { accessToken } = session;
|
|
82
95
|
const generation = this._projects.generation;
|
|
96
|
+
const evictions = this._projectEvictions.get(accessToken);
|
|
83
97
|
try {
|
|
84
|
-
const organizations = await this.getProviderResourcesForUser(session);
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
for (const project of projects) {
|
|
89
|
-
const organization = organizations.find((o) => o.id === project.resourceId);
|
|
90
|
-
if (organization == null) continue;
|
|
91
|
-
autolinks.push(...createIssueAutolinkReferences(project.key, `${organization.url}/browse/${project.key}-<num>`, organization));
|
|
98
|
+
const organizations = await this.getProviderResourcesForUser(session, false, reader);
|
|
99
|
+
if (organizations != null && this._projects.generation === generation && this._projectEvictions.get(accessToken) === evictions) {
|
|
100
|
+
const projects = await this.getProviderProjectsForResourcesWithMetadata(session, organizations, false, reader);
|
|
101
|
+
if ((this._projects.generation !== generation || this._projectEvictions.get(accessToken) !== evictions) && (projects.values.length > 0 || !projects.metadata?.failures?.length)) return organizations.flatMap((organization) => getProjectAutolinks(organization, projects.values.filter((p) => p.resourceId === organization.id)));
|
|
92
102
|
}
|
|
93
|
-
if ((metadata == null || metadata.completeness === "complete") && this._projects.generation === generation) this._autolinks.set(accessToken, {
|
|
94
|
-
autolinks,
|
|
95
|
-
builtAt: Date.now()
|
|
96
|
-
});
|
|
97
|
-
return autolinks;
|
|
98
103
|
} catch (ex) {
|
|
99
104
|
_logger.error(ex, "JiraIntegration.autolinks");
|
|
100
|
-
return this._autolinks.get(accessToken)?.autolinks ?? [];
|
|
101
105
|
}
|
|
106
|
+
return this.deriveAutolinks(accessToken, { store: this._projects.generation === generation && this._projectEvictions.get(accessToken) === evictions });
|
|
107
|
+
}
|
|
108
|
+
deriveAutolinks(accessToken, options) {
|
|
109
|
+
const organizations = this._organizations.peek(accessToken);
|
|
110
|
+
let complete = this._organizations.get(accessToken) != null;
|
|
111
|
+
const autolinks = [];
|
|
112
|
+
for (const organization of organizations ?? []) {
|
|
113
|
+
const key = `${accessToken}:${organization.id}`;
|
|
114
|
+
complete &&= this._projects.get(key) != null;
|
|
115
|
+
autolinks.push(...getProjectAutolinks(organization, this._projects.peek(key) ?? []));
|
|
116
|
+
}
|
|
117
|
+
if (options?.store !== false) this._autolinks.set(accessToken, {
|
|
118
|
+
autolinks,
|
|
119
|
+
complete,
|
|
120
|
+
builtAt: options?.settled !== false ? Date.now() : this._autolinks.get(accessToken)?.builtAt || (complete ? Date.now() : 0)
|
|
121
|
+
});
|
|
122
|
+
return autolinks;
|
|
123
|
+
}
|
|
124
|
+
onDiscoveryStored(accessToken, reader) {
|
|
125
|
+
if (this._autolinksBuilds.get(accessToken) !== reader?.()) this._autolinksBuilds.delete(accessToken);
|
|
126
|
+
this.deriveAutolinks(accessToken, { settled: false });
|
|
102
127
|
}
|
|
103
128
|
async getProviderAccountForResource(session, resource) {
|
|
104
129
|
const user = await (await this.getProvidersApi()).getCurrentUserForResource(toTokenWithInfo(this.id, session), resource.id);
|
|
@@ -128,20 +153,20 @@ var JiraIntegration = class extends IssuesIntegration {
|
|
|
128
153
|
*/
|
|
129
154
|
_organizations = new DiscoveryCache();
|
|
130
155
|
_projects = new DiscoveryCache();
|
|
131
|
-
|
|
132
|
-
_discoveryInvalidatedAt = 0;
|
|
133
|
-
async getProviderResourcesForUser(session, force = false) {
|
|
156
|
+
async getProviderResourcesForUser(session, force = false, reader) {
|
|
134
157
|
const { accessToken } = session;
|
|
135
158
|
const cachedResources = this._organizations.get(accessToken);
|
|
136
159
|
if (cachedResources != null && !force) return cachedResources;
|
|
137
160
|
const generation = this._organizations.generation;
|
|
161
|
+
const started = this._organizations.startRead();
|
|
138
162
|
const organizations = await this.readOrganizations(session);
|
|
139
|
-
if (organizations == null)
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
163
|
+
if (organizations == null) return void 0;
|
|
164
|
+
const stored = this._organizations.set(accessToken, organizations, {
|
|
165
|
+
generation,
|
|
166
|
+
read: started
|
|
167
|
+
});
|
|
168
|
+
if (stored === "changed") this.onDiscoveryStored(accessToken, reader);
|
|
169
|
+
return stored === false && this._organizations.generation === generation ? this._organizations.peek(accessToken) : organizations;
|
|
145
170
|
}
|
|
146
171
|
getProviderUncachedResourcesForUser(session) {
|
|
147
172
|
return this.readOrganizations(session);
|
|
@@ -155,10 +180,12 @@ var JiraIntegration = class extends IssuesIntegration {
|
|
|
155
180
|
async getProviderProjectsForResources(session, resources, force = false) {
|
|
156
181
|
return (await this.getProviderProjectsForResourcesWithMetadata(session, resources, force)).values;
|
|
157
182
|
}
|
|
158
|
-
async getProviderProjectsForResourcesWithMetadata(session, resources, force = false) {
|
|
183
|
+
async getProviderProjectsForResourcesWithMetadata(session, resources, force = false, reader) {
|
|
159
184
|
const { accessToken } = session;
|
|
160
185
|
const projectsCache = this._projects;
|
|
161
186
|
const generation = projectsCache.generation;
|
|
187
|
+
const evictions = this._projectEvictions.get(accessToken);
|
|
188
|
+
const started = projectsCache.startRead();
|
|
162
189
|
const cachedProjects = /* @__PURE__ */ new Map();
|
|
163
190
|
for (const resource of resources) {
|
|
164
191
|
const projects = projectsCache.get(`${accessToken}:${resource.id}`);
|
|
@@ -166,46 +193,68 @@ var JiraIntegration = class extends IssuesIntegration {
|
|
|
166
193
|
}
|
|
167
194
|
const resourcesWithoutProjects = force ? resources : resources.filter((resource) => !cachedProjects.has(resource.id));
|
|
168
195
|
const read = await this.readProjects(session, resourcesWithoutProjects);
|
|
169
|
-
const values = [
|
|
170
|
-
|
|
196
|
+
const values = [];
|
|
197
|
+
let metadata = read.metadata;
|
|
198
|
+
let changed = false;
|
|
199
|
+
for (const [resourceId, projects] of [...read.complete, ...read.incomplete]) {
|
|
200
|
+
if (this._projectEvictions.get(accessToken) !== evictions) continue;
|
|
201
|
+
if (projectsCache.set(`${accessToken}:${resourceId}`, projects, {
|
|
202
|
+
generation,
|
|
203
|
+
read: started,
|
|
204
|
+
complete: read.complete.has(resourceId)
|
|
205
|
+
}) === "changed") changed = true;
|
|
206
|
+
}
|
|
207
|
+
if (changed) this.onDiscoveryStored(accessToken, reader);
|
|
208
|
+
const current = projectsCache.generation === generation && this._projectEvictions.get(accessToken) === evictions;
|
|
171
209
|
for (const resource of resources) {
|
|
172
|
-
const resourceProjects = read.complete.get(resource.id) ?? cachedProjects.get(resource.id);
|
|
173
|
-
if (resourceProjects
|
|
210
|
+
const resourceProjects = read.complete.get(resource.id) ?? read.incomplete.get(resource.id) ?? cachedProjects.get(resource.id);
|
|
211
|
+
if (resourceProjects == null) continue;
|
|
212
|
+
const stored = current ? projectsCache.peek(`${accessToken}:${resource.id}`) : void 0;
|
|
213
|
+
values.push(...stored ?? resourceProjects);
|
|
214
|
+
if (stored != null && projectsCache.get(`${accessToken}:${resource.id}`) == null) metadata = mergeCollectionMetadata(metadata, { completeness: "unknown" });
|
|
174
215
|
}
|
|
175
216
|
return {
|
|
176
217
|
values: uniqueProjects(values),
|
|
177
|
-
metadata
|
|
218
|
+
metadata
|
|
178
219
|
};
|
|
179
220
|
}
|
|
180
221
|
async getProviderUncachedProjectsForResourcesWithMetadata(session, resources) {
|
|
181
222
|
const read = await this.readProjects(session, resources);
|
|
182
223
|
return {
|
|
183
|
-
values: uniqueProjects([...read.
|
|
224
|
+
values: uniqueProjects([...read.incomplete.values(), ...read.complete.values()].flat()),
|
|
184
225
|
metadata: read.metadata
|
|
185
226
|
};
|
|
186
227
|
}
|
|
187
228
|
/**
|
|
188
229
|
* Reads the projects of each resource from the provider, apart by whether a resource's list came back complete:
|
|
189
|
-
*
|
|
230
|
+
* incomplete lists remain available for decoration but cannot satisfy a fresh discovery read.
|
|
190
231
|
*/
|
|
191
232
|
async readProjects(session, resources) {
|
|
192
233
|
const complete = /* @__PURE__ */ new Map();
|
|
193
|
-
const
|
|
234
|
+
const incompleteLists = /* @__PURE__ */ new Map();
|
|
194
235
|
let metadata;
|
|
195
236
|
if (resources.length === 0) return {
|
|
196
237
|
complete,
|
|
197
|
-
|
|
238
|
+
incomplete: incompleteLists,
|
|
198
239
|
metadata
|
|
199
240
|
};
|
|
200
241
|
const api = await this.getProvidersApi();
|
|
201
242
|
const tokenWithInfo = toTokenWithInfo(this.id, session);
|
|
202
|
-
(await Promise.allSettled(resources.map(async (resource) =>
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
243
|
+
(await Promise.allSettled(resources.map(async (resource) => {
|
|
244
|
+
let readPage = false;
|
|
245
|
+
return {
|
|
246
|
+
resource,
|
|
247
|
+
result: await collectProviderPagedResult(async (cursor) => {
|
|
248
|
+
const page = await api.getJiraProjectsForResource(tokenWithInfo, resource.id, { cursor });
|
|
249
|
+
readPage ||= page != null && (page.values.length > 0 || !page.metadata?.failures?.length);
|
|
250
|
+
return page;
|
|
251
|
+
}, maxPagesPerRequest, {
|
|
252
|
+
providerId: this.id,
|
|
253
|
+
resourceId: resource.id
|
|
254
|
+
}),
|
|
255
|
+
readPage
|
|
256
|
+
};
|
|
257
|
+
}))).forEach((drain, index) => {
|
|
209
258
|
if (drain.status === "rejected") {
|
|
210
259
|
const resource = resources[index];
|
|
211
260
|
if (resource == null) return;
|
|
@@ -218,11 +267,11 @@ var JiraIntegration = class extends IssuesIntegration {
|
|
|
218
267
|
});
|
|
219
268
|
return;
|
|
220
269
|
}
|
|
221
|
-
const { resource, result } = drain.value;
|
|
270
|
+
const { resource, result, readPage } = drain.value;
|
|
222
271
|
metadata = mergeCollectionMetadata(metadata, result.metadata);
|
|
223
272
|
const projects = result.values.filter((project) => project.resourceId === resource.id).map((project) => ({ ...project }));
|
|
224
273
|
if (result.truncated === true || result.metadata != null && result.metadata.completeness !== "complete") {
|
|
225
|
-
|
|
274
|
+
if (readPage) incompleteLists.set(resource.id, projects);
|
|
226
275
|
if (result.truncated === true && (result.metadata == null || result.metadata.completeness === "complete")) metadata = mergeCollectionMetadata(metadata, { completeness: "partial" });
|
|
227
276
|
return;
|
|
228
277
|
}
|
|
@@ -230,7 +279,7 @@ var JiraIntegration = class extends IssuesIntegration {
|
|
|
230
279
|
});
|
|
231
280
|
return {
|
|
232
281
|
complete,
|
|
233
|
-
|
|
282
|
+
incomplete: incompleteLists,
|
|
234
283
|
metadata
|
|
235
284
|
};
|
|
236
285
|
}
|
|
@@ -258,8 +307,11 @@ var JiraIntegration = class extends IssuesIntegration {
|
|
|
258
307
|
isEmptyFailure: (ex) => {
|
|
259
308
|
if (!isJiraMissingProjectError(ex)) return false;
|
|
260
309
|
_logger.warn(`Jira project '${project.key}' no longer exists or is not visible`);
|
|
261
|
-
|
|
262
|
-
this.
|
|
310
|
+
const { accessToken } = session;
|
|
311
|
+
this._projects.delete(`${accessToken}:${project.resourceId}`);
|
|
312
|
+
this._projectEvictions.set(accessToken, (this._projectEvictions.get(accessToken) ?? 0) + 1);
|
|
313
|
+
this._autolinks.delete(accessToken);
|
|
314
|
+
this._autolinksBuilds.delete(accessToken);
|
|
263
315
|
return true;
|
|
264
316
|
}
|
|
265
317
|
};
|
|
@@ -509,63 +561,26 @@ var JiraIntegration = class extends IssuesIntegration {
|
|
|
509
561
|
this._autolinks.clear();
|
|
510
562
|
if (this._session == null) return;
|
|
511
563
|
const session = this._session;
|
|
512
|
-
const
|
|
513
|
-
|
|
514
|
-
const projectsGeneration = this._projects.generation;
|
|
515
|
-
const isFresh = (timestamp) => typeof timestamp === "number" && timestamp > this._discoveryInvalidatedAt && Date.now() - timestamp < 3e5;
|
|
516
|
-
const storedOrganizations = this.ctx.storage.get(`jira:${accessToken}:organizations`);
|
|
517
|
-
const storedProjects = storedOrganizations != null ? this.ctx.storage.get(`jira:${accessToken}:projects`) : void 0;
|
|
518
|
-
let organizations;
|
|
519
|
-
if (storedOrganizations?.data != null && isFresh(storedOrganizations.timestamp)) {
|
|
520
|
-
const seeded = storedOrganizations.data.map((o) => ({ ...o }));
|
|
521
|
-
organizations = seeded;
|
|
522
|
-
this._organizations.set(accessToken, seeded, {
|
|
523
|
-
generation: organizationsGeneration,
|
|
524
|
-
storedAt: storedOrganizations.timestamp
|
|
525
|
-
});
|
|
526
|
-
} else {
|
|
527
|
-
const readAt = Date.now();
|
|
528
|
-
organizations = await this.getProviderResourcesForUser(session, true);
|
|
529
|
-
if (storedOrganizations == null) await this.ctx.storage.deleteWithPrefix("jira");
|
|
530
|
-
if (this._organizations.generation === organizationsGeneration) await this.ctx.storage.store(`jira:${accessToken}:organizations`, {
|
|
531
|
-
v: 1,
|
|
532
|
-
timestamp: readAt,
|
|
533
|
-
data: organizations
|
|
534
|
-
});
|
|
535
|
-
}
|
|
536
|
-
if (storedProjects?.data != null && isFresh(storedProjects.timestamp)) {
|
|
537
|
-
const projectsByResource = /* @__PURE__ */ new Map();
|
|
538
|
-
for (const project of storedProjects.data) {
|
|
539
|
-
const projects = projectsByResource.get(project.resourceId);
|
|
540
|
-
if (projects == null) projectsByResource.set(project.resourceId, [{ ...project }]);
|
|
541
|
-
else if (!projects.some((p) => p.id === project.id)) projects.push({ ...project });
|
|
542
|
-
}
|
|
543
|
-
for (const [resourceId, projects] of projectsByResource) this._projects.set(`${accessToken}:${resourceId}`, projects, {
|
|
544
|
-
generation: projectsGeneration,
|
|
545
|
-
storedAt: storedProjects.timestamp
|
|
546
|
-
});
|
|
547
|
-
} else if (organizations?.length) {
|
|
548
|
-
const readAt = Date.now();
|
|
549
|
-
const projects = await this.getProviderProjectsForResources(session, organizations, true);
|
|
550
|
-
if (this._projects.generation === projectsGeneration) await this.ctx.storage.store(`jira:${accessToken}:projects`, {
|
|
551
|
-
v: 1,
|
|
552
|
-
timestamp: readAt,
|
|
553
|
-
data: projects
|
|
554
|
-
});
|
|
555
|
-
}
|
|
564
|
+
const organizations = await this.getProviderResourcesForUser(session, true);
|
|
565
|
+
if (organizations?.length) await this.getProviderProjectsForResources(session, organizations, true);
|
|
556
566
|
}
|
|
557
567
|
clearDiscoveryCaches() {
|
|
558
|
-
this._discoveryInvalidatedAt = Date.now();
|
|
559
568
|
this._organizations.clear();
|
|
560
569
|
this._projects.clear();
|
|
570
|
+
this._projectEvictions.clear();
|
|
561
571
|
this._autolinks.clear();
|
|
572
|
+
this._autolinksBuilds.clear();
|
|
562
573
|
}
|
|
563
574
|
providerOnDisconnect() {
|
|
564
575
|
this._organizations.clear();
|
|
565
576
|
this._projects.clear();
|
|
577
|
+
this._projectEvictions.clear();
|
|
566
578
|
this._autolinks.clear();
|
|
567
579
|
}
|
|
568
580
|
};
|
|
581
|
+
function getProjectAutolinks(organization, projects) {
|
|
582
|
+
return projects.flatMap((project) => createIssueAutolinkReferences(project.key, `${organization.url}/browse/${project.key}-<num>`, organization));
|
|
583
|
+
}
|
|
569
584
|
/** The projects once each, by site and id. */
|
|
570
585
|
function uniqueProjects(projects) {
|
|
571
586
|
const projectsByIdentity = /* @__PURE__ */ new Map();
|