@gitkraken/core-gitlens 0.45.0 → 0.47.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 +35 -1
- package/dist/git/models/remote.js +2 -2
- package/dist/git/models/remote.js.map +1 -1
- package/dist/git/remotes/matcher.js +25 -3
- package/dist/git/remotes/matcher.js.map +1 -1
- package/dist/git/utils/branchLanded.utils.d.ts +7 -0
- package/dist/git/utils/branchLanded.utils.js +10 -1
- package/dist/git/utils/branchLanded.utils.js.map +1 -1
- package/dist/git/utils/remote.utils.d.ts +1 -0
- package/dist/git/utils/remote.utils.js +14 -5
- package/dist/git/utils/remote.utils.js.map +1 -1
- package/dist/git-cli/parsers/logParser.js +227 -468
- package/dist/git-cli/parsers/logParser.js.map +1 -1
- package/dist/git-cli/parsers/refParser.js +4 -4
- package/dist/git-cli/parsers/refParser.js.map +1 -1
- package/dist/git-cli/providers/branches.d.ts +5 -0
- package/dist/git-cli/providers/branches.js +25 -21
- package/dist/git-cli/providers/branches.js.map +1 -1
- package/dist/git-cli/providers/config.js +2 -2
- package/dist/git-cli/providers/pausedOperations.js +2 -2
- package/dist/git-cli/providers/pausedOperations.js.map +1 -1
- package/dist/git-cli/providers/staging.js +1 -1
- package/dist/ipc/discovery.js +1 -1
- package/dist/plus/agents/providers/claudeCodeTranscript.js +6 -6
- package/dist/plus/agents/providers/claudeCodeTranscript.js.map +1 -1
- package/dist/plus/ai/providers/openAICompatibleProviderBase.js +1 -1
- package/dist/plus/git-github/api/enterprisePullRequestMergePolicy.d.ts +31 -0
- package/dist/plus/git-github/api/enterprisePullRequestMergePolicy.js +166 -0
- package/dist/plus/git-github/api/enterprisePullRequestMergePolicy.js.map +1 -0
- package/dist/plus/git-github/api/github.d.ts +13 -5
- package/dist/plus/git-github/api/github.js +53 -13
- package/dist/plus/git-github/api/github.js.map +1 -1
- package/dist/plus/git-github/api/issueWrites.d.ts +7 -1
- package/dist/plus/git-github/api/issueWrites.js +62 -32
- package/dist/plus/git-github/api/issueWrites.js.map +1 -1
- package/dist/plus/git-github/api/pullRequestWrites.d.ts +7 -3
- package/dist/plus/git-github/api/pullRequestWrites.js +120 -67
- package/dist/plus/git-github/api/pullRequestWrites.js.map +1 -1
- package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.d.ts +44 -0
- package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.js +199 -0
- package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.js.map +1 -0
- package/dist/plus/integrations/authentication/configuredIntegrationService.d.ts +7 -0
- package/dist/plus/integrations/authentication/configuredIntegrationService.js +53 -7
- package/dist/plus/integrations/authentication/configuredIntegrationService.js.map +1 -1
- package/dist/plus/integrations/authentication/integrationAuthenticationProvider.d.ts +2 -38
- package/dist/plus/integrations/authentication/integrationAuthenticationProvider.js +0 -199
- package/dist/plus/integrations/authentication/integrationAuthenticationService.d.ts +4 -2
- package/dist/plus/integrations/authentication/integrationAuthenticationService.js +12 -1
- package/dist/plus/integrations/authentication/integrationAuthenticationService.js.map +1 -1
- package/dist/plus/integrations/authentication/models.d.ts +0 -1
- package/dist/plus/integrations/authentication/models.js +1 -2
- package/dist/plus/integrations/authentication/models.js.map +1 -1
- package/dist/plus/integrations/constants.d.ts +0 -10
- package/dist/plus/integrations/constants.js +1 -95
- package/dist/plus/integrations/constants.js.map +1 -1
- package/dist/plus/integrations/context.d.ts +17 -17
- package/dist/plus/integrations/index.d.ts +44 -25
- package/dist/plus/integrations/index.js +41 -8
- package/dist/plus/integrations/index.js.map +1 -1
- package/dist/plus/integrations/integrationService.d.ts +24 -24
- package/dist/plus/integrations/integrationService.js +125 -34
- package/dist/plus/integrations/integrationService.js.map +1 -1
- package/dist/plus/integrations/lite.js +1 -1
- package/dist/plus/integrations/lite.js.map +1 -1
- package/dist/plus/integrations/manager.d.ts +81 -21
- package/dist/plus/integrations/models/actionablePullRequest.d.ts +213 -0
- package/dist/plus/integrations/models/actionablePullRequest.js +25 -0
- package/dist/plus/integrations/models/actionablePullRequest.js.map +1 -0
- package/dist/plus/integrations/models/gitHostIntegration.d.ts +13 -46
- package/dist/plus/integrations/models/gitHostIntegration.js +22 -8
- package/dist/plus/integrations/models/gitHostIntegration.js.map +1 -1
- package/dist/plus/integrations/models/integration.d.ts +11 -175
- package/dist/plus/integrations/models/integration.js +22 -76
- package/dist/plus/integrations/models/integration.js.map +1 -1
- package/dist/plus/integrations/models/issueTrackerWrites.d.ts +128 -0
- package/dist/plus/integrations/models/issueTrackerWrites.js +0 -0
- package/dist/plus/integrations/models/issuesIntegration.d.ts +9 -5
- package/dist/plus/integrations/models/issuesIntegration.js +5 -3
- package/dist/plus/integrations/models/issuesIntegration.js.map +1 -1
- package/dist/plus/integrations/models/publicIntegration.d.ts +257 -0
- package/dist/plus/integrations/models/publicIntegration.js +21 -0
- package/dist/plus/integrations/models/publicIntegration.js.map +1 -0
- package/dist/plus/integrations/providerFilters.d.ts +58 -0
- package/dist/plus/integrations/providerFilters.js.map +1 -1
- package/dist/plus/integrations/providers/actionablePullRequests.d.ts +19 -0
- package/dist/plus/integrations/providers/actionablePullRequests.js +32 -0
- package/dist/plus/integrations/providers/actionablePullRequests.js.map +1 -0
- package/dist/plus/integrations/providers/apiClients.d.ts +1 -2
- package/dist/plus/integrations/providers/apiClients.js.map +1 -1
- package/dist/plus/integrations/providers/asana.d.ts +3 -2
- package/dist/plus/integrations/providers/asana.js +2 -1
- package/dist/plus/integrations/providers/asana.js.map +1 -1
- package/dist/plus/integrations/providers/azure/azure.d.ts +1 -1
- package/dist/plus/integrations/providers/azure/azure.js +1 -1
- package/dist/plus/integrations/providers/azure/azure.utils.d.ts +10 -3
- package/dist/plus/integrations/providers/azure/azure.utils.js +5 -1
- package/dist/plus/integrations/providers/azure/azure.utils.js.map +1 -1
- package/dist/plus/integrations/providers/azure/models.d.ts +1 -5
- package/dist/plus/integrations/providers/azure/models.js +1 -1
- package/dist/plus/integrations/providers/azure/models.js.map +1 -1
- package/dist/plus/integrations/providers/azureDevOps.d.ts +8 -5
- package/dist/plus/integrations/providers/azureDevOps.js +2 -1
- package/dist/plus/integrations/providers/azureDevOps.js.map +1 -1
- package/dist/plus/integrations/providers/azureDevOpsServer.d.ts +5 -4
- package/dist/plus/integrations/providers/azureDevOpsServer.js +3 -1
- package/dist/plus/integrations/providers/azureDevOpsServer.js.map +1 -1
- package/dist/plus/integrations/providers/bitbucket/bitbucket.d.ts +2 -2
- package/dist/plus/integrations/providers/bitbucket/bitbucket.js.map +1 -1
- package/dist/plus/integrations/providers/bitbucket/models.d.ts +1 -1
- package/dist/plus/integrations/providers/bitbucket/models.js.map +1 -1
- package/dist/plus/integrations/providers/bitbucket-server.d.ts +5 -4
- package/dist/plus/integrations/providers/bitbucket-server.js +2 -1
- package/dist/plus/integrations/providers/bitbucket-server.js.map +1 -1
- package/dist/plus/integrations/providers/bitbucket.d.ts +4 -3
- package/dist/plus/integrations/providers/bitbucket.js +2 -1
- package/dist/plus/integrations/providers/bitbucket.js.map +1 -1
- package/dist/plus/integrations/providers/github/github.d.ts +0 -1
- package/dist/plus/integrations/providers/github/github.js +1 -1
- package/dist/plus/integrations/providers/github/github.js.map +1 -1
- package/dist/plus/integrations/providers/github.d.ts +29 -11
- package/dist/plus/integrations/providers/github.js +195 -78
- package/dist/plus/integrations/providers/github.js.map +1 -1
- package/dist/plus/integrations/providers/gitlab/gitlab.d.ts +2 -2
- package/dist/plus/integrations/providers/gitlab/gitlab.js +1 -2
- package/dist/plus/integrations/providers/gitlab/gitlab.js.map +1 -1
- package/dist/plus/integrations/providers/gitlab/gitlab.utils.d.ts +14 -1
- package/dist/plus/integrations/providers/gitlab/gitlab.utils.js.map +1 -1
- package/dist/plus/integrations/providers/gitlab/models.d.ts +2 -10
- package/dist/plus/integrations/providers/gitlab/models.js.map +1 -1
- package/dist/plus/integrations/providers/gitlab.d.ts +7 -5
- package/dist/plus/integrations/providers/gitlab.js +2 -1
- package/dist/plus/integrations/providers/gitlab.js.map +1 -1
- package/dist/plus/integrations/providers/issueSorts.d.ts +1 -0
- package/dist/plus/integrations/providers/jira-server.d.ts +4 -4
- package/dist/plus/integrations/providers/jira-server.js +3 -2
- package/dist/plus/integrations/providers/jira-server.js.map +1 -1
- package/dist/plus/integrations/providers/jira.d.ts +3 -3
- package/dist/plus/integrations/providers/jira.js +4 -3
- package/dist/plus/integrations/providers/jira.js.map +1 -1
- package/dist/plus/integrations/providers/jiraIssueByKey.d.ts +3 -1
- package/dist/plus/integrations/providers/jiraIssueByKey.js +1 -1
- package/dist/plus/integrations/providers/jiraIssueByKey.js.map +1 -1
- package/dist/plus/integrations/providers/jiraIssueWriteErrors.d.ts +10 -0
- package/dist/plus/integrations/providers/jiraIssueWriteErrors.js +68 -0
- package/dist/plus/integrations/providers/jiraIssueWriteErrors.js.map +1 -0
- package/dist/plus/integrations/providers/jiraIssueWrites.d.ts +40 -0
- package/dist/plus/integrations/providers/jiraIssueWrites.js +397 -0
- package/dist/plus/integrations/providers/jiraIssueWrites.js.map +1 -0
- package/dist/plus/integrations/providers/linear.d.ts +4 -3
- package/dist/plus/integrations/providers/linear.js +3 -2
- package/dist/plus/integrations/providers/linear.js.map +1 -1
- package/dist/plus/integrations/providers/linearIssuesEtag.d.ts +1 -1
- package/dist/plus/integrations/providers/linearIssuesEtag.js +1 -1
- package/dist/plus/integrations/providers/linearIssuesEtag.js.map +1 -1
- package/dist/plus/integrations/providers/metadata.d.ts +136 -0
- package/dist/plus/integrations/providers/metadata.js +513 -0
- package/dist/plus/integrations/providers/metadata.js.map +1 -0
- package/dist/plus/integrations/providers/models.d.ts +10 -206
- package/dist/plus/integrations/providers/models.js +8 -539
- package/dist/plus/integrations/providers/models.js.map +1 -1
- package/dist/plus/integrations/providers/providersApi.d.ts +7 -3
- package/dist/plus/integrations/providers/providersApi.js +23 -11
- package/dist/plus/integrations/providers/providersApi.js.map +1 -1
- package/dist/plus/integrations/providers/trello.d.ts +1 -1
- package/dist/plus/integrations/providers/trello.js +2 -1
- package/dist/plus/integrations/providers/trello.js.map +1 -1
- package/dist/plus/integrations/providers/utils/providerPaging.d.ts +2 -0
- package/dist/plus/integrations/providers/utils/providerPaging.js +3 -2
- package/dist/plus/integrations/providers/utils/providerPaging.js.map +1 -1
- package/dist/plus/integrations/providers/utils.d.ts +119 -10
- package/dist/plus/integrations/providers/utils.js +57 -3
- package/dist/plus/integrations/providers/utils.js.map +1 -1
- package/dist/plus/integrations/reads/autolinks.d.ts +1 -1
- package/dist/plus/integrations/reads/autolinks.js +1 -1
- package/dist/plus/integrations/reads/autolinks.js.map +1 -1
- package/dist/plus/integrations/reads/broaden.d.ts +1 -1
- package/dist/plus/integrations/reads/broaden.js +3 -2
- package/dist/plus/integrations/reads/broaden.js.map +1 -1
- package/dist/plus/integrations/reads/context.d.ts +1 -1
- package/dist/plus/integrations/reads/counts.d.ts +1 -88
- package/dist/plus/integrations/reads/counts.js +4 -2
- package/dist/plus/integrations/reads/counts.js.map +1 -1
- package/dist/plus/integrations/reads/currentAccount.d.ts +1 -18
- package/dist/plus/integrations/reads/currentAccount.js.map +1 -1
- package/dist/plus/integrations/reads/drains.d.ts +4 -3
- package/dist/plus/integrations/reads/drains.js +1 -1
- package/dist/plus/integrations/reads/drains.js.map +1 -1
- package/dist/plus/integrations/reads/etag.d.ts +174 -3
- package/dist/plus/integrations/reads/etag.js +69 -14
- package/dist/plus/integrations/reads/etag.js.map +1 -1
- package/dist/plus/integrations/reads/filters.d.ts +3 -61
- package/dist/plus/integrations/reads/filters.js +1 -1
- package/dist/plus/integrations/reads/filters.js.map +1 -1
- package/dist/plus/integrations/reads/hierarchy.d.ts +1 -1
- package/dist/plus/integrations/reads/hierarchy.js +4 -2
- package/dist/plus/integrations/reads/hierarchy.js.map +1 -1
- package/dist/plus/integrations/reads/issueBatch.d.ts +2 -102
- package/dist/plus/integrations/reads/issueBatch.js +3 -4
- package/dist/plus/integrations/reads/issueBatch.js.map +1 -1
- package/dist/plus/integrations/reads/issueTracker.d.ts +1 -1
- package/dist/plus/integrations/reads/issueTracker.js +4 -3
- package/dist/plus/integrations/reads/issueTracker.js.map +1 -1
- package/dist/plus/integrations/reads/issues.d.ts +1 -1
- package/dist/plus/integrations/reads/issues.js +4 -2
- package/dist/plus/integrations/reads/issues.js.map +1 -1
- package/dist/plus/integrations/reads/paging.d.ts +1 -1
- package/dist/plus/integrations/reads/paging.js +1 -1
- package/dist/plus/integrations/reads/paging.js.map +1 -1
- package/dist/plus/integrations/reads/pullRequestActivity.d.ts +1 -24
- package/dist/plus/integrations/reads/pullRequestActivity.js +2 -1
- package/dist/plus/integrations/reads/pullRequestActivity.js.map +1 -1
- package/dist/plus/integrations/reads/pullRequestBatch.d.ts +2 -56
- package/dist/plus/integrations/reads/pullRequestBatch.js +23 -3
- package/dist/plus/integrations/reads/pullRequestBatch.js.map +1 -1
- package/dist/plus/integrations/reads/pullRequestBranches.d.ts +1 -47
- package/dist/plus/integrations/reads/pullRequestBranches.js +2 -1
- package/dist/plus/integrations/reads/pullRequestBranches.js.map +1 -1
- package/dist/plus/integrations/reads/pullRequestCheckLogs.d.ts +1 -15
- package/dist/plus/integrations/reads/pullRequestCheckLogs.js +2 -1
- package/dist/plus/integrations/reads/pullRequestCheckLogs.js.map +1 -1
- package/dist/plus/integrations/reads/pullRequests.js +4 -2
- package/dist/plus/integrations/reads/pullRequests.js.map +1 -1
- package/dist/plus/integrations/reads/pullRequestsForCommits.d.ts +1 -16
- package/dist/plus/integrations/reads/pullRequestsForCommits.js +2 -1
- package/dist/plus/integrations/reads/pullRequestsForCommits.js.map +1 -1
- package/dist/plus/integrations/reads/resolveRepository.js +10 -5
- package/dist/plus/integrations/reads/resolveRepository.js.map +1 -1
- package/dist/plus/integrations/reads/searchIssues.js +2 -1
- package/dist/plus/integrations/reads/searchIssues.js.map +1 -1
- package/dist/plus/integrations/reads/searchPullRequests.js +2 -1
- package/dist/plus/integrations/reads/searchPullRequests.js.map +1 -1
- package/dist/plus/integrations/reads/sweeps.d.ts +1 -1
- package/dist/plus/integrations/reads/sweeps.js +3 -2
- package/dist/plus/integrations/reads/sweeps.js.map +1 -1
- package/dist/plus/integrations/reads/warnings.d.ts +1 -1
- package/dist/plus/integrations/reads/warnings.js +1 -1
- package/dist/plus/integrations/reads/warnings.js.map +1 -1
- package/dist/plus/integrations/results.d.ts +324 -2
- package/dist/plus/integrations/results.js.map +1 -1
- package/dist/plus/integrations/telemetry.d.ts +0 -10
- package/dist/plus/integrations/telemetry.js +0 -11
- package/dist/plus/integrations/utils/domain.utils.d.ts +1 -0
- package/dist/plus/integrations/utils/domain.utils.js +10 -2
- package/dist/plus/integrations/utils/domain.utils.js.map +1 -1
- package/dist/plus/integrations/utils/integration.utils.d.ts +2 -6
- package/dist/plus/integrations/utils/integration.utils.js +8 -9
- package/dist/plus/integrations/utils/integration.utils.js.map +1 -1
- package/dist/utils/env/node/exec.js +2 -2
- package/dist/utils/keys/chord.d.ts +13 -2
- package/dist/utils/keys/chord.js +76 -17
- package/dist/utils/keys/chord.js.map +1 -1
- package/dist/utils/keys/keybinding.d.ts +12 -0
- package/dist/utils/keys/keybinding.js +52 -2
- package/dist/utils/keys/keybinding.js.map +1 -1
- package/dist/utils/markdown.d.ts +21 -0
- package/dist/utils/markdown.js +33 -1
- package/dist/utils/markdown.js.map +1 -1
- package/docs/integrations.md +174 -19
- package/package.json +5 -1
- package/dist/plus/integrations/authentication/integrationAuthenticationProvider.js.map +0 -1
- package/dist/plus/integrations/telemetry.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"counts.js","names":[],"sources":["../../../../../plus/integrations/src/reads/counts.ts"],"sourcesContent":["import type { IssueSearchCriteria } from '@gitlens/git/models/issue.js';\nimport type { PullRequestSearchCriteria } from '@gitlens/git/models/pullRequest.js';\nimport { chunk } from '@gitlens/utils/array.js';\nimport { mapBounded } from '@gitlens/utils/promise.js';\nimport type { IntegrationIds } from '../constants.js';\nimport { GitSelfManagedHostIntegrationId, providerFanOutConcurrency } from '../constants.js';\nimport type { ProviderSearchCount } from '../models/integration.js';\nimport type { ProviderRepoInput, ProviderReposInput } from '../providers/models.js';\nimport { providersMetadata } from '../providers/models.js';\nimport type { ProviderResult, ProviderWarning } from '../results.js';\nimport { appendDedupedWarning, toProviderWarning } from '../results.js';\nimport {\n\tisGitHostIntegration,\n\tisIssuesHostIntegrationId,\n\twarnOnMissingSessionForDomain,\n} from '../utils/integration.utils.js';\nimport type { ProviderReadContext } from './context.js';\nimport { runCaptured } from './drains.js';\nimport {\n\tresolveIssueSearchCriteria,\n\tresolveIssueSearchScope,\n\tresolvePullRequestSearchCriteria,\n\tresolvePullRequestSearchScope,\n} from './filters.js';\nimport {\n\tgitHostOnlySurfaceWarning,\n\tissuesUnsupportedWarning,\n\totherWarning,\n\tunsupportedIssueSearchCriteriaWarning,\n\tunsupportedPullRequestSearchCriteriaWarning,\n\tunsupportedWarning,\n\tunusableSearchScopeMessage,\n} from './warnings.js';\n\n/**\n * How many scopes go into one upstream request.\n *\n * Measured against the live GitHub API, 30 aliased counts cost a single rate-limit point and ~2s, and 60 cost the\n * same point and roughly twice as long — so the constraint isn't rate limit, it's latency and the provider's\n * (uncontracted, so not to be leaned on) query-complexity limits. 25 keeps a chunk comfortably inside both while\n * still collapsing a realistic filter matrix into one or two requests.\n */\nconst issueCountChunkSize = 25;\n\n/**\n * How many pull-request scopes go into one upstream request.\n *\n * The same latency/complexity reasoning as {@link issueCountChunkSize}, kept slightly smaller because a pull-request\n * scope can fan out into one aliased count PER requested state (open/closed/merged), so a chunk of scopes carries a\n * small multiple of that many `search` aliases.\n *\n * A provider that counts by reading batches nothing, so it is chunked one scope at a time instead: a chunk is then\n * just a scope, and the facade's bounded concurrency is what paces the requests.\n */\nconst pullRequestCountChunkSize = 15;\n\n/**\n * Whether a provider counts pull requests by READING the matches rather than asking for a total — Bitbucket Data\n * Center, which has no count query. Two rules follow from it: it batches nothing, and it deduplicates the rows\n * themselves, so a relationship set is an exact union it can count in one scope rather than a refusal.\n */\nfunction countsPullRequestsByReading(providerId: IntegrationIds): boolean {\n\treturn providerId === GitSelfManagedHostIntegrationId.BitbucketServer;\n}\n\n/**\n * One scope to count.\n *\n * `key` is caller-owned and echoed back verbatim, so a batch result needs no positional matching by the consumer.\n * It never reaches the provider query — the aliases in the upstream document are generated — so it can be any\n * string the caller finds meaningful.\n */\nexport interface IssueCountScope {\n\tkey: string;\n\t/** Repositories to count over. Combines with `org`, exactly as in `searchIssuesPage`. */\n\trepos?: ProviderReposInput;\n\torg?: string;\n\t/**\n\t * Same criteria model as `searchIssuesPage`, validated against the same capability table.\n\t *\n\t * `criteria.sort` does not affect the count — a total is invariant under ordering — but it is still VALIDATED,\n\t * and an unsupported key refuses this scope exactly as it would refuse the read. That is the point of the\n\t * count: it previews the constraints the read will apply, so one that accepted what the read refuses would\n\t * promise a fetch that can't happen, which is worse than no preview at all.\n\t */\n\tcriteria?: IssueSearchCriteria;\n}\n\n/** The count for one {@link IssueCountScope}, echoed back under the caller's own `key`. */\nexport interface IssueCountResult {\n\tkey: string;\n\t/**\n\t * Total matches the provider reports. `undefined` when the provider didn't report one for this scope — NEVER\n\t * zero, which is a real answer. Render the difference: an unreported count means \"unknown\", and showing it as\n\t * 0 would tell the user this filter matches nothing.\n\t */\n\tcount?: number;\n\t/**\n\t * True when `count` exceeds the provider's own result ceiling, so a full read CANNOT return everything no\n\t * matter how it is paged. This is the signal to warn before starting an expensive fetch.\n\t */\n\texceedsProviderLimit: boolean;\n\t/** The ceiling itself, when the provider declares one. */\n\tproviderLimit?: number;\n}\n\n/**\n * One scope to count pull requests over — the PR twin of {@link IssueCountScope}.\n *\n * `key` is caller-owned and echoed back verbatim, never reaching the provider query (the aliases are generated), so\n * it can be any string the caller finds meaningful.\n */\nexport interface PullRequestCountScope {\n\tkey: string;\n\t/** Repositories to count over. Combines with `org`, exactly as in `searchPullRequestsPage`. */\n\trepos?: ProviderReposInput;\n\torg?: string;\n\t/**\n\t * Same criteria model as `searchPullRequestsPage`, validated against the same capability table — so a count\n\t * refuses exactly what the read would, and never previews a fetch that can't happen.\n\t */\n\tcriteria?: PullRequestSearchCriteria;\n}\n\n/** The count for one {@link PullRequestCountScope}, echoed back under the caller's own `key`. */\nexport interface PullRequestCountResult {\n\tkey: string;\n\t/**\n\t * Total matches the provider reports. `undefined` when the provider didn't report one for this scope — NEVER\n\t * zero, which is a real answer.\n\t *\n\t * For a multi-state scope, GitHub/GHE report the LARGEST of their per-state counts (the same total\n\t * `searchPullRequestsPage` surfaces, since each state is its own capped search), not their sum. Bitbucket Data\n\t * Center has no ceiling to stay under, so it reports the exact union — the number of rows the search returns —\n\t * and so does Azure DevOps Server, which reads every state in one drain.\n\t */\n\tcount?: number;\n\t/**\n\t * True when `count` is a FLOOR rather than the total: the provider has no count query (Bitbucket Data Center),\n\t * so it counts by reading within a budget, and this scope had more than the budget read. Render it as \"N+\", and\n\t * treat the scope as at least that expensive. Absent means `count` is exact — the provider's own total, or for a\n\t * provider that counts by reading, every match it read.\n\t */\n\tlowerBound?: boolean;\n\t/**\n\t * True when `count` exceeds the provider's own per-search result ceiling, so a full read CANNOT return\n\t * everything no matter how it is paged. This is the signal to warn before starting an expensive fetch.\n\t */\n\texceedsProviderLimit: boolean;\n\t/** The ceiling itself, when the provider declares one. */\n\tproviderLimit?: number;\n}\n\n/**\n * Counts issues for many scopes without fetching any — the probe behind a \"this will fetch ~N issues\" preview.\n *\n * A distinct method rather than a `countOnly` flag on `searchIssuesPage`, because transferring ZERO issues is the\n * entire value: a flag would return a paged result whose `items`, `cursor` and `hasMore` are all meaningless, and\n * every consumer would have to know which fields to ignore. A separate method has a return type that only\n * describes counts.\n *\n * Scopes are batched into as few upstream requests as possible ({@link issueCountChunkSize} each). A chunk that\n * fails warns and drops only its own scopes, leaving the successful chunks' counts intact — so a partial answer is\n * still useful — with `fetchFailed` set. A scope refused for its own reasons (unscoped, inexpressible criteria) is\n * likewise isolated: its siblings are still counted.\n *\n * Cheap is not free: each chunk is a network request, so a caller driving this from UI state is expected to\n * debounce and cache.\n */\nexport async function countIssues(\n\tctx: ProviderReadContext,\n\toptions: {\n\t\tproviderId: IntegrationIds;\n\t\tscopes: readonly IssueCountScope[];\n\t\tconnectionId?: string;\n\t\t/**\n\t\t * Explicit self-managed host domain. Used only when the requested connection has no configured domain;\n\t\t * it must come from the trusted authentication configuration, not repository or remote data.\n\t\t */\n\t\tdomain?: string;\n\t},\n): Promise<ProviderResult<IssueCountResult>> {\n\tconst refused = (warning: ProviderWarning): ProviderResult<IssueCountResult> => ({\n\t\titems: [],\n\t\twarnings: [warning],\n\t\tfetchFailed: true,\n\t});\n\n\tif (isIssuesHostIntegrationId(options.providerId)) {\n\t\treturn refused(gitHostOnlySurfaceWarning(options.providerId, undefined, options.connectionId, 'Issue counts'));\n\t}\n\n\t// Nothing was asked for, so nothing is missing: an empty success, not a refusal.\n\tif (options.scopes.length === 0) return { items: [], warnings: [] };\n\n\tconst duplicateKey = findDuplicateKey(options.scopes);\n\tif (duplicateKey != null) {\n\t\t// Refuses the whole call rather than deduping: `key` exists so the caller can match results without\n\t\t// positional bookkeeping, and two results under one key make that ambiguous for EVERY scope, not just the\n\t\t// repeated one.\n\t\treturn refused(\n\t\t\totherWarning(\n\t\t\t\toptions.providerId,\n\t\t\t\tundefined,\n\t\t\t\toptions.connectionId,\n\t\t\t\t`Duplicate issue count scope key '${duplicateKey}'; keys identify results, so each must be unique.`,\n\t\t\t),\n\t\t);\n\t}\n\n\tconst integration = await ctx.getIntegrationForRead(options.providerId, options.connectionId, options.domain);\n\tif (integration == null) {\n\t\t// A supplied connection or domain that no longer resolves is a broken target, not an empty account.\n\t\tconst early = ctx.earlyReturnConnectionWarnings(options.providerId, options.connectionId, options.domain);\n\t\treturn { items: [], warnings: early.warnings, fetchFailed: early.fetchFailed || undefined };\n\t}\n\tif (!isGitHostIntegration(integration)) {\n\t\treturn refused(gitHostOnlySurfaceWarning(options.providerId, undefined, options.connectionId, 'Issue counts'));\n\t}\n\n\tconst domain = ctx.domainForRead(integration, options.providerId, options.connectionId, options.domain);\n\tconst warnOnMissingSession = warnOnMissingSessionForDomain(options.providerId, options.domain);\n\n\tif (!integration.supportsIssues) {\n\t\treturn refused(issuesUnsupportedWarning(options.providerId, domain, options.connectionId));\n\t}\n\n\t// A provider with no filtered issue search has no count either: refuse ONCE for the provider rather than\n\t// letting every scope repeat the same rejection. `undefined` criteria probes only the search's existence.\n\t// Matches `countPullRequests`. Refusing it here rather than per scope also keeps the loop's warnings from\n\t// being dominated by N copies of one provider-level fact — see the dedupe below, which handles the\n\t// keyless refusals that remain.\n\tconst searchSupport = resolveIssueSearchCriteria(options.providerId, undefined);\n\tif (searchSupport.rejection != null) {\n\t\treturn refused(\n\t\t\tunsupportedIssueSearchCriteriaWarning(\n\t\t\t\toptions.providerId,\n\t\t\t\tdomain,\n\t\t\t\toptions.connectionId,\n\t\t\t\tsearchSupport.rejection,\n\t\t\t),\n\t\t);\n\t}\n\n\tconst providerLimit = providersMetadata[options.providerId]?.issueSearchResultLimit;\n\tconst warnings: ProviderWarning[] = [];\n\tlet fetchFailed = false;\n\n\t// Validate every scope first, so a refusal costs no request at all and the countable ones are still batched\n\t// together.\n\tconst countable: IssueCountScope[] = [];\n\tfor (const scope of options.scopes) {\n\t\tconst warning = rejectScope(options.providerId, domain, options.connectionId, scope);\n\t\tif (warning != null) {\n\t\t\t// Deduped rather than pushed. The rejections that name the offending SCOPE embed its own key, and\n\t\t\t// duplicate keys were already refused above, so those can never collapse. But the ones that report a\n\t\t\t// PROVIDER-level fact — a criterion it cannot express, a contradictory relationship pair — name no\n\t\t\t// scope, so several scopes failing the same way produce byte-identical warnings, and one refusal\n\t\t\t// reported N times reads as N different problems.\n\t\t\tappendDedupedWarning(warnings, warning);\n\t\t\tfetchFailed = true;\n\t\t\tcontinue;\n\t\t}\n\n\t\tcountable.push(scope);\n\t}\n\n\t// Chunks are independent requests over their own slice of scopes — nothing in one reads what another produced,\n\t// and `runCaptured` never throws — so they run concurrently, bounded like every other fan-out on the facade.\n\t// Sequentially they would spend exactly the resource this probe is tuned to conserve: latency, ~2s per chunk.\n\t// `mapBounded` returns in input order, so `items` and `warnings` stay in scope order.\n\tconst batches = await mapBounded(chunk(countable, issueCountChunkSize), providerFanOutConcurrency, batch =>\n\t\trunCaptured(\n\t\t\toptions.providerId,\n\t\t\tdomain,\n\t\t\toptions.connectionId,\n\t\t\t() =>\n\t\t\t\tintegration.countIssuesResult(\n\t\t\t\t\tbatch.map(s => ({\n\t\t\t\t\t\trepos: s.repos as ProviderRepoInput[] | undefined,\n\t\t\t\t\t\torg: s.org,\n\t\t\t\t\t\tcriteria: s.criteria,\n\t\t\t\t\t})),\n\t\t\t\t\tundefined,\n\t\t\t\t\toptions.connectionId,\n\t\t\t\t),\n\t\t\t{ warnOnMissingSession: warnOnMissingSession },\n\t\t).then(result => ({ batch: batch, ...result })),\n\t);\n\n\tconst items: IssueCountResult[] = [];\n\tfor (const { batch, value, warning } of batches) {\n\t\tif (warning != null) {\n\t\t\tappendDedupedWarning(warnings, warning);\n\t\t}\n\t\tif (value == null) {\n\t\t\t// This batch contributes nothing, but the batches around it still do. Drop only these scopes.\n\t\t\tfetchFailed = true;\n\t\t\tcontinue;\n\t\t}\n\n\t\tfetchFailed =\n\t\t\tcollectCounts(batch, value, providerLimit, items, (key, error) => {\n\t\t\t\tconst warning = toProviderWarning(options.providerId, domain, options.connectionId, error);\n\t\t\t\tappendDedupedWarning(warnings, {\n\t\t\t\t\t...warning,\n\t\t\t\t\tmessage: `Issue count scope '${key}': ${warning.message}`,\n\t\t\t\t});\n\t\t\t}) || fetchFailed;\n\t}\n\n\t// A provider with no count support returns `undefined` with no error, which lands as an empty `items` and no\n\t// warning. Say so explicitly rather than letting it read as \"every scope matched nothing\".\n\tif (items.length === 0 && warnings.length === 0) {\n\t\treturn refused(\n\t\t\tunsupportedIssueSearchCriteriaWarning(options.providerId, domain, options.connectionId, {\n\t\t\t\treason: 'unsupported-search',\n\t\t\t}),\n\t\t);\n\t}\n\n\treturn { items: items, warnings: warnings, fetchFailed: fetchFailed || undefined };\n}\n\n/**\n * Turns one batch of positional issue counts into keyed results, returning whether any scope was refused.\n *\n * A slot holding an `Error` is a scope the PROVIDER refused for its own reasons (a scope naming a collection it\n * can't search, say): reported and dropped exactly like a scope the facade refuses, so its siblings in the batch\n * still come back. `'exceeds-limit'` is a count the provider can only bound — more than its ceiling matched — which\n * is reported as `exceedsProviderLimit` with no `count` rather than as the ceiling, which would understate it.\n */\nfunction collectCounts<T extends { key: string }>(\n\tbatch: readonly T[],\n\tvalue: readonly ProviderSearchCount[],\n\tproviderLimit: number | undefined,\n\titems: { key: string; count?: number; exceedsProviderLimit: boolean; providerLimit?: number }[],\n\tonRefused: (key: string, error: Error) => void,\n): boolean {\n\tlet refused = false;\n\tfor (let i = 0; i < batch.length; i++) {\n\t\tconst count = value[i];\n\t\tif (count instanceof Error) {\n\t\t\tonRefused(batch[i].key, count);\n\t\t\trefused = true;\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst exceeds = count === 'exceeds-limit';\n\t\titems.push({\n\t\t\tkey: batch[i].key,\n\t\t\tcount: exceeds ? undefined : count,\n\t\t\t// Only a reported count can exceed a declared ceiling; unknown-vs-limit is not a comparison.\n\t\t\texceedsProviderLimit: exceeds || (count != null && providerLimit != null && count > providerLimit),\n\t\t\tproviderLimit: providerLimit,\n\t\t});\n\t}\n\treturn refused;\n}\n\n/** The first key that appears twice, or `undefined` when every key is unique. */\nfunction findDuplicateKey(scopes: readonly { key: string }[]): string | undefined {\n\tconst seen = new Set<string>();\n\tfor (const scope of scopes) {\n\t\tif (seen.has(scope.key)) return scope.key;\n\n\t\tseen.add(scope.key);\n\t}\n\treturn undefined;\n}\n\n/**\n * Why one scope can't be counted, as the warning to report — or `undefined` when it can.\n *\n * The scope and criteria rules come from {@link resolveIssueSearchScope} / {@link resolveIssueSearchCriteria},\n * the same validators `searchIssuesPage` uses, so a count always previews the constraints the read would apply.\n * That is not cosmetic: a count computed under different constraints is a WRONG number rather than a missing\n * one, which is worse. Only the wording is local, because these name the offending scope's key.\n */\nfunction rejectScope(\n\tproviderId: IntegrationIds,\n\tdomain: string | undefined,\n\tconnectionId: string | undefined,\n\tscope: IssueCountScope,\n): ProviderWarning | undefined {\n\tconst resolved = resolveIssueSearchCriteria(providerId, scope.criteria);\n\tif (resolved.rejection != null) {\n\t\treturn unsupportedIssueSearchCriteriaWarning(providerId, domain, connectionId, resolved.rejection);\n\t}\n\n\t// AFTER the criteria check, mirroring `searchIssuesPage`: a provider with no filtered issue search is the more\n\t// fundamental refusal, and a count must preview the refusal its read would give.\n\tconst scoping = resolveIssueSearchScope(providerId, scope.repos, scope.org, scope.criteria);\n\tswitch (scoping.rejection?.reason) {\n\t\tcase 'repo-ids':\n\t\t\treturn otherWarning(\n\t\t\t\tproviderId,\n\t\t\t\tdomain,\n\t\t\t\tconnectionId,\n\t\t\t\t`Issue count scope '${scope.key}' cannot be scoped by repository id; pass repository descriptors (namespace + name) instead.`,\n\t\t\t);\n\t\tcase 'unscoped':\n\t\t\treturn otherWarning(\n\t\t\t\tproviderId,\n\t\t\t\tdomain,\n\t\t\t\tconnectionId,\n\t\t\t\t`Issue count scope '${scope.key}' is unscoped; pass \\`repos\\`, \\`org\\`, or a relationship to the current user. \\`any-assignee\\` and \\`unassigned\\` are not scopes.`,\n\t\t\t);\n\t\t// A count applies exactly the qualifiers its search would, so an unusable scope would make it agree with\n\t\t// the wrong search rather than expose it — see `isUsableSearchScopeName`.\n\t\tcase 'unusable-scope':\n\t\t\treturn otherWarning(\n\t\t\t\tproviderId,\n\t\t\t\tdomain,\n\t\t\t\tconnectionId,\n\t\t\t\tunusableSearchScopeMessage('scopes', scoping.rejection.scopes, `Issue count scope '${scope.key}'`),\n\t\t\t);\n\t}\n\n\t// Count-only, with no counterpart in the read: a relationship set is an OR across several searches, which one\n\t// count can't express — summing them would double-count anything matching two, and taking the max would\n\t// under-report. Rather than answer with a wrong number, ask the caller to count each relationship as its own\n\t// scope, where the keys make the OR explicit.\n\tif ((scope.criteria?.relationships?.length ?? 0) > 1) {\n\t\treturn otherWarning(\n\t\t\tproviderId,\n\t\t\tdomain,\n\t\t\tconnectionId,\n\t\t\t`Issue count scope '${scope.key}' requests several relationships, which a single count can't express (they are OR-ed, so overlapping matches would be double-counted); pass one scope per relationship.`,\n\t\t);\n\t}\n\n\treturn undefined;\n}\n\n/**\n * Counts pull requests for many scopes without fetching any — the PR twin of {@link countIssues}, and the probe\n * behind a \"this will fetch ~N pull requests\" preview.\n *\n * Identical batching, per-scope isolation, and `key`-echo contract as {@link countIssues}; see it for the cost\n * model and the `count: undefined` ≠ zero rule. The one difference is inherent to pull requests: a scope's criteria\n * can name several STATES, which GitHub/GHE count as independent searches — the reported `count` is the LARGEST\n * of them (mirroring `searchPullRequestsPage`'s total), so an unpaged read still can't exceed a single search's\n * ceiling undetected. Bitbucket Data Center has no ceiling and no count query: it counts the exact union by reading\n * each scope within a budget, and flags a scope that had more as `lowerBound`. Because it deduplicates rows, it is\n * also the one provider that accepts several relationships in one scope. Azure DevOps Server counts the union of the\n * states from the one drain its search pages through.\n */\nexport async function countPullRequests(\n\tctx: ProviderReadContext,\n\toptions: {\n\t\tproviderId: IntegrationIds;\n\t\tscopes: readonly PullRequestCountScope[];\n\t\tconnectionId?: string;\n\t\t/**\n\t\t * Explicit self-managed host domain. Used only when the requested connection has no configured domain;\n\t\t * it must come from the trusted authentication configuration, not repository or remote data.\n\t\t */\n\t\tdomain?: string;\n\t},\n): Promise<ProviderResult<PullRequestCountResult>> {\n\tconst refused = (warning: ProviderWarning): ProviderResult<PullRequestCountResult> => ({\n\t\titems: [],\n\t\twarnings: [warning],\n\t\tfetchFailed: true,\n\t});\n\n\tif (isIssuesHostIntegrationId(options.providerId)) {\n\t\treturn refused(\n\t\t\tgitHostOnlySurfaceWarning(options.providerId, undefined, options.connectionId, 'Pull request counts'),\n\t\t);\n\t}\n\n\t// Nothing was asked for, so nothing is missing: an empty success, not a refusal.\n\tif (options.scopes.length === 0) return { items: [], warnings: [] };\n\n\tconst duplicateKey = findDuplicateKey(options.scopes);\n\tif (duplicateKey != null) {\n\t\t// Refuses the whole call rather than deduping: `key` exists so the caller can match results without\n\t\t// positional bookkeeping, and two results under one key make that ambiguous for EVERY scope, not just the\n\t\t// repeated one.\n\t\treturn refused(\n\t\t\totherWarning(\n\t\t\t\toptions.providerId,\n\t\t\t\tundefined,\n\t\t\t\toptions.connectionId,\n\t\t\t\t`Duplicate pull request count scope key '${duplicateKey}'; keys identify results, so each must be unique.`,\n\t\t\t),\n\t\t);\n\t}\n\n\tconst integration = await ctx.getIntegrationForRead(options.providerId, options.connectionId, options.domain);\n\tif (integration == null) {\n\t\t// A supplied connection or domain that no longer resolves is a broken target, not an empty account.\n\t\tconst early = ctx.earlyReturnConnectionWarnings(options.providerId, options.connectionId, options.domain);\n\t\treturn { items: [], warnings: early.warnings, fetchFailed: early.fetchFailed || undefined };\n\t}\n\tif (!isGitHostIntegration(integration)) {\n\t\treturn refused(\n\t\t\tgitHostOnlySurfaceWarning(options.providerId, undefined, options.connectionId, 'Pull request counts'),\n\t\t);\n\t}\n\n\tconst domain = ctx.domainForRead(integration, options.providerId, options.connectionId, options.domain);\n\tconst warnOnMissingSession = warnOnMissingSessionForDomain(options.providerId, options.domain);\n\n\t// A provider with no filtered pull-request search has no count either: refuse ONCE for the provider rather than\n\t// letting every scope repeat the same rejection. `undefined` criteria probes only the search's existence.\n\tconst searchSupport = resolvePullRequestSearchCriteria(options.providerId, undefined);\n\tif (searchSupport.rejection != null) {\n\t\treturn refused(\n\t\t\tunsupportedPullRequestSearchCriteriaWarning(\n\t\t\t\toptions.providerId,\n\t\t\t\tdomain,\n\t\t\t\toptions.connectionId,\n\t\t\t\tsearchSupport.rejection,\n\t\t\t),\n\t\t);\n\t}\n\n\tconst providerLimit = providersMetadata[options.providerId]?.pullRequestSearchResultLimit;\n\tconst warnings: ProviderWarning[] = [];\n\tlet fetchFailed = false;\n\n\t// Validate every scope first, so a refusal costs no request at all and the countable ones are still batched\n\t// together.\n\tconst countable: PullRequestCountScope[] = [];\n\tfor (const scope of options.scopes) {\n\t\tconst warning = rejectPullRequestScope(options.providerId, domain, options.connectionId, scope);\n\t\tif (warning != null) {\n\t\t\t// Deduped rather than pushed: see the issue twin. Here the keyless set is wider — besides the criteria\n\t\t\t// rejections, `unsupported-repository-scope` and `unsupported-organization-scope` are scope rejections\n\t\t\t// that route through the criteria warning and name no key, and both are provider-level facts every\n\t\t\t// scope would repeat.\n\t\t\tappendDedupedWarning(warnings, warning);\n\t\t\tfetchFailed = true;\n\t\t\tcontinue;\n\t\t}\n\n\t\tcountable.push(scope);\n\t}\n\n\t// Chunks are independent requests over their own slice of scopes, `runCaptured` never throws, so they run\n\t// concurrently, bounded like every other fan-out on the facade. `mapBounded` returns in input order, so `items`\n\t// and `warnings` stay in scope order.\n\tconst chunks = chunk(countable, countsPullRequestsByReading(options.providerId) ? 1 : pullRequestCountChunkSize);\n\tconst batches = await mapBounded(chunks, providerFanOutConcurrency, batch =>\n\t\trunCaptured(\n\t\t\toptions.providerId,\n\t\t\tdomain,\n\t\t\toptions.connectionId,\n\t\t\t() =>\n\t\t\t\tintegration.countPullRequestsResult(\n\t\t\t\t\tbatch.map(s => ({\n\t\t\t\t\t\trepos: s.repos as ProviderRepoInput[] | undefined,\n\t\t\t\t\t\torg: s.org,\n\t\t\t\t\t\tcriteria: s.criteria,\n\t\t\t\t\t})),\n\t\t\t\t\tundefined,\n\t\t\t\t\toptions.connectionId,\n\t\t\t\t),\n\t\t\t{ warnOnMissingSession: warnOnMissingSession },\n\t\t).then(result => ({ batch: batch, ...result })),\n\t);\n\n\tconst items: PullRequestCountResult[] = [];\n\tfor (const { batch, value, warning } of batches) {\n\t\tif (warning != null) {\n\t\t\tappendDedupedWarning(warnings, warning);\n\t\t}\n\t\tif (value == null) {\n\t\t\t// This batch contributes nothing, but the batches around it still do. Drop only these scopes.\n\t\t\tfetchFailed = true;\n\t\t\tcontinue;\n\t\t}\n\n\t\tfor (let i = 0; i < batch.length; i++) {\n\t\t\tconst slot = value[i];\n\t\t\t// A scope the provider refused for its own reasons: reported and dropped like one the facade refuses.\n\t\t\tif (slot instanceof Error) {\n\t\t\t\tconst warning = toProviderWarning(options.providerId, domain, options.connectionId, slot);\n\t\t\t\tappendDedupedWarning(warnings, {\n\t\t\t\t\t...warning,\n\t\t\t\t\tmessage: `Pull request count scope '${batch[i].key}': ${warning.message}`,\n\t\t\t\t});\n\t\t\t\tfetchFailed = true;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst count = slot?.count;\n\t\t\titems.push({\n\t\t\t\tkey: batch[i].key,\n\t\t\t\tcount: count,\n\t\t\t\t...(count != null && slot?.lowerBound === true ? { lowerBound: true } : {}),\n\t\t\t\t// Only a reported count can exceed a declared ceiling; unknown-vs-limit is not a comparison.\n\t\t\t\texceedsProviderLimit: count != null && providerLimit != null && count > providerLimit,\n\t\t\t\tproviderLimit: providerLimit,\n\t\t\t});\n\t\t}\n\t}\n\n\t// A provider that reported nothing for any scope and raised no warning: say so explicitly rather than letting it\n\t// read as \"every scope matched nothing\".\n\tif (items.length === 0 && warnings.length === 0) {\n\t\treturn refused(\n\t\t\tunsupportedPullRequestSearchCriteriaWarning(options.providerId, domain, options.connectionId, {\n\t\t\t\treason: 'unsupported-search',\n\t\t\t}),\n\t\t);\n\t}\n\n\treturn { items: items, warnings: warnings, fetchFailed: fetchFailed || undefined };\n}\n\n/**\n * Why one pull-request scope can't be counted, as the warning to report — or `undefined` when it can. The PR twin\n * of {@link rejectScope}, validating against the same {@link resolvePullRequestSearchScope} /\n * {@link resolvePullRequestSearchCriteria} the read uses, so a count always previews the constraints the read\n * would apply.\n */\nfunction rejectPullRequestScope(\n\tproviderId: IntegrationIds,\n\tdomain: string | undefined,\n\tconnectionId: string | undefined,\n\tscope: PullRequestCountScope,\n): ProviderWarning | undefined {\n\tconst scoping = resolvePullRequestSearchScope(providerId, scope.repos, scope.org, scope.criteria);\n\tswitch (scoping.rejection?.reason) {\n\t\tcase 'repo-ids':\n\t\t\treturn otherWarning(\n\t\t\t\tproviderId,\n\t\t\t\tdomain,\n\t\t\t\tconnectionId,\n\t\t\t\t`Pull request count scope '${scope.key}' cannot be scoped by repository id; pass repository descriptors (namespace + name) instead.`,\n\t\t\t);\n\t\tcase 'unscoped':\n\t\t\treturn otherWarning(\n\t\t\t\tproviderId,\n\t\t\t\tdomain,\n\t\t\t\tconnectionId,\n\t\t\t\t`Pull request count scope '${scope.key}' is unscoped; pass \\`repos\\`, \\`org\\`, or at least one current-user relationship.`,\n\t\t\t);\n\t\tcase 'unsupported-repository-scope':\n\t\tcase 'unsupported-organization-scope':\n\t\t\treturn unsupportedPullRequestSearchCriteriaWarning(providerId, domain, connectionId, {\n\t\t\t\treason: 'unsupported-criteria',\n\t\t\t\tcriteria: [\n\t\t\t\t\tscoping.rejection.reason === 'unsupported-repository-scope'\n\t\t\t\t\t\t? 'repositoryScope'\n\t\t\t\t\t\t: 'organizationScope',\n\t\t\t\t],\n\t\t\t});\n\t\t// See the issue twin, and `isUsableSearchScopeName` for the rule.\n\t\tcase 'unusable-scope':\n\t\t\treturn otherWarning(\n\t\t\t\tproviderId,\n\t\t\t\tdomain,\n\t\t\t\tconnectionId,\n\t\t\t\tunusableSearchScopeMessage(\n\t\t\t\t\t'scopes',\n\t\t\t\t\tscoping.rejection.scopes,\n\t\t\t\t\t`Pull request count scope '${scope.key}'`,\n\t\t\t\t),\n\t\t\t);\n\t}\n\n\tconst resolved = resolvePullRequestSearchCriteria(providerId, scope.criteria);\n\tif (resolved.rejection != null) {\n\t\treturn unsupportedPullRequestSearchCriteriaWarning(providerId, domain, connectionId, resolved.rejection);\n\t}\n\n\t// Count-only, with no counterpart in the read: a relationship set is an OR across several searches, which one\n\t// count can't express — summing would double-count overlaps and max would under-report. Ask the caller to count\n\t// each relationship as its own scope, where the keys make the OR explicit. (States are disjoint, so a scope may\n\t// still name several — the provider counts them as the max, not a refusal.) A provider that counts by reading\n\t// deduplicates the matching rows themselves, so it counts the OR exactly, as the search it previews returns it.\n\t// That makes the refusal the provider's capability, so `unsupported`; the issue twin refuses on every provider.\n\tif ((scope.criteria?.relationships?.length ?? 0) > 1 && !countsPullRequestsByReading(providerId)) {\n\t\treturn unsupportedWarning(\n\t\t\tproviderId,\n\t\t\tdomain,\n\t\t\tconnectionId,\n\t\t\t`Pull request count scope '${scope.key}' requests several relationships, which a single count can't express (they are OR-ed, so overlapping matches would be double-counted); pass one scope per relationship.`,\n\t\t);\n\t}\n\n\treturn undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA0CA,MAAM,sBAAsB;;;;;;;;;;;AAY5B,MAAM,4BAA4B;;;;;;AAOlC,SAAS,4BAA4B,YAAqC;CACzE,OAAO,eAAA;AACR;;;;;;;;;;;;;;;;;AA0GA,eAAsB,YACrB,KACA,SAU4C;CAC5C,MAAM,WAAW,aAAgE;EAChF,OAAO,CAAC;EACR,UAAU,CAAC,OAAO;EAClB,aAAa;CACd;CAEA,IAAI,0BAA0B,QAAQ,UAAU,GAC/C,OAAO,QAAQ,0BAA0B,QAAQ,YAAY,KAAA,GAAW,QAAQ,cAAc,cAAc,CAAC;CAI9G,IAAI,QAAQ,OAAO,WAAW,GAAG,OAAO;EAAE,OAAO,CAAC;EAAG,UAAU,CAAC;CAAE;CAElE,MAAM,eAAe,iBAAiB,QAAQ,MAAM;CACpD,IAAI,gBAAgB,MAInB,OAAO,QACN,aACC,QAAQ,YACR,KAAA,GACA,QAAQ,cACR,oCAAoC,aAAa,kDAClD,CACD;CAGD,MAAM,cAAc,MAAM,IAAI,sBAAsB,QAAQ,YAAY,QAAQ,cAAc,QAAQ,MAAM;CAC5G,IAAI,eAAe,MAAM;EAExB,MAAM,QAAQ,IAAI,8BAA8B,QAAQ,YAAY,QAAQ,cAAc,QAAQ,MAAM;EACxG,OAAO;GAAE,OAAO,CAAC;GAAG,UAAU,MAAM;G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;EAEF,KAAK,kBACJ,OAAO,aACN,YACA,QACA,cACA,2BACC,UACA,QAAQ,UAAU,QAClB,6BAA6B,MAAM,IAAI,EACxC,CACD;CACF;CAEA,MAAM,WAAW,iCAAiC,YAAY,MAAM,QAAQ;CAC5E,IAAI,SAAS,aAAa,MACzB,OAAO,4CAA4C,YAAY,QAAQ,cAAc,SAAS,SAAS;CASxG,KAAK,MAAM,UAAU,eAAe,UAAU,KAAK,KAAK,CAAC,4BAA4B,UAAU,GAC9F,OAAO,mBACN,YACA,QACA,cACA,6BAA6B,MAAM,IAAI,wKACxC;AAIF"}
|
|
1
|
+
{"version":3,"file":"counts.js","names":[],"sources":["../../../../../plus/integrations/src/reads/counts.ts"],"sourcesContent":["import { chunk } from '@gitlens/utils/array.js';\nimport { mapBounded } from '@gitlens/utils/promise.js';\nimport type { IntegrationIds } from '../constants.js';\nimport { GitSelfManagedHostIntegrationId } from '../constants.js';\nimport type { ProviderSearchCount } from '../models/integration.js';\nimport { isGitHostIntegration } from '../models/publicIntegration.js';\nimport { providersMetadata } from '../providers/metadata.js';\nimport type { ProviderRepoInput } from '../providers/models.js';\nimport { providerFanOutConcurrency } from '../providers/utils/providerPaging.js';\nimport type {\n\tIssueCountResult,\n\tIssueCountScope,\n\tProviderResult,\n\tProviderWarning,\n\tPullRequestCountResult,\n\tPullRequestCountScope,\n} from '../results.js';\nimport { appendDedupedWarning, toProviderWarning } from '../results.js';\nimport { isIssuesHostIntegrationId, warnOnMissingSessionForDomain } from '../utils/integration.utils.js';\nimport type { ProviderReadContext } from './context.js';\nimport { runCaptured } from './drains.js';\nimport {\n\tresolveIssueSearchCriteria,\n\tresolveIssueSearchScope,\n\tresolvePullRequestSearchCriteria,\n\tresolvePullRequestSearchScope,\n} from './filters.js';\nimport {\n\tgitHostOnlySurfaceWarning,\n\tissuesUnsupportedWarning,\n\totherWarning,\n\tunsupportedIssueSearchCriteriaWarning,\n\tunsupportedPullRequestSearchCriteriaWarning,\n\tunsupportedWarning,\n\tunusableSearchScopeMessage,\n} from './warnings.js';\n\n/**\n * How many scopes go into one upstream request.\n *\n * Measured against the live GitHub API, 30 aliased counts cost a single rate-limit point and ~2s, and 60 cost the\n * same point and roughly twice as long — so the constraint isn't rate limit, it's latency and the provider's\n * (uncontracted, so not to be leaned on) query-complexity limits. 25 keeps a chunk comfortably inside both while\n * still collapsing a realistic filter matrix into one or two requests.\n */\nconst issueCountChunkSize = 25;\n\n/**\n * How many pull-request scopes go into one upstream request.\n *\n * The same latency/complexity reasoning as {@link issueCountChunkSize}, kept slightly smaller because a pull-request\n * scope can fan out into one aliased count PER requested state (open/closed/merged), so a chunk of scopes carries a\n * small multiple of that many `search` aliases.\n *\n * A provider that counts by reading batches nothing, so it is chunked one scope at a time instead: a chunk is then\n * just a scope, and the facade's bounded concurrency is what paces the requests.\n */\nconst pullRequestCountChunkSize = 15;\n\n/**\n * Whether a provider counts pull requests by READING the matches rather than asking for a total — Bitbucket Data\n * Center, which has no count query. Two rules follow from it: it batches nothing, and it deduplicates the rows\n * themselves, so a relationship set is an exact union it can count in one scope rather than a refusal.\n */\nfunction countsPullRequestsByReading(providerId: IntegrationIds): boolean {\n\treturn providerId === GitSelfManagedHostIntegrationId.BitbucketServer;\n}\n\n/**\n * Counts issues for many scopes without fetching any — the probe behind a \"this will fetch ~N issues\" preview.\n *\n * A distinct method rather than a `countOnly` flag on `searchIssuesPage`, because transferring ZERO issues is the\n * entire value: a flag would return a paged result whose `items`, `cursor` and `hasMore` are all meaningless, and\n * every consumer would have to know which fields to ignore. A separate method has a return type that only\n * describes counts.\n *\n * Scopes are batched into as few upstream requests as possible ({@link issueCountChunkSize} each). A chunk that\n * fails warns and drops only its own scopes, leaving the successful chunks' counts intact — so a partial answer is\n * still useful — with `fetchFailed` set. A scope refused for its own reasons (unscoped, inexpressible criteria) is\n * likewise isolated: its siblings are still counted.\n *\n * Cheap is not free: each chunk is a network request, so a caller driving this from UI state is expected to\n * debounce and cache.\n */\nexport async function countIssues(\n\tctx: ProviderReadContext,\n\toptions: {\n\t\tproviderId: IntegrationIds;\n\t\tscopes: readonly IssueCountScope[];\n\t\tconnectionId?: string;\n\t\t/**\n\t\t * Explicit self-managed host domain. Used only when the requested connection has no configured domain;\n\t\t * it must come from the trusted authentication configuration, not repository or remote data.\n\t\t */\n\t\tdomain?: string;\n\t},\n): Promise<ProviderResult<IssueCountResult>> {\n\tconst refused = (warning: ProviderWarning): ProviderResult<IssueCountResult> => ({\n\t\titems: [],\n\t\twarnings: [warning],\n\t\tfetchFailed: true,\n\t});\n\n\tif (isIssuesHostIntegrationId(options.providerId)) {\n\t\treturn refused(gitHostOnlySurfaceWarning(options.providerId, undefined, options.connectionId, 'Issue counts'));\n\t}\n\n\t// Nothing was asked for, so nothing is missing: an empty success, not a refusal.\n\tif (options.scopes.length === 0) return { items: [], warnings: [] };\n\n\tconst duplicateKey = findDuplicateKey(options.scopes);\n\tif (duplicateKey != null) {\n\t\t// Refuses the whole call rather than deduping: `key` exists so the caller can match results without\n\t\t// positional bookkeeping, and two results under one key make that ambiguous for EVERY scope, not just the\n\t\t// repeated one.\n\t\treturn refused(\n\t\t\totherWarning(\n\t\t\t\toptions.providerId,\n\t\t\t\tundefined,\n\t\t\t\toptions.connectionId,\n\t\t\t\t`Duplicate issue count scope key '${duplicateKey}'; keys identify results, so each must be unique.`,\n\t\t\t),\n\t\t);\n\t}\n\n\tconst integration = await ctx.getIntegrationForRead(options.providerId, options.connectionId, options.domain);\n\tif (integration == null) {\n\t\t// A supplied connection or domain that no longer resolves is a broken target, not an empty account.\n\t\tconst early = ctx.earlyReturnConnectionWarnings(options.providerId, options.connectionId, options.domain);\n\t\treturn { items: [], warnings: early.warnings, fetchFailed: early.fetchFailed || undefined };\n\t}\n\tif (!isGitHostIntegration(integration)) {\n\t\treturn refused(gitHostOnlySurfaceWarning(options.providerId, undefined, options.connectionId, 'Issue counts'));\n\t}\n\n\tconst domain = ctx.domainForRead(integration, options.providerId, options.connectionId, options.domain);\n\tconst warnOnMissingSession = warnOnMissingSessionForDomain(options.providerId, options.domain);\n\n\tif (!integration.supportsIssues) {\n\t\treturn refused(issuesUnsupportedWarning(options.providerId, domain, options.connectionId));\n\t}\n\n\t// A provider with no filtered issue search has no count either: refuse ONCE for the provider rather than\n\t// letting every scope repeat the same rejection. `undefined` criteria probes only the search's existence.\n\t// Matches `countPullRequests`. Refusing it here rather than per scope also keeps the loop's warnings from\n\t// being dominated by N copies of one provider-level fact — see the dedupe below, which handles the\n\t// keyless refusals that remain.\n\tconst searchSupport = resolveIssueSearchCriteria(options.providerId, undefined);\n\tif (searchSupport.rejection != null) {\n\t\treturn refused(\n\t\t\tunsupportedIssueSearchCriteriaWarning(\n\t\t\t\toptions.providerId,\n\t\t\t\tdomain,\n\t\t\t\toptions.connectionId,\n\t\t\t\tsearchSupport.rejection,\n\t\t\t),\n\t\t);\n\t}\n\n\tconst providerLimit = providersMetadata[options.providerId]?.issueSearchResultLimit;\n\tconst warnings: ProviderWarning[] = [];\n\tlet fetchFailed = false;\n\n\t// Validate every scope first, so a refusal costs no request at all and the countable ones are still batched\n\t// together.\n\tconst countable: IssueCountScope[] = [];\n\tfor (const scope of options.scopes) {\n\t\tconst warning = rejectScope(options.providerId, domain, options.connectionId, scope);\n\t\tif (warning != null) {\n\t\t\t// Deduped rather than pushed. The rejections that name the offending SCOPE embed its own key, and\n\t\t\t// duplicate keys were already refused above, so those can never collapse. But the ones that report a\n\t\t\t// PROVIDER-level fact — a criterion it cannot express, a contradictory relationship pair — name no\n\t\t\t// scope, so several scopes failing the same way produce byte-identical warnings, and one refusal\n\t\t\t// reported N times reads as N different problems.\n\t\t\tappendDedupedWarning(warnings, warning);\n\t\t\tfetchFailed = true;\n\t\t\tcontinue;\n\t\t}\n\n\t\tcountable.push(scope);\n\t}\n\n\t// Chunks are independent requests over their own slice of scopes — nothing in one reads what another produced,\n\t// and `runCaptured` never throws — so they run concurrently, bounded like every other fan-out on the facade.\n\t// Sequentially they would spend exactly the resource this probe is tuned to conserve: latency, ~2s per chunk.\n\t// `mapBounded` returns in input order, so `items` and `warnings` stay in scope order.\n\tconst batches = await mapBounded(chunk(countable, issueCountChunkSize), providerFanOutConcurrency, batch =>\n\t\trunCaptured(\n\t\t\toptions.providerId,\n\t\t\tdomain,\n\t\t\toptions.connectionId,\n\t\t\t() =>\n\t\t\t\tintegration.countIssuesResult(\n\t\t\t\t\tbatch.map(s => ({\n\t\t\t\t\t\trepos: s.repos as ProviderRepoInput[] | undefined,\n\t\t\t\t\t\torg: s.org,\n\t\t\t\t\t\tcriteria: s.criteria,\n\t\t\t\t\t})),\n\t\t\t\t\tundefined,\n\t\t\t\t\toptions.connectionId,\n\t\t\t\t),\n\t\t\t{ warnOnMissingSession: warnOnMissingSession },\n\t\t).then(result => ({ batch: batch, ...result })),\n\t);\n\n\tconst items: IssueCountResult[] = [];\n\tfor (const { batch, value, warning } of batches) {\n\t\tif (warning != null) {\n\t\t\tappendDedupedWarning(warnings, warning);\n\t\t}\n\t\tif (value == null) {\n\t\t\t// This batch contributes nothing, but the batches around it still do. Drop only these scopes.\n\t\t\tfetchFailed = true;\n\t\t\tcontinue;\n\t\t}\n\n\t\tfetchFailed =\n\t\t\tcollectCounts(batch, value, providerLimit, items, (key, error) => {\n\t\t\t\tconst warning = toProviderWarning(options.providerId, domain, options.connectionId, error);\n\t\t\t\tappendDedupedWarning(warnings, {\n\t\t\t\t\t...warning,\n\t\t\t\t\tmessage: `Issue count scope '${key}': ${warning.message}`,\n\t\t\t\t});\n\t\t\t}) || fetchFailed;\n\t}\n\n\t// A provider with no count support returns `undefined` with no error, which lands as an empty `items` and no\n\t// warning. Say so explicitly rather than letting it read as \"every scope matched nothing\".\n\tif (items.length === 0 && warnings.length === 0) {\n\t\treturn refused(\n\t\t\tunsupportedIssueSearchCriteriaWarning(options.providerId, domain, options.connectionId, {\n\t\t\t\treason: 'unsupported-search',\n\t\t\t}),\n\t\t);\n\t}\n\n\treturn { items: items, warnings: warnings, fetchFailed: fetchFailed || undefined };\n}\n\n/**\n * Turns one batch of positional issue counts into keyed results, returning whether any scope was refused.\n *\n * A slot holding an `Error` is a scope the PROVIDER refused for its own reasons (a scope naming a collection it\n * can't search, say): reported and dropped exactly like a scope the facade refuses, so its siblings in the batch\n * still come back. `'exceeds-limit'` is a count the provider can only bound — more than its ceiling matched — which\n * is reported as `exceedsProviderLimit` with no `count` rather than as the ceiling, which would understate it.\n */\nfunction collectCounts<T extends { key: string }>(\n\tbatch: readonly T[],\n\tvalue: readonly ProviderSearchCount[],\n\tproviderLimit: number | undefined,\n\titems: { key: string; count?: number; exceedsProviderLimit: boolean; providerLimit?: number }[],\n\tonRefused: (key: string, error: Error) => void,\n): boolean {\n\tlet refused = false;\n\tfor (let i = 0; i < batch.length; i++) {\n\t\tconst count = value[i];\n\t\tif (count instanceof Error) {\n\t\t\tonRefused(batch[i].key, count);\n\t\t\trefused = true;\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst exceeds = count === 'exceeds-limit';\n\t\titems.push({\n\t\t\tkey: batch[i].key,\n\t\t\tcount: exceeds ? undefined : count,\n\t\t\t// Only a reported count can exceed a declared ceiling; unknown-vs-limit is not a comparison.\n\t\t\texceedsProviderLimit: exceeds || (count != null && providerLimit != null && count > providerLimit),\n\t\t\tproviderLimit: providerLimit,\n\t\t});\n\t}\n\treturn refused;\n}\n\n/** The first key that appears twice, or `undefined` when every key is unique. */\nfunction findDuplicateKey(scopes: readonly { key: string }[]): string | undefined {\n\tconst seen = new Set<string>();\n\tfor (const scope of scopes) {\n\t\tif (seen.has(scope.key)) return scope.key;\n\n\t\tseen.add(scope.key);\n\t}\n\treturn undefined;\n}\n\n/**\n * Why one scope can't be counted, as the warning to report — or `undefined` when it can.\n *\n * The scope and criteria rules come from {@link resolveIssueSearchScope} / {@link resolveIssueSearchCriteria},\n * the same validators `searchIssuesPage` uses, so a count always previews the constraints the read would apply.\n * That is not cosmetic: a count computed under different constraints is a WRONG number rather than a missing\n * one, which is worse. Only the wording is local, because these name the offending scope's key.\n */\nfunction rejectScope(\n\tproviderId: IntegrationIds,\n\tdomain: string | undefined,\n\tconnectionId: string | undefined,\n\tscope: IssueCountScope,\n): ProviderWarning | undefined {\n\tconst resolved = resolveIssueSearchCriteria(providerId, scope.criteria);\n\tif (resolved.rejection != null) {\n\t\treturn unsupportedIssueSearchCriteriaWarning(providerId, domain, connectionId, resolved.rejection);\n\t}\n\n\t// AFTER the criteria check, mirroring `searchIssuesPage`: a provider with no filtered issue search is the more\n\t// fundamental refusal, and a count must preview the refusal its read would give.\n\tconst scoping = resolveIssueSearchScope(providerId, scope.repos, scope.org, scope.criteria);\n\tswitch (scoping.rejection?.reason) {\n\t\tcase 'repo-ids':\n\t\t\treturn otherWarning(\n\t\t\t\tproviderId,\n\t\t\t\tdomain,\n\t\t\t\tconnectionId,\n\t\t\t\t`Issue count scope '${scope.key}' cannot be scoped by repository id; pass repository descriptors (namespace + name) instead.`,\n\t\t\t);\n\t\tcase 'unscoped':\n\t\t\treturn otherWarning(\n\t\t\t\tproviderId,\n\t\t\t\tdomain,\n\t\t\t\tconnectionId,\n\t\t\t\t`Issue count scope '${scope.key}' is unscoped; pass \\`repos\\`, \\`org\\`, or a relationship to the current user. \\`any-assignee\\` and \\`unassigned\\` are not scopes.`,\n\t\t\t);\n\t\t// A count applies exactly the qualifiers its search would, so an unusable scope would make it agree with\n\t\t// the wrong search rather than expose it — see `isUsableSearchScopeName`.\n\t\tcase 'unusable-scope':\n\t\t\treturn otherWarning(\n\t\t\t\tproviderId,\n\t\t\t\tdomain,\n\t\t\t\tconnectionId,\n\t\t\t\tunusableSearchScopeMessage('scopes', scoping.rejection.scopes, `Issue count scope '${scope.key}'`),\n\t\t\t);\n\t}\n\n\t// Count-only, with no counterpart in the read: a relationship set is an OR across several searches, which one\n\t// count can't express — summing them would double-count anything matching two, and taking the max would\n\t// under-report. Rather than answer with a wrong number, ask the caller to count each relationship as its own\n\t// scope, where the keys make the OR explicit.\n\tif ((scope.criteria?.relationships?.length ?? 0) > 1) {\n\t\treturn otherWarning(\n\t\t\tproviderId,\n\t\t\tdomain,\n\t\t\tconnectionId,\n\t\t\t`Issue count scope '${scope.key}' requests several relationships, which a single count can't express (they are OR-ed, so overlapping matches would be double-counted); pass one scope per relationship.`,\n\t\t);\n\t}\n\n\treturn undefined;\n}\n\n/**\n * Counts pull requests for many scopes without fetching any — the PR twin of {@link countIssues}, and the probe\n * behind a \"this will fetch ~N pull requests\" preview.\n *\n * Identical batching, per-scope isolation, and `key`-echo contract as {@link countIssues}; see it for the cost\n * model and the `count: undefined` ≠ zero rule. The one difference is inherent to pull requests: a scope's criteria\n * can name several STATES, which GitHub/GHE count as independent searches — the reported `count` is the LARGEST\n * of them (mirroring `searchPullRequestsPage`'s total), so an unpaged read still can't exceed a single search's\n * ceiling undetected. Bitbucket Data Center has no ceiling and no count query: it counts the exact union by reading\n * each scope within a budget, and flags a scope that had more as `lowerBound`. Because it deduplicates rows, it is\n * also the one provider that accepts several relationships in one scope. Azure DevOps Server counts the union of the\n * states from the one drain its search pages through.\n */\nexport async function countPullRequests(\n\tctx: ProviderReadContext,\n\toptions: {\n\t\tproviderId: IntegrationIds;\n\t\tscopes: readonly PullRequestCountScope[];\n\t\tconnectionId?: string;\n\t\t/**\n\t\t * Explicit self-managed host domain. Used only when the requested connection has no configured domain;\n\t\t * it must come from the trusted authentication configuration, not repository or remote data.\n\t\t */\n\t\tdomain?: string;\n\t},\n): Promise<ProviderResult<PullRequestCountResult>> {\n\tconst refused = (warning: ProviderWarning): ProviderResult<PullRequestCountResult> => ({\n\t\titems: [],\n\t\twarnings: [warning],\n\t\tfetchFailed: true,\n\t});\n\n\tif (isIssuesHostIntegrationId(options.providerId)) {\n\t\treturn refused(\n\t\t\tgitHostOnlySurfaceWarning(options.providerId, undefined, options.connectionId, 'Pull request counts'),\n\t\t);\n\t}\n\n\t// Nothing was asked for, so nothing is missing: an empty success, not a refusal.\n\tif (options.scopes.length === 0) return { items: [], warnings: [] };\n\n\tconst duplicateKey = findDuplicateKey(options.scopes);\n\tif (duplicateKey != null) {\n\t\t// Refuses the whole call rather than deduping: `key` exists so the caller can match results without\n\t\t// positional bookkeeping, and two results under one key make that ambiguous for EVERY scope, not just the\n\t\t// repeated one.\n\t\treturn refused(\n\t\t\totherWarning(\n\t\t\t\toptions.providerId,\n\t\t\t\tundefined,\n\t\t\t\toptions.connectionId,\n\t\t\t\t`Duplicate pull request count scope key '${duplicateKey}'; keys identify results, so each must be unique.`,\n\t\t\t),\n\t\t);\n\t}\n\n\tconst integration = await ctx.getIntegrationForRead(options.providerId, options.connectionId, options.domain);\n\tif (integration == null) {\n\t\t// A supplied connection or domain that no longer resolves is a broken target, not an empty account.\n\t\tconst early = ctx.earlyReturnConnectionWarnings(options.providerId, options.connectionId, options.domain);\n\t\treturn { items: [], warnings: early.warnings, fetchFailed: early.fetchFailed || undefined };\n\t}\n\tif (!isGitHostIntegration(integration)) {\n\t\treturn refused(\n\t\t\tgitHostOnlySurfaceWarning(options.providerId, undefined, options.connectionId, 'Pull request counts'),\n\t\t);\n\t}\n\n\tconst domain = ctx.domainForRead(integration, options.providerId, options.connectionId, options.domain);\n\tconst warnOnMissingSession = warnOnMissingSessionForDomain(options.providerId, options.domain);\n\n\t// A provider with no filtered pull-request search has no count either: refuse ONCE for the provider rather than\n\t// letting every scope repeat the same rejection. `undefined` criteria probes only the search's existence.\n\tconst searchSupport = resolvePullRequestSearchCriteria(options.providerId, undefined);\n\tif (searchSupport.rejection != null) {\n\t\treturn refused(\n\t\t\tunsupportedPullRequestSearchCriteriaWarning(\n\t\t\t\toptions.providerId,\n\t\t\t\tdomain,\n\t\t\t\toptions.connectionId,\n\t\t\t\tsearchSupport.rejection,\n\t\t\t),\n\t\t);\n\t}\n\n\tconst providerLimit = providersMetadata[options.providerId]?.pullRequestSearchResultLimit;\n\tconst warnings: ProviderWarning[] = [];\n\tlet fetchFailed = false;\n\n\t// Validate every scope first, so a refusal costs no request at all and the countable ones are still batched\n\t// together.\n\tconst countable: PullRequestCountScope[] = [];\n\tfor (const scope of options.scopes) {\n\t\tconst warning = rejectPullRequestScope(options.providerId, domain, options.connectionId, scope);\n\t\tif (warning != null) {\n\t\t\t// Deduped rather than pushed: see the issue twin. Here the keyless set is wider — besides the criteria\n\t\t\t// rejections, `unsupported-repository-scope` and `unsupported-organization-scope` are scope rejections\n\t\t\t// that route through the criteria warning and name no key, and both are provider-level facts every\n\t\t\t// scope would repeat.\n\t\t\tappendDedupedWarning(warnings, warning);\n\t\t\tfetchFailed = true;\n\t\t\tcontinue;\n\t\t}\n\n\t\tcountable.push(scope);\n\t}\n\n\t// Chunks are independent requests over their own slice of scopes, `runCaptured` never throws, so they run\n\t// concurrently, bounded like every other fan-out on the facade. `mapBounded` returns in input order, so `items`\n\t// and `warnings` stay in scope order.\n\tconst chunks = chunk(countable, countsPullRequestsByReading(options.providerId) ? 1 : pullRequestCountChunkSize);\n\tconst batches = await mapBounded(chunks, providerFanOutConcurrency, batch =>\n\t\trunCaptured(\n\t\t\toptions.providerId,\n\t\t\tdomain,\n\t\t\toptions.connectionId,\n\t\t\t() =>\n\t\t\t\tintegration.countPullRequestsResult(\n\t\t\t\t\tbatch.map(s => ({\n\t\t\t\t\t\trepos: s.repos as ProviderRepoInput[] | undefined,\n\t\t\t\t\t\torg: s.org,\n\t\t\t\t\t\tcriteria: s.criteria,\n\t\t\t\t\t})),\n\t\t\t\t\tundefined,\n\t\t\t\t\toptions.connectionId,\n\t\t\t\t),\n\t\t\t{ warnOnMissingSession: warnOnMissingSession },\n\t\t).then(result => ({ batch: batch, ...result })),\n\t);\n\n\tconst items: PullRequestCountResult[] = [];\n\tfor (const { batch, value, warning } of batches) {\n\t\tif (warning != null) {\n\t\t\tappendDedupedWarning(warnings, warning);\n\t\t}\n\t\tif (value == null) {\n\t\t\t// This batch contributes nothing, but the batches around it still do. Drop only these scopes.\n\t\t\tfetchFailed = true;\n\t\t\tcontinue;\n\t\t}\n\n\t\tfor (let i = 0; i < batch.length; i++) {\n\t\t\tconst slot = value[i];\n\t\t\t// A scope the provider refused for its own reasons: reported and dropped like one the facade refuses.\n\t\t\tif (slot instanceof Error) {\n\t\t\t\tconst warning = toProviderWarning(options.providerId, domain, options.connectionId, slot);\n\t\t\t\tappendDedupedWarning(warnings, {\n\t\t\t\t\t...warning,\n\t\t\t\t\tmessage: `Pull request count scope '${batch[i].key}': ${warning.message}`,\n\t\t\t\t});\n\t\t\t\tfetchFailed = true;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst count = slot?.count;\n\t\t\titems.push({\n\t\t\t\tkey: batch[i].key,\n\t\t\t\tcount: count,\n\t\t\t\t...(count != null && slot?.lowerBound === true ? { lowerBound: true } : {}),\n\t\t\t\t// Only a reported count can exceed a declared ceiling; unknown-vs-limit is not a comparison.\n\t\t\t\texceedsProviderLimit: count != null && providerLimit != null && count > providerLimit,\n\t\t\t\tproviderLimit: providerLimit,\n\t\t\t});\n\t\t}\n\t}\n\n\t// A provider that reported nothing for any scope and raised no warning: say so explicitly rather than letting it\n\t// read as \"every scope matched nothing\".\n\tif (items.length === 0 && warnings.length === 0) {\n\t\treturn refused(\n\t\t\tunsupportedPullRequestSearchCriteriaWarning(options.providerId, domain, options.connectionId, {\n\t\t\t\treason: 'unsupported-search',\n\t\t\t}),\n\t\t);\n\t}\n\n\treturn { items: items, warnings: warnings, fetchFailed: fetchFailed || undefined };\n}\n\n/**\n * Why one pull-request scope can't be counted, as the warning to report — or `undefined` when it can. The PR twin\n * of {@link rejectScope}, validating against the same {@link resolvePullRequestSearchScope} /\n * {@link resolvePullRequestSearchCriteria} the read uses, so a count always previews the constraints the read\n * would apply.\n */\nfunction rejectPullRequestScope(\n\tproviderId: IntegrationIds,\n\tdomain: string | undefined,\n\tconnectionId: string | undefined,\n\tscope: PullRequestCountScope,\n): ProviderWarning | undefined {\n\tconst scoping = resolvePullRequestSearchScope(providerId, scope.repos, scope.org, scope.criteria);\n\tswitch (scoping.rejection?.reason) {\n\t\tcase 'repo-ids':\n\t\t\treturn otherWarning(\n\t\t\t\tproviderId,\n\t\t\t\tdomain,\n\t\t\t\tconnectionId,\n\t\t\t\t`Pull request count scope '${scope.key}' cannot be scoped by repository id; pass repository descriptors (namespace + name) instead.`,\n\t\t\t);\n\t\tcase 'unscoped':\n\t\t\treturn otherWarning(\n\t\t\t\tproviderId,\n\t\t\t\tdomain,\n\t\t\t\tconnectionId,\n\t\t\t\t`Pull request count scope '${scope.key}' is unscoped; pass \\`repos\\`, \\`org\\`, or at least one current-user relationship.`,\n\t\t\t);\n\t\tcase 'unsupported-repository-scope':\n\t\tcase 'unsupported-organization-scope':\n\t\t\treturn unsupportedPullRequestSearchCriteriaWarning(providerId, domain, connectionId, {\n\t\t\t\treason: 'unsupported-criteria',\n\t\t\t\tcriteria: [\n\t\t\t\t\tscoping.rejection.reason === 'unsupported-repository-scope'\n\t\t\t\t\t\t? 'repositoryScope'\n\t\t\t\t\t\t: 'organizationScope',\n\t\t\t\t],\n\t\t\t});\n\t\t// See the issue twin, and `isUsableSearchScopeName` for the rule.\n\t\tcase 'unusable-scope':\n\t\t\treturn otherWarning(\n\t\t\t\tproviderId,\n\t\t\t\tdomain,\n\t\t\t\tconnectionId,\n\t\t\t\tunusableSearchScopeMessage(\n\t\t\t\t\t'scopes',\n\t\t\t\t\tscoping.rejection.scopes,\n\t\t\t\t\t`Pull request count scope '${scope.key}'`,\n\t\t\t\t),\n\t\t\t);\n\t}\n\n\tconst resolved = resolvePullRequestSearchCriteria(providerId, scope.criteria);\n\tif (resolved.rejection != null) {\n\t\treturn unsupportedPullRequestSearchCriteriaWarning(providerId, domain, connectionId, resolved.rejection);\n\t}\n\n\t// Count-only, with no counterpart in the read: a relationship set is an OR across several searches, which one\n\t// count can't express — summing would double-count overlaps and max would under-report. Ask the caller to count\n\t// each relationship as its own scope, where the keys make the OR explicit. (States are disjoint, so a scope may\n\t// still name several — the provider counts them as the max, not a refusal.) A provider that counts by reading\n\t// deduplicates the matching rows themselves, so it counts the OR exactly, as the search it previews returns it.\n\t// That makes the refusal the provider's capability, so `unsupported`; the issue twin refuses on every provider.\n\tif ((scope.criteria?.relationships?.length ?? 0) > 1 && !countsPullRequestsByReading(providerId)) {\n\t\treturn unsupportedWarning(\n\t\t\tproviderId,\n\t\t\tdomain,\n\t\t\tconnectionId,\n\t\t\t`Pull request count scope '${scope.key}' requests several relationships, which a single count can't express (they are OR-ed, so overlapping matches would be double-counted); pass one scope per relationship.`,\n\t\t);\n\t}\n\n\treturn undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA6CA,MAAM,sBAAsB;;;;;;;;;;;AAY5B,MAAM,4BAA4B;;;;;;AAOlC,SAAS,4BAA4B,YAAqC;CACzE,OAAO,eAAA;AACR;;;;;;;;;;;;;;;;;AAkBA,eAAsB,YACrB,KACA,SAU4C;CAC5C,MAAM,WAAW,aAAgE;EAChF,OAAO,CAAC;EACR,UAAU,CAAC,OAAO;EAClB,aAAa;CACd;CAEA,IAAI,0BAA0B,QAAQ,UAAU,GAC/C,OAAO,QAAQ,0BAA0B,QAAQ,YAAY,KAAA,GAAW,QAAQ,cAAc,cAAc,CAAC;CAI9G,IAAI,QAAQ,OAAO,WAAW,GAAG,OAAO;EAAE,OAAO,CAAC;EAAG,UAAU,CAAC;CAAE;CAElE,MAAM,eAAe,iBAAiB,QAAQ,MAAM;CACpD,IAAI,gBAAgB,MAInB,OAAO,QACN,aACC,QAAQ,YACR,KAAA,GACA,QAAQ,cACR,oCAAoC,aAAa,kDAClD,CACD;CAGD,MAAM,cAAc,MAAM,IAAI,sBAAsB,QAAQ,YAAY,QAAQ,cAAc,QAAQ,MAAM;CAC5G,IAAI,eAAe,MAAM;EAExB,MAAM,QAAQ,IAAI,8BAA8B,QAAQ,YAAY,QAAQ,cAAc,QAAQ,MAAM;EACxG,OAAO;GAAE,OAAO,CAAC;GAAG,UAAU,MAAM;GAAU,aAAa,MAAM,eAAe,KAAA;EAAU;CAC3F;CACA,IAAI,CAAC,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AQ,UAAU,QAClB,6BAA6B,MAAM,IAAI,EACxC,CACD;CACF;CAEA,MAAM,WAAW,iCAAiC,YAAY,MAAM,QAAQ;CAC5E,IAAI,SAAS,aAAa,MACzB,OAAO,4CAA4C,YAAY,QAAQ,cAAc,SAAS,SAAS;CASxG,KAAK,MAAM,UAAU,eAAe,UAAU,KAAK,KAAK,CAAC,4BAA4B,UAAU,GAC9F,OAAO,mBACN,YACA,QACA,cACA,6BAA6B,MAAM,IAAI,wKACxC;AAIF"}
|
|
@@ -1,24 +1,7 @@
|
|
|
1
|
-
import { Account } from "../../../git/models/author.js";
|
|
2
1
|
import { IntegrationIds } from "../constants.js";
|
|
3
|
-
import {
|
|
2
|
+
import { CurrentAccountResult } from "../results.js";
|
|
4
3
|
import { ProviderReadContext } from "./context.js";
|
|
5
4
|
//#region ../plus/integrations/src/reads/currentAccount.d.ts
|
|
6
|
-
/**
|
|
7
|
-
* "Who am I on this provider / connection" — {@link IntegrationBase.getCurrentAccount}'s own answer, exposed on
|
|
8
|
-
* the manager so a caller can ask for it directly instead of waiting for some other read to warm it as a side
|
|
9
|
-
* effect.
|
|
10
|
-
*/
|
|
11
|
-
export interface CurrentAccountResult {
|
|
12
|
-
/** The signed-in account, when the provider answered. */
|
|
13
|
-
account?: Account;
|
|
14
|
-
warnings: ProviderWarning[];
|
|
15
|
-
/**
|
|
16
|
-
* Set whenever `account` is absent. Unlike a list/batch read, this one has no benign empty answer — "who am
|
|
17
|
-
* I" is either resolved or it couldn't be told, never a legitimately empty result — so `account` is never
|
|
18
|
-
* missing without a warning explaining why.
|
|
19
|
-
*/
|
|
20
|
-
fetchFailed?: boolean;
|
|
21
|
-
}
|
|
22
5
|
/**
|
|
23
6
|
* Resolves the viewer's own account for a connection. Jira Data Center refuses: it has no account-wide lookup.
|
|
24
7
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currentAccount.js","names":[],"sources":["../../../../../plus/integrations/src/reads/currentAccount.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"currentAccount.js","names":[],"sources":["../../../../../plus/integrations/src/reads/currentAccount.ts"],"sourcesContent":["import type { IntegrationIds } from '../constants.js';\nimport type { CurrentAccountResult, ProviderWarning } from '../results.js';\nimport { appendDedupedWarning } from '../results.js';\nimport type { ProviderReadContext } from './context.js';\nimport { runCaptured } from './drains.js';\nimport { noConnectionWarning, unsupportedWarning } from './warnings.js';\n\n/**\n * Resolves the viewer's own account for a connection. Jira Data Center refuses: it has no account-wide lookup.\n *\n * Goes THROUGH `Integration.getCurrentAccount`'s own cache (the hook a host supplies as\n * `IntegrationManagerCacheProvider.getCurrentAccount`) rather than adding a second one, so this read and\n * whatever else warms that cache — today, authorship enrichment on the pull request reads — stay one cache.\n */\nexport async function getCurrentAccount(\n\tctx: ProviderReadContext,\n\toptions: { providerId: IntegrationIds; connectionId?: string; domain?: string },\n): Promise<CurrentAccountResult> {\n\tconst integration = await ctx.getIntegrationForRead(options.providerId, options.connectionId, options.domain);\n\tif (integration == null) {\n\t\tconst early = ctx.earlyReturnConnectionWarnings(options.providerId, options.connectionId, options.domain);\n\t\tif (early.warnings.length > 0) return { warnings: early.warnings, fetchFailed: true };\n\n\t\t// The untargeted primary path reads a disconnected provider as a silent empty result on the list reads; an\n\t\t// absent account must still carry a warning here, as on the batch reads — see `CurrentAccountResult.fetchFailed`.\n\t\tconst domain = ctx.resolveDomainForRead(options.providerId, options.connectionId, options.domain);\n\t\treturn { warnings: [noConnectionWarning(options.providerId, domain, options.connectionId)], fetchFailed: true };\n\t}\n\n\tconst domain = ctx.domainForRead(integration, options.providerId, options.connectionId, options.domain);\n\n\tif (!integration.supportsCurrentAccount) {\n\t\treturn {\n\t\t\twarnings: [\n\t\t\t\tunsupportedWarning(\n\t\t\t\t\toptions.providerId,\n\t\t\t\t\tdomain,\n\t\t\t\t\toptions.connectionId,\n\t\t\t\t\t`Current account lookup is not supported by '${options.providerId}'.`,\n\t\t\t\t),\n\t\t\t],\n\t\t\tfetchFailed: true,\n\t\t};\n\t}\n\n\tconst { value: account, warning } = await runCaptured(\n\t\toptions.providerId,\n\t\tdomain,\n\t\toptions.connectionId,\n\t\tasync () => {\n\t\t\tconst resolved = await integration.getCurrentAccount({ connectionId: options.connectionId });\n\t\t\t// `undefined` is returned bare (not `{ value: undefined }`) so `runCaptured` treats it the same as\n\t\t\t// a session it couldn't resolve — the only other way this read core answers nothing.\n\t\t\treturn resolved != null ? { value: resolved } : undefined;\n\t\t},\n\t\t{ warnOnMissingSession: true },\n\t);\n\n\tconst warnings: ProviderWarning[] = [];\n\tif (warning != null) {\n\t\tappendDedupedWarning(warnings, warning);\n\t}\n\n\treturn {\n\t\t...(account != null ? { account: account } : {}),\n\t\twarnings: warnings,\n\t\tfetchFailed: account == null ? true : undefined,\n\t};\n}\n"],"mappings":";;;;;;;;;;;AAcA,eAAsB,kBACrB,KACA,SACgC;CAChC,MAAM,cAAc,MAAM,IAAI,sBAAsB,QAAQ,YAAY,QAAQ,cAAc,QAAQ,MAAM;CAC5G,IAAI,eAAe,MAAM;EACxB,MAAM,QAAQ,IAAI,8BAA8B,QAAQ,YAAY,QAAQ,cAAc,QAAQ,MAAM;EACxG,IAAI,MAAM,SAAS,SAAS,GAAG,OAAO;GAAE,UAAU,MAAM;GAAU,aAAa;EAAK;EAIpF,MAAM,SAAS,IAAI,qBAAqB,QAAQ,YAAY,QAAQ,cAAc,QAAQ,MAAM;EAChG,OAAO;GAAE,UAAU,CAAC,oBAAoB,QAAQ,YAAY,QAAQ,QAAQ,YAAY,CAAC;GAAG,aAAa;EAAK;CAC/G;CAEA,MAAM,SAAS,IAAI,cAAc,aAAa,QAAQ,YAAY,QAAQ,cAAc,QAAQ,MAAM;CAEtG,IAAI,CAAC,YAAY,wBAChB,OAAO;EACN,UAAU,CACT,mBACC,QAAQ,YACR,QACA,QAAQ,cACR,+CAA+C,QAAQ,WAAW,GACnE,CACD;EACA,aAAa;CACd;CAGD,MAAM,EAAE,OAAO,SAAS,YAAY,MAAM,YACzC,QAAQ,YACR,QACA,QAAQ,cACR,YAAY;EACX,MAAM,WAAW,MAAM,YAAY,kBAAkB,EAAE,cAAc,QAAQ,aAAa,CAAC;EAG3F,OAAO,YAAY,OAAO,EAAE,OAAO,SAAS,IAAI,KAAA;CACjD,GACA,EAAE,sBAAsB,KAAK,CAC9B;CAEA,MAAM,WAA8B,CAAC;CACrC,IAAI,WAAW,MACd,qBAAqB,UAAU,OAAO;CAGvC,OAAO;EACN,GAAI,WAAW,OAAO,EAAW,QAAQ,IAAI,CAAC;EACpC;EACV,aAAa,WAAW,OAAO,OAAO,KAAA;CACvC;AACD"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { ResourceDescriptor } from "../../../git/models/resourceDescriptor.js";
|
|
2
2
|
import { PullRequest, PullRequestFilter, PullRequestStateFilter } from "../../../git/models/pullRequest.js";
|
|
3
3
|
import { IntegrationIds } from "../constants.js";
|
|
4
|
+
import "../providerFilters.js";
|
|
4
5
|
import { ProviderWarning } from "../results.js";
|
|
6
|
+
import { ProviderSweepTarget, PullRequestSweepOptions } from "../manager.js";
|
|
7
|
+
import { IntegrationResult } from "../models/publicIntegration.js";
|
|
8
|
+
import { IssuesIntegration } from "../models/issuesIntegration.js";
|
|
5
9
|
import { ProviderPullRequest, ProviderReposInput, ProviderRepository } from "../providers/models.js";
|
|
6
10
|
import { GitHostIntegration } from "../models/gitHostIntegration.js";
|
|
7
|
-
import { IssuesIntegration } from "../models/issuesIntegration.js";
|
|
8
|
-
import { IntegrationResult } from "../models/integration.js";
|
|
9
|
-
import { ProviderSweepTarget, PullRequestSweepOptions } from "../manager.js";
|
|
10
11
|
import { CollectionMetadata } from "@gitkraken/provider-apis";
|
|
11
12
|
//#region ../plus/integrations/src/reads/drains.d.ts
|
|
12
13
|
/**
|
|
@@ -3,8 +3,8 @@ import { supportedOrderedCloudIntegrationIds } from "../constants.js";
|
|
|
3
3
|
import { appendDedupedWarning, reconcileOmissionsWithFailure, toProviderWarning } from "../results.js";
|
|
4
4
|
import { mergeAssessmentInto } from "../collectionMetadata.js";
|
|
5
5
|
import { hostFromDomain } from "../utils/domain.utils.js";
|
|
6
|
-
import { getProviderPullRequestIdentity, pullRequestNamesPeople } from "../providers/models.js";
|
|
7
6
|
import { isIssuesHostIntegrationId, isSelfManagedHostIntegrationId } from "../utils/integration.utils.js";
|
|
7
|
+
import { getProviderPullRequestIdentity, pullRequestNamesPeople } from "../providers/models.js";
|
|
8
8
|
import { cappedBesideBudgetWarning, noConnectionWarning, pullRequestSearchCapResultWarning, truncationWarning } from "./warnings.js";
|
|
9
9
|
//#region ../plus/integrations/src/reads/drains.ts
|
|
10
10
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drains.js","names":[],"sources":["../../../../../plus/integrations/src/reads/drains.ts"],"sourcesContent":["import type { CollectionMetadata } from '@gitkraken/provider-apis';\nimport type { PullRequest, PullRequestStateFilter } from '@gitlens/git/models/pullRequest.js';\nimport { defaultPullRequestSort } from '@gitlens/git/models/pullRequest.js';\nimport type { ResourceDescriptor } from '@gitlens/git/models/resourceDescriptor.js';\nimport { mergeAssessmentInto } from '../collectionMetadata.js';\nimport type { IntegrationIds } from '../constants.js';\nimport { supportedOrderedCloudIntegrationIds } from '../constants.js';\nimport type { ProviderSweepTarget, PullRequestSweepOptions } from '../manager.js';\nimport type { GitHostIntegration } from '../models/gitHostIntegration.js';\nimport type { IntegrationResult } from '../models/integration.js';\nimport type { IssuesIntegration } from '../models/issuesIntegration.js';\nimport type { PullRequestFilter } from '../providerFilters.js';\nimport type { ProviderPullRequest, ProviderReposInput, ProviderRepository } from '../providers/models.js';\nimport { getProviderPullRequestIdentity, pullRequestNamesPeople } from '../providers/models.js';\nimport type { ProviderWarning } from '../results.js';\nimport { appendDedupedWarning, reconcileOmissionsWithFailure, toProviderWarning } from '../results.js';\nimport { hostFromDomain } from '../utils/domain.utils.js';\nimport { isIssuesHostIntegrationId, isSelfManagedHostIntegrationId } from '../utils/integration.utils.js';\nimport {\n\tcappedBesideBudgetWarning,\n\tnoConnectionWarning,\n\tpullRequestSearchCapResultWarning,\n\ttruncationWarning,\n} from './warnings.js';\n\n/**\n * The all-pages reads: a provider read run repeatedly until it runs out of pages, as opposed to the single-page\n * reads the facade's paged surface exposes. `sweepPullRequests` and `broadenIssues` are built on these.\n *\n * A drain's job is to keep going where a single page would stop, so what distinguishes it is its failure\n * bookkeeping rather than its loop: it must return the prefix it did read plus enough signal for the caller to\n * know the result is not authoritative — `truncated` when pages remain unread (a page backstop, or a provider\n * claiming another page while handing back no usable cursor), `fetchFailed` when a page or scope failed\n * outright. Discarding the prefix on a late failure, or returning it as if complete, are the two mistakes these\n * exist to prevent.\n */\n\n/**\n * Runs a result-returning read and captures failure as a neutral {@link ProviderWarning} rather than\n * letting it throw or silently vanish. Handles both a returned `{ error }` (the read cores' contract)\n * and a hard throw; a soft warning (`{ value, error }`) yields the value *and* a warning.\n */\nexport async function runCaptured<T>(\n\tid: IntegrationIds,\n\tdomain: string | undefined,\n\tconnectionId: string | undefined,\n\tfn: () => Promise<IntegrationResult<T>>,\n\toptions?: { warnOnMissingSession?: boolean },\n): Promise<{ value?: T; warning?: ProviderWarning }> {\n\ttry {\n\t\tconst result = await fn();\n\t\tif (result == null) {\n\t\t\t// The read core returns undefined only when it couldn't resolve a session. For a per-connection\n\t\t\t// or explicit-domain read that means the requested target is gone or its authentication is invalid,\n\t\t\t// which must not be reported as an empty account. The untargeted primary path legitimately yields\n\t\t\t// nothing when the provider isn't connected, so leave it as an empty result.\n\t\t\treturn connectionId != null || options?.warnOnMissingSession\n\t\t\t\t? { warning: noConnectionWarning(id, domain, connectionId) }\n\t\t\t\t: {};\n\t\t}\n\t\tif (result.error != null) {\n\t\t\treturn { value: result.value, warning: toProviderWarning(id, domain, connectionId, result.error) };\n\t\t}\n\t\treturn { value: result.value };\n\t} catch (ex) {\n\t\treturn { warning: toProviderWarning(id, domain, connectionId, ex) };\n\t}\n}\n\n/**\n * {@link runCaptured} over an issue tracker's resource (site, organization, board) discovery. A read that resolved a\n * session yet answered with no data and no error carries `completeness: 'unknown'` metadata, so it reads as an\n * incomplete discovery rather than as an account with no resources, which `runCaptured` alone can't tell apart from\n * an untargeted read with no session.\n */\nexport async function discoverResources(\n\tintegration: IssuesIntegration,\n\tid: IntegrationIds,\n\tdomain: string | undefined,\n\tconnectionId: string | undefined,\n\toptions?: { warnOnMissingSession?: boolean },\n): Promise<{ value?: ResourceDescriptor[]; warning?: ProviderWarning; metadata?: CollectionMetadata }> {\n\tlet noData = false;\n\tconst captured = await runCaptured(\n\t\tid,\n\t\tdomain,\n\t\tconnectionId,\n\t\tasync () => {\n\t\t\tconst result = await integration.getResourcesForUserResult(connectionId);\n\t\t\tnoData = result != null && result.error == null && result.value == null;\n\t\t\treturn result;\n\t\t},\n\t\toptions,\n\t);\n\treturn noData ? { ...captured, metadata: { completeness: 'unknown' } } : captured;\n}\n\n/**\n * Drains every page of the user's pull requests for one git-host integration, threading the opaque\n * next-cursor the provider returns (so it works for both page- and cursor-based hosts). Stops at\n * `maxPages` (marking `truncated`) or on a hard read failure (marking `fetchFailed`), keeping the\n * pages fetched so far. A soft warning (`{ value, error }`) is recorded but the drain continues.\n */\nexport async function drainPullRequests(\n\tintegration: GitHostIntegration,\n\tid: IntegrationIds,\n\tdomain: string | undefined,\n\trepos: ProviderReposInput,\n\tstate: PullRequestStateFilter[] | undefined,\n\tfilters: PullRequestFilter[] | undefined,\n\t/**\n\t * The sweep options the drain reads beyond its query: the breadth opt-ins only the account-wide read can\n\t * express, and the repo-scoped read's fan-out bound and clone-URL lookup. Grouped rather than passed\n\t * positionally because the opt-ins are same-typed neighbors a transposition would silently swap, and picked\n\t * from the sweep options rather than restated so a new one is declared once.\n\t */\n\tsweepOptions:\n\t\t| Pick<\n\t\t\t\tPullRequestSweepOptions,\n\t\t\t\t'includeReviewRequested' | 'includeReviews' | 'scopeConcurrency' | 'includeRemoteInfo' | 'mergeQueue'\n\t\t >\n\t\t| undefined,\n\tconnectionId: string | undefined,\n\tmaxPages: number,\n\tattributeUnavailableProvider: boolean,\n): Promise<{\n\titems: (ProviderPullRequest | PullRequest)[];\n\twarnings: ProviderWarning[];\n\tfetchFailed: boolean;\n\ttruncated: boolean;\n\tfailedProvider: boolean;\n}> {\n\tconst items: (ProviderPullRequest | PullRequest)[] = [];\n\tconst itemIndexByIdentity = new Map<string, number>();\n\tconst warnings: ProviderWarning[] = [];\n\tlet cursor: string | undefined;\n\tlet page = 0;\n\t// SDK metadata failures across pages mean the collection is incomplete even when no page threw; carry\n\t// this through the terminal returns instead of resetting it to false at the last page.\n\tlet fetchFailed = false;\n\tlet truncated = false;\n\t// A page the provider capped or couldn't vouch for, and which no other warning already explains — decides\n\t// whether this drain raises one of its own for that part.\n\tlet unexplainedTruncation = false;\n\t// The largest match count reported on a truncated page, from which the drain derives the provider's cap.\n\tlet truncatedTotalCount: number | undefined;\n\tconst capWarning = (): ProviderWarning | undefined =>\n\t\tpullRequestSearchCapResultWarning(id, domain, connectionId, truncatedTotalCount, defaultPullRequestSort);\n\tconst appendTruncationWarnings = (cause: 'interrupted' | 'exhausted'): void => {\n\t\tconst cap = capWarning();\n\t\tif (cap != null) {\n\t\t\tappendDedupedWarning(warnings, cap);\n\t\t}\n\t\t// A cap explains the missing tail of a read that succeeded; a failed read still owes its own warning.\n\t\tif (unexplainedTruncation && (cap == null || cause === 'interrupted')) {\n\t\t\tappendDedupedWarning(warnings, truncationWarning(id, domain, connectionId, 'Pull request', cause));\n\t\t}\n\t};\n\n\t// With no repos this is an account-wide \"my PRs\" sweep. The repo-scoped core rejects an empty `repos`\n\t// input, so read the provider-native account-wide core instead.\n\tconst accountWide = repos.length === 0;\n\t// The breadth opt-ins are only expressible on the account-wide core, so gate them here — the single place\n\t// that already knows which core it is about to call.\n\tconst includeReviewRequested = accountWide && (sweepOptions?.includeReviewRequested ?? false);\n\tconst includeReviews = accountWide && (sweepOptions?.includeReviews ?? false);\n\t/** Every cursor already followed, so a provider that cycles them can't keep the drain walking in circles. */\n\tconst seenCursors = new Set<string>();\n\n\tfor (;;) {\n\t\tpage++;\n\t\t// Snapshot the mutable loop cursor so the read closure doesn't capture a later-reassigned value.\n\t\tconst pageCursor = cursor;\n\t\tconst { value, warning } = await runCaptured(id, domain, connectionId, () =>\n\t\t\taccountWide\n\t\t\t\t? integration.getMyPullRequestsForUserResult(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tstate: state,\n\t\t\t\t\t\t\tcursor: pageCursor,\n\t\t\t\t\t\t\tincludeReviewRequested: includeReviewRequested,\n\t\t\t\t\t\t\tfilters: filters,\n\t\t\t\t\t\t\t// Lite by default; the full projection (reviews) only when a caller opts in.\n\t\t\t\t\t\t\tsummary: !includeReviews,\n\t\t\t\t\t\t\tmergeQueue: sweepOptions?.mergeQueue,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tconnectionId,\n\t\t\t\t\t)\n\t\t\t\t: integration.getMyPullRequestsForReposResult(\n\t\t\t\t\t\trepos,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tstate: state,\n\t\t\t\t\t\t\tfilters: filters,\n\t\t\t\t\t\t\tcursor: pageCursor,\n\t\t\t\t\t\t\tscopeConcurrency: sweepOptions?.scopeConcurrency,\n\t\t\t\t\t\t\tincludeRemoteInfo: sweepOptions?.includeRemoteInfo,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tconnectionId,\n\t\t\t\t\t),\n\t\t);\n\t\tif (warning != null) {\n\t\t\tappendDedupedWarning(warnings, warning);\n\t\t}\n\t\tif (value == null) {\n\t\t\t// An implicit sweep may silently skip a provider that has no session before it yields data.\n\t\t\t// Once a page has been returned, however, losing that session leaves an unread tail and must\n\t\t\t// be attributed even when the provider wasn't explicitly requested.\n\t\t\tconst sessionLostAfterProgress = warning == null && page > 1;\n\t\t\tconst unavailable = warning == null && (attributeUnavailableProvider || sessionLostAfterProgress);\n\t\t\tif (unavailable) {\n\t\t\t\tappendDedupedWarning(warnings, noConnectionWarning(id, domain, connectionId));\n\t\t\t}\n\t\t\t// `warning` set → a hard read failure (incomplete items); otherwise not connected / no session.\n\t\t\tconst failed = fetchFailed || warning != null || unavailable;\n\t\t\t// A cap seen on an earlier page still left results out, so it is still worth saying — but as part\n\t\t\t// of a read that failed, never as an omission. (`failed` is always true here when anything was\n\t\t\t// latched: reaching this exit past page 1 means a later page was lost.)\n\t\t\tappendTruncationWarnings(failed ? 'interrupted' : 'exhausted');\n\t\t\t// An earlier page may already have emitted an omission before this one died; it asserts the read\n\t\t\t// succeeded, which is no longer true.\n\t\t\treconcileOmissionsWithFailure(warnings, failed);\n\t\t\treturn {\n\t\t\t\titems: items,\n\t\t\t\twarnings: warnings,\n\t\t\t\tfetchFailed: failed,\n\t\t\t\ttruncated: truncated || sessionLostAfterProgress,\n\t\t\t\t// Only a top-level first-page rejection means the provider itself failed. A later-page or\n\t\t\t\t// per-scope failure still yielded a usable provider slice and stays represented separately.\n\t\t\t\tfailedProvider: page === 1 && (warning != null || unavailable),\n\t\t\t};\n\t\t}\n\n\t\t// Composite account-wide queries can surface the same PR on different relationship/state pages\n\t\t// (for example authored + review-requested, or closed + merged). Keep the first stable position but\n\t\t// replace its value with the latest representation so a later, richer merged state wins. Repository\n\t\t// identity is what keys a row (see `getProviderPullRequestIdentity`), falling back to the canonical\n\t\t// URL; a row with neither stays unkeyed and is retained so unrelated incomplete rows are never\n\t\t// collapsed.\n\t\tfor (const pullRequest of value.values) {\n\t\t\tconst identity = getProviderPullRequestIdentity(pullRequest);\n\t\t\tif (identity == null) {\n\t\t\t\titems.push(pullRequest);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst existingIndex = itemIndexByIdentity.get(identity);\n\t\t\tif (existingIndex == null) {\n\t\t\t\titemIndexByIdentity.set(identity, items.length);\n\t\t\t\titems.push(pullRequest);\n\t\t\t} else {\n\t\t\t\titems[existingIndex] = pullRequest;\n\t\t\t}\n\t\t}\n\n\t\t// Assess this page's SDK metadata: append scope-aware warnings (deduped across pages), and remember\n\t\t// whether a structured failure or incompleteness occurred.\n\t\tconst assessment = mergeAssessmentInto(warnings, id, domain, connectionId, value.metadata);\n\t\tfetchFailed = fetchFailed || assessment.fetchFailed;\n\t\tconst pageTruncated =\n\t\t\t(value as { truncated?: boolean }).truncated === true ||\n\t\t\tvalue.paging?.truncated === true ||\n\t\t\tassessment.truncated;\n\t\ttruncated = truncated || pageTruncated;\n\t\t// Whether this drain owes its OWN warning for a capped page — `mergeAssessmentInto` has already appended\n\t\t// one when the fact came from SDK metadata, and repeating it would be noise.\n\t\tunexplainedTruncation = unexplainedTruncation || (pageTruncated && !assessment.truncated);\n\t\t// Only the account-wide read reports a search match count here; the repo-scoped one reports the item\n\t\t// total, which no cap is derived from. Latched even when SDK metadata explains the page: a composite page\n\t\t// reports a failed or cursorless sibling facet there, which says nothing about the cap another reached.\n\t\tif (accountWide && pageTruncated && value.paging?.totalCount != null) {\n\t\t\ttruncatedTotalCount = Math.max(truncatedTotalCount ?? 0, value.paging.totalCount);\n\t\t}\n\n\t\tif (!(value.paging?.more ?? false)) {\n\t\t\t// A read that can't confirm completeness (single-page provider reads with no `hasNextPage`)\n\t\t\t// sets `paging.truncated`; propagate it (and any top-level `truncated` and SDK incompleteness)\n\t\t\t// so the sweep doesn't claim an all-pages result.\n\t\t\tappendTruncationWarnings(fetchFailed ? 'interrupted' : 'exhausted');\n\t\t\treconcileOmissionsWithFailure(warnings, fetchFailed);\n\t\t\treturn {\n\t\t\t\titems: items,\n\t\t\t\twarnings: warnings,\n\t\t\t\tfetchFailed: fetchFailed,\n\t\t\t\ttruncated: truncated,\n\t\t\t\tfailedProvider: false,\n\t\t\t};\n\t\t}\n\n\t\t// Resolve the continuation BEFORE deciding why the drain stops. `page-budget` claims the missing items\n\t\t// are reachable, which is only true with a usable cursor in hand — and a provider can report another\n\t\t// page while handing back none (Bitbucket Server does, when it omits `nextPageStart`). Checking the\n\t\t// budget first would label that unreachable tail as merely unfetched, so raising `maxPages` would\n\t\t// return the identical set.\n\t\tconst nextCursor = value.paging?.cursor;\n\t\t// A cursor already used isn't a continuation either — following it refetches a page we have, and a\n\t\t// provider that cycles (A→B→A) would otherwise burn the whole budget and then be reported as merely\n\t\t// out of budget. Tracked as a SET rather than compared one-back, matching the SDK's own `followCursors`:\n\t\t// `drainToRequestedPage` and `collectProviderPagedResult` compare only the previous cursor, which a\n\t\t// cycle slips past. That is tolerable there and not here, because only this drain reports `page-budget`.\n\t\tconst continuable = nextCursor != null && nextCursor !== '{}' && !seenCursors.has(nextCursor);\n\t\tif (!continuable || page >= maxPages) {\n\t\t\t// A usable cursor in hand means `page-budget`, even when an earlier page was capped: a composite\n\t\t\t// read caps its facets independently, so one facet reaching the provider's ceiling leaves its\n\t\t\t// siblings' cursors live, and raising the budget returns more of them. What no budget returns is the\n\t\t\t// capped part, so that is reported BESIDE the budget stop rather than in place of it — unless an SDK\n\t\t\t// omission already says so. Neither warning then misstates the part the other describes.\n\t\t\tconst budgetStop = !fetchFailed && continuable;\n\t\t\tappendDedupedWarning(\n\t\t\t\twarnings,\n\t\t\t\ttruncationWarning(\n\t\t\t\t\tid,\n\t\t\t\t\tdomain,\n\t\t\t\t\tconnectionId,\n\t\t\t\t\t'Pull request',\n\t\t\t\t\tfetchFailed ? 'interrupted' : budgetStop ? 'page-budget' : 'exhausted',\n\t\t\t\t),\n\t\t\t);\n\t\t\tconst cap = capWarning();\n\t\t\tif (cap != null) {\n\t\t\t\tappendDedupedWarning(warnings, cap);\n\t\t\t} else if (budgetStop && unexplainedTruncation) {\n\t\t\t\tappendDedupedWarning(warnings, cappedBesideBudgetWarning(id, domain, connectionId, 'Pull request'));\n\t\t\t}\n\t\t\treconcileOmissionsWithFailure(warnings, fetchFailed);\n\t\t\treturn {\n\t\t\t\titems: items,\n\t\t\t\twarnings: warnings,\n\t\t\t\tfetchFailed: fetchFailed,\n\t\t\t\ttruncated: true,\n\t\t\t\tfailedProvider: false,\n\t\t\t};\n\t\t}\n\n\t\tseenCursors.add(nextCursor);\n\t\tcursor = nextCursor;\n\t}\n}\n\n/**\n * Drains every page of repositories under an org for one git-host integration, threading the opaque\n * next-cursor the provider returns. Stops at `maxPages` (marking `truncated`) or on a hard read failure\n * (marking `fetchFailed`), keeping the pages fetched so far.\n */\nexport async function drainRepositories(\n\tintegration: GitHostIntegration,\n\tid: IntegrationIds,\n\tdomain: string | undefined,\n\torg: string,\n\tproject: string | undefined,\n\tconnectionId: string | undefined,\n\tmaxPages: number,\n): Promise<{\n\trepos: ProviderRepository[];\n\twarnings: ProviderWarning[];\n\tfetchFailed: boolean;\n\ttruncated: boolean;\n}> {\n\tconst repos: ProviderRepository[] = [];\n\tconst warnings: ProviderWarning[] = [];\n\tlet fetchFailed = false;\n\tlet truncated = false;\n\tlet cursor: string | undefined;\n\tlet page = 0;\n\n\tfor (;;) {\n\t\tpage++;\n\t\tconst pageCursor = cursor;\n\t\tconst { value, warning } = await runCaptured(\n\t\t\tid,\n\t\t\tdomain,\n\t\t\tconnectionId,\n\t\t\t() =>\n\t\t\t\tintegration.getRepositoriesForOrgResult(org, {\n\t\t\t\t\tproject: project,\n\t\t\t\t\tcursor: pageCursor,\n\t\t\t\t\tconnectionId: connectionId,\n\t\t\t\t}),\n\t\t\t{ warnOnMissingSession: true },\n\t\t);\n\t\tif (warning != null) {\n\t\t\t// Deduped, like every other accumulation here: a soft warning (`{ value, error }`) repeats verbatim on\n\t\t\t// each page that hits the same condition, and the array's contract is that no two entries are equal.\n\t\t\tappendDedupedWarning(warnings, warning);\n\t\t}\n\t\tif (value == null) {\n\t\t\tconst interruptedAfterProgress = page > 1;\n\t\t\tif (interruptedAfterProgress && warning == null) {\n\t\t\t\t// Not a backstop: the read was cut short mid-drain, which is why it also sets `fetchFailed`\n\t\t\t\t// below. A retry may complete it, so this must not claim the succeeded-but-capped omission.\n\t\t\t\tappendDedupedWarning(\n\t\t\t\t\twarnings,\n\t\t\t\t\ttruncationWarning(id, domain, connectionId, 'Repository', 'interrupted'),\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst failed = fetchFailed || warning != null || interruptedAfterProgress;\n\t\t\t// An SDK omission from an earlier page asserts the read succeeded; this one didn't.\n\t\t\treconcileOmissionsWithFailure(warnings, failed);\n\t\t\treturn {\n\t\t\t\trepos: repos,\n\t\t\t\twarnings: warnings,\n\t\t\t\tfetchFailed: failed,\n\t\t\t\ttruncated: truncated || interruptedAfterProgress,\n\t\t\t};\n\t\t}\n\n\t\trepos.push(...value.values);\n\t\tconst assessment = mergeAssessmentInto(warnings, id, domain, connectionId, value.metadata);\n\t\tfetchFailed = fetchFailed || assessment.fetchFailed;\n\t\ttruncated = truncated || value.truncated === true || value.paging?.truncated === true || assessment.truncated;\n\t\tif (!(value.paging?.more ?? false)) {\n\t\t\treconcileOmissionsWithFailure(warnings, fetchFailed);\n\t\t\treturn {\n\t\t\t\trepos: repos,\n\t\t\t\twarnings: warnings,\n\t\t\t\tfetchFailed: fetchFailed,\n\t\t\t\ttruncated: truncated,\n\t\t\t};\n\t\t}\n\n\t\tif (page >= maxPages) {\n\t\t\treconcileOmissionsWithFailure(warnings, fetchFailed);\n\t\t\treturn { repos: repos, warnings: warnings, fetchFailed: fetchFailed, truncated: true };\n\t\t}\n\n\t\tconst nextCursor = value.paging?.cursor;\n\t\tif (nextCursor == null || nextCursor === '{}') {\n\t\t\t// Provider says there is more but didn't return a usable cursor; stop rather than refetch the same page.\n\t\t\treconcileOmissionsWithFailure(warnings, fetchFailed);\n\t\t\treturn { repos: repos, warnings: warnings, fetchFailed: fetchFailed, truncated: true };\n\t\t}\n\n\t\tcursor = nextCursor;\n\t}\n}\n\nfunction describeSweepTargetSelector(target: ProviderSweepTarget): string {\n\tconst parts: string[] = [];\n\tif (target.connectionId != null) {\n\t\tparts.push(`connectionId '${target.connectionId}'`);\n\t}\n\tif (target.domain != null) {\n\t\tparts.push(`domain '${target.domain}'`);\n\t}\n\treturn parts.length !== 0 ? ` (${parts.join(', ')})` : '';\n}\n\nexport function resolvePullRequestSweepTargets(options: PullRequestSweepOptions | undefined): {\n\ttargets: readonly ProviderSweepTarget[];\n\tattributeUnavailableProviders: boolean;\n} {\n\tif (options?.targets != null) {\n\t\tif (options.providerIds != null || options.connectionId != null) {\n\t\t\tthrow new TypeError(\"Pull request sweep 'targets' cannot be combined with 'providerIds' or 'connectionId'\");\n\t\t}\n\n\t\t// Keyed by the selector as the read resolves it, so a repeat is a duplicate however its domain is spelled.\n\t\t// Several targets of one provider are legitimate (one per connection), but each must name its connection:\n\t\t// an unnamed one reads the primary connection, which may be one of the named ones. A domain names a host\n\t\t// only on a self-managed provider; a cloud provider's read ignores it.\n\t\tconst seenTargets = new Set<string>();\n\t\tconst targetCounts = new Map<IntegrationIds, number>();\n\t\tconst unnamedTargets: ProviderSweepTarget[] = [];\n\t\tfor (const target of options.targets) {\n\t\t\tconst host = isSelfManagedHostIntegrationId(target.providerId) ? hostFromDomain(target.domain) : undefined;\n\t\t\tconst key = JSON.stringify([target.providerId, target.connectionId ?? '', host ?? '']);\n\t\t\tif (seenTargets.has(key)) {\n\t\t\t\tthrow new TypeError(\n\t\t\t\t\t`Pull request sweep targets must be unique; duplicate '${target.providerId}' target${describeSweepTargetSelector(target)}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tseenTargets.add(key);\n\t\t\ttargetCounts.set(target.providerId, (targetCounts.get(target.providerId) ?? 0) + 1);\n\t\t\tif (target.connectionId == null && host == null) {\n\t\t\t\tunnamedTargets.push(target);\n\t\t\t}\n\t\t}\n\n\t\tfor (const target of unnamedTargets) {\n\t\t\tif ((targetCounts.get(target.providerId) ?? 0) > 1) {\n\t\t\t\tthrow new TypeError(\n\t\t\t\t\t`Pull request sweep targets for '${target.providerId}' must each name a connectionId or domain when there is more than one (a domain only on a self-managed host); an unnamed target reads the primary connection`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn { targets: options.targets, attributeUnavailableProviders: true };\n\t}\n\n\tconst providerIds =\n\t\toptions?.providerIds ?? supportedOrderedCloudIntegrationIds.filter(id => !isIssuesHostIntegrationId(id));\n\tconst connectionId = providerIds.length === 1 ? options?.connectionId : undefined;\n\treturn {\n\t\ttargets: providerIds.map(providerId => ({ providerId: providerId, connectionId: connectionId })),\n\t\tattributeUnavailableProviders: options?.providerIds != null,\n\t};\n}\n\nexport async function getCurrentAccountIdentity(\n\tintegration: GitHostIntegration,\n\tconnectionId: string | undefined,\n): Promise<{ id: string; username?: string } | undefined> {\n\ttry {\n\t\tconst account = await integration.getCurrentAccount({ connectionId: connectionId });\n\t\treturn account != null ? { id: account.id, username: account.username } : undefined;\n\t} catch {\n\t\t// Authorship is optional enrichment; don't turn a successful PR read into a failure if identity lookup fails.\n\t\treturn undefined;\n\t}\n}\n\n/**\n * The current account to map each raw row against, in order (see {@link GitHostIntegration.getPullRequestViewers}).\n * Rows that name no one can't be matched, so a read of only those resolves nothing; a failed lookup leaves every\n * row's authorship unknown rather than failing the read.\n */\nexport async function getPullRequestViewers(\n\tintegration: GitHostIntegration,\n\tconnectionId: string | undefined,\n\tpullRequests: readonly (ProviderPullRequest | PullRequest)[],\n): Promise<({ id: string; username?: string } | null | undefined)[]> {\n\tif (!pullRequests.some(pullRequestNamesPeople)) return pullRequests.map(() => undefined);\n\n\ttry {\n\t\treturn await integration.getPullRequestViewers(pullRequests, connectionId);\n\t} catch {\n\t\treturn pullRequests.map(() => undefined);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,eAAsB,YACrB,IACA,QACA,cACA,IACA,SACoD;CACpD,IAAI;EACH,MAAM,SAAS,MAAM,GAAG;EACxB,IAAI,UAAU,MAKb,OAAO,gBAAgB,QAAQ,SAAS,uBACrC,EAAE,SAAS,oBAAoB,IAAI,QAAQ,YAAY,EAAE,IACzD,CAAC;EAEL,IAAI,OAAO,SAAS,MACnB,OAAO;GAAE,OAAO,OAAO;GAAO,SAAS,kBAAkB,IAAI,QAAQ,cAAc,OAAO,KAAK;E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AAA,CAAS;CAEvF,IAAI;EACH,OAAO,MAAM,YAAY,sBAAsB,cAAc,YAAY;CAC1E,QAAQ;EACP,OAAO,aAAa,UAAU,KAAA,CAAS;CACxC;AACD"}
|
|
1
|
+
{"version":3,"file":"drains.js","names":[],"sources":["../../../../../plus/integrations/src/reads/drains.ts"],"sourcesContent":["import type { CollectionMetadata } from '@gitkraken/provider-apis';\nimport type { PullRequest, PullRequestStateFilter } from '@gitlens/git/models/pullRequest.js';\nimport { defaultPullRequestSort } from '@gitlens/git/models/pullRequest.js';\nimport type { ResourceDescriptor } from '@gitlens/git/models/resourceDescriptor.js';\nimport { mergeAssessmentInto } from '../collectionMetadata.js';\nimport type { IntegrationIds } from '../constants.js';\nimport { supportedOrderedCloudIntegrationIds } from '../constants.js';\nimport type { ProviderSweepTarget, PullRequestSweepOptions } from '../manager.js';\nimport type { GitHostIntegration } from '../models/gitHostIntegration.js';\nimport type { IssuesIntegration } from '../models/issuesIntegration.js';\nimport type { IntegrationResult } from '../models/publicIntegration.js';\nimport type { PullRequestFilter } from '../providerFilters.js';\nimport type { ProviderPullRequest, ProviderReposInput, ProviderRepository } from '../providers/models.js';\nimport { getProviderPullRequestIdentity, pullRequestNamesPeople } from '../providers/models.js';\nimport type { ProviderWarning } from '../results.js';\nimport { appendDedupedWarning, reconcileOmissionsWithFailure, toProviderWarning } from '../results.js';\nimport { hostFromDomain } from '../utils/domain.utils.js';\nimport { isIssuesHostIntegrationId, isSelfManagedHostIntegrationId } from '../utils/integration.utils.js';\nimport {\n\tcappedBesideBudgetWarning,\n\tnoConnectionWarning,\n\tpullRequestSearchCapResultWarning,\n\ttruncationWarning,\n} from './warnings.js';\n\n/**\n * The all-pages reads: a provider read run repeatedly until it runs out of pages, as opposed to the single-page\n * reads the facade's paged surface exposes. `sweepPullRequests` and `broadenIssues` are built on these.\n *\n * A drain's job is to keep going where a single page would stop, so what distinguishes it is its failure\n * bookkeeping rather than its loop: it must return the prefix it did read plus enough signal for the caller to\n * know the result is not authoritative — `truncated` when pages remain unread (a page backstop, or a provider\n * claiming another page while handing back no usable cursor), `fetchFailed` when a page or scope failed\n * outright. Discarding the prefix on a late failure, or returning it as if complete, are the two mistakes these\n * exist to prevent.\n */\n\n/**\n * Runs a result-returning read and captures failure as a neutral {@link ProviderWarning} rather than\n * letting it throw or silently vanish. Handles both a returned `{ error }` (the read cores' contract)\n * and a hard throw; a soft warning (`{ value, error }`) yields the value *and* a warning.\n */\nexport async function runCaptured<T>(\n\tid: IntegrationIds,\n\tdomain: string | undefined,\n\tconnectionId: string | undefined,\n\tfn: () => Promise<IntegrationResult<T>>,\n\toptions?: { warnOnMissingSession?: boolean },\n): Promise<{ value?: T; warning?: ProviderWarning }> {\n\ttry {\n\t\tconst result = await fn();\n\t\tif (result == null) {\n\t\t\t// The read core returns undefined only when it couldn't resolve a session. For a per-connection\n\t\t\t// or explicit-domain read that means the requested target is gone or its authentication is invalid,\n\t\t\t// which must not be reported as an empty account. The untargeted primary path legitimately yields\n\t\t\t// nothing when the provider isn't connected, so leave it as an empty result.\n\t\t\treturn connectionId != null || options?.warnOnMissingSession\n\t\t\t\t? { warning: noConnectionWarning(id, domain, connectionId) }\n\t\t\t\t: {};\n\t\t}\n\t\tif (result.error != null) {\n\t\t\treturn { value: result.value, warning: toProviderWarning(id, domain, connectionId, result.error) };\n\t\t}\n\t\treturn { value: result.value };\n\t} catch (ex) {\n\t\treturn { warning: toProviderWarning(id, domain, connectionId, ex) };\n\t}\n}\n\n/**\n * {@link runCaptured} over an issue tracker's resource (site, organization, board) discovery. A read that resolved a\n * session yet answered with no data and no error carries `completeness: 'unknown'` metadata, so it reads as an\n * incomplete discovery rather than as an account with no resources, which `runCaptured` alone can't tell apart from\n * an untargeted read with no session.\n */\nexport async function discoverResources(\n\tintegration: IssuesIntegration,\n\tid: IntegrationIds,\n\tdomain: string | undefined,\n\tconnectionId: string | undefined,\n\toptions?: { warnOnMissingSession?: boolean },\n): Promise<{ value?: ResourceDescriptor[]; warning?: ProviderWarning; metadata?: CollectionMetadata }> {\n\tlet noData = false;\n\tconst captured = await runCaptured(\n\t\tid,\n\t\tdomain,\n\t\tconnectionId,\n\t\tasync () => {\n\t\t\tconst result = await integration.getResourcesForUserResult(connectionId);\n\t\t\tnoData = result != null && result.error == null && result.value == null;\n\t\t\treturn result;\n\t\t},\n\t\toptions,\n\t);\n\treturn noData ? { ...captured, metadata: { completeness: 'unknown' } } : captured;\n}\n\n/**\n * Drains every page of the user's pull requests for one git-host integration, threading the opaque\n * next-cursor the provider returns (so it works for both page- and cursor-based hosts). Stops at\n * `maxPages` (marking `truncated`) or on a hard read failure (marking `fetchFailed`), keeping the\n * pages fetched so far. A soft warning (`{ value, error }`) is recorded but the drain continues.\n */\nexport async function drainPullRequests(\n\tintegration: GitHostIntegration,\n\tid: IntegrationIds,\n\tdomain: string | undefined,\n\trepos: ProviderReposInput,\n\tstate: PullRequestStateFilter[] | undefined,\n\tfilters: PullRequestFilter[] | undefined,\n\t/**\n\t * The sweep options the drain reads beyond its query: the breadth opt-ins only the account-wide read can\n\t * express, and the repo-scoped read's fan-out bound and clone-URL lookup. Grouped rather than passed\n\t * positionally because the opt-ins are same-typed neighbors a transposition would silently swap, and picked\n\t * from the sweep options rather than restated so a new one is declared once.\n\t */\n\tsweepOptions:\n\t\t| Pick<\n\t\t\t\tPullRequestSweepOptions,\n\t\t\t\t'includeReviewRequested' | 'includeReviews' | 'scopeConcurrency' | 'includeRemoteInfo' | 'mergeQueue'\n\t\t >\n\t\t| undefined,\n\tconnectionId: string | undefined,\n\tmaxPages: number,\n\tattributeUnavailableProvider: boolean,\n): Promise<{\n\titems: (ProviderPullRequest | PullRequest)[];\n\twarnings: ProviderWarning[];\n\tfetchFailed: boolean;\n\ttruncated: boolean;\n\tfailedProvider: boolean;\n}> {\n\tconst items: (ProviderPullRequest | PullRequest)[] = [];\n\tconst itemIndexByIdentity = new Map<string, number>();\n\tconst warnings: ProviderWarning[] = [];\n\tlet cursor: string | undefined;\n\tlet page = 0;\n\t// SDK metadata failures across pages mean the collection is incomplete even when no page threw; carry\n\t// this through the terminal returns instead of resetting it to false at the last page.\n\tlet fetchFailed = false;\n\tlet truncated = false;\n\t// A page the provider capped or couldn't vouch for, and which no other warning already explains — decides\n\t// whether this drain raises one of its own for that part.\n\tlet unexplainedTruncation = false;\n\t// The largest match count reported on a truncated page, from which the drain derives the provider's cap.\n\tlet truncatedTotalCount: number | undefined;\n\tconst capWarning = (): ProviderWarning | undefined =>\n\t\tpullRequestSearchCapResultWarning(id, domain, connectionId, truncatedTotalCount, defaultPullRequestSort);\n\tconst appendTruncationWarnings = (cause: 'interrupted' | 'exhausted'): void => {\n\t\tconst cap = capWarning();\n\t\tif (cap != null) {\n\t\t\tappendDedupedWarning(warnings, cap);\n\t\t}\n\t\t// A cap explains the missing tail of a read that succeeded; a failed read still owes its own warning.\n\t\tif (unexplainedTruncation && (cap == null || cause === 'interrupted')) {\n\t\t\tappendDedupedWarning(warnings, truncationWarning(id, domain, connectionId, 'Pull request', cause));\n\t\t}\n\t};\n\n\t// With no repos this is an account-wide \"my PRs\" sweep. The repo-scoped core rejects an empty `repos`\n\t// input, so read the provider-native account-wide core instead.\n\tconst accountWide = repos.length === 0;\n\t// The breadth opt-ins are only expressible on the account-wide core, so gate them here — the single place\n\t// that already knows which core it is about to call.\n\tconst includeReviewRequested = accountWide && (sweepOptions?.includeReviewRequested ?? false);\n\tconst includeReviews = accountWide && (sweepOptions?.includeReviews ?? false);\n\t/** Every cursor already followed, so a provider that cycles them can't keep the drain walking in circles. */\n\tconst seenCursors = new Set<string>();\n\n\tfor (;;) {\n\t\tpage++;\n\t\t// Snapshot the mutable loop cursor so the read closure doesn't capture a later-reassigned value.\n\t\tconst pageCursor = cursor;\n\t\tconst { value, warning } = await runCaptured(id, domain, connectionId, () =>\n\t\t\taccountWide\n\t\t\t\t? integration.getMyPullRequestsForUserResult(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tstate: state,\n\t\t\t\t\t\t\tcursor: pageCursor,\n\t\t\t\t\t\t\tincludeReviewRequested: includeReviewRequested,\n\t\t\t\t\t\t\tfilters: filters,\n\t\t\t\t\t\t\t// Lite by default; the full projection (reviews) only when a caller opts in.\n\t\t\t\t\t\t\tsummary: !includeReviews,\n\t\t\t\t\t\t\tmergeQueue: sweepOptions?.mergeQueue,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tconnectionId,\n\t\t\t\t\t)\n\t\t\t\t: integration.getMyPullRequestsForReposResult(\n\t\t\t\t\t\trepos,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tstate: state,\n\t\t\t\t\t\t\tfilters: filters,\n\t\t\t\t\t\t\tcursor: pageCursor,\n\t\t\t\t\t\t\tscopeConcurrency: sweepOptions?.scopeConcurrency,\n\t\t\t\t\t\t\tincludeRemoteInfo: sweepOptions?.includeRemoteInfo,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tconnectionId,\n\t\t\t\t\t),\n\t\t);\n\t\tif (warning != null) {\n\t\t\tappendDedupedWarning(warnings, warning);\n\t\t}\n\t\tif (value == null) {\n\t\t\t// An implicit sweep may silently skip a provider that has no session before it yields data.\n\t\t\t// Once a page has been returned, however, losing that session leaves an unread tail and must\n\t\t\t// be attributed even when the provider wasn't explicitly requested.\n\t\t\tconst sessionLostAfterProgress = warning == null && page > 1;\n\t\t\tconst unavailable = warning == null && (attributeUnavailableProvider || sessionLostAfterProgress);\n\t\t\tif (unavailable) {\n\t\t\t\tappendDedupedWarning(warnings, noConnectionWarning(id, domain, connectionId));\n\t\t\t}\n\t\t\t// `warning` set → a hard read failure (incomplete items); otherwise not connected / no session.\n\t\t\tconst failed = fetchFailed || warning != null || unavailable;\n\t\t\t// A cap seen on an earlier page still left results out, so it is still worth saying — but as part\n\t\t\t// of a read that failed, never as an omission. (`failed` is always true here when anything was\n\t\t\t// latched: reaching this exit past page 1 means a later page was lost.)\n\t\t\tappendTruncationWarnings(failed ? 'interrupted' : 'exhausted');\n\t\t\t// An earlier page may already have emitted an omission before this one died; it asserts the read\n\t\t\t// succeeded, which is no longer true.\n\t\t\treconcileOmissionsWithFailure(warnings, failed);\n\t\t\treturn {\n\t\t\t\titems: items,\n\t\t\t\twarnings: warnings,\n\t\t\t\tfetchFailed: failed,\n\t\t\t\ttruncated: truncated || sessionLostAfterProgress,\n\t\t\t\t// Only a top-level first-page rejection means the provider itself failed. A later-page or\n\t\t\t\t// per-scope failure still yielded a usable provider slice and stays represented separately.\n\t\t\t\tfailedProvider: page === 1 && (warning != null || unavailable),\n\t\t\t};\n\t\t}\n\n\t\t// Composite account-wide queries can surface the same PR on different relationship/state pages\n\t\t// (for example authored + review-requested, or closed + merged). Keep the first stable position but\n\t\t// replace its value with the latest representation so a later, richer merged state wins. Repository\n\t\t// identity is what keys a row (see `getProviderPullRequestIdentity`), falling back to the canonical\n\t\t// URL; a row with neither stays unkeyed and is retained so unrelated incomplete rows are never\n\t\t// collapsed.\n\t\tfor (const pullRequest of value.values) {\n\t\t\tconst identity = getProviderPullRequestIdentity(pullRequest);\n\t\t\tif (identity == null) {\n\t\t\t\titems.push(pullRequest);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst existingIndex = itemIndexByIdentity.get(identity);\n\t\t\tif (existingIndex == null) {\n\t\t\t\titemIndexByIdentity.set(identity, items.length);\n\t\t\t\titems.push(pullRequest);\n\t\t\t} else {\n\t\t\t\titems[existingIndex] = pullRequest;\n\t\t\t}\n\t\t}\n\n\t\t// Assess this page's SDK metadata: append scope-aware warnings (deduped across pages), and remember\n\t\t// whether a structured failure or incompleteness occurred.\n\t\tconst assessment = mergeAssessmentInto(warnings, id, domain, connectionId, value.metadata);\n\t\tfetchFailed = fetchFailed || assessment.fetchFailed;\n\t\tconst pageTruncated =\n\t\t\t(value as { truncated?: boolean }).truncated === true ||\n\t\t\tvalue.paging?.truncated === true ||\n\t\t\tassessment.truncated;\n\t\ttruncated = truncated || pageTruncated;\n\t\t// Whether this drain owes its OWN warning for a capped page — `mergeAssessmentInto` has already appended\n\t\t// one when the fact came from SDK metadata, and repeating it would be noise.\n\t\tunexplainedTruncation = unexplainedTruncation || (pageTruncated && !assessment.truncated);\n\t\t// Only the account-wide read reports a search match count here; the repo-scoped one reports the item\n\t\t// total, which no cap is derived from. Latched even when SDK metadata explains the page: a composite page\n\t\t// reports a failed or cursorless sibling facet there, which says nothing about the cap another reached.\n\t\tif (accountWide && pageTruncated && value.paging?.totalCount != null) {\n\t\t\ttruncatedTotalCount = Math.max(truncatedTotalCount ?? 0, value.paging.totalCount);\n\t\t}\n\n\t\tif (!(value.paging?.more ?? false)) {\n\t\t\t// A read that can't confirm completeness (single-page provider reads with no `hasNextPage`)\n\t\t\t// sets `paging.truncated`; propagate it (and any top-level `truncated` and SDK incompleteness)\n\t\t\t// so the sweep doesn't claim an all-pages result.\n\t\t\tappendTruncationWarnings(fetchFailed ? 'interrupted' : 'exhausted');\n\t\t\treconcileOmissionsWithFailure(warnings, fetchFailed);\n\t\t\treturn {\n\t\t\t\titems: items,\n\t\t\t\twarnings: warnings,\n\t\t\t\tfetchFailed: fetchFailed,\n\t\t\t\ttruncated: truncated,\n\t\t\t\tfailedProvider: false,\n\t\t\t};\n\t\t}\n\n\t\t// Resolve the continuation BEFORE deciding why the drain stops. `page-budget` claims the missing items\n\t\t// are reachable, which is only true with a usable cursor in hand — and a provider can report another\n\t\t// page while handing back none (Bitbucket Server does, when it omits `nextPageStart`). Checking the\n\t\t// budget first would label that unreachable tail as merely unfetched, so raising `maxPages` would\n\t\t// return the identical set.\n\t\tconst nextCursor = value.paging?.cursor;\n\t\t// A cursor already used isn't a continuation either — following it refetches a page we have, and a\n\t\t// provider that cycles (A→B→A) would otherwise burn the whole budget and then be reported as merely\n\t\t// out of budget. Tracked as a SET rather than compared one-back, matching the SDK's own `followCursors`:\n\t\t// `drainToRequestedPage` and `collectProviderPagedResult` compare only the previous cursor, which a\n\t\t// cycle slips past. That is tolerable there and not here, because only this drain reports `page-budget`.\n\t\tconst continuable = nextCursor != null && nextCursor !== '{}' && !seenCursors.has(nextCursor);\n\t\tif (!continuable || page >= maxPages) {\n\t\t\t// A usable cursor in hand means `page-budget`, even when an earlier page was capped: a composite\n\t\t\t// read caps its facets independently, so one facet reaching the provider's ceiling leaves its\n\t\t\t// siblings' cursors live, and raising the budget returns more of them. What no budget returns is the\n\t\t\t// capped part, so that is reported BESIDE the budget stop rather than in place of it — unless an SDK\n\t\t\t// omission already says so. Neither warning then misstates the part the other describes.\n\t\t\tconst budgetStop = !fetchFailed && continuable;\n\t\t\tappendDedupedWarning(\n\t\t\t\twarnings,\n\t\t\t\ttruncationWarning(\n\t\t\t\t\tid,\n\t\t\t\t\tdomain,\n\t\t\t\t\tconnectionId,\n\t\t\t\t\t'Pull request',\n\t\t\t\t\tfetchFailed ? 'interrupted' : budgetStop ? 'page-budget' : 'exhausted',\n\t\t\t\t),\n\t\t\t);\n\t\t\tconst cap = capWarning();\n\t\t\tif (cap != null) {\n\t\t\t\tappendDedupedWarning(warnings, cap);\n\t\t\t} else if (budgetStop && unexplainedTruncation) {\n\t\t\t\tappendDedupedWarning(warnings, cappedBesideBudgetWarning(id, domain, connectionId, 'Pull request'));\n\t\t\t}\n\t\t\treconcileOmissionsWithFailure(warnings, fetchFailed);\n\t\t\treturn {\n\t\t\t\titems: items,\n\t\t\t\twarnings: warnings,\n\t\t\t\tfetchFailed: fetchFailed,\n\t\t\t\ttruncated: true,\n\t\t\t\tfailedProvider: false,\n\t\t\t};\n\t\t}\n\n\t\tseenCursors.add(nextCursor);\n\t\tcursor = nextCursor;\n\t}\n}\n\n/**\n * Drains every page of repositories under an org for one git-host integration, threading the opaque\n * next-cursor the provider returns. Stops at `maxPages` (marking `truncated`) or on a hard read failure\n * (marking `fetchFailed`), keeping the pages fetched so far.\n */\nexport async function drainRepositories(\n\tintegration: GitHostIntegration,\n\tid: IntegrationIds,\n\tdomain: string | undefined,\n\torg: string,\n\tproject: string | undefined,\n\tconnectionId: string | undefined,\n\tmaxPages: number,\n): Promise<{\n\trepos: ProviderRepository[];\n\twarnings: ProviderWarning[];\n\tfetchFailed: boolean;\n\ttruncated: boolean;\n}> {\n\tconst repos: ProviderRepository[] = [];\n\tconst warnings: ProviderWarning[] = [];\n\tlet fetchFailed = false;\n\tlet truncated = false;\n\tlet cursor: string | undefined;\n\tlet page = 0;\n\n\tfor (;;) {\n\t\tpage++;\n\t\tconst pageCursor = cursor;\n\t\tconst { value, warning } = await runCaptured(\n\t\t\tid,\n\t\t\tdomain,\n\t\t\tconnectionId,\n\t\t\t() =>\n\t\t\t\tintegration.getRepositoriesForOrgResult(org, {\n\t\t\t\t\tproject: project,\n\t\t\t\t\tcursor: pageCursor,\n\t\t\t\t\tconnectionId: connectionId,\n\t\t\t\t}),\n\t\t\t{ warnOnMissingSession: true },\n\t\t);\n\t\tif (warning != null) {\n\t\t\t// Deduped, like every other accumulation here: a soft warning (`{ value, error }`) repeats verbatim on\n\t\t\t// each page that hits the same condition, and the array's contract is that no two entries are equal.\n\t\t\tappendDedupedWarning(warnings, warning);\n\t\t}\n\t\tif (value == null) {\n\t\t\tconst interruptedAfterProgress = page > 1;\n\t\t\tif (interruptedAfterProgress && warning == null) {\n\t\t\t\t// Not a backstop: the read was cut short mid-drain, which is why it also sets `fetchFailed`\n\t\t\t\t// below. A retry may complete it, so this must not claim the succeeded-but-capped omission.\n\t\t\t\tappendDedupedWarning(\n\t\t\t\t\twarnings,\n\t\t\t\t\ttruncationWarning(id, domain, connectionId, 'Repository', 'interrupted'),\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst failed = fetchFailed || warning != null || interruptedAfterProgress;\n\t\t\t// An SDK omission from an earlier page asserts the read succeeded; this one didn't.\n\t\t\treconcileOmissionsWithFailure(warnings, failed);\n\t\t\treturn {\n\t\t\t\trepos: repos,\n\t\t\t\twarnings: warnings,\n\t\t\t\tfetchFailed: failed,\n\t\t\t\ttruncated: truncated || interruptedAfterProgress,\n\t\t\t};\n\t\t}\n\n\t\trepos.push(...value.values);\n\t\tconst assessment = mergeAssessmentInto(warnings, id, domain, connectionId, value.metadata);\n\t\tfetchFailed = fetchFailed || assessment.fetchFailed;\n\t\ttruncated = truncated || value.truncated === true || value.paging?.truncated === true || assessment.truncated;\n\t\tif (!(value.paging?.more ?? false)) {\n\t\t\treconcileOmissionsWithFailure(warnings, fetchFailed);\n\t\t\treturn {\n\t\t\t\trepos: repos,\n\t\t\t\twarnings: warnings,\n\t\t\t\tfetchFailed: fetchFailed,\n\t\t\t\ttruncated: truncated,\n\t\t\t};\n\t\t}\n\n\t\tif (page >= maxPages) {\n\t\t\treconcileOmissionsWithFailure(warnings, fetchFailed);\n\t\t\treturn { repos: repos, warnings: warnings, fetchFailed: fetchFailed, truncated: true };\n\t\t}\n\n\t\tconst nextCursor = value.paging?.cursor;\n\t\tif (nextCursor == null || nextCursor === '{}') {\n\t\t\t// Provider says there is more but didn't return a usable cursor; stop rather than refetch the same page.\n\t\t\treconcileOmissionsWithFailure(warnings, fetchFailed);\n\t\t\treturn { repos: repos, warnings: warnings, fetchFailed: fetchFailed, truncated: true };\n\t\t}\n\n\t\tcursor = nextCursor;\n\t}\n}\n\nfunction describeSweepTargetSelector(target: ProviderSweepTarget): string {\n\tconst parts: string[] = [];\n\tif (target.connectionId != null) {\n\t\tparts.push(`connectionId '${target.connectionId}'`);\n\t}\n\tif (target.domain != null) {\n\t\tparts.push(`domain '${target.domain}'`);\n\t}\n\treturn parts.length !== 0 ? ` (${parts.join(', ')})` : '';\n}\n\nexport function resolvePullRequestSweepTargets(options: PullRequestSweepOptions | undefined): {\n\ttargets: readonly ProviderSweepTarget[];\n\tattributeUnavailableProviders: boolean;\n} {\n\tif (options?.targets != null) {\n\t\tif (options.providerIds != null || options.connectionId != null) {\n\t\t\tthrow new TypeError(\"Pull request sweep 'targets' cannot be combined with 'providerIds' or 'connectionId'\");\n\t\t}\n\n\t\t// Keyed by the selector as the read resolves it, so a repeat is a duplicate however its domain is spelled.\n\t\t// Several targets of one provider are legitimate (one per connection), but each must name its connection:\n\t\t// an unnamed one reads the primary connection, which may be one of the named ones. A domain names a host\n\t\t// only on a self-managed provider; a cloud provider's read ignores it.\n\t\tconst seenTargets = new Set<string>();\n\t\tconst targetCounts = new Map<IntegrationIds, number>();\n\t\tconst unnamedTargets: ProviderSweepTarget[] = [];\n\t\tfor (const target of options.targets) {\n\t\t\tconst host = isSelfManagedHostIntegrationId(target.providerId) ? hostFromDomain(target.domain) : undefined;\n\t\t\tconst key = JSON.stringify([target.providerId, target.connectionId ?? '', host ?? '']);\n\t\t\tif (seenTargets.has(key)) {\n\t\t\t\tthrow new TypeError(\n\t\t\t\t\t`Pull request sweep targets must be unique; duplicate '${target.providerId}' target${describeSweepTargetSelector(target)}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tseenTargets.add(key);\n\t\t\ttargetCounts.set(target.providerId, (targetCounts.get(target.providerId) ?? 0) + 1);\n\t\t\tif (target.connectionId == null && host == null) {\n\t\t\t\tunnamedTargets.push(target);\n\t\t\t}\n\t\t}\n\n\t\tfor (const target of unnamedTargets) {\n\t\t\tif ((targetCounts.get(target.providerId) ?? 0) > 1) {\n\t\t\t\tthrow new TypeError(\n\t\t\t\t\t`Pull request sweep targets for '${target.providerId}' must each name a connectionId or domain when there is more than one (a domain only on a self-managed host); an unnamed target reads the primary connection`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn { targets: options.targets, attributeUnavailableProviders: true };\n\t}\n\n\tconst providerIds =\n\t\toptions?.providerIds ?? supportedOrderedCloudIntegrationIds.filter(id => !isIssuesHostIntegrationId(id));\n\tconst connectionId = providerIds.length === 1 ? options?.connectionId : undefined;\n\treturn {\n\t\ttargets: providerIds.map(providerId => ({ providerId: providerId, connectionId: connectionId })),\n\t\tattributeUnavailableProviders: options?.providerIds != null,\n\t};\n}\n\nexport async function getCurrentAccountIdentity(\n\tintegration: GitHostIntegration,\n\tconnectionId: string | undefined,\n): Promise<{ id: string; username?: string } | undefined> {\n\ttry {\n\t\tconst account = await integration.getCurrentAccount({ connectionId: connectionId });\n\t\treturn account != null ? { id: account.id, username: account.username } : undefined;\n\t} catch {\n\t\t// Authorship is optional enrichment; don't turn a successful PR read into a failure if identity lookup fails.\n\t\treturn undefined;\n\t}\n}\n\n/**\n * The current account to map each raw row against, in order (see {@link GitHostIntegration.getPullRequestViewers}).\n * Rows that name no one can't be matched, so a read of only those resolves nothing; a failed lookup leaves every\n * row's authorship unknown rather than failing the read.\n */\nexport async function getPullRequestViewers(\n\tintegration: GitHostIntegration,\n\tconnectionId: string | undefined,\n\tpullRequests: readonly (ProviderPullRequest | PullRequest)[],\n): Promise<({ id: string; username?: string } | null | undefined)[]> {\n\tif (!pullRequests.some(pullRequestNamesPeople)) return pullRequests.map(() => undefined);\n\n\ttry {\n\t\treturn await integration.getPullRequestViewers(pullRequests, connectionId);\n\t} catch {\n\t\treturn pullRequests.map(() => undefined);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,eAAsB,YACrB,IACA,QACA,cACA,IACA,SACoD;CACpD,IAAI;EACH,MAAM,SAAS,MAAM,GAAG;EACxB,IAAI,UAAU,MAKb,OAAO,gBAAgB,QAAQ,SAAS,uBACrC,EAAE,SAAS,oBAAoB,IAAI,QAAQ,YAAY,EAAE,IACzD,CAAC;EAEL,IAAI,OAAO,SAAS,MACnB,OAAO;GAAE,OAAO,OAAO;GAAO,SAAS,kBAAkB,IAAI,QAAQ,cAAc,OAAO,KAAK;EAAE;EAElG,OAAO,EAAE,OAAO,OAAO,MAAM;CAC9B,SAAS,IAAI;EACZ,OAAO,EAAE,SAAS,kBAAkB,IAAI,QAAQ,cAAc,EAAE,EAAE;CACnE;AACD;;;;;;;AAQA,eAAsB,kBACrB,aACA,IACA,QACA,cACA,SACsG;CACtG,IAAI,SAAS;CACb,MAAM,WAAW,MAAM,YACtB,IACA,QACA,cACA,YAAY;EACX,MAAM,SAAS,MAAM,YAAY,0BAA0B,YAAY;EACvE,SAAS,UA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4B,MAAM,GACxH;GAGD,YAAY,IAAI,GAAG;GACnB,aAAa,IAAI,OAAO,aAAa,aAAa,IAAI,OAAO,UAAU,KAAK,KAAK,CAAC;GAClF,IAAI,OAAO,gBAAgB,QAAQ,QAAQ,MAC1C,eAAe,KAAK,MAAM;EAE5B;EAEA,KAAK,MAAM,UAAU,gBACpB,KAAK,aAAa,IAAI,OAAO,UAAU,KAAK,KAAK,GAChD,MAAM,IAAI,UACT,mCAAmC,OAAO,WAAW,6JACtD;EAIF,OAAO;GAAE,SAAS,QAAQ;GAAS,+BAA+B;EAAK;CACxE;CAEA,MAAM,cACL,SAAS,eAAe,oCAAoC,QAAO,OAAM,CAAC,0BAA0B,EAAE,CAAC;CACxG,MAAM,eAAe,YAAY,WAAW,IAAI,SAAS,eAAe,KAAA;CACxE,OAAO;EACN,SAAS,YAAY,KAAI,gBAAe;GAAc;GAA0B;EAAa,EAAE;EAC/F,+BAA+B,SAAS,eAAe;CACxD;AACD;AAEA,eAAsB,0BACrB,aACA,cACyD;CACzD,IAAI;EACH,MAAM,UAAU,MAAM,YAAY,kBAAkB,EAAgB,aAAa,CAAC;EAClF,OAAO,WAAW,OAAO;GAAE,IAAI,QAAQ;GAAI,UAAU,QAAQ;EAAS,IAAI,KAAA;CAC3E,QAAQ;EAEP;CACD;AACD;;;;;;AAOA,eAAsB,sBACrB,aACA,cACA,cACoE;CACpE,IAAI,CAAC,aAAa,KAAK,sBAAsB,GAAG,OAAO,aAAa,UAAU,KAAA,CAAS;CAEvF,IAAI;EACH,OAAO,MAAM,YAAY,sBAAsB,cAAc,YAAY;CAC1E,QAAQ;EACP,OAAO,aAAa,UAAU,KAAA,CAAS;CACxC;AACD"}
|
|
@@ -1,7 +1,178 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { IssueOrPullRequestState } from "../../../git/models/issueOrPullRequest.js";
|
|
2
|
+
import { IssueShape, IssueSyncedWith } from "../../../git/models/issue.js";
|
|
3
|
+
import { PullRequestCheckRun, PullRequestMergeQueueEntry, PullRequestMergeableState, PullRequestReviewDecision, PullRequestReviewState, PullRequestShape, PullRequestStatusCheckRollupState } from "../../../git/models/pullRequest.js";
|
|
4
4
|
//#region ../plus/integrations/src/reads/etag.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* The etags the batch reads hand back (`getPullRequestsBatch`, `getIssuesBatch`): an opaque stamp of an item's
|
|
7
|
+
* change state, which a caller sends back so a cheap check can answer "unchanged" without a full read.
|
|
8
|
+
*
|
|
9
|
+
* Computed by core, never the provider's HTTP ETag, and from the fields alone — not the item's id, since the
|
|
10
|
+
* caller's key already identifies the target and ids cross vocabularies between reads. Not hashed: the stamp IS
|
|
11
|
+
* the serialized fields, so two different change states can never collide into a false `unchanged` — except for two
|
|
12
|
+
* 64-bit hashes, where a collision (about 2^-64) is the only way a change can hide: an Azure DevOps pull request's
|
|
13
|
+
* `revision`, of the fields Azure changes without a timestamp, and a GitHub pull request's `checkRuns`, of its head's
|
|
14
|
+
* checks, which keeps the stamp the same length at any number of checks. The prefix names the scheme (`pr1`, `is1`)
|
|
15
|
+
* and every include it covers ({@link PullRequestEtagInclude}, {@link IssueEtagInclude}), in canonical order
|
|
16
|
+
* (`pr1+mergeable+checks:`, `is1+reactions:`), so two different sets can never collide even when their values do (a
|
|
17
|
+
* `null` mergeability and a `null` rollup). A stamp from another scheme or another set just compares unequal and
|
|
18
|
+
* costs a full read.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* An input a pull request's etag can be widened to, each of which a host changes without moving `updatedAt`. Every
|
|
22
|
+
* entry costs its own fields in the cheap check, so a caller picks only the ones it needs. `'checks'` is the check
|
|
23
|
+
* rollup.
|
|
24
|
+
*/
|
|
25
|
+
export type PullRequestEtagInclude = 'mergeable' | 'reviewDecision' | 'checks';
|
|
26
|
+
/** Every {@link PullRequestEtagInclude}, in the canonical order an etag lists them in. */
|
|
27
|
+
export declare const pullRequestEtagIncludes: readonly PullRequestEtagInclude[];
|
|
28
|
+
/**
|
|
29
|
+
* The change state a batch read's etag is computed from ({@link pullRequestEtag}), in the NORMALIZED vocabulary of
|
|
30
|
+
* `PullRequestShape` — the values a full row carries after its provider's whole conversion chain, so a cheap
|
|
31
|
+
* check and a full read of the same pull request yield the same fields. Each of `mergeableState`, `reviewDecision`
|
|
32
|
+
* and `statusCheckRollupState` counts only when its {@link PullRequestEtagInclude} is requested.
|
|
33
|
+
*/
|
|
34
|
+
export interface PullRequestEtagFields {
|
|
35
|
+
state: IssueOrPullRequestState;
|
|
36
|
+
isDraft?: boolean;
|
|
37
|
+
updatedDate: Date;
|
|
38
|
+
headSha?: string;
|
|
39
|
+
mergeableState?: PullRequestMergeableState;
|
|
40
|
+
reviewDecision?: PullRequestReviewDecision;
|
|
41
|
+
statusCheckRollupState?: PullRequestStatusCheckRollupState;
|
|
42
|
+
/**
|
|
43
|
+
* A fingerprint of the fields a host changes without moving an update time ({@link pullRequestRevision}); set
|
|
44
|
+
* only for hosts that keep none (Azure DevOps and Server). Part of the etag whenever it is set, not an include.
|
|
45
|
+
*/
|
|
46
|
+
revision?: string;
|
|
47
|
+
/**
|
|
48
|
+
* A full row marked `viewerUnresolved`, which no cheap check ever sets: such a row never compares unchanged, so it
|
|
49
|
+
* is read in full again rather than kept without a viewer until the pull request changes.
|
|
50
|
+
*/
|
|
51
|
+
viewerUnresolved?: true;
|
|
52
|
+
/**
|
|
53
|
+
* The pull request's merge-queue entry, as far as the etag reads it: whether it's queued, in which state and since
|
|
54
|
+
* when, none of which moves `updatedDate`. Part of the etag whenever it is set, not an include, and set only on a
|
|
55
|
+
* queued pull request, so every other pull request's etag is unchanged by it. Read only where the queue is
|
|
56
|
+
* (github.com).
|
|
57
|
+
*/
|
|
58
|
+
mergeQueue?: Pick<PullRequestMergeQueueEntry, 'state' | 'enqueuedAt'>;
|
|
59
|
+
/**
|
|
60
|
+
* When the pull request's `mergeQueueRemoval` happened, set only while it has one. Like `mergeQueue`, part of the
|
|
61
|
+
* etag whenever it is set, not an include: a pull request that joins its queue and is removed between two checks
|
|
62
|
+
* moves neither its update time nor, at either check, `mergeQueue`.
|
|
63
|
+
*/
|
|
64
|
+
mergeQueueRemovedAt?: Date;
|
|
65
|
+
/**
|
|
66
|
+
* The read selected merge-queue data (GitHub.com, for a read that asks for it or a host that opts in), whatever
|
|
67
|
+
* that data says. Part of the etag whenever it is set, as a marker: without it a pull request that isn't queued and
|
|
68
|
+
* has no removal computes the etag it has without the data, so a host that starts asking for the data would keep a
|
|
69
|
+
* held row lacking it as `unchanged`. A full row sets it from its `mergeQueueRequired`, which only a read that
|
|
70
|
+
* selected the data carries; a cheap check sets it from the same selection.
|
|
71
|
+
*/
|
|
72
|
+
mergeQueueRead?: true;
|
|
73
|
+
/**
|
|
74
|
+
* The head's checks, from {@link pullRequestCheckRunsEtag}, set whenever the read selected check runs (a count of 0
|
|
75
|
+
* when the head has none), so it also marks such a read, as {@link mergeQueueRead} does.
|
|
76
|
+
*/
|
|
77
|
+
checkRuns?: PullRequestCheckRunsEtag;
|
|
78
|
+
}
|
|
79
|
+
/** A head's checks, as a pull request's etag reads them. */
|
|
80
|
+
export interface PullRequestCheckRunsEtag {
|
|
81
|
+
/** A 64-bit hash of each check's id, kind, name, status and conclusion, in id order. */
|
|
82
|
+
readonly hash: string;
|
|
83
|
+
readonly count: number;
|
|
84
|
+
/** The head has checks the read lacks (the row's `checkRunsTruncated`). */
|
|
85
|
+
readonly truncated: boolean;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* {@link PullRequestEtagFields.checkRuns}, which the cheap check and the full read build alike from the same fields.
|
|
89
|
+
* Hashed to keep the etag short at any number of checks, so a collision is the only way a change can hide, at about
|
|
90
|
+
* 2^-64.
|
|
91
|
+
*/
|
|
92
|
+
export declare function pullRequestCheckRunsEtag(runs: readonly Pick<PullRequestCheckRun, 'id' | 'kind' | 'name' | 'status' | 'conclusion'>[], truncated: boolean): PullRequestCheckRunsEtag;
|
|
93
|
+
/**
|
|
94
|
+
* The fields of a pull request {@link pullRequestRevision} reads, as a full row carries them. A `PullRequestShape`
|
|
95
|
+
* is one, so a full read passes its row as is and a cheap check builds one from the same mapped values.
|
|
96
|
+
*/
|
|
97
|
+
export interface PullRequestRevisionSource {
|
|
98
|
+
readonly title: string;
|
|
99
|
+
readonly body?: string;
|
|
100
|
+
readonly refs?: {
|
|
101
|
+
readonly base: {
|
|
102
|
+
readonly branch: string;
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
readonly reviewRequests?: readonly PullRequestRevisionReviewer[];
|
|
106
|
+
readonly latestReviews?: readonly PullRequestRevisionReviewer[];
|
|
107
|
+
}
|
|
108
|
+
interface PullRequestRevisionReviewer {
|
|
109
|
+
readonly reviewer: {
|
|
110
|
+
readonly id: string;
|
|
111
|
+
};
|
|
112
|
+
readonly state: PullRequestReviewState;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* {@link PullRequestEtagFields.revision}: a 64-bit hash of a pull request's title, description, target branch and
|
|
116
|
+
* reviewers (each one's id and review state, in a canonical order). Hashed to keep the etag short, so a collision is
|
|
117
|
+
* the only way a change can hide, at about 2^-64.
|
|
118
|
+
*/
|
|
119
|
+
export declare function pullRequestRevision(pr: PullRequestRevisionSource): string;
|
|
120
|
+
/**
|
|
121
|
+
* An input an issue's etag can be widened to, which a host changes without moving `updatedAt`. `'reactions'` is the
|
|
122
|
+
* thumbs-up count, and widens the etag only on hosts whose rows really fetch one (GitHub/GHE and GitLab).
|
|
123
|
+
*/
|
|
124
|
+
export type IssueEtagInclude = 'reactions';
|
|
125
|
+
/** Every {@link IssueEtagInclude}, in the canonical order an etag lists them in. */
|
|
126
|
+
export declare const issueEtagIncludes: readonly IssueEtagInclude[];
|
|
127
|
+
/** The issue twin of {@link PullRequestEtagFields}, in {@link IssueShape}'s normalized vocabulary. */
|
|
128
|
+
export interface IssueEtagFields {
|
|
129
|
+
state: IssueOrPullRequestState | undefined;
|
|
130
|
+
updatedDate: Date;
|
|
131
|
+
/** Counts only when `'reactions'` is requested, and only from a row whose read fetched reactions. */
|
|
132
|
+
thumbsUpCount?: number;
|
|
133
|
+
/**
|
|
134
|
+
* Azure DevOps only: the version of the rule a work item's body is read by ({@link azureWorkItemDescriptionRule}).
|
|
135
|
+
* A change of rule changes the body without moving `updatedDate`, so a row read under an earlier one must not
|
|
136
|
+
* compare unchanged.
|
|
137
|
+
*/
|
|
138
|
+
descriptionRule?: number;
|
|
139
|
+
/**
|
|
140
|
+
* Azure DevOps only: the version of the rule a work item's `viewer` is set by ({@link azureWorkItemViewerRule}).
|
|
141
|
+
* A full row that names someone but got no viewer (its organization's identity couldn't be read) leaves it out, so
|
|
142
|
+
* it never compares unchanged and is read in full again rather than kept without one.
|
|
143
|
+
*/
|
|
144
|
+
viewerRule?: number;
|
|
145
|
+
/**
|
|
146
|
+
* Linear only: the row's `syncedWith` links as {@link linearSyncedWithEtagKeys} spells them, so a link added, removed
|
|
147
|
+
* or moved to other coordinates changes the etag whether or not the issue's update time moves. `null` on a
|
|
148
|
+
* full row without `syncedWith` (held from before it existed, or read while Linear failed to resolve it), which
|
|
149
|
+
* never compares unchanged with a cheap check's list.
|
|
150
|
+
*/
|
|
151
|
+
syncedWithKeys?: readonly string[] | null;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* {@link IssueEtagFields.descriptionRule}: the version of the rule an Azure DevOps work item's body is read by, stamped
|
|
155
|
+
* on both sides of its etag. Bumped whenever the rule changes which field a work item's body comes from, so every row
|
|
156
|
+
* a caller holds from before is read in full once. 1: the first rich text field with content (provider-apis'
|
|
157
|
+
* `getAzureWorkItemDescription`), where it used to be only Description. The rule lives in provider-apis, so a bump of
|
|
158
|
+
* that package that changes it must bump this too; the etag tests pin the rule to catch one.
|
|
159
|
+
*
|
|
160
|
+
* It can't cover a row whose read found the organization's field catalog unavailable: that row's body falls back to
|
|
161
|
+
* the built-in fields, and a cheap check, which reads no body, can't tell it from a complete one, so it stays as read
|
|
162
|
+
* until the work item changes.
|
|
163
|
+
*/
|
|
164
|
+
export declare const azureWorkItemDescriptionRule = 1;
|
|
165
|
+
/**
|
|
166
|
+
* {@link IssueEtagFields.viewerRule}: the version of the rule an Azure DevOps work item's `viewer` is set by, stamped
|
|
167
|
+
* on both sides of its etag, so every row a caller holds from before it was set is read in full once. 1: the user's
|
|
168
|
+
* identity in the work item's organization (gitkraken/kepler#4291).
|
|
169
|
+
*/
|
|
170
|
+
export declare const azureWorkItemViewerRule = 1;
|
|
171
|
+
/**
|
|
172
|
+
* A Linear row's sync links in its etag, sorted: each as its GitHub id and, when known, the coordinates a host matches
|
|
173
|
+
* the GitHub row by, so a link whose coordinates Linear fills in or changes later compares changed.
|
|
174
|
+
*/
|
|
175
|
+
export declare function linearSyncedWithEtagKeys(links: readonly IssueSyncedWith[]): string[];
|
|
5
176
|
export declare function pullRequestEtagFieldsFromShape(pr: PullRequestShape): PullRequestEtagFields;
|
|
6
177
|
export declare function issueEtagFieldsFromShape(issue: IssueShape): IssueEtagFields;
|
|
7
178
|
/**
|