@gitkraken/core-gitlens 0.28.0 → 0.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/CHANGELOG.md +48 -1
  2. package/dist/git/cache.d.ts +39 -1
  3. package/dist/git/cache.js +108 -7
  4. package/dist/git/cache.js.map +1 -1
  5. package/dist/git/providers/branches.d.ts +17 -12
  6. package/dist/git/providers/revision.d.ts +4 -0
  7. package/dist/git/watching/worktreeSummary.d.ts +16 -7
  8. package/dist/git/watching/worktreeSummary.js +44 -14
  9. package/dist/git/watching/worktreeSummary.js.map +1 -1
  10. package/dist/git-cli/cliGitProvider.js +3 -3
  11. package/dist/git-cli/cliGitProvider.js.map +1 -1
  12. package/dist/git-cli/exec/exec.d.ts +2 -2
  13. package/dist/git-cli/exec/exec.js +2 -2
  14. package/dist/git-cli/exec/gitDirResolver.d.ts +6 -1
  15. package/dist/git-cli/exec/gitDirResolver.js +9 -4
  16. package/dist/git-cli/exec/gitDirResolver.js.map +1 -1
  17. package/dist/git-cli/providers/branches.d.ts +91 -13
  18. package/dist/git-cli/providers/branches.js +673 -176
  19. package/dist/git-cli/providers/branches.js.map +1 -1
  20. package/dist/git-cli/providers/config.js +1 -1
  21. package/dist/git-cli/providers/config.js.map +1 -1
  22. package/dist/git-cli/providers/revision.d.ts +4 -0
  23. package/dist/git-cli/providers/revision.js +64 -3
  24. package/dist/git-cli/providers/revision.js.map +1 -1
  25. package/dist/ipc/ipcServer.d.ts +6 -1
  26. package/dist/ipc/ipcServer.js +15 -6
  27. package/dist/ipc/ipcServer.js.map +1 -1
  28. package/dist/plus/ai/errors.js +4 -4
  29. package/dist/plus/ai/errors.js.map +1 -1
  30. package/dist/plus/ai/models/model.d.ts +1 -1
  31. package/dist/plus/ai/models/model.js.map +1 -1
  32. package/dist/plus/ai/models/promptTemplates.d.ts +45 -2
  33. package/dist/plus/ai/models/results.d.ts +41 -0
  34. package/dist/plus/ai/models/results.js +14 -0
  35. package/dist/plus/ai/models/results.js.map +1 -0
  36. package/dist/plus/ai/prompts.d.ts +6 -0
  37. package/dist/plus/ai/prompts.js +255 -5
  38. package/dist/plus/ai/prompts.js.map +1 -1
  39. package/dist/plus/ai/providers/gitkrakenProvider.js +2 -2
  40. package/dist/plus/ai/providers/gitkrakenProvider.js.map +1 -1
  41. package/dist/plus/ai/providers/openAICompatibleProviderBase.js +1 -0
  42. package/dist/plus/ai/providers/openAICompatibleProviderBase.js.map +1 -1
  43. package/dist/plus/ai/utils/ai.utils.d.ts +4 -0
  44. package/dist/plus/ai/utils/ai.utils.js +8 -1
  45. package/dist/plus/ai/utils/ai.utils.js.map +1 -1
  46. package/dist/plus/ai/utils/results.utils.d.ts +15 -1
  47. package/dist/plus/ai/utils/results.utils.js +80 -4
  48. package/dist/plus/ai/utils/results.utils.js.map +1 -1
  49. package/dist/plus/integrations/authentication/integrationAuthenticationService.js +2 -0
  50. package/dist/plus/integrations/authentication/integrationAuthenticationService.js.map +1 -1
  51. package/dist/plus/integrations/authentication/models.d.ts +1 -1
  52. package/dist/plus/integrations/authentication/models.js +2 -0
  53. package/dist/plus/integrations/authentication/models.js.map +1 -1
  54. package/dist/plus/integrations/constants.d.ts +2 -1
  55. package/dist/plus/integrations/constants.js +12 -2
  56. package/dist/plus/integrations/constants.js.map +1 -1
  57. package/dist/plus/integrations/fieldPresence.js +17 -1
  58. package/dist/plus/integrations/fieldPresence.js.map +1 -1
  59. package/dist/plus/integrations/integrationService.d.ts +1 -1
  60. package/dist/plus/integrations/integrationService.js +8 -2
  61. package/dist/plus/integrations/integrationService.js.map +1 -1
  62. package/dist/plus/integrations/lite.js +5 -6
  63. package/dist/plus/integrations/lite.js.map +1 -1
  64. package/dist/plus/integrations/models/gitHostIntegration.d.ts +11 -1
  65. package/dist/plus/integrations/models/gitHostIntegration.js.map +1 -1
  66. package/dist/plus/integrations/providers/asana.d.ts +91 -0
  67. package/dist/plus/integrations/providers/asana.js +344 -0
  68. package/dist/plus/integrations/providers/asana.js.map +1 -0
  69. package/dist/plus/integrations/providers/azure/azure.js +3 -2
  70. package/dist/plus/integrations/providers/azure/azure.js.map +1 -1
  71. package/dist/plus/integrations/providers/azure/models.js +3 -2
  72. package/dist/plus/integrations/providers/azure/models.js.map +1 -1
  73. package/dist/plus/integrations/providers/azureDevOps.d.ts +7 -1
  74. package/dist/plus/integrations/providers/azureDevOps.js +9 -1
  75. package/dist/plus/integrations/providers/azureDevOps.js.map +1 -1
  76. package/dist/plus/integrations/providers/bitbucket-server/discovery.js +2 -1
  77. package/dist/plus/integrations/providers/bitbucket-server/discovery.js.map +1 -1
  78. package/dist/plus/integrations/providers/bitbucket-server/models.js.map +1 -1
  79. package/dist/plus/integrations/providers/github.d.ts +2 -2
  80. package/dist/plus/integrations/providers/github.js +2 -2
  81. package/dist/plus/integrations/providers/github.js.map +1 -1
  82. package/dist/plus/integrations/providers/issueSorts.d.ts +5 -0
  83. package/dist/plus/integrations/providers/issueSorts.js +6 -1
  84. package/dist/plus/integrations/providers/issueSorts.js.map +1 -1
  85. package/dist/plus/integrations/providers/jiraIssueByKey.js +2 -1
  86. package/dist/plus/integrations/providers/jiraIssueByKey.js.map +1 -1
  87. package/dist/plus/integrations/providers/models.d.ts +19 -3
  88. package/dist/plus/integrations/providers/models.js +12 -1
  89. package/dist/plus/integrations/providers/models.js.map +1 -1
  90. package/dist/plus/integrations/providers/providerApiClient.d.ts +0 -3
  91. package/dist/plus/integrations/providers/providerApiClient.js +1 -3
  92. package/dist/plus/integrations/providers/providerApiClient.js.map +1 -1
  93. package/dist/plus/integrations/providers/providersApi.d.ts +22 -1
  94. package/dist/plus/integrations/providers/providersApi.js +63 -12
  95. package/dist/plus/integrations/providers/providersApi.js.map +1 -1
  96. package/dist/plus/integrations/providers/utils.d.ts +1 -0
  97. package/dist/plus/integrations/providers/utils.js +8 -2
  98. package/dist/plus/integrations/providers/utils.js.map +1 -1
  99. package/dist/plus/integrations/reads/hierarchy.utils.d.ts +3 -3
  100. package/dist/plus/integrations/reads/hierarchy.utils.js +4 -4
  101. package/dist/plus/integrations/reads/hierarchy.utils.js.map +1 -1
  102. package/dist/plus/integrations/reads/resolveRepository.js +29 -21
  103. package/dist/plus/integrations/reads/resolveRepository.js.map +1 -1
  104. package/dist/plus/integrations/results.d.ts +18 -10
  105. package/dist/plus/integrations/results.js.map +1 -1
  106. package/dist/plus/integrations/utils/domain.utils.js +2 -1
  107. package/dist/plus/integrations/utils/domain.utils.js.map +1 -1
  108. package/dist/plus/integrations/utils/integration.utils.js +5 -13
  109. package/dist/plus/integrations/utils/integration.utils.js.map +1 -1
  110. package/dist/utils/diff.d.ts +19 -0
  111. package/dist/utils/diff.js +121 -3
  112. package/dist/utils/diff.js.map +1 -1
  113. package/dist/utils/env/node/exec.d.ts +0 -1
  114. package/dist/utils/env/node/exec.js +2 -14
  115. package/dist/utils/env/node/exec.js.map +1 -1
  116. package/dist/utils/path.d.ts +2 -0
  117. package/dist/utils/path.js +7 -1
  118. package/dist/utils/path.js.map +1 -1
  119. package/docs/integrations.md +72 -43
  120. package/package.json +2 -2
@@ -19,6 +19,7 @@ export declare const EntityIdentifierProviderType: {
19
19
  readonly JiraServer: 'jiraServer';
20
20
  readonly Linear: 'linear';
21
21
  readonly Trello: 'trello';
22
+ readonly Asana: 'asana';
22
23
  };
23
24
  export declare const EntityType: {
24
25
  readonly PullRequest: 'pr';
@@ -17,7 +17,8 @@ const EntityIdentifierProviderType = {
17
17
  Jira: "jira",
18
18
  JiraServer: "jiraServer",
19
19
  Linear: "linear",
20
- Trello: "trello"
20
+ Trello: "trello",
21
+ Asana: "asana"
21
22
  };
22
23
  const EntityType = {
23
24
  PullRequest: "pr",
@@ -69,6 +70,9 @@ function getEntityIdentifierInput(entity) {
69
70
  if (!isIssue(entity) || entity.project == null) throw new Error("Trello issues must have a board project to be encoded");
70
71
  projectId = entity.project.id;
71
72
  accountOrOrgId = entity.project.resourceId || entity.project.id;
73
+ } else if (provider === EntityIdentifierProviderType.Asana) {
74
+ if (!isIssue(entity) || !entity.project?.resourceId) throw new Error("Asana issues must have a workspace to be encoded");
75
+ accountOrOrgId = entity.project.resourceId;
72
76
  } else if (provider === EntityIdentifierProviderType.Bitbucket || provider === EntityIdentifierProviderType.BitbucketServer) repoId = isLaunchpadItem(entity) ? entity.underlyingPullRequest?.repository?.id : entity.repository?.id;
73
77
  let entityId = isLaunchpadItem(entity) ? entity.graphQLId : entity.nodeId;
74
78
  if (provider === EntityIdentifierProviderType.Azure || provider === EntityIdentifierProviderType.AzureDevOpsServer) entityId = isLaunchpadItem(entity) ? entity.underlyingPullRequest?.id : entity.id;
@@ -95,6 +99,7 @@ function getProviderIdFromEntityIdentifier(entityIdentifier) {
95
99
  case EntityIdentifierProviderType.JiraServer: return "jira-server";
96
100
  case EntityIdentifierProviderType.Linear: return "linear";
97
101
  case EntityIdentifierProviderType.Trello: return "trello";
102
+ case EntityIdentifierProviderType.Asana: return "asana";
98
103
  case EntityIdentifierProviderType.Azure: return "azureDevOps";
99
104
  case EntityIdentifierProviderType.AzureDevOpsServer: return "azure-devops-server";
100
105
  case EntityIdentifierProviderType.Bitbucket: return "bitbucket";
@@ -112,6 +117,7 @@ function fromStringToEntityIdentifierProviderType(str) {
112
117
  case "jira-server": return EntityIdentifierProviderType.JiraServer;
113
118
  case "linear": return EntityIdentifierProviderType.Linear;
114
119
  case "trello": return EntityIdentifierProviderType.Trello;
120
+ case "asana": return EntityIdentifierProviderType.Asana;
115
121
  case "azure":
116
122
  case "azureDevOps":
117
123
  case "azure-devops": return EntityIdentifierProviderType.Azure;
@@ -183,7 +189,7 @@ function getDomainFromEntityIdentifier(identifier) {
183
189
  */
184
190
  async function getIssueFromGitConfigEntityIdentifier(resolveIntegration, identifier, options) {
185
191
  if (identifier.entityType !== EntityType.Issue) return;
186
- if (identifier.provider !== EntityIdentifierProviderType.Jira && identifier.provider !== EntityIdentifierProviderType.JiraServer && identifier.provider !== EntityIdentifierProviderType.Linear && identifier.provider !== EntityIdentifierProviderType.Github && identifier.provider !== EntityIdentifierProviderType.Gitlab && identifier.provider !== EntityIdentifierProviderType.GithubEnterprise && identifier.provider !== EntityIdentifierProviderType.GitlabSelfHosted && identifier.provider !== EntityIdentifierProviderType.Bitbucket && identifier.provider !== EntityIdentifierProviderType.BitbucketServer && identifier.provider !== EntityIdentifierProviderType.AzureDevOpsServer && identifier.provider !== EntityIdentifierProviderType.Azure && identifier.provider !== EntityIdentifierProviderType.Trello) return;
192
+ if (identifier.provider !== EntityIdentifierProviderType.Jira && identifier.provider !== EntityIdentifierProviderType.JiraServer && identifier.provider !== EntityIdentifierProviderType.Linear && identifier.provider !== EntityIdentifierProviderType.Github && identifier.provider !== EntityIdentifierProviderType.Gitlab && identifier.provider !== EntityIdentifierProviderType.GithubEnterprise && identifier.provider !== EntityIdentifierProviderType.GitlabSelfHosted && identifier.provider !== EntityIdentifierProviderType.Bitbucket && identifier.provider !== EntityIdentifierProviderType.BitbucketServer && identifier.provider !== EntityIdentifierProviderType.AzureDevOpsServer && identifier.provider !== EntityIdentifierProviderType.Azure && identifier.provider !== EntityIdentifierProviderType.Trello && identifier.provider !== EntityIdentifierProviderType.Asana) return;
187
193
  const integrationId = getProviderIdFromEntityIdentifier(identifier);
188
194
  if (integrationId == null) return;
189
195
  let domain = getDomainFromEntityIdentifier(identifier);
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","names":[],"sources":["../../../../../plus/integrations/src/providers/utils.ts"],"sourcesContent":["import type { AnyEntityIdentifierInput, EntityIdentifier } from '@gitkraken/provider-apis';\nimport type { Issue, IssueShape } from '@gitlens/git/models/issue.js';\nimport type { IssueOrPullRequest } from '@gitlens/git/models/issueOrPullRequest.js';\nimport type { PullRequest } from '@gitlens/git/models/pullRequest.js';\nimport type {\n\tIssueResourceDescriptor,\n\tRepositoryDescriptor,\n\tResourceDescriptor,\n} from '@gitlens/git/models/resourceDescriptor.js';\nimport { isIssueResourceDescriptor, isRepositoryDescriptor } from '@gitlens/git/utils/resourceDescriptor.utils.js';\nimport { Logger } from '@gitlens/utils/logger.js';\nimport type { IntegrationIds } from '../constants.js';\nimport {\n\tGitCloudHostIntegrationId,\n\tGitSelfManagedHostIntegrationId,\n\tIssuesCloudHostIntegrationId,\n\tIssuesSelfManagedHostIntegrationId,\n} from '../constants.js';\nimport { getSingleConfiguredDomain } from '../utils/domain.utils.js';\nimport {\n\tisCloudGitSelfManagedHostIntegrationId,\n\tisGitSelfManagedHostIntegrationId,\n\tisSelfManagedHostIntegrationId,\n} from '../utils/integration.utils.js';\nimport type { AzureProjectInputDescriptor } from './azure/models.js';\nimport type { GitConfigEntityIdentifier } from './models.js';\nimport { isGitHubDotCom, isGitLabDotCom } from './models.js';\n\n// Local runtime copies of the `@gitkraken/provider-apis` entity-identifier string enums, duplicated for\n// the same CJS-from-ESM reason as the enums in `models.ts`. Exported so the enum-parity test can guard\n// them against upstream drift. `EntityVersion` is an intentional subset: the package only ever writes\n// version 1, so the parity test asserts each local entry matches the SDK rather than a full mirror.\nexport const EntityIdentifierProviderType = {\n\tAzure: 'azure',\n\tAzureDevOpsServer: 'azureDevOpsServer',\n\tGithub: 'github',\n\tGithubEnterprise: 'githubEnterprise',\n\tGitlab: 'gitlab',\n\tGitlabSelfHosted: 'gitlabSelfHosted',\n\tBitbucket: 'bitbucket',\n\tBitbucketServer: 'bitbucketServer',\n\tJira: 'jira',\n\tJiraServer: 'jiraServer',\n\tLinear: 'linear',\n\tTrello: 'trello',\n} as const;\n\nexport const EntityType = {\n\tPullRequest: 'pr',\n\tIssue: 'issue',\n} as const;\n\nexport const EntityVersion = {\n\tOne: '1',\n} as const;\n\n/**\n * Forward-compatible structural shape of the host's `LaunchpadItem`. The package\n * uses this for narrowing inside {@link getEntityIdentifierInput}; the host's\n * actual `LaunchpadItem` (in `src/plus/launchpad/launchpadProvider.ts`) carries\n * many more fields. The declared shape only includes fields integrations inspect.\n */\ntype LaunchpadItem = {\n\tuuid: string;\n\ttype: 'issue' | 'pullrequest';\n\tgraphQLId?: string;\n\tprovider: { id: string; domain?: string };\n\tunderlyingPullRequest?: {\n\t\tid: string;\n\t\tproject?: { id: string; resourceName?: string };\n\t\trepository?: { id?: string };\n\t};\n};\n\nfunction isLaunchpadItem(item: IssueOrPullRequest | LaunchpadItem): item is LaunchpadItem {\n\treturn (item as LaunchpadItem).uuid !== undefined;\n}\n\nfunction isIssue(item: IssueOrPullRequest | LaunchpadItem): item is Issue {\n\treturn item.type === 'issue';\n}\n\nexport function getEntityIdentifierInput(entity: Issue | PullRequest | LaunchpadItem): AnyEntityIdentifierInput {\n\tlet entityType: (typeof EntityType)[keyof typeof EntityType] = EntityType.Issue;\n\tif (entity.type === 'pullrequest') {\n\t\tentityType = EntityType.PullRequest;\n\t}\n\n\tlet provider = fromStringToEntityIdentifierProviderType(entity.provider.id);\n\tlet domain = null;\n\tif (provider === EntityIdentifierProviderType.Github && !isGitHubDotCom(entity.provider.domain)) {\n\t\tprovider = EntityIdentifierProviderType.GithubEnterprise;\n\t\tdomain = entity.provider.domain ?? null;\n\t}\n\tif (provider === EntityIdentifierProviderType.Gitlab && !isGitLabDotCom(entity.provider.domain)) {\n\t\tprovider = EntityIdentifierProviderType.GitlabSelfHosted;\n\t\tdomain = entity.provider.domain ?? null;\n\t}\n\t// An issue read through the self-managed integration already carries the enterprise id, so the rewrites above\n\t// never see it and its host was dropped — for exactly the issues that have one. A branch association has to\n\t// name it to be read back from the right server, since two hosts routinely share `owner/repo#number`. Issues\n\t// only: a pull request's identifier is also its Launchpad uuid, which keys stored pins and snoozes, so giving it\n\t// a host would orphan every existing one.\n\tif (\n\t\tentityType === EntityType.Issue &&\n\t\tdomain == null &&\n\t\t(provider === EntityIdentifierProviderType.GithubEnterprise ||\n\t\t\tprovider === EntityIdentifierProviderType.GitlabSelfHosted ||\n\t\t\tprovider === EntityIdentifierProviderType.BitbucketServer)\n\t) {\n\t\tdomain = entity.provider.domain ?? null;\n\t}\n\tif (provider === EntityIdentifierProviderType.AzureDevOpsServer) {\n\t\tdomain = entity.provider.domain ?? null;\n\t}\n\tif (provider === EntityIdentifierProviderType.JiraServer) {\n\t\t// The host is the identity here, not a decoration: two self-hosted instances routinely issue the same\n\t\t// project and issue keys, so an identifier without it collides across them. The SDK's\n\t\t// `JiraIssueEntityIdentifierInput` says as much — its `JiraServer` arm requires `domain` where the\n\t\t// `Jira` arm requires `resourceId`.\n\t\tdomain = entity.provider.domain ?? null;\n\t}\n\n\tlet projectId = null;\n\tlet resourceId = null;\n\tlet accountOrOrgId = null;\n\tlet organizationName = null;\n\tlet repoId = null;\n\tif (provider === EntityIdentifierProviderType.Jira) {\n\t\tif (!isIssue(entity) || entity.project == null) {\n\t\t\tthrow new Error('Jira issues must have a project');\n\t\t}\n\n\t\tprojectId = entity.project.id;\n\t\tresourceId = entity.project.resourceId;\n\t} else if (provider === EntityIdentifierProviderType.JiraServer) {\n\t\tif (!isIssue(entity) || entity.project == null) {\n\t\t\tthrow new Error('Jira Server issues must have a project');\n\t\t}\n\n\t\t// `projectId` only; the SDK's `JiraServer` arm carries `domain` where Cloud carries `resourceId`, and a\n\t\t// self-hosted instance's single synthetic resource is the host the `domain` above already names.\n\t\tprojectId = entity.project.id;\n\t} else if (\n\t\tprovider === EntityIdentifierProviderType.Azure ||\n\t\tprovider === EntityIdentifierProviderType.AzureDevOpsServer\n\t) {\n\t\tconst project = isLaunchpadItem(entity) ? entity.underlyingPullRequest?.project : entity.project;\n\t\tif (project == null) {\n\t\t\tthrow new Error('Azure issues and PRs must have a project to be encoded');\n\t\t}\n\n\t\tprojectId = project.id;\n\t\torganizationName = project.resourceName;\n\t\trepoId = isLaunchpadItem(entity) ? entity.underlyingPullRequest?.repository?.id : entity.repository?.id;\n\t\tif (entityType === EntityType.PullRequest && repoId == null) {\n\t\t\tthrow new Error('Azure PRs must have a repository ID to be encoded');\n\t\t}\n\t} else if (provider === EntityIdentifierProviderType.Trello) {\n\t\tif (!isIssue(entity) || entity.project == null) {\n\t\t\tthrow new Error('Trello issues must have a board project to be encoded');\n\t\t}\n\n\t\tprojectId = entity.project.id;\n\t\t// Trello currently exposes the board but not a separate workspace/org id here. Reuse the board id in\n\t\t// both serialization slots so branch associations remain round-trippable until the upstream shape grows.\n\t\taccountOrOrgId = entity.project.resourceId || entity.project.id;\n\t} else if (\n\t\tprovider === EntityIdentifierProviderType.Bitbucket ||\n\t\tprovider === EntityIdentifierProviderType.BitbucketServer\n\t) {\n\t\trepoId = isLaunchpadItem(entity) ? entity.underlyingPullRequest?.repository?.id : entity.repository?.id;\n\t}\n\n\tlet entityId = isLaunchpadItem(entity) ? entity.graphQLId! : entity.nodeId!;\n\tif (\n\t\tprovider === EntityIdentifierProviderType.Azure ||\n\t\tprovider === EntityIdentifierProviderType.AzureDevOpsServer\n\t) {\n\t\tentityId = (isLaunchpadItem(entity) ? entity.underlyingPullRequest?.id : entity.id) as string;\n\t}\n\n\t// `AnyEntityIdentifierInput` includes the catch-all `EntityIdentifier`\n\t// variant which requires all fields, while each provider-specific variant\n\t// requires a different subset. The function builds a polymorphic value\n\t// that's correct at runtime per `provider` but the literal can't be\n\t// structurally narrowed to any single variant. The 2-step cast through\n\t// `unknown` is the documented escape for this discriminated-union pattern.\n\treturn {\n\t\taccountOrOrgId: accountOrOrgId,\n\t\torganizationName: organizationName, // needed for Azure issues and PRs, once supported\n\t\tprojectId: projectId,\n\t\trepoId: repoId ?? null, // needed for Azure and BitBucket PRs, once supported\n\t\tresourceId: resourceId, // needed for Jira issues\n\t\tprovider: provider,\n\t\tentityType: entityType,\n\t\tversion: EntityVersion.One,\n\t\tdomain: domain,\n\t\tentityId: entityId,\n\t} as unknown as AnyEntityIdentifierInput;\n}\n\nexport function getProviderIdFromEntityIdentifier(\n\tentityIdentifier: EntityIdentifier | AnyEntityIdentifierInput | GitConfigEntityIdentifier,\n): IntegrationIds | undefined {\n\tswitch (entityIdentifier.provider) {\n\t\tcase EntityIdentifierProviderType.Github:\n\t\t\treturn GitCloudHostIntegrationId.GitHub;\n\t\tcase EntityIdentifierProviderType.GithubEnterprise:\n\t\t\treturn GitSelfManagedHostIntegrationId.CloudGitHubEnterprise;\n\t\tcase EntityIdentifierProviderType.Gitlab:\n\t\t\treturn GitCloudHostIntegrationId.GitLab;\n\t\tcase EntityIdentifierProviderType.GitlabSelfHosted:\n\t\t\treturn GitSelfManagedHostIntegrationId.CloudGitLabSelfHosted;\n\t\tcase EntityIdentifierProviderType.Jira:\n\t\t\treturn IssuesCloudHostIntegrationId.Jira;\n\t\tcase EntityIdentifierProviderType.JiraServer:\n\t\t\treturn IssuesSelfManagedHostIntegrationId.JiraServer;\n\t\tcase EntityIdentifierProviderType.Linear:\n\t\t\treturn IssuesCloudHostIntegrationId.Linear;\n\t\tcase EntityIdentifierProviderType.Trello:\n\t\t\treturn IssuesCloudHostIntegrationId.Trello;\n\t\tcase EntityIdentifierProviderType.Azure:\n\t\t\treturn GitCloudHostIntegrationId.AzureDevOps;\n\t\tcase EntityIdentifierProviderType.AzureDevOpsServer:\n\t\t\treturn GitSelfManagedHostIntegrationId.AzureDevOpsServer;\n\t\tcase EntityIdentifierProviderType.Bitbucket:\n\t\t\treturn GitCloudHostIntegrationId.Bitbucket;\n\t\tcase EntityIdentifierProviderType.BitbucketServer:\n\t\t\treturn isGitConfigEntityIdentifier(entityIdentifier) && entityIdentifier.metadata.isCloudEnterprise\n\t\t\t\t? GitSelfManagedHostIntegrationId.BitbucketServer\n\t\t\t\t: undefined;\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n}\n\nfunction fromStringToEntityIdentifierProviderType(\n\tstr: string,\n): (typeof EntityIdentifierProviderType)[keyof typeof EntityIdentifierProviderType] {\n\tswitch (str) {\n\t\tcase 'github':\n\t\t\treturn EntityIdentifierProviderType.Github;\n\t\tcase 'cloud-github-enterprise':\n\t\t\treturn EntityIdentifierProviderType.GithubEnterprise;\n\t\tcase 'cloud-gitlab-self-hosted':\n\t\t\treturn EntityIdentifierProviderType.GitlabSelfHosted;\n\t\tcase 'gitlab':\n\t\t\treturn EntityIdentifierProviderType.Gitlab;\n\t\tcase 'jira':\n\t\t\treturn EntityIdentifierProviderType.Jira;\n\t\tcase 'jira-server':\n\t\t\treturn EntityIdentifierProviderType.JiraServer;\n\t\tcase 'linear':\n\t\t\treturn EntityIdentifierProviderType.Linear;\n\t\tcase 'trello':\n\t\t\treturn EntityIdentifierProviderType.Trello;\n\t\tcase 'azure':\n\t\tcase 'azureDevOps':\n\t\tcase 'azure-devops':\n\t\t\treturn EntityIdentifierProviderType.Azure;\n\t\tcase GitSelfManagedHostIntegrationId.AzureDevOpsServer:\n\t\t\treturn EntityIdentifierProviderType.AzureDevOpsServer;\n\t\tcase 'bitbucket':\n\t\t\treturn EntityIdentifierProviderType.Bitbucket;\n\t\tcase 'bitbucket-server':\n\t\t\treturn EntityIdentifierProviderType.BitbucketServer;\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown provider type '${str}'`);\n\t}\n}\n\nexport function encodeIssueOrPullRequestForGitConfig(\n\tentity: Issue | PullRequest,\n\towner: RepositoryDescriptor | IssueResourceDescriptor,\n): GitConfigEntityIdentifier {\n\tconst encodedOwner: GitConfigEntityIdentifier['metadata']['owner'] = {\n\t\tkey: owner.key,\n\t\tname: owner.name,\n\t\tid: undefined,\n\t\towner: undefined,\n\t};\n\tif (isRepositoryDescriptor(owner)) {\n\t\tencodedOwner.owner = owner.owner;\n\t} else if (isIssueResourceDescriptor(owner)) {\n\t\tencodedOwner.id = owner.id;\n\t} else {\n\t\tthrow new Error('Invalid owner');\n\t}\n\n\treturn {\n\t\t...getEntityIdentifierInput(entity),\n\t\tmetadata: {\n\t\t\tid: entity.id,\n\t\t\towner: encodedOwner,\n\t\t\tcreatedDate: new Date().toISOString(),\n\t\t\tisCloudEnterprise: isCloudGitSelfManagedHostIntegrationId(entity.provider.id as IntegrationIds),\n\t\t},\n\t};\n}\n\nexport function isGitConfigEntityIdentifier(entity: unknown): entity is GitConfigEntityIdentifier {\n\treturn (\n\t\tentity != null &&\n\t\ttypeof entity === 'object' &&\n\t\t'provider' in entity &&\n\t\tentity.provider != null &&\n\t\t'entityType' in entity &&\n\t\tentity.entityType != null &&\n\t\t'version' in entity &&\n\t\tentity.version != null &&\n\t\t'entityId' in entity &&\n\t\tentity.entityId != null &&\n\t\t'metadata' in entity &&\n\t\tentity.metadata != null &&\n\t\ttypeof entity.metadata === 'object' &&\n\t\t'id' in entity.metadata &&\n\t\tentity.metadata.id != null &&\n\t\t'owner' in entity.metadata &&\n\t\tentity.metadata.owner != null &&\n\t\t'createdDate' in entity.metadata &&\n\t\tentity.metadata.createdDate != null\n\t);\n}\n\nexport function isGitConfigEntityIdentifiers(entities: unknown): entities is GitConfigEntityIdentifier[] {\n\treturn Array.isArray(entities) && entities.every(entity => isGitConfigEntityIdentifier(entity));\n}\n\nexport function decodeEntityIdentifiersFromGitConfig(str: string): GitConfigEntityIdentifier[] {\n\tconst decoded = JSON.parse(str);\n\n\tif (!isGitConfigEntityIdentifiers(decoded)) {\n\t\tdebugger;\n\t\tLogger.error('Invalid entity identifiers in git config');\n\t\treturn [];\n\t}\n\n\tfor (const decodedEntity of decoded) {\n\t\tif (\n\t\t\tdecodedEntity.provider === EntityIdentifierProviderType.Jira &&\n\t\t\t(decodedEntity.resourceId == null || decodedEntity.projectId == null)\n\t\t) {\n\t\t\tdebugger;\n\t\t\tLogger.error('Invalid Jira issue in git config');\n\t\t}\n\n\t\t// The host is the identity of a self-hosted issue (see `getEntityIdentifierInput`); without it the\n\t\t// identifier cannot be resolved against any instance and `getIssueFromGitConfigEntityIdentifier` drops it.\n\t\tif (\n\t\t\tdecodedEntity.provider === EntityIdentifierProviderType.JiraServer &&\n\t\t\t(getDomainFromEntityIdentifier(decodedEntity) == null || decodedEntity.projectId == null)\n\t\t) {\n\t\t\tdebugger;\n\t\t\tLogger.error('Invalid Jira Server issue in git config');\n\t\t}\n\t}\n\n\treturn decoded;\n}\n\n/**\n * The host a self-managed identifier names, or `undefined` for a cloud one (or a malformed self-managed one).\n * `domain` lives on some arms of `AnyEntityIdentifierInput` and on the catch-all, so the read is structural.\n */\nfunction getDomainFromEntityIdentifier(identifier: GitConfigEntityIdentifier): string | undefined {\n\tconst domain = 'domain' in identifier ? identifier.domain : undefined;\n\treturn typeof domain === 'string' && domain.trim().length > 0 ? domain : undefined;\n}\n\ninterface IssueResolvableIntegration {\n\tgetIssue(owner: unknown, id: string): Promise<Issue | undefined>;\n}\n\n/**\n * Resolves the issue a branch association names.\n *\n * `resolveIntegration` receives the identifier's `domain` alongside the integration id, so a host-keyed\n * provider resolves the instance the association was encoded for rather than whichever connection is primary\n * (#5872). It is `undefined` for a cloud provider, which has a single host.\n */\nexport async function getIssueFromGitConfigEntityIdentifier(\n\tresolveIntegration: (id: IntegrationIds, domain?: string) => Promise<IssueResolvableIntegration | undefined>,\n\tidentifier: GitConfigEntityIdentifier,\n\toptions?: {\n\t\t/** Legacy git-host associations need configured connections to prove their host is unambiguous. */\n\t\tgetConfiguredIntegrations?: (id: IntegrationIds) => readonly { domain?: string }[];\n\t\t/** Only return a value already in the local cache. No remote fetch — returns undefined on cache miss. */\n\t\tcached?: boolean;\n\t\t/**\n\t\t * Host-supplied cache reader used when {@link cached} is set. The package is cache-agnostic, so the\n\t\t * host (which owns the cache) provides this to satisfy a cache-only read. When omitted, `cached`\n\t\t * yields undefined rather than falling through to a remote fetch.\n\t\t */\n\t\tpeekCachedIssue?: (\n\t\t\tintegration: IssueResolvableIntegration | undefined,\n\t\t\tresource: ResourceDescriptor,\n\t\t\tid: string,\n\t\t) => Issue | undefined;\n\t},\n): Promise<Issue | undefined> {\n\tif (identifier.entityType !== EntityType.Issue) {\n\t\treturn undefined;\n\t}\n\n\t// TODO: Centralize where we represent all supported providers for issues\n\tif (\n\t\tidentifier.provider !== EntityIdentifierProviderType.Jira &&\n\t\tidentifier.provider !== EntityIdentifierProviderType.JiraServer &&\n\t\tidentifier.provider !== EntityIdentifierProviderType.Linear &&\n\t\tidentifier.provider !== EntityIdentifierProviderType.Github &&\n\t\tidentifier.provider !== EntityIdentifierProviderType.Gitlab &&\n\t\tidentifier.provider !== EntityIdentifierProviderType.GithubEnterprise &&\n\t\tidentifier.provider !== EntityIdentifierProviderType.GitlabSelfHosted &&\n\t\tidentifier.provider !== EntityIdentifierProviderType.Bitbucket &&\n\t\tidentifier.provider !== EntityIdentifierProviderType.BitbucketServer &&\n\t\tidentifier.provider !== EntityIdentifierProviderType.AzureDevOpsServer &&\n\t\tidentifier.provider !== EntityIdentifierProviderType.Azure &&\n\t\tidentifier.provider !== EntityIdentifierProviderType.Trello\n\t) {\n\t\treturn undefined;\n\t}\n\n\tconst integrationId = getProviderIdFromEntityIdentifier(identifier);\n\tif (integrationId == null) {\n\t\treturn undefined;\n\t}\n\n\tlet domain = getDomainFromEntityIdentifier(identifier);\n\tif (domain == null && isGitSelfManagedHostIntegrationId(integrationId)) {\n\t\tdomain = getSingleConfiguredDomain(options?.getConfiguredIntegrations?.(integrationId) ?? []);\n\t}\n\t// Hosts can share issue keys. Legacy git associations may omit the host, but can only be recovered when\n\t// configuration identifies exactly one; self-hosted tracker associations always require an explicit host.\n\tif (domain == null && isSelfManagedHostIntegrationId(integrationId)) {\n\t\tLogger.error(`Cannot resolve a '${integrationId}' issue from git config without an unambiguous domain`);\n\t\treturn undefined;\n\t}\n\n\tconst integration = await resolveIntegration(integrationId, domain);\n\n\tconst resource: ResourceDescriptor = {\n\t\tid: identifier.metadata.owner.id,\n\t\tkey: identifier.metadata.owner.key,\n\t\towner: identifier.metadata.owner.owner,\n\t\tname: identifier.metadata.owner.name,\n\t};\n\tconst remoteLookupId =\n\t\tidentifier.provider === EntityIdentifierProviderType.Trello ? identifier.entityId : identifier.metadata.id;\n\n\t// Cache-only read (no remote fetch). The package can't reach the host cache directly, so defer to the\n\t// host-supplied reader; without one, honor the no-fetch contract by returning undefined. For a cloud\n\t// provider the cache key is resource+id (the integration only affects the etag), so peek even when the\n\t// integration is unresolvable — a still-cached issue must survive an unconfigured/disconnected integration.\n\t// A self-managed host's key also names the host, which only a resolved integration can supply: without one\n\t// the peek would fall back to the unscoped key a cloud provider writes for the same resource, so skip it.\n\tif (options?.cached) {\n\t\tif (integration == null && isSelfManagedHostIntegrationId(integrationId)) return undefined;\n\n\t\tconst cachedIssue = options.peekCachedIssue?.(integration, resource, identifier.metadata.id);\n\t\tif (\n\t\t\tcachedIssue != null ||\n\t\t\t(identifier.provider !== EntityIdentifierProviderType.Trello &&\n\t\t\t\tidentifier.provider !== EntityIdentifierProviderType.Linear)\n\t\t) {\n\t\t\treturn cachedIssue;\n\t\t}\n\n\t\t// Two id generations coexist for these providers: Trello identifiers persisted before the stable-id\n\t\t// switch carry the board-local `idShort` in `metadata.id` while the cache is keyed by the stable card\n\t\t// id (`entityId`); Linear identifiers persisted before `Issue.id` became the human identifier carry\n\t\t// the UUID in `metadata.id` while fresh cache entries key by the identifier — and vice versa, the\n\t\t// UUID always survives in `entityId` (via `nodeId`). Peeking both keys resolves either generation.\n\t\treturn options.peekCachedIssue?.(integration, resource, identifier.entityId);\n\t}\n\n\tif (integration == null) {\n\t\treturn undefined;\n\t}\n\n\treturn integration.getIssue(resource, remoteLookupId);\n}\n\nexport function getIssueOwner(\n\tissue: IssueShape,\n): RepositoryDescriptor | IssueResourceDescriptor | AzureProjectInputDescriptor | undefined {\n\tconst isAzure = ['azure', GitCloudHostIntegrationId.AzureDevOps, 'azure-devops'].includes(issue.provider.id);\n\treturn issue.repository\n\t\t? {\n\t\t\t\tkey: `${issue.repository.owner}/${issue.repository.repo}`,\n\t\t\t\towner: issue.repository.owner,\n\t\t\t\tname: issue.repository.repo,\n\t\t\t}\n\t\t: issue.project\n\t\t\t? {\n\t\t\t\t\tkey: isAzure ? issue.project.id : issue.project.resourceId,\n\t\t\t\t\tid: isAzure ? issue.project.id : issue.project.resourceId,\n\t\t\t\t\towner: isAzure ? issue.project.resourceName : undefined,\n\t\t\t\t\tname: isAzure ? issue.project.name : issue.project.resourceName,\n\t\t\t\t}\n\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,aAAa,6BAA6B,UACrD,WAAW,aAAa,6BAA6B,QAEtD,OAAO;EAQR,OAAO,QAAQ,kBAAkB,aAAa,UAAU,WAAW,QAAQ;CAC5E;CAEA,IAAI,eAAe,MAClB;CAGD,OAAO,YAAY,SAAS,UAAU,cAAc;AACrD;AAEA,SAAgB,cACf,OAC2F;CAC3F,MAAM,UAAU;EAAC;;EAAgD;CAAc,CAAC,CAAC,SAAS,MAAM,SAAS,EAAE;CAC3G,OAAO,MAAM,aACV;EACA,KAAK,GAAG,MAAM,WAAW,MAAM,GAAG,MAAM,WAAW;EACnD,OAAO,MAAM,WAAW;EACxB,MAAM,MAAM,WAAW;CACxB,IACC,MAAM,UACL;EACA,KAAK,UAAU,MAAM,QAAQ,KAAK,MAAM,QAAQ;EAChD,IAAI,UAAU,MAAM,QAAQ,KAAK,MAAM,QAAQ;EAC/C,OAAO,UAAU,MAAM,QAAQ,eAAe,KAAA;EAC9C,MAAM,UAAU,MAAM,QAAQ,OAAO,MAAM,QAAQ;CACpD,IACC,KAAA;AACL"}
1
+ {"version":3,"file":"utils.js","names":[],"sources":["../../../../../plus/integrations/src/providers/utils.ts"],"sourcesContent":["import type { AnyEntityIdentifierInput, EntityIdentifier } from '@gitkraken/provider-apis';\nimport type { Issue, IssueShape } from '@gitlens/git/models/issue.js';\nimport type { IssueOrPullRequest } from '@gitlens/git/models/issueOrPullRequest.js';\nimport type { PullRequest } from '@gitlens/git/models/pullRequest.js';\nimport type {\n\tIssueResourceDescriptor,\n\tRepositoryDescriptor,\n\tResourceDescriptor,\n} from '@gitlens/git/models/resourceDescriptor.js';\nimport { isIssueResourceDescriptor, isRepositoryDescriptor } from '@gitlens/git/utils/resourceDescriptor.utils.js';\nimport { Logger } from '@gitlens/utils/logger.js';\nimport type { IntegrationIds } from '../constants.js';\nimport {\n\tGitCloudHostIntegrationId,\n\tGitSelfManagedHostIntegrationId,\n\tIssuesCloudHostIntegrationId,\n\tIssuesSelfManagedHostIntegrationId,\n} from '../constants.js';\nimport { getSingleConfiguredDomain } from '../utils/domain.utils.js';\nimport {\n\tisCloudGitSelfManagedHostIntegrationId,\n\tisGitSelfManagedHostIntegrationId,\n\tisSelfManagedHostIntegrationId,\n} from '../utils/integration.utils.js';\nimport type { AzureProjectInputDescriptor } from './azure/models.js';\nimport type { GitConfigEntityIdentifier } from './models.js';\nimport { isGitHubDotCom, isGitLabDotCom } from './models.js';\n\n// Local runtime copies of the `@gitkraken/provider-apis` entity-identifier string enums. Exported so the\n// enum-parity test can guard them against upstream drift. `EntityVersion` is an intentional subset: the\n// package only ever writes version 1, so the parity test asserts each local entry matches the SDK rather\n// than a full mirror.\nexport const EntityIdentifierProviderType = {\n\tAzure: 'azure',\n\tAzureDevOpsServer: 'azureDevOpsServer',\n\tGithub: 'github',\n\tGithubEnterprise: 'githubEnterprise',\n\tGitlab: 'gitlab',\n\tGitlabSelfHosted: 'gitlabSelfHosted',\n\tBitbucket: 'bitbucket',\n\tBitbucketServer: 'bitbucketServer',\n\tJira: 'jira',\n\tJiraServer: 'jiraServer',\n\tLinear: 'linear',\n\tTrello: 'trello',\n\tAsana: 'asana',\n} as const;\n\nexport const EntityType = {\n\tPullRequest: 'pr',\n\tIssue: 'issue',\n} as const;\n\nexport const EntityVersion = {\n\tOne: '1',\n} as const;\n\n/**\n * Forward-compatible structural shape of the host's `LaunchpadItem`. The package\n * uses this for narrowing inside {@link getEntityIdentifierInput}; the host's\n * actual `LaunchpadItem` (in `src/plus/launchpad/launchpadProvider.ts`) carries\n * many more fields. The declared shape only includes fields integrations inspect.\n */\ntype LaunchpadItem = {\n\tuuid: string;\n\ttype: 'issue' | 'pullrequest';\n\tgraphQLId?: string;\n\tprovider: { id: string; domain?: string };\n\tunderlyingPullRequest?: {\n\t\tid: string;\n\t\tproject?: { id: string; resourceName?: string };\n\t\trepository?: { id?: string };\n\t};\n};\n\nfunction isLaunchpadItem(item: IssueOrPullRequest | LaunchpadItem): item is LaunchpadItem {\n\treturn (item as LaunchpadItem).uuid !== undefined;\n}\n\nfunction isIssue(item: IssueOrPullRequest | LaunchpadItem): item is Issue {\n\treturn item.type === 'issue';\n}\n\nexport function getEntityIdentifierInput(entity: Issue | PullRequest | LaunchpadItem): AnyEntityIdentifierInput {\n\tlet entityType: (typeof EntityType)[keyof typeof EntityType] = EntityType.Issue;\n\tif (entity.type === 'pullrequest') {\n\t\tentityType = EntityType.PullRequest;\n\t}\n\n\tlet provider = fromStringToEntityIdentifierProviderType(entity.provider.id);\n\tlet domain = null;\n\tif (provider === EntityIdentifierProviderType.Github && !isGitHubDotCom(entity.provider.domain)) {\n\t\tprovider = EntityIdentifierProviderType.GithubEnterprise;\n\t\tdomain = entity.provider.domain ?? null;\n\t}\n\tif (provider === EntityIdentifierProviderType.Gitlab && !isGitLabDotCom(entity.provider.domain)) {\n\t\tprovider = EntityIdentifierProviderType.GitlabSelfHosted;\n\t\tdomain = entity.provider.domain ?? null;\n\t}\n\t// An issue read through the self-managed integration already carries the enterprise id, so the rewrites above\n\t// never see it and its host was dropped — for exactly the issues that have one. A branch association has to\n\t// name it to be read back from the right server, since two hosts routinely share `owner/repo#number`. Issues\n\t// only: a pull request's identifier is also its Launchpad uuid, which keys stored pins and snoozes, so giving it\n\t// a host would orphan every existing one.\n\tif (\n\t\tentityType === EntityType.Issue &&\n\t\tdomain == null &&\n\t\t(provider === EntityIdentifierProviderType.GithubEnterprise ||\n\t\t\tprovider === EntityIdentifierProviderType.GitlabSelfHosted ||\n\t\t\tprovider === EntityIdentifierProviderType.BitbucketServer)\n\t) {\n\t\tdomain = entity.provider.domain ?? null;\n\t}\n\tif (provider === EntityIdentifierProviderType.AzureDevOpsServer) {\n\t\tdomain = entity.provider.domain ?? null;\n\t}\n\tif (provider === EntityIdentifierProviderType.JiraServer) {\n\t\t// The host is the identity here, not a decoration: two self-hosted instances routinely issue the same\n\t\t// project and issue keys, so an identifier without it collides across them. The SDK's\n\t\t// `JiraIssueEntityIdentifierInput` says as much — its `JiraServer` arm requires `domain` where the\n\t\t// `Jira` arm requires `resourceId`.\n\t\tdomain = entity.provider.domain ?? null;\n\t}\n\n\tlet projectId = null;\n\tlet resourceId = null;\n\tlet accountOrOrgId = null;\n\tlet organizationName = null;\n\tlet repoId = null;\n\tif (provider === EntityIdentifierProviderType.Jira) {\n\t\tif (!isIssue(entity) || entity.project == null) {\n\t\t\tthrow new Error('Jira issues must have a project');\n\t\t}\n\n\t\tprojectId = entity.project.id;\n\t\tresourceId = entity.project.resourceId;\n\t} else if (provider === EntityIdentifierProviderType.JiraServer) {\n\t\tif (!isIssue(entity) || entity.project == null) {\n\t\t\tthrow new Error('Jira Server issues must have a project');\n\t\t}\n\n\t\t// `projectId` only; the SDK's `JiraServer` arm carries `domain` where Cloud carries `resourceId`, and a\n\t\t// self-hosted instance's single synthetic resource is the host the `domain` above already names.\n\t\tprojectId = entity.project.id;\n\t} else if (\n\t\tprovider === EntityIdentifierProviderType.Azure ||\n\t\tprovider === EntityIdentifierProviderType.AzureDevOpsServer\n\t) {\n\t\tconst project = isLaunchpadItem(entity) ? entity.underlyingPullRequest?.project : entity.project;\n\t\tif (project == null) {\n\t\t\tthrow new Error('Azure issues and PRs must have a project to be encoded');\n\t\t}\n\n\t\tprojectId = project.id;\n\t\torganizationName = project.resourceName;\n\t\trepoId = isLaunchpadItem(entity) ? entity.underlyingPullRequest?.repository?.id : entity.repository?.id;\n\t\tif (entityType === EntityType.PullRequest && repoId == null) {\n\t\t\tthrow new Error('Azure PRs must have a repository ID to be encoded');\n\t\t}\n\t} else if (provider === EntityIdentifierProviderType.Trello) {\n\t\tif (!isIssue(entity) || entity.project == null) {\n\t\t\tthrow new Error('Trello issues must have a board project to be encoded');\n\t\t}\n\n\t\tprojectId = entity.project.id;\n\t\t// Trello currently exposes the board but not a separate workspace/org id here. Reuse the board id in\n\t\t// both serialization slots so branch associations remain round-trippable until the upstream shape grows.\n\t\taccountOrOrgId = entity.project.resourceId || entity.project.id;\n\t} else if (provider === EntityIdentifierProviderType.Asana) {\n\t\tif (!isIssue(entity) || !entity.project?.resourceId) {\n\t\t\tthrow new Error('Asana issues must have a workspace to be encoded');\n\t\t}\n\n\t\t// An Asana task is addressed by its gid alone; the workspace is what the SDK's identifier keys it under.\n\t\taccountOrOrgId = entity.project.resourceId;\n\t} else if (\n\t\tprovider === EntityIdentifierProviderType.Bitbucket ||\n\t\tprovider === EntityIdentifierProviderType.BitbucketServer\n\t) {\n\t\trepoId = isLaunchpadItem(entity) ? entity.underlyingPullRequest?.repository?.id : entity.repository?.id;\n\t}\n\n\tlet entityId = isLaunchpadItem(entity) ? entity.graphQLId! : entity.nodeId!;\n\tif (\n\t\tprovider === EntityIdentifierProviderType.Azure ||\n\t\tprovider === EntityIdentifierProviderType.AzureDevOpsServer\n\t) {\n\t\tentityId = (isLaunchpadItem(entity) ? entity.underlyingPullRequest?.id : entity.id) as string;\n\t}\n\n\t// `AnyEntityIdentifierInput` includes the catch-all `EntityIdentifier`\n\t// variant which requires all fields, while each provider-specific variant\n\t// requires a different subset. The function builds a polymorphic value\n\t// that's correct at runtime per `provider` but the literal can't be\n\t// structurally narrowed to any single variant. The 2-step cast through\n\t// `unknown` is the documented escape for this discriminated-union pattern.\n\treturn {\n\t\taccountOrOrgId: accountOrOrgId,\n\t\torganizationName: organizationName, // needed for Azure issues and PRs, once supported\n\t\tprojectId: projectId,\n\t\trepoId: repoId ?? null, // needed for Azure and BitBucket PRs, once supported\n\t\tresourceId: resourceId, // needed for Jira issues\n\t\tprovider: provider,\n\t\tentityType: entityType,\n\t\tversion: EntityVersion.One,\n\t\tdomain: domain,\n\t\tentityId: entityId,\n\t} as unknown as AnyEntityIdentifierInput;\n}\n\nexport function getProviderIdFromEntityIdentifier(\n\tentityIdentifier: EntityIdentifier | AnyEntityIdentifierInput | GitConfigEntityIdentifier,\n): IntegrationIds | undefined {\n\tswitch (entityIdentifier.provider) {\n\t\tcase EntityIdentifierProviderType.Github:\n\t\t\treturn GitCloudHostIntegrationId.GitHub;\n\t\tcase EntityIdentifierProviderType.GithubEnterprise:\n\t\t\treturn GitSelfManagedHostIntegrationId.CloudGitHubEnterprise;\n\t\tcase EntityIdentifierProviderType.Gitlab:\n\t\t\treturn GitCloudHostIntegrationId.GitLab;\n\t\tcase EntityIdentifierProviderType.GitlabSelfHosted:\n\t\t\treturn GitSelfManagedHostIntegrationId.CloudGitLabSelfHosted;\n\t\tcase EntityIdentifierProviderType.Jira:\n\t\t\treturn IssuesCloudHostIntegrationId.Jira;\n\t\tcase EntityIdentifierProviderType.JiraServer:\n\t\t\treturn IssuesSelfManagedHostIntegrationId.JiraServer;\n\t\tcase EntityIdentifierProviderType.Linear:\n\t\t\treturn IssuesCloudHostIntegrationId.Linear;\n\t\tcase EntityIdentifierProviderType.Trello:\n\t\t\treturn IssuesCloudHostIntegrationId.Trello;\n\t\tcase EntityIdentifierProviderType.Asana:\n\t\t\treturn IssuesCloudHostIntegrationId.Asana;\n\t\tcase EntityIdentifierProviderType.Azure:\n\t\t\treturn GitCloudHostIntegrationId.AzureDevOps;\n\t\tcase EntityIdentifierProviderType.AzureDevOpsServer:\n\t\t\treturn GitSelfManagedHostIntegrationId.AzureDevOpsServer;\n\t\tcase EntityIdentifierProviderType.Bitbucket:\n\t\t\treturn GitCloudHostIntegrationId.Bitbucket;\n\t\tcase EntityIdentifierProviderType.BitbucketServer:\n\t\t\treturn isGitConfigEntityIdentifier(entityIdentifier) && entityIdentifier.metadata.isCloudEnterprise\n\t\t\t\t? GitSelfManagedHostIntegrationId.BitbucketServer\n\t\t\t\t: undefined;\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n}\n\nfunction fromStringToEntityIdentifierProviderType(\n\tstr: string,\n): (typeof EntityIdentifierProviderType)[keyof typeof EntityIdentifierProviderType] {\n\tswitch (str) {\n\t\tcase 'github':\n\t\t\treturn EntityIdentifierProviderType.Github;\n\t\tcase 'cloud-github-enterprise':\n\t\t\treturn EntityIdentifierProviderType.GithubEnterprise;\n\t\tcase 'cloud-gitlab-self-hosted':\n\t\t\treturn EntityIdentifierProviderType.GitlabSelfHosted;\n\t\tcase 'gitlab':\n\t\t\treturn EntityIdentifierProviderType.Gitlab;\n\t\tcase 'jira':\n\t\t\treturn EntityIdentifierProviderType.Jira;\n\t\tcase 'jira-server':\n\t\t\treturn EntityIdentifierProviderType.JiraServer;\n\t\tcase 'linear':\n\t\t\treturn EntityIdentifierProviderType.Linear;\n\t\tcase 'trello':\n\t\t\treturn EntityIdentifierProviderType.Trello;\n\t\tcase 'asana':\n\t\t\treturn EntityIdentifierProviderType.Asana;\n\t\tcase 'azure':\n\t\tcase 'azureDevOps':\n\t\tcase 'azure-devops':\n\t\t\treturn EntityIdentifierProviderType.Azure;\n\t\tcase GitSelfManagedHostIntegrationId.AzureDevOpsServer:\n\t\t\treturn EntityIdentifierProviderType.AzureDevOpsServer;\n\t\tcase 'bitbucket':\n\t\t\treturn EntityIdentifierProviderType.Bitbucket;\n\t\tcase 'bitbucket-server':\n\t\t\treturn EntityIdentifierProviderType.BitbucketServer;\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown provider type '${str}'`);\n\t}\n}\n\nexport function encodeIssueOrPullRequestForGitConfig(\n\tentity: Issue | PullRequest,\n\towner: RepositoryDescriptor | IssueResourceDescriptor,\n): GitConfigEntityIdentifier {\n\tconst encodedOwner: GitConfigEntityIdentifier['metadata']['owner'] = {\n\t\tkey: owner.key,\n\t\tname: owner.name,\n\t\tid: undefined,\n\t\towner: undefined,\n\t};\n\tif (isRepositoryDescriptor(owner)) {\n\t\tencodedOwner.owner = owner.owner;\n\t} else if (isIssueResourceDescriptor(owner)) {\n\t\tencodedOwner.id = owner.id;\n\t} else {\n\t\tthrow new Error('Invalid owner');\n\t}\n\n\treturn {\n\t\t...getEntityIdentifierInput(entity),\n\t\tmetadata: {\n\t\t\tid: entity.id,\n\t\t\towner: encodedOwner,\n\t\t\tcreatedDate: new Date().toISOString(),\n\t\t\tisCloudEnterprise: isCloudGitSelfManagedHostIntegrationId(entity.provider.id as IntegrationIds),\n\t\t},\n\t};\n}\n\nexport function isGitConfigEntityIdentifier(entity: unknown): entity is GitConfigEntityIdentifier {\n\treturn (\n\t\tentity != null &&\n\t\ttypeof entity === 'object' &&\n\t\t'provider' in entity &&\n\t\tentity.provider != null &&\n\t\t'entityType' in entity &&\n\t\tentity.entityType != null &&\n\t\t'version' in entity &&\n\t\tentity.version != null &&\n\t\t'entityId' in entity &&\n\t\tentity.entityId != null &&\n\t\t'metadata' in entity &&\n\t\tentity.metadata != null &&\n\t\ttypeof entity.metadata === 'object' &&\n\t\t'id' in entity.metadata &&\n\t\tentity.metadata.id != null &&\n\t\t'owner' in entity.metadata &&\n\t\tentity.metadata.owner != null &&\n\t\t'createdDate' in entity.metadata &&\n\t\tentity.metadata.createdDate != null\n\t);\n}\n\nexport function isGitConfigEntityIdentifiers(entities: unknown): entities is GitConfigEntityIdentifier[] {\n\treturn Array.isArray(entities) && entities.every(entity => isGitConfigEntityIdentifier(entity));\n}\n\nexport function decodeEntityIdentifiersFromGitConfig(str: string): GitConfigEntityIdentifier[] {\n\tconst decoded = JSON.parse(str);\n\n\tif (!isGitConfigEntityIdentifiers(decoded)) {\n\t\tdebugger;\n\t\tLogger.error('Invalid entity identifiers in git config');\n\t\treturn [];\n\t}\n\n\tfor (const decodedEntity of decoded) {\n\t\tif (\n\t\t\tdecodedEntity.provider === EntityIdentifierProviderType.Jira &&\n\t\t\t(decodedEntity.resourceId == null || decodedEntity.projectId == null)\n\t\t) {\n\t\t\tdebugger;\n\t\t\tLogger.error('Invalid Jira issue in git config');\n\t\t}\n\n\t\t// The host is the identity of a self-hosted issue (see `getEntityIdentifierInput`); without it the\n\t\t// identifier cannot be resolved against any instance and `getIssueFromGitConfigEntityIdentifier` drops it.\n\t\tif (\n\t\t\tdecodedEntity.provider === EntityIdentifierProviderType.JiraServer &&\n\t\t\t(getDomainFromEntityIdentifier(decodedEntity) == null || decodedEntity.projectId == null)\n\t\t) {\n\t\t\tdebugger;\n\t\t\tLogger.error('Invalid Jira Server issue in git config');\n\t\t}\n\t}\n\n\treturn decoded;\n}\n\n/**\n * The host a self-managed identifier names, or `undefined` for a cloud one (or a malformed self-managed one).\n * `domain` lives on some arms of `AnyEntityIdentifierInput` and on the catch-all, so the read is structural.\n */\nfunction getDomainFromEntityIdentifier(identifier: GitConfigEntityIdentifier): string | undefined {\n\tconst domain = 'domain' in identifier ? identifier.domain : undefined;\n\treturn typeof domain === 'string' && domain.trim().length > 0 ? domain : undefined;\n}\n\ninterface IssueResolvableIntegration {\n\tgetIssue(owner: unknown, id: string): Promise<Issue | undefined>;\n}\n\n/**\n * Resolves the issue a branch association names.\n *\n * `resolveIntegration` receives the identifier's `domain` alongside the integration id, so a host-keyed\n * provider resolves the instance the association was encoded for rather than whichever connection is primary\n * (#5872). It is `undefined` for a cloud provider, which has a single host.\n */\nexport async function getIssueFromGitConfigEntityIdentifier(\n\tresolveIntegration: (id: IntegrationIds, domain?: string) => Promise<IssueResolvableIntegration | undefined>,\n\tidentifier: GitConfigEntityIdentifier,\n\toptions?: {\n\t\t/** Legacy git-host associations need configured connections to prove their host is unambiguous. */\n\t\tgetConfiguredIntegrations?: (id: IntegrationIds) => readonly { domain?: string }[];\n\t\t/** Only return a value already in the local cache. No remote fetch — returns undefined on cache miss. */\n\t\tcached?: boolean;\n\t\t/**\n\t\t * Host-supplied cache reader used when {@link cached} is set. The package is cache-agnostic, so the\n\t\t * host (which owns the cache) provides this to satisfy a cache-only read. When omitted, `cached`\n\t\t * yields undefined rather than falling through to a remote fetch.\n\t\t */\n\t\tpeekCachedIssue?: (\n\t\t\tintegration: IssueResolvableIntegration | undefined,\n\t\t\tresource: ResourceDescriptor,\n\t\t\tid: string,\n\t\t) => Issue | undefined;\n\t},\n): Promise<Issue | undefined> {\n\tif (identifier.entityType !== EntityType.Issue) {\n\t\treturn undefined;\n\t}\n\n\t// TODO: Centralize where we represent all supported providers for issues\n\tif (\n\t\tidentifier.provider !== EntityIdentifierProviderType.Jira &&\n\t\tidentifier.provider !== EntityIdentifierProviderType.JiraServer &&\n\t\tidentifier.provider !== EntityIdentifierProviderType.Linear &&\n\t\tidentifier.provider !== EntityIdentifierProviderType.Github &&\n\t\tidentifier.provider !== EntityIdentifierProviderType.Gitlab &&\n\t\tidentifier.provider !== EntityIdentifierProviderType.GithubEnterprise &&\n\t\tidentifier.provider !== EntityIdentifierProviderType.GitlabSelfHosted &&\n\t\tidentifier.provider !== EntityIdentifierProviderType.Bitbucket &&\n\t\tidentifier.provider !== EntityIdentifierProviderType.BitbucketServer &&\n\t\tidentifier.provider !== EntityIdentifierProviderType.AzureDevOpsServer &&\n\t\tidentifier.provider !== EntityIdentifierProviderType.Azure &&\n\t\tidentifier.provider !== EntityIdentifierProviderType.Trello &&\n\t\tidentifier.provider !== EntityIdentifierProviderType.Asana\n\t) {\n\t\treturn undefined;\n\t}\n\n\tconst integrationId = getProviderIdFromEntityIdentifier(identifier);\n\tif (integrationId == null) {\n\t\treturn undefined;\n\t}\n\n\tlet domain = getDomainFromEntityIdentifier(identifier);\n\tif (domain == null && isGitSelfManagedHostIntegrationId(integrationId)) {\n\t\tdomain = getSingleConfiguredDomain(options?.getConfiguredIntegrations?.(integrationId) ?? []);\n\t}\n\t// Hosts can share issue keys. Legacy git associations may omit the host, but can only be recovered when\n\t// configuration identifies exactly one; self-hosted tracker associations always require an explicit host.\n\tif (domain == null && isSelfManagedHostIntegrationId(integrationId)) {\n\t\tLogger.error(`Cannot resolve a '${integrationId}' issue from git config without an unambiguous domain`);\n\t\treturn undefined;\n\t}\n\n\tconst integration = await resolveIntegration(integrationId, domain);\n\n\tconst resource: ResourceDescriptor = {\n\t\tid: identifier.metadata.owner.id,\n\t\tkey: identifier.metadata.owner.key,\n\t\towner: identifier.metadata.owner.owner,\n\t\tname: identifier.metadata.owner.name,\n\t};\n\tconst remoteLookupId =\n\t\tidentifier.provider === EntityIdentifierProviderType.Trello ? identifier.entityId : identifier.metadata.id;\n\n\t// Cache-only read (no remote fetch). The package can't reach the host cache directly, so defer to the\n\t// host-supplied reader; without one, honor the no-fetch contract by returning undefined. For a cloud\n\t// provider the cache key is resource+id (the integration only affects the etag), so peek even when the\n\t// integration is unresolvable — a still-cached issue must survive an unconfigured/disconnected integration.\n\t// A self-managed host's key also names the host, which only a resolved integration can supply: without one\n\t// the peek would fall back to the unscoped key a cloud provider writes for the same resource, so skip it.\n\tif (options?.cached) {\n\t\tif (integration == null && isSelfManagedHostIntegrationId(integrationId)) return undefined;\n\n\t\tconst cachedIssue = options.peekCachedIssue?.(integration, resource, identifier.metadata.id);\n\t\tif (\n\t\t\tcachedIssue != null ||\n\t\t\t(identifier.provider !== EntityIdentifierProviderType.Trello &&\n\t\t\t\tidentifier.provider !== EntityIdentifierProviderType.Linear)\n\t\t) {\n\t\t\treturn cachedIssue;\n\t\t}\n\n\t\t// Two id generations coexist for these providers: Trello identifiers persisted before the stable-id\n\t\t// switch carry the board-local `idShort` in `metadata.id` while the cache is keyed by the stable card\n\t\t// id (`entityId`); Linear identifiers persisted before `Issue.id` became the human identifier carry\n\t\t// the UUID in `metadata.id` while fresh cache entries key by the identifier — and vice versa, the\n\t\t// UUID always survives in `entityId` (via `nodeId`). Peeking both keys resolves either generation.\n\t\treturn options.peekCachedIssue?.(integration, resource, identifier.entityId);\n\t}\n\n\tif (integration == null) {\n\t\treturn undefined;\n\t}\n\n\treturn integration.getIssue(resource, remoteLookupId);\n}\n\nexport function getIssueOwner(\n\tissue: IssueShape,\n): RepositoryDescriptor | IssueResourceDescriptor | AzureProjectInputDescriptor | undefined {\n\tconst isAzure = ['azure', GitCloudHostIntegrationId.AzureDevOps, 'azure-devops'].includes(issue.provider.id);\n\treturn issue.repository\n\t\t? {\n\t\t\t\tkey: `${issue.repository.owner}/${issue.repository.repo}`,\n\t\t\t\towner: issue.repository.owner,\n\t\t\t\tname: issue.repository.repo,\n\t\t\t}\n\t\t: issue.project\n\t\t\t? {\n\t\t\t\t\tkey: isAzure ? issue.project.id : issue.project.resourceId,\n\t\t\t\t\tid: isAzure ? issue.project.id : issue.project.resourceId,\n\t\t\t\t\towner: isAzure ? issue.project.resourceName : undefined,\n\t\t\t\t\tname: isAzure ? issue.project.name : issue.project.resourceName,\n\t\t\t\t}\n\t\t\t: undefined;\n}\n"],"mappings":";;;;;;;AAgCA,MAAa,+BAA+B;CAC3C,OAAO;CACP,mBAAmB;CACnB,QAAQ;CACR,kBAAkB;CAClB,QAAQ;CACR,kBAAkB;CAClB,WAAW;CACX,iBAAiB;CACjB,MAAM;CACN,YAAY;CACZ,QAAQ;CACR,QAAQ;CACR,OAAO;AACR;AAEA,MAAa,aAAa;CACzB,aAAa;CACb,OAAO;AACR;AAEA,MAAa,gBAAgB,EAC5B,KAAK,IACN;AAoBA,SAAS,gBAAgB,MAAiE;CACzF,OAAQ,KAAuB,SAAS,KAAA;AACzC;AAEA,SAAS,QAAQ,MAAyD;CACzE,OAAO,KAAK,SAAS;AACtB;AAEA,SAAgB,yBAAyB,QAAuE;CAC/G,IAAI,aAA2D,WAAW;CAC1E,IAAI,OAAO,SAAS,eACnB,aAAa,WAAW;CAGzB,IAAI,WAAW,yCAAyC,OAAO,SAAS,EAAE;CAC1E,IAAI,SAAS;CACb,IAAI,aAAa,6BAA6B,UAAU,CAAC,eAAe,OAAO,SAAS,MAAM,GAAG;EAChG,WAAW,6BAA6B;EACxC,SAAS,OAAO,SAAS,UAAU;CACpC;CACA,IAAI,aAAa,6BAA6B,UAAU,CAAC,eAAe,OAAO,SAAS,MAAM,GAAG;EAChG,WAAW,6BAA6B;EACxC,SAAS,OAAO,SAAS,UAAU;CACpC;CAMA,IACC,eAAe,WAAW,SAC1B,UAAU,SACT,aAAa,6BAA6B,oBAC1C,aAAa,6BAA6B,oBAC1C,aAAa,6BAA6B,kBAE3C,SAAS,OAAO,SAAS,UAAU;CAEpC,IAAI,aAAa,6BAA6B,mBAC7C,SAAS,OAAO,SAAS,UAAU;CAEpC,IAAI,aAAa,6BAA6B,YAK7C,SAAS,OAAO,SAAS,UA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M;CAElE,MAAM,WAA+B;EACpC,IAAI,WAAW,SAAS,MAAM;EAC9B,KAAK,WAAW,SAAS,MAAM;EAC/B,OAAO,WAAW,SAAS,MAAM;EACjC,MAAM,WAAW,SAAS,MAAM;CACjC;CACA,MAAM,iBACL,WAAW,aAAa,6BAA6B,SAAS,WAAW,WAAW,WAAW,SAAS;CAQzG,IAAI,SAAS,QAAQ;EACpB,IAAI,eAAe,QAAQ,+BAA+B,aAAa,GAAG,OAAO,KAAA;EAEjF,MAAM,cAAc,QAAQ,kBAAkB,aAAa,UAAU,WAAW,SAAS,EAAE;EAC3F,IACC,eAAe,QACd,WAAW,aAAa,6BAA6B,UACrD,WAAW,aAAa,6BAA6B,QAEtD,OAAO;EAQR,OAAO,QAAQ,kBAAkB,aAAa,UAAU,WAAW,QAAQ;CAC5E;CAEA,IAAI,eAAe,MAClB;CAGD,OAAO,YAAY,SAAS,UAAU,cAAc;AACrD;AAEA,SAAgB,cACf,OAC2F;CAC3F,MAAM,UAAU;EAAC;;EAAgD;CAAc,CAAC,CAAC,SAAS,MAAM,SAAS,EAAE;CAC3G,OAAO,MAAM,aACV;EACA,KAAK,GAAG,MAAM,WAAW,MAAM,GAAG,MAAM,WAAW;EACnD,OAAO,MAAM,WAAW;EACxB,MAAM,MAAM,WAAW;CACxB,IACC,MAAM,UACL;EACA,KAAK,UAAU,MAAM,QAAQ,KAAK,MAAM,QAAQ;EAChD,IAAI,UAAU,MAAM,QAAQ,KAAK,MAAM,QAAQ;EAC/C,OAAO,UAAU,MAAM,QAAQ,eAAe,KAAA;EAC9C,MAAM,UAAU,MAAM,QAAQ,OAAO,MAAM,QAAQ;CACpD,IACC,KAAA;AACL"}
@@ -22,9 +22,9 @@ export declare function resourceLabel(resource: ResourceDescriptor): string;
22
22
  export declare function resourceMatchesOrg(resource: ResourceDescriptor, org: string): boolean;
23
23
  /**
24
24
  * Whether a caller's `org`/`project` selector addresses this resource or project, for the reads that act on a
25
- * remembered selection. Jira's only by its canonical key (a site's id, a project's key): a site or project that was
26
- * removed must select nothing, not resolve through its old name or id to another one that happens to carry it as a
27
- * name, id or key. Every other provider by any identifier, as {@link resourceMatchesOrg}.
25
+ * remembered selection. Jira matches only its canonical key (a site's id, a project's key), and Asana its gid:
26
+ * a removed resource must select nothing, and a name matching another resource's identifier must not widen a read.
27
+ * Every other provider matches by any identifier, as {@link resourceMatchesOrg}.
28
28
  */
29
29
  export declare function selectorMatches(providerId: IntegrationIds, resource: ResourceDescriptor, selector: string): boolean;
30
30
  /**
@@ -28,12 +28,12 @@ function resourceMatchesOrg(resource, org) {
28
28
  }
29
29
  /**
30
30
  * Whether a caller's `org`/`project` selector addresses this resource or project, for the reads that act on a
31
- * remembered selection. Jira's only by its canonical key (a site's id, a project's key): a site or project that was
32
- * removed must select nothing, not resolve through its old name or id to another one that happens to carry it as a
33
- * name, id or key. Every other provider by any identifier, as {@link resourceMatchesOrg}.
31
+ * remembered selection. Jira matches only its canonical key (a site's id, a project's key), and Asana its gid:
32
+ * a removed resource must select nothing, and a name matching another resource's identifier must not widen a read.
33
+ * Every other provider matches by any identifier, as {@link resourceMatchesOrg}.
34
34
  */
35
35
  function selectorMatches(providerId, resource, selector) {
36
- return isJiraIntegrationId(providerId) ? resource.key === selector : resourceMatchesOrg(resource, selector);
36
+ return isJiraIntegrationId(providerId) || providerId === "asana" ? resource.key === selector : resourceMatchesOrg(resource, selector);
37
37
  }
38
38
  /**
39
39
  * The id of the RESOURCE a project belongs to, used to look up which account (and therefore which user) that
@@ -1 +1 @@
1
- {"version":3,"file":"hierarchy.utils.js","names":[],"sources":["../../../../../plus/integrations/src/reads/hierarchy.utils.ts"],"sourcesContent":["import type { IssueResourceDescriptor, ResourceDescriptor } from '@gitlens/git/models/resourceDescriptor.js';\nimport { IssuesCloudHostIntegrationId } from '../constants.js';\nimport type { IntegrationIds } from '../constants.js';\nimport type { ProviderOrganization, ProviderResult, ProviderWarning } from '../results.js';\nimport { appendDedupedWarning } from '../results.js';\nimport { isJiraIntegrationId } from '../utils/integration.utils.js';\n\n/**\n * Mapping of a provider's own hierarchy vocabulary onto the single {@link ProviderOrganization} shape the facade\n * publishes.\n *\n * Providers disagree about what sits above a repo or an issue: git hosts have orgs (and Azure DevOps a project\n * tier below that), while issue trackers have \"resources\" (Jira sites, Linear orgs, Trello workspaces) with\n * projects beneath them. `listOrgs`/`listProjects` unify all of it, so these helpers exist to keep the\n * per-provider shape-guessing — which field is the id, which is the display label, which resource is a\n * project's parent — in one place instead of inline in those reads.\n *\n * Everything here reads through the base {@link ResourceDescriptor} (which only guarantees `key`) and casts to\n * the concrete {@link IssueResourceDescriptor} for the optional `id`/`name`. That cast is why the fallbacks are\n * spelled out rather than assumed.\n */\n\n/** The label to show for a resource: its name, else its id, else the key that is always present. */\nexport function resourceLabel(resource: ResourceDescriptor): string {\n\tconst typed = resource as IssueResourceDescriptor;\n\treturn typed.name ?? typed.id ?? resource.key;\n}\n\n/** Whether `org` addresses this resource by any of the identifiers a caller could reasonably have. */\nexport function resourceMatchesOrg(resource: ResourceDescriptor, org: string): boolean {\n\tconst typed = resource as IssueResourceDescriptor;\n\treturn resource.key === org || typed.id === org || typed.name === org;\n}\n\n/**\n * Whether a caller's `org`/`project` selector addresses this resource or project, for the reads that act on a\n * remembered selection. Jira's only by its canonical key (a site's id, a project's key): a site or project that was\n * removed must select nothing, not resolve through its old name or id to another one that happens to carry it as a\n * name, id or key. Every other provider by any identifier, as {@link resourceMatchesOrg}.\n */\nexport function selectorMatches(providerId: IntegrationIds, resource: ResourceDescriptor, selector: string): boolean {\n\treturn isJiraIntegrationId(providerId) ? resource.key === selector : resourceMatchesOrg(resource, selector);\n}\n\n/**\n * The id of the RESOURCE a project belongs to, used to look up which account (and therefore which user) that\n * project's issues should be scoped to. Falls back through the project's own identifiers because some providers\n * (and test doubles) return project descriptors without naming their parent.\n */\nexport function resourceIdForProject(project: ResourceDescriptor): string | undefined {\n\tconst typed = project as IssueResourceDescriptor & { resourceId?: string };\n\treturn typed.resourceId ?? typed.id ?? project.key;\n}\n\n/**\n * A stable identity for one project across facade pages, for the retry/completed bookkeeping an issue-tracker\n * cursor carries. The resource is included because two resources can reuse the same project id. The key is left\n * out because it can be renamed between pages (a Jira project key), which would re-read a completed project and\n * drop a retrying one; it stands in only for a descriptor with no id.\n */\nexport function projectKey(project: ResourceDescriptor): string {\n\tconst typed = project as IssueResourceDescriptor & { resourceId?: string };\n\treturn JSON.stringify([typed.resourceId ?? '', typed.id || project.key]);\n}\n\n/**\n * Maps an issue-tracker resource descriptor to the unified {@link ProviderOrganization} org shape. `url` is\n * synthesized when the descriptor carries none, rather than widening the shared `ProviderOrganization.url` to\n * optional for the one provider family that may omit it.\n */\nexport function resourceToOrg(\n\tproviderId: IntegrationIds,\n\tresource: ResourceDescriptor,\n\torg?: string,\n): ProviderOrganization {\n\tconst typed = resource as IssueResourceDescriptor & { url?: string };\n\treturn {\n\t\tid: typed.id ?? resource.key,\n\t\tproviderId: providerId,\n\t\tname: resourceLabel(resource),\n\t\t...(org != null ? { org: org } : {}),\n\t\turl: typed.url ?? '',\n\t};\n}\n\n/**\n * Maps an issue-tracker project descriptor to the unified org shape, as {@link resourceToOrg} does with its parent's\n * label as `org`. A Jira project is published by what its reads take: `name` is its key (its display name can collide\n * with another project's key), and `orgId` its site's id, since the label in `org` can't address the site.\n */\nexport function projectToOrg(\n\tproviderId: IntegrationIds,\n\tproject: ResourceDescriptor,\n\tresources: ResourceDescriptor[],\n): ProviderOrganization {\n\tconst item = resourceToOrg(providerId, project, orgForProject(providerId, project, resources));\n\tif (!isJiraIntegrationId(providerId)) return item;\n\n\t// The descriptor's own parent id only: `resourceIdForProject` would fall back to the project's id or key.\n\tconst { resourceId } = project;\n\treturn { ...item, name: project.key, ...(typeof resourceId === 'string' ? { orgId: resourceId } : {}) };\n}\n\n/**\n * The resource a project belongs under, as a display label — the `org` of the project's unified org shape.\n *\n * A project doesn't reliably name its parent, so try each identifier it does carry against the resources that\n * were read alongside it. When none matches but only ONE resource was in scope, that resource is the parent by\n * construction. Trello is excluded: its boards have no enclosing resource to name.\n */\nexport function orgForProject(\n\tproviderId: IntegrationIds,\n\tproject: ResourceDescriptor,\n\tresources: ResourceDescriptor[],\n): string | undefined {\n\tif (providerId === IssuesCloudHostIntegrationId.Trello) return undefined;\n\n\tconst typedProject = project as IssueResourceDescriptor & { resourceId?: string };\n\tconst parentMatch = [typedProject.resourceId, typedProject.id, project.key]\n\t\t.filter((value): value is string => value != null)\n\t\t.map(candidate => resources.find(resource => resourceMatchesOrg(resource, candidate)))\n\t\t.find((resource): resource is ResourceDescriptor => resource != null);\n\n\treturn parentMatch != null\n\t\t? resourceLabel(parentMatch)\n\t\t: resources.length === 1\n\t\t\t? resourceLabel(resources[0])\n\t\t\t: undefined;\n}\n\n/**\n * Stamps the provider onto an org the provider's own client produced. A git host's client fills the rest of the\n * shape but doesn't know which integration id it was reached through — and on a self-managed host the same\n * client serves several — so the fan-out attributes it here.\n */\nexport function withProviderContext(providerId: IntegrationIds, item: ProviderOrganization): ProviderOrganization {\n\treturn {\n\t\t...item,\n\t\tproviderId: providerId,\n\t\t...(item.org != null ? { org: item.org } : {}),\n\t};\n}\n\n/**\n * Merges the per-provider slices of a hierarchy fan-out into one flat result.\n *\n * `ProviderResult` has no page object, so `fetchFailed` is its only non-authoritative signal — any slice that\n * failed or came back incomplete has to set it, or a caller would treat a short list as the whole account.\n * Warnings are deduped because the same account can surface under two ids in one fan-out.\n */\nexport function mergeHierarchyResults<T>(\n\tresults: readonly ({ items: T[]; warnings: ProviderWarning[]; fetchFailed: boolean } | undefined)[],\n): ProviderResult<T> {\n\tconst items: T[] = [];\n\tconst warnings: ProviderWarning[] = [];\n\tlet fetchFailed = false;\n\tfor (const result of results) {\n\t\tif (result == null) continue;\n\n\t\titems.push(...result.items);\n\t\tfor (const warning of result.warnings) {\n\t\t\tappendDedupedWarning(warnings, warning);\n\t\t}\n\t\tif (result.fetchFailed) {\n\t\t\tfetchFailed = true;\n\t\t}\n\t}\n\n\treturn { items: items, warnings: warnings, fetchFailed: fetchFailed || undefined };\n}\n\n/**\n * Rejects a hierarchy read whose scoped selectors have no provider to apply to. `connectionId` and `domain`\n * both select among the connections OF a provider, so either one without `providerId` is ambiguous rather than\n * merely redundant — the fan-out would have to guess which provider the caller meant, and silently picking one\n * would read that connection's data under another provider's name.\n */\nexport function assertHierarchyReadTarget(\n\tmethod: 'listOrgs' | 'listProjects',\n\toptions: { providerId?: IntegrationIds; connectionId?: string; domain?: string } | undefined,\n): void {\n\tif (options?.providerId == null && (options?.connectionId != null || options?.domain != null)) {\n\t\tthrow new TypeError(`'${method}' requires 'providerId' when 'connectionId' or 'domain' is supplied`);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,cAAc,UAAsC;CACnE,MAAM,QAAQ;CACd,OAAO,MAAM,QAAQ,MAAM,MAAM,SAAS;AAC3C;;AAGA,SAAgB,mBAAmB,UAA8B,KAAsB;CACtF,MAAM,QAAQ;CACd,OAAO,SAAS,QAAQ,OAAO,MAAM,OAAO,OAAO,MAAM,SAAS;AACnE;;;;;;;AAQA,SAAgB,gBAAgB,YAA4B,UAA8B,UAA2B;CACpH,OAAO,oBAAoB,UAAU,IAAI,SAAS,QAAQ,WAAW,mBAAmB,UAAU,QAAQ;AAC3G;;;;;;AAOA,SAAgB,qBAAqB,SAAiD;CACrF,MAAM,QAAQ;CACd,OAAO,MAAM,cAAc,MAAM,MAAM,QAAQ;AAChD;;;;;;;AAQA,SAAgB,WAAW,SAAqC;CAC/D,MAAM,QAAQ;CACd,OAAO,KAAK,UAAU,CAAC,MAAM,cAAc,IAAI,MAAM,MAAM,QAAQ,GAAG,CAAC;AACxE;;;;;;AAOA,SAAgB,cACf,YACA,UACA,KACuB;CACvB,MAAM,QAAQ;CACd,OAAO;EACN,IAAI,MAAM,MAAM,SAAS;EACb;EACZ,MAAM,cAAc,QAAQ;EAC5B,GAAI,OAAO,OAAO,EAAO,IAAI,IAAI,CAAC;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;;;;;AAQA,SAAgB,0BACf,QACA,SACO;CACP,IAAI,SAAS,cAAc,SAAS,SAAS,gBAAgB,QAAQ,SAAS,UAAU,OACvF,MAAM,IAAI,UAAU,IAAI,OAAO,oEAAoE;AAErG"}
1
+ {"version":3,"file":"hierarchy.utils.js","names":[],"sources":["../../../../../plus/integrations/src/reads/hierarchy.utils.ts"],"sourcesContent":["import type { IssueResourceDescriptor, ResourceDescriptor } from '@gitlens/git/models/resourceDescriptor.js';\nimport { IssuesCloudHostIntegrationId } from '../constants.js';\nimport type { IntegrationIds } from '../constants.js';\nimport type { ProviderOrganization, ProviderResult, ProviderWarning } from '../results.js';\nimport { appendDedupedWarning } from '../results.js';\nimport { isJiraIntegrationId } from '../utils/integration.utils.js';\n\n/**\n * Mapping of a provider's own hierarchy vocabulary onto the single {@link ProviderOrganization} shape the facade\n * publishes.\n *\n * Providers disagree about what sits above a repo or an issue: git hosts have orgs (and Azure DevOps a project\n * tier below that), while issue trackers have \"resources\" (Jira sites, Linear orgs, Trello workspaces) with\n * projects beneath them. `listOrgs`/`listProjects` unify all of it, so these helpers exist to keep the\n * per-provider shape-guessing — which field is the id, which is the display label, which resource is a\n * project's parent — in one place instead of inline in those reads.\n *\n * Everything here reads through the base {@link ResourceDescriptor} (which only guarantees `key`) and casts to\n * the concrete {@link IssueResourceDescriptor} for the optional `id`/`name`. That cast is why the fallbacks are\n * spelled out rather than assumed.\n */\n\n/** The label to show for a resource: its name, else its id, else the key that is always present. */\nexport function resourceLabel(resource: ResourceDescriptor): string {\n\tconst typed = resource as IssueResourceDescriptor;\n\treturn typed.name ?? typed.id ?? resource.key;\n}\n\n/** Whether `org` addresses this resource by any of the identifiers a caller could reasonably have. */\nexport function resourceMatchesOrg(resource: ResourceDescriptor, org: string): boolean {\n\tconst typed = resource as IssueResourceDescriptor;\n\treturn resource.key === org || typed.id === org || typed.name === org;\n}\n\n/**\n * Whether a caller's `org`/`project` selector addresses this resource or project, for the reads that act on a\n * remembered selection. Jira matches only its canonical key (a site's id, a project's key), and Asana its gid:\n * a removed resource must select nothing, and a name matching another resource's identifier must not widen a read.\n * Every other provider matches by any identifier, as {@link resourceMatchesOrg}.\n */\nexport function selectorMatches(providerId: IntegrationIds, resource: ResourceDescriptor, selector: string): boolean {\n\treturn isJiraIntegrationId(providerId) || providerId === IssuesCloudHostIntegrationId.Asana\n\t\t? resource.key === selector\n\t\t: resourceMatchesOrg(resource, selector);\n}\n\n/**\n * The id of the RESOURCE a project belongs to, used to look up which account (and therefore which user) that\n * project's issues should be scoped to. Falls back through the project's own identifiers because some providers\n * (and test doubles) return project descriptors without naming their parent.\n */\nexport function resourceIdForProject(project: ResourceDescriptor): string | undefined {\n\tconst typed = project as IssueResourceDescriptor & { resourceId?: string };\n\treturn typed.resourceId ?? typed.id ?? project.key;\n}\n\n/**\n * A stable identity for one project across facade pages, for the retry/completed bookkeeping an issue-tracker\n * cursor carries. The resource is included because two resources can reuse the same project id. The key is left\n * out because it can be renamed between pages (a Jira project key), which would re-read a completed project and\n * drop a retrying one; it stands in only for a descriptor with no id.\n */\nexport function projectKey(project: ResourceDescriptor): string {\n\tconst typed = project as IssueResourceDescriptor & { resourceId?: string };\n\treturn JSON.stringify([typed.resourceId ?? '', typed.id || project.key]);\n}\n\n/**\n * Maps an issue-tracker resource descriptor to the unified {@link ProviderOrganization} org shape. `url` is\n * synthesized when the descriptor carries none, rather than widening the shared `ProviderOrganization.url` to\n * optional for the one provider family that may omit it.\n */\nexport function resourceToOrg(\n\tproviderId: IntegrationIds,\n\tresource: ResourceDescriptor,\n\torg?: string,\n): ProviderOrganization {\n\tconst typed = resource as IssueResourceDescriptor & { url?: string };\n\treturn {\n\t\tid: typed.id ?? resource.key,\n\t\tproviderId: providerId,\n\t\tname: resourceLabel(resource),\n\t\t...(org != null ? { org: org } : {}),\n\t\turl: typed.url ?? '',\n\t};\n}\n\n/**\n * Maps an issue-tracker project descriptor to the unified org shape, as {@link resourceToOrg} does with its parent's\n * label as `org`. A Jira project is published by what its reads take: `name` is its key (its display name can collide\n * with another project's key), and `orgId` its site's id, since the label in `org` can't address the site.\n */\nexport function projectToOrg(\n\tproviderId: IntegrationIds,\n\tproject: ResourceDescriptor,\n\tresources: ResourceDescriptor[],\n): ProviderOrganization {\n\tconst item = resourceToOrg(providerId, project, orgForProject(providerId, project, resources));\n\tif (!isJiraIntegrationId(providerId)) return item;\n\n\t// The descriptor's own parent id only: `resourceIdForProject` would fall back to the project's id or key.\n\tconst { resourceId } = project;\n\treturn { ...item, name: project.key, ...(typeof resourceId === 'string' ? { orgId: resourceId } : {}) };\n}\n\n/**\n * The resource a project belongs under, as a display label — the `org` of the project's unified org shape.\n *\n * A project doesn't reliably name its parent, so try each identifier it does carry against the resources that\n * were read alongside it. When none matches but only ONE resource was in scope, that resource is the parent by\n * construction. Trello is excluded: its boards have no enclosing resource to name.\n */\nexport function orgForProject(\n\tproviderId: IntegrationIds,\n\tproject: ResourceDescriptor,\n\tresources: ResourceDescriptor[],\n): string | undefined {\n\tif (providerId === IssuesCloudHostIntegrationId.Trello) return undefined;\n\n\tconst typedProject = project as IssueResourceDescriptor & { resourceId?: string };\n\tconst parentMatch = [typedProject.resourceId, typedProject.id, project.key]\n\t\t.filter((value): value is string => value != null)\n\t\t.map(candidate => resources.find(resource => resourceMatchesOrg(resource, candidate)))\n\t\t.find((resource): resource is ResourceDescriptor => resource != null);\n\n\treturn parentMatch != null\n\t\t? resourceLabel(parentMatch)\n\t\t: resources.length === 1\n\t\t\t? resourceLabel(resources[0])\n\t\t\t: undefined;\n}\n\n/**\n * Stamps the provider onto an org the provider's own client produced. A git host's client fills the rest of the\n * shape but doesn't know which integration id it was reached through — and on a self-managed host the same\n * client serves several — so the fan-out attributes it here.\n */\nexport function withProviderContext(providerId: IntegrationIds, item: ProviderOrganization): ProviderOrganization {\n\treturn {\n\t\t...item,\n\t\tproviderId: providerId,\n\t\t...(item.org != null ? { org: item.org } : {}),\n\t};\n}\n\n/**\n * Merges the per-provider slices of a hierarchy fan-out into one flat result.\n *\n * `ProviderResult` has no page object, so `fetchFailed` is its only non-authoritative signal — any slice that\n * failed or came back incomplete has to set it, or a caller would treat a short list as the whole account.\n * Warnings are deduped because the same account can surface under two ids in one fan-out.\n */\nexport function mergeHierarchyResults<T>(\n\tresults: readonly ({ items: T[]; warnings: ProviderWarning[]; fetchFailed: boolean } | undefined)[],\n): ProviderResult<T> {\n\tconst items: T[] = [];\n\tconst warnings: ProviderWarning[] = [];\n\tlet fetchFailed = false;\n\tfor (const result of results) {\n\t\tif (result == null) continue;\n\n\t\titems.push(...result.items);\n\t\tfor (const warning of result.warnings) {\n\t\t\tappendDedupedWarning(warnings, warning);\n\t\t}\n\t\tif (result.fetchFailed) {\n\t\t\tfetchFailed = true;\n\t\t}\n\t}\n\n\treturn { items: items, warnings: warnings, fetchFailed: fetchFailed || undefined };\n}\n\n/**\n * Rejects a hierarchy read whose scoped selectors have no provider to apply to. `connectionId` and `domain`\n * both select among the connections OF a provider, so either one without `providerId` is ambiguous rather than\n * merely redundant — the fan-out would have to guess which provider the caller meant, and silently picking one\n * would read that connection's data under another provider's name.\n */\nexport function assertHierarchyReadTarget(\n\tmethod: 'listOrgs' | 'listProjects',\n\toptions: { providerId?: IntegrationIds; connectionId?: string; domain?: string } | undefined,\n): void {\n\tif (options?.providerId == null && (options?.connectionId != null || options?.domain != null)) {\n\t\tthrow new TypeError(`'${method}' requires 'providerId' when 'connectionId' or 'domain' is supplied`);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,cAAc,UAAsC;CACnE,MAAM,QAAQ;CACd,OAAO,MAAM,QAAQ,MAAM,MAAM,SAAS;AAC3C;;AAGA,SAAgB,mBAAmB,UAA8B,KAAsB;CACtF,MAAM,QAAQ;CACd,OAAO,SAAS,QAAQ,OAAO,MAAM,OAAO,OAAO,MAAM,SAAS;AACnE;;;;;;;AAQA,SAAgB,gBAAgB,YAA4B,UAA8B,UAA2B;CACpH,OAAO,oBAAoB,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A,SAAgB,oBAAoB,YAA4B,MAAkD;CACjH,OAAO;EACN,GAAG;EACS;EACZ,GAAI,KAAK,OAAO,OAAO,EAAE,KAAK,KAAK,IAAI,IAAI,CAAC;CAC7C;AACD;;;;;;;;AASA,SAAgB,sBACf,SACoB;CACpB,MAAM,QAAa,CAAC;CACpB,MAAM,WAA8B,CAAC;CACrC,IAAI,cAAc;CAClB,KAAK,MAAM,UAAU,SAAS;EAC7B,IAAI,UAAU,MAAM;EAEpB,MAAM,KAAK,GAAG,OAAO,KAAK;EAC1B,KAAK,MAAM,WAAW,OAAO,UAC5B,qBAAqB,UAAU,OAAO;EAEvC,IAAI,OAAO,aACV,cAAc;CAEhB;CAEA,OAAO;EAAS;EAAiB;EAAU,aAAa,eAAe,KAAA;CAAU;AAClF;;;;;;;AAQA,SAAgB,0BACf,QACA,SACO;CACP,IAAI,SAAS,cAAc,SAAS,SAAS,gBAAgB,QAAQ,SAAS,UAAU,OACvF,MAAM,IAAI,UAAU,IAAI,OAAO,oEAAoE;AAErG"}
@@ -1,3 +1,4 @@
1
+ import { trimTrailingSlashes } from "../../../utils/path.js";
1
2
  import { AuthenticationError, RequestNotFoundError } from "../../../git/errors.js";
2
3
  import { parseGitRemoteUrl } from "../../../git/utils/remote.utils.js";
3
4
  import { createRemoteProviderMatcher } from "../../../git/remotes/matcher.js";
@@ -22,7 +23,8 @@ import { getAzureRepositoryIdentity } from "../providers/azure/azure.utils.js";
22
23
  */
23
24
  async function resolveRepository(ctx, options) {
24
25
  const result = (status) => ({ resolution: { status } });
25
- const [scheme, parsedDomain, path] = parseGitRemoteUrl(options.remoteUrl);
26
+ const [scheme, parsedDomain, parsedPath] = parseGitRemoteUrl(options.remoteUrl);
27
+ const path = trimTrailingSlashes(parsedPath);
26
28
  const hostsMatch = getRemoteHostMatcher(scheme);
27
29
  const parsedHost = hostFromDomain(parsedDomain);
28
30
  const explicitHost = hostFromDomain(options.host);
@@ -85,6 +87,10 @@ async function resolveRepository(ctx, options) {
85
87
  const project = provider.id === "azure-devops" ? provider.providerDesc?.repoDomain : void 0;
86
88
  const domain = trustedHost ?? provider.domain;
87
89
  if (provider.id === "azure-devops" && project == null) return result("invalid-remote-url");
90
+ const repositoryName = project != null ? getAzureRepositoryIdentity({
91
+ owner,
92
+ name
93
+ }).repositoryName : name;
88
94
  try {
89
95
  const repo = await integration.getRepoInfo({
90
96
  ...providerRepo,
@@ -97,9 +103,17 @@ async function resolveRepository(ctx, options) {
97
103
  status: "unauthorized",
98
104
  warning: noConnectionWarning(id, domain, connectionId)
99
105
  } };
100
- const canonicalOwner = repo.namespace || owner;
101
- const canonicalName = repo.name || name;
102
- const renamed = canonicalOwner.toLowerCase() !== owner.toLowerCase() || canonicalName.toLowerCase() !== name.toLowerCase();
106
+ const readAt = repo.readAt ?? {
107
+ owner,
108
+ name: repositoryName,
109
+ project
110
+ };
111
+ const canonicalOwner = repo.namespace || readAt.owner;
112
+ const canonicalName = repo.name || readAt.name;
113
+ const readAtProject = project != null ? readAt.project || project : void 0;
114
+ const canonicalProject = readAtProject != null ? repo.project || readAtProject : void 0;
115
+ const differs = (a, b) => a?.toLowerCase() !== b?.toLowerCase();
116
+ const renamed = differs(`${canonicalOwner}/${canonicalName}`, `${readAt.owner}/${readAt.name}`) || differs(canonicalProject, readAtProject);
103
117
  return { resolution: {
104
118
  status: "resolved",
105
119
  identity: {
@@ -107,7 +121,7 @@ async function resolveRepository(ctx, options) {
107
121
  domain,
108
122
  owner: canonicalOwner,
109
123
  name: canonicalName,
110
- project: project != null ? repo.project || project : void 0,
124
+ project: canonicalProject,
111
125
  remoteUrl: options.remoteUrl,
112
126
  renamed,
113
127
  ...getForkInfo(repo)
@@ -121,10 +135,7 @@ async function resolveRepository(ctx, options) {
121
135
  try {
122
136
  const failure = await integration.settleRepositoryRefusal({
123
137
  owner,
124
- name: project != null ? getAzureRepositoryIdentity({
125
- owner,
126
- name
127
- }).repositoryName : name,
138
+ name: repositoryName,
128
139
  project,
129
140
  connectionId
130
141
  }, ex);
@@ -151,24 +162,21 @@ async function resolveRepository(ctx, options) {
151
162
  }
152
163
  }
153
164
  /**
154
- * The fork fields of a provider repository, read defensively: `@gitkraken/provider-apis` does not declare `isFork`
155
- * or `parent` on its repository type, so a build of the SDK that carries them is read without the type knowing,
156
- * and one that doesn't reads as "unknown" (no `isFork`, no `parent`). `namespace` is the owner, workspace, project key
157
- * or Azure organization, as the SDK uses it elsewhere. A malformed value is dropped rather than half-trusted. A named
158
- * parent is itself a report of a fork, so it settles an unreported `isFork` to `true`; one beside `isFork: false`
159
- * contradicts the flag and is dropped.
165
+ * The fork fields of a provider repository. `namespace` is the owner, workspace, project key, Azure organization or
166
+ * GitLab group path (`group/subgroup`), as the SDK uses it elsewhere. A named parent is itself a report of a fork, so
167
+ * it settles an unreported `isFork` to `true`; one beside `isFork: false` contradicts the flag and is dropped. So is
168
+ * one with an empty namespace or name: the type allows it, and GitLab's is split from a path the server sends, which
169
+ * leaves no namespace when it has no `/`. It can't address a repository, but the fork is still reported.
160
170
  */
161
171
  function getForkInfo(repo) {
162
- const fork = "isFork" in repo && typeof repo.isFork === "boolean" ? repo.isFork : void 0;
163
- const parent = "parent" in repo ? repo.parent : void 0;
164
- if (fork === false || parent == null || typeof parent !== "object" || !("namespace" in parent) || !("name" in parent) || typeof parent.namespace !== "string" || typeof parent.name !== "string" || !parent.namespace || !parent.name) return { isFork: fork };
165
- const project = "project" in parent && typeof parent.project === "string" && parent.project ? parent.project : void 0;
172
+ const { isFork, parent } = repo;
173
+ if (isFork === false || !parent?.namespace || !parent.name) return { isFork };
166
174
  return {
167
175
  isFork: true,
168
176
  parent: {
169
177
  owner: parent.namespace,
170
178
  name: parent.name,
171
- ...project != null ? { project } : {}
179
+ ...parent.project ? { project: parent.project } : {}
172
180
  }
173
181
  };
174
182
  }
@@ -188,7 +196,7 @@ function matchInstallation(ctx, options, id, connections, remote) {
188
196
  if (!isWebRemoteScheme(remote.scheme)) return void 0;
189
197
  const installationPath = (connection) => {
190
198
  const baseUrl = getSelfManagedBaseUrl(id, connection != null ? connection.baseUrl ?? connection.domain : options.domain);
191
- return baseUrl != null ? new URL(baseUrl).pathname.replace(/\/+$/, "") : void 0;
199
+ return baseUrl != null ? trimTrailingSlashes(new URL(baseUrl).pathname) : void 0;
192
200
  };
193
201
  const defaultConnection = connections.find((c) => c.primary) ?? connections[0];
194
202
  const cloudConnections = connections.filter((c) => c.cloud);
@@ -1 +1 @@
1
- {"version":3,"file":"resolveRepository.js","names":[],"sources":["../../../../../plus/integrations/src/reads/resolveRepository.ts"],"sourcesContent":["import type { RemoteProvider } from '@gitlens/git/models/remoteProvider.js';\nimport type { ResourceDescriptor } from '@gitlens/git/models/resourceDescriptor.js';\nimport type { RemoteProviderConfig } from '@gitlens/git/remotes/matcher.js';\nimport { createRemoteProviderMatcher } from '@gitlens/git/remotes/matcher.js';\nimport { parseGitRemoteUrl } from '@gitlens/git/utils/remote.utils.js';\nimport type { ConfiguredIntegrationDescriptor } from '../authentication/models.js';\nimport { mergeAssessmentInto } from '../collectionMetadata.js';\nimport type { IntegrationIds } from '../constants.js';\nimport { GitCloudHostIntegrationId, GitSelfManagedHostIntegrationId } from '../constants.js';\nimport { AuthenticationError, RequestNotFoundError } from '../errors.js';\nimport { isIssuesIntegration } from '../models/issuesIntegration.js';\nimport { getAzureRepositoryIdentity } from '../providers/azure/azure.utils.js';\nimport { isAzureCloudDomain, isBitbucketCloudDomain, isGitHubDotCom, isGitLabDotCom } from '../providers/models.js';\nimport type { ProviderWarning, RepositoryIdentity, RepositoryResolution, ResolveRepositoryResult } from '../results.js';\nimport { toProviderWarning } from '../results.js';\nimport { decodePathSegment, getRemoteHostMatcher, hostFromDomain, isWebRemoteScheme } from '../utils/domain.utils.js';\nimport {\n\tgetIntegrationIdForRemote,\n\tgetSelfManagedBaseUrl,\n\tisGitCloudHostIntegrationId,\n\tisGitSelfManagedHostIntegrationId,\n\tremoteProviderTypeForConfig,\n\tremoteProviderTypeForIntegration,\n} from '../utils/integration.utils.js';\nimport type { RepositoryResolutionContext } from './context.js';\nimport { noConnectionWarning } from './warnings.js';\n\ntype ResolveRepositoryOptions = {\n\tproviderId?: IntegrationIds;\n\tremoteUrl: string;\n\thost?: string;\n\tconnectionId?: string;\n\t/**\n\t * Explicit self-managed host domain used to select the integration instance. Used only when the requested\n\t * connection has no configured domain; it must come from the trusted authentication configuration, not\n\t * repository or remote data.\n\t */\n\tdomain?: string;\n};\n\n/**\n * Resolution of a remote URL to a provider repository identity — the facade's equivalent of `gk repo resolve`.\n *\n * Unlike every other read here, this one's input is REPOSITORY data, so most of the code below is about not\n * letting that data choose the credentials: an explicit cloud `providerId` must agree with the remote's canonical\n * host, and a self-managed host resolves only against a domain the user already authenticated. The\n * `host-mismatch` returns are those guards, not edge cases — resolving `owner/repo` against the wrong account\n * would hand back a confidently wrong identity and seed the domain-keyed instance cache from remote data.\n */\nexport async function resolveRepository(\n\tctx: RepositoryResolutionContext,\n\toptions: ResolveRepositoryOptions,\n): Promise<ResolveRepositoryResult> {\n\tconst result = (status: RepositoryResolution['status']): ResolveRepositoryResult => ({\n\t\tresolution: { status: status },\n\t});\n\n\tconst [scheme, parsedDomain, path] = parseGitRemoteUrl(options.remoteUrl);\n\t// An SSH remote's port belongs to its SSH daemon, not to the web authority a connection is keyed by.\n\tconst hostsMatch = getRemoteHostMatcher(scheme);\n\tconst parsedHost = hostFromDomain(parsedDomain);\n\tconst explicitHost = hostFromDomain(options.host);\n\tif (parsedHost != null && explicitHost != null && !hostsMatch(parsedHost, explicitHost)) {\n\t\treturn result('host-mismatch');\n\t}\n\n\tconst matcherDomain = parsedDomain || options.host || '';\n\n\t// An explicit cloud provider must agree with the remote's canonical cloud host. Without this guard the\n\t// synthetic matcher below can reinterpret, for example, a gitlab.com URL as GitHub and then resolve a\n\t// homonymous owner/repo through the wrong account. Match once without caller configs/synthetic entries;\n\t// Azure's matcher also normalizes ssh.dev.azure.com and vs-ssh.visualstudio.com to their web host.\n\tif (options.providerId != null && isGitCloudHostIntegrationId(options.providerId)) {\n\t\tconst nativeProvider = createRemoteProviderMatcher([])(options.remoteUrl, matcherDomain, path, scheme);\n\t\tconst nativeId = nativeProvider != null ? getIntegrationIdForRemote(nativeProvider) : undefined;\n\t\tconst nativeDomain = nativeProvider?.domain ?? matcherDomain;\n\t\tconst canonicalHost =\n\t\t\toptions.providerId === GitCloudHostIntegrationId.GitHub\n\t\t\t\t? isGitHubDotCom(nativeDomain)\n\t\t\t\t: options.providerId === GitCloudHostIntegrationId.GitLab\n\t\t\t\t\t? isGitLabDotCom(nativeDomain)\n\t\t\t\t\t: options.providerId === GitCloudHostIntegrationId.Bitbucket\n\t\t\t\t\t\t? isBitbucketCloudDomain(nativeDomain)\n\t\t\t\t\t\t: isAzureCloudDomain(nativeDomain);\n\t\tif (nativeId !== options.providerId || !canonicalHost) return result('host-mismatch');\n\t}\n\n\tlet provider = createRemoteProviderMatcher(buildMatcherConfigs(ctx, options, parsedDomain))(\n\t\toptions.remoteUrl,\n\t\tmatcherDomain,\n\t\tpath,\n\t\tscheme,\n\t);\n\tif (provider == null) return result('invalid-remote-url');\n\n\tlet id = options.providerId ?? getIntegrationIdForRemote(provider);\n\t// Custom Azure DevOps Server domains matched via getRemoteConfigs return undefined from\n\t// getIntegrationIdForRemote because the provider is marked custom; map them to the server id so the\n\t// project-scoped lookup uses that host's configured connection and API base URL.\n\tif (id == null && provider.id === 'azure-devops' && provider.custom) {\n\t\tid = GitSelfManagedHostIntegrationId.AzureDevOpsServer;\n\t}\n\tif (id == null) return result('unsupported-provider');\n\n\t// On a self-managed host, resolve only against a TRUSTED host: the pinned connection's configured\n\t// domain, the explicit `domain`, or — when neither was supplied — a configured host matching the\n\t// remote's. That last case keeps `remoteUrl` (repository-supplied) out of the trusted path: it selects\n\t// among hosts the user already authenticated and can never introduce a new one. Resolving `owner/repo`\n\t// against some other host's account would, if that host has the same owner/repo, return a confidently\n\t// wrong identity — and would seed the domain-keyed integration cache (never evicted before dispose) with\n\t// an entry derived from repository data.\n\tconst urlHost = hostFromDomain(provider.domain);\n\t// Normalize BOTH sides before comparing: a stored connection domain is usually a full URL\n\t// (`https://git.example.com`) while `urlHost` is already a bare host, so a raw compare would fail on\n\t// scheme/trailing-slash alone and wrongly reject a correctly-configured connection.\n\tlet trustedHost =\n\t\toptions.connectionId != null || options.domain != null\n\t\t\t? hostFromDomain(ctx.resolveDomainForRead(id, options.connectionId, options.domain))\n\t\t\t: undefined;\n\tlet connectionId = options.connectionId;\n\tlet providerRepo: ResourceDescriptor | undefined;\n\tif (isGitSelfManagedHostIntegrationId(id)) {\n\t\tif (path.split('/').some(segment => /^(?:\\.|%2e){1,2}$/i.test(segment) || /%2f|%5c|\\\\/i.test(segment))) {\n\t\t\treturn result('invalid-remote-url');\n\t\t}\n\n\t\tconst configured = ctx.getConfigured(id);\n\t\tconst configuredHosts = configured.map(c => hostFromDomain(c.domain));\n\t\tif (trustedHost == null && urlHost != null) {\n\t\t\tconst matchingHosts = new Set(configuredHosts.filter(host => hostsMatch(host, urlHost)));\n\t\t\tif (matchingHosts.size > 1) return result('host-mismatch');\n\n\t\t\ttrustedHost = matchingHosts.values().next().value;\n\t\t}\n\t\t// A configured host that doesn't match the remote's is a genuine mismatch. With nothing configured\n\t\t// there is no host to mismatch against — it's simply not connected, so fall through to the\n\t\t// `unauthorized` path below (still WITHOUT resolving by the URL domain, so repo data can't seed the\n\t\t// cache).\n\t\tif (trustedHost == null && configuredHosts.length !== 0) return result('host-mismatch');\n\t\tif (trustedHost != null && urlHost != null && !hostsMatch(trustedHost, urlHost)) {\n\t\t\treturn result('host-mismatch');\n\t\t}\n\n\t\tconst installation = matchInstallation(\n\t\t\tctx,\n\t\t\toptions,\n\t\t\tid,\n\t\t\tconfigured.filter(c => hostFromDomain(c.domain) === trustedHost),\n\t\t\t{ scheme: scheme, domain: parsedDomain, path: path },\n\t\t);\n\t\tif (typeof installation === 'string') return result(installation);\n\n\t\tif (installation != null) {\n\t\t\tprovider = installation.provider;\n\t\t\tconnectionId = installation.connectionId;\n\t\t\tproviderRepo = installation.repoDesc;\n\t\t}\n\t}\n\n\tconst owner = provider.owner;\n\tconst name = provider.repoName;\n\tif (owner == null || name == null) return result('invalid-remote-url');\n\n\tproviderRepo ??= provider.repoDesc;\n\n\tlet integration;\n\ttry {\n\t\t// Resolve the instance through the trusted target (as `getIntegrationForRead` does):\n\t\t// `resolveReadSession` looks the session up against the instance's domain-scoped descriptor, so\n\t\t// selecting the instance by the URL domain could miss the session and degrade to `no-connection`.\n\t\tintegration = isGitSelfManagedHostIntegrationId(id)\n\t\t\t? trustedHost != null\n\t\t\t\t? await ctx.getIntegrationForRead(id, connectionId, trustedHost)\n\t\t\t\t: undefined\n\t\t\t: await ctx.getIntegrationForDomain(id, provider.domain);\n\t} catch {\n\t\tintegration = undefined;\n\t}\n\tif (integration == null) {\n\t\t// Attach a warning, as the thrown-AuthenticationError branch below does: a consumer driving auth\n\t\t// recovery off `warning.kind` would otherwise get nothing for an unresolvable target.\n\t\treturn {\n\t\t\tresolution: {\n\t\t\t\tstatus: 'unauthorized',\n\t\t\t\twarning: noConnectionWarning(id, provider.domain, connectionId),\n\t\t\t},\n\t\t};\n\t}\n\t// Issue trackers have no `getRepo` client; a git host without `getRepoFn` leaves `getRepoInfo`\n\t// undefined. Either way this provider can't resolve repositories.\n\tif (isIssuesIntegration(integration) || integration.getRepoInfo == null) {\n\t\treturn result('unsupported-provider');\n\t}\n\n\t// Azure repos are org + project scoped; the remote provider exposes project as `providerDesc.repoDomain`.\n\tconst project = provider.id === 'azure-devops' ? provider.providerDesc?.repoDomain : undefined;\n\tconst domain = trustedHost ?? provider.domain;\n\n\t// Azure's lookup is project-scoped and returns `undefined` without one, which the connection-gap branch\n\t// below would misreport as `unauthorized` (driving a pointless reconnect). A remote URL that carries no\n\t// project simply can't address an Azure repo.\n\tif (provider.id === 'azure-devops' && project == null) return result('invalid-remote-url');\n\n\ttry {\n\t\tconst repo = await integration.getRepoInfo({\n\t\t\t...providerRepo,\n\t\t\towner: owner,\n\t\t\tname: name,\n\t\t\tproject: project,\n\t\t\tconnectionId: connectionId,\n\t\t});\n\t\tif (repo == null) {\n\t\t\t// `getRepoInfo` returns undefined only when no session could be resolved (not connected, or the\n\t\t\t// requested connection is gone) — a real 404 throws below. So this is a connection gap. Attach a\n\t\t\t// warning so a consumer driving auth recovery off `warning.kind` sees the same signal it gets from\n\t\t\t// the thrown-AuthenticationError branch below; without it, the most common unauthorized case is\n\t\t\t// silent.\n\t\t\treturn {\n\t\t\t\tresolution: {\n\t\t\t\t\tstatus: 'unauthorized',\n\t\t\t\t\twarning: noConnectionWarning(id, domain, connectionId),\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\t// Prefer the provider's canonical namespace/name (GitHub's REST/GraphQL lookup follows the 301\n\t\t// rename redirect, so a stale old name resolves to the new canonical identity), falling back to the\n\t\t// parsed remote when the response omits them. `renamed` is a case-insensitive compare of input vs\n\t\t// canonical, mirroring gkcli's `EqualFold`, so hosts that merely echo the input casing (e.g.\n\t\t// Bitbucket Server/Azure) don't get spuriously flagged.\n\t\tconst canonicalOwner = repo.namespace || owner;\n\t\tconst canonicalName = repo.name || name;\n\t\tconst renamed =\n\t\t\tcanonicalOwner.toLowerCase() !== owner.toLowerCase() || canonicalName.toLowerCase() !== name.toLowerCase();\n\n\t\tconst identity: RepositoryIdentity = {\n\t\t\tproviderId: id,\n\t\t\tdomain: domain,\n\t\t\towner: canonicalOwner,\n\t\t\tname: canonicalName,\n\t\t\t// Azure's own project for the repository: an Azure DevOps Server remote's path may name the collection where\n\t\t\t// the parser read the project (see `AzureDevOpsServerIntegration.getRepositoryTarget`).\n\t\t\tproject: project != null ? repo.project || project : undefined,\n\t\t\tremoteUrl: options.remoteUrl,\n\t\t\trenamed: renamed,\n\t\t\t...getForkInfo(repo),\n\t\t};\n\t\treturn { resolution: { status: 'resolved', identity: identity } };\n\t} catch (ex) {\n\t\t// Order matters: 404 throws RequestNotFoundError (not `undefined`), so check not-found before auth\n\t\t// and before the generic 5xx/unknown bucket — never classify a 401/403 as not-found.\n\t\tlet resolution: RepositoryResolution;\n\t\tif (ex instanceof RequestNotFoundError) {\n\t\t\tresolution = { status: 'not-found' };\n\t\t} else if (ex instanceof AuthenticationError) {\n\t\t\t// One repository refusing a credential that works (e.g. GitHub's OAuth App access restrictions) is that\n\t\t\t// repository's warning, scoped and with its cause, not a dead connection's.\n\t\t\tlet warning = toProviderWarning(id, domain, connectionId, ex);\n\t\t\ttry {\n\t\t\t\tconst failure = await integration.settleRepositoryRefusal(\n\t\t\t\t\t{\n\t\t\t\t\t\towner: owner,\n\t\t\t\t\t\tname:\n\t\t\t\t\t\t\tproject != null\n\t\t\t\t\t\t\t\t? getAzureRepositoryIdentity({ owner: owner, name: name }).repositoryName\n\t\t\t\t\t\t\t\t: name,\n\t\t\t\t\t\tproject: project,\n\t\t\t\t\t\tconnectionId: connectionId,\n\t\t\t\t\t},\n\t\t\t\t\tex,\n\t\t\t\t);\n\t\t\t\tif (failure != null) {\n\t\t\t\t\tconst warnings: ProviderWarning[] = [];\n\t\t\t\t\tmergeAssessmentInto(warnings, id, domain, connectionId, {\n\t\t\t\t\t\tcompleteness: 'partial',\n\t\t\t\t\t\tfailures: [failure],\n\t\t\t\t\t});\n\t\t\t\t\twarning = warnings[0] ?? warning;\n\t\t\t\t}\n\t\t\t} catch (credentialError) {\n\t\t\t\tif (credentialError instanceof AuthenticationError) {\n\t\t\t\t\twarning = toProviderWarning(id, domain, connectionId, credentialError);\n\t\t\t\t}\n\t\t\t}\n\t\t\tresolution = {\n\t\t\t\tstatus: 'unauthorized',\n\t\t\t\twarning: warning,\n\t\t\t};\n\t\t} else {\n\t\t\tresolution = { status: 'undetermined', warning: toProviderWarning(id, domain, connectionId, ex) };\n\t\t}\n\t\treturn { resolution: resolution };\n\t}\n}\n\n/**\n * The fork fields of a provider repository, read defensively: `@gitkraken/provider-apis` does not declare `isFork`\n * or `parent` on its repository type, so a build of the SDK that carries them is read without the type knowing,\n * and one that doesn't reads as \"unknown\" (no `isFork`, no `parent`). `namespace` is the owner, workspace, project key\n * or Azure organization, as the SDK uses it elsewhere. A malformed value is dropped rather than half-trusted. A named\n * parent is itself a report of a fork, so it settles an unreported `isFork` to `true`; one beside `isFork: false`\n * contradicts the flag and is dropped.\n */\nfunction getForkInfo(repo: object): Pick<RepositoryIdentity, 'isFork' | 'parent'> {\n\tconst fork = 'isFork' in repo && typeof repo.isFork === 'boolean' ? repo.isFork : undefined;\n\n\tconst parent = 'parent' in repo ? repo.parent : undefined;\n\tif (\n\t\tfork === false ||\n\t\tparent == null ||\n\t\ttypeof parent !== 'object' ||\n\t\t!('namespace' in parent) ||\n\t\t!('name' in parent) ||\n\t\ttypeof parent.namespace !== 'string' ||\n\t\ttypeof parent.name !== 'string' ||\n\t\t!parent.namespace ||\n\t\t!parent.name\n\t) {\n\t\treturn { isFork: fork };\n\t}\n\n\tconst project =\n\t\t'project' in parent && typeof parent.project === 'string' && parent.project ? parent.project : undefined;\n\treturn {\n\t\tisFork: true,\n\t\tparent: { owner: parent.namespace, name: parent.name, ...(project != null ? { project: project } : {}) },\n\t};\n}\n\n/** Whether `path` is `{x}/_git/{repo}`, the Azure repository path the remote parser reads without a project segment. */\nfunction isProjectlessAzurePath(path: string | undefined): boolean {\n\tconst segments = path?.split('/');\n\treturn segments?.length === 3 && decodePathSegment(segments[1]).toLowerCase() === '_git';\n}\n\n/**\n * Narrows a web remote on a self-managed host to the configured installation it lives under: the pinned\n * connection's or, unpinned, the one whose installation path is the longest prefix of the remote's, so two\n * installations behind one host each resolve with their own credentials. The provider is re-matched against the\n * path relative to that installation, because the remote parsers expect the repository path to start at the\n * host root. An SSH remote carries no installation path, so it is left to the host-level checks.\n */\nfunction matchInstallation(\n\tctx: RepositoryResolutionContext,\n\toptions: ResolveRepositoryOptions,\n\tid: GitSelfManagedHostIntegrationId,\n\tconnections: ConfiguredIntegrationDescriptor[],\n\tremote: { scheme: string; domain: string; path: string },\n):\n\t| { provider: RemoteProvider; connectionId: string | undefined; repoDesc: ResourceDescriptor }\n\t| 'host-mismatch'\n\t| 'invalid-remote-url'\n\t| undefined {\n\tif (!isWebRemoteScheme(remote.scheme)) return undefined;\n\n\tconst installationPath = (connection: ConfiguredIntegrationDescriptor | undefined): string | undefined => {\n\t\tconst baseUrl = getSelfManagedBaseUrl(\n\t\t\tid,\n\t\t\tconnection != null ? (connection.baseUrl ?? connection.domain) : options.domain,\n\t\t);\n\t\treturn baseUrl != null ? new URL(baseUrl).pathname.replace(/\\/+$/, '') : undefined;\n\t};\n\n\t// The connection an unpinned read already targets comes first, so it wins a tie between installations.\n\tconst defaultConnection = connections.find(c => c.primary) ?? connections[0];\n\t// A cloud sync serves the host's cloud-scoped default instead, even over a local primary (see\n\t// `getStoredSession`), so an unpinned read reaches the default's installation only when both agree.\n\tconst cloudConnections = connections.filter(c => c.cloud);\n\tconst cloudDefault = cloudConnections.find(c => c.primary) ?? cloudConnections[0];\n\tconst isDefaultReadable =\n\t\tdefaultConnection?.cloud !== false ||\n\t\tcloudDefault == null ||\n\t\tinstallationPath(cloudDefault) === installationPath(defaultConnection);\n\t// Whether an unpinned read can reach this connection's session: the default one is read without an id, any\n\t// other only by a real cloud token id. Session lookup treats every connection id as one, and a local (PAT)\n\t// descriptor's or domain-derived legacy id is not (see `getConfiguredConnectionId`).\n\tconst isReadable = (connection: ConfiguredIntegrationDescriptor | undefined): boolean =>\n\t\toptions.connectionId != null ||\n\t\t(connection === defaultConnection\n\t\t\t? isDefaultReadable\n\t\t\t: connection?.cloud === true && hostFromDomain(connection.id) !== connection.domain);\n\n\tconst candidates: (ConfiguredIntegrationDescriptor | undefined)[] =\n\t\toptions.connectionId != null\n\t\t\t? connections.filter(c => c.id === options.connectionId)\n\t\t\t: [defaultConnection, ...connections.filter(c => c !== defaultConnection)];\n\t// With no configured candidate, the explicit (trusted) `domain` is the only installation address there is.\n\tif (!candidates.length) {\n\t\tcandidates.push(undefined);\n\t}\n\n\tconst remotePath = `/${remote.path}`;\n\tconst remoteSegments = remote.path.split('/');\n\t// The remote's path below an installation, or `undefined` when it isn't under it. Azure DevOps Server runs on\n\t// IIS, which serves its paths decoded and case-insensitively, so it compares segment by segment.\n\tconst relativeTo = (basePath: string): string | undefined => {\n\t\tif (id !== GitSelfManagedHostIntegrationId.AzureDevOpsServer) {\n\t\t\treturn remotePath.startsWith(`${basePath}/`) ? remotePath.slice(basePath.length + 1) : undefined;\n\t\t}\n\n\t\tconst baseSegments = basePath.split('/').filter(Boolean);\n\t\tconst isUnder =\n\t\t\tremoteSegments.length > baseSegments.length &&\n\t\t\tbaseSegments.every(\n\t\t\t\t(segment, i) =>\n\t\t\t\t\tdecodePathSegment(segment).toLowerCase() === decodePathSegment(remoteSegments[i]).toLowerCase(),\n\t\t\t);\n\t\treturn isUnder ? remoteSegments.slice(baseSegments.length).join('/') : undefined;\n\t};\n\tlet match: { connection: ConfiguredIntegrationDescriptor | undefined; basePath: string } | undefined;\n\tlet checked = false;\n\tfor (const connection of candidates) {\n\t\tconst basePath = installationPath(connection);\n\t\tif (basePath == null) continue;\n\n\t\tchecked = true;\n\t\tif (relativeTo(basePath) == null) continue;\n\n\t\t// The longest installation wins; on a tie, a readable connection replaces an unreadable one.\n\t\tconst isBetter =\n\t\t\tmatch == null ||\n\t\t\tbasePath.length > match.basePath.length ||\n\t\t\t(basePath.length === match.basePath.length && !isReadable(match.connection) && isReadable(connection));\n\t\tif (isBetter) {\n\t\t\tmatch = { connection: connection, basePath: basePath };\n\t\t}\n\t}\n\tif (match == null) return checked ? 'host-mismatch' : undefined;\n\t// Reading through the default connection instead would address its installation with a path relative to\n\t// another one, so an unreachable installation fails closed.\n\tif (!isReadable(match.connection)) return 'host-mismatch';\n\n\tconst connectionId =\n\t\toptions.connectionId ?? (match.connection !== defaultConnection ? match.connection?.id : undefined);\n\n\tconst matcher = createRemoteProviderMatcher(\n\t\tbuildMatcherConfigs(ctx, { ...options, providerId: id }, remote.domain),\n\t);\n\tconst rematch = (path: string) => matcher(options.remoteUrl, remote.domain, relativeTo(path) ?? '', remote.scheme);\n\tlet basePath = match.basePath;\n\tlet provider = rematch(basePath);\n\tif (id !== GitSelfManagedHostIntegrationId.AzureDevOpsServer) {\n\t\treturn provider != null\n\t\t\t? { provider: provider, connectionId: connectionId, repoDesc: provider.repoDesc }\n\t\t\t: 'invalid-remote-url';\n\t}\n\n\t// An Azure DevOps Server address may name the collection as well as the virtual directory; the parser expects\n\t// the collection in the path, so re-base on the address's parent when no project was found. A relative\n\t// `{x}/_git/{repo}` re-bases too: `x` is a collection only if the address is the installation rather than a\n\t// collection, which the path can't tell, so the integration settles it against the collections it discovers.\n\tif (basePath && (provider?.providerDesc?.repoDomain == null || isProjectlessAzurePath(relativeTo(basePath)))) {\n\t\tbasePath = basePath.slice(0, basePath.lastIndexOf('/'));\n\t\tprovider = rematch(basePath);\n\t}\n\tif (provider == null) return 'invalid-remote-url';\n\n\t// Requests address the repository's virtual directory from the host root, not from the installation the\n\t// re-match made it relative to; the absolute form also tells a directory apart from a collection of that name.\n\tconst repoDesc = provider.repoDesc;\n\tconst relative = typeof repoDesc.virtualDirectory === 'string' ? repoDesc.virtualDirectory : undefined;\n\tconst virtualDirectory =\n\t\t[...basePath.split('/').filter(Boolean).map(decodePathSegment), ...(relative?.split('/') ?? [])].join('/') ||\n\t\tundefined;\n\treturn {\n\t\tprovider: provider,\n\t\tconnectionId: connectionId,\n\t\trepoDesc: { ...repoDesc, virtualDirectory: virtualDirectory },\n\t};\n}\n\n/**\n * The remote-matcher configs for this resolution: the user's own host remote configs (self-managed/custom\n * domains), plus a synthetic exact-domain entry for an explicit `providerId` + host so a custom domain still maps\n * to the right provider for path parsing.\n */\nfunction buildMatcherConfigs(\n\tctx: RepositoryResolutionContext,\n\toptions: { providerId?: IntegrationIds; host?: string },\n\tparsedDomain: string,\n): RemoteProviderConfig[] {\n\tconst configs: RemoteProviderConfig[] = [];\n\tfor (const cfg of ctx.getRemoteConfigs()) {\n\t\tconst type = remoteProviderTypeForConfig(cfg.type);\n\t\tif (type == null) continue;\n\n\t\t// Forward both domain- and regex-based custom remotes (carrying any protocol override), so a\n\t\t// regex-configured host resolves instead of falling through to `unsupported`.\n\t\tif (cfg.domain) {\n\t\t\tconfigs.push({ type: type, domain: cfg.domain, protocol: cfg.protocol });\n\t\t} else if (cfg.regex) {\n\t\t\tconfigs.push({ type: type, regex: cfg.regex, protocol: cfg.protocol });\n\t\t}\n\t}\n\tif (options.providerId == null) return configs;\n\n\tconst type = remoteProviderTypeForIntegration(options.providerId);\n\tconst domain = parsedDomain || options.host;\n\tif (type == null || !domain) return configs;\n\n\t// The synthetic exact-domain entry is unshifted to the front, so it wins the match over the user's own\n\t// config for the same host. Carry that config's protocol override across (matched by domain or regex,\n\t// mirroring `ignoreSSLErrors`) so a self-managed host configured for a custom protocol — e.g. plain\n\t// `http` — isn't silently downgraded to the provider default here.\n\tconst lowerDomain = domain.toLowerCase();\n\tconst protocol = configs.find(c => {\n\t\tif (c.type !== type) return false;\n\t\tif (c.domain != null) return c.domain.toLowerCase() === lowerDomain;\n\n\t\t// Truthy (not just non-null): an empty regex would compile to a match-everything pattern.\n\t\tif (c.regex) {\n\t\t\ttry {\n\t\t\t\treturn new RegExp(c.regex, 'i').test(lowerDomain);\n\t\t\t} catch {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn false;\n\t})?.protocol;\n\tconfigs.unshift({ type: type, domain: domain, protocol: protocol });\n\treturn configs;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAiDA,eAAsB,kBACrB,KACA,SACmC;CACnC,MAAM,UAAU,YAAqE,EACpF,YAAY,EAAU,OAAO,EAC9B;CAEA,MAAM,CAAC,QAAQ,cAAc,QAAQ,kBAAkB,QAAQ,SAAS;CAExE,MAAM,aAAa,qBAAqB,MAAM;CAC9C,MAAM,aAAa,eAAe,YAAY;CAC9C,MAAM,eAAe,eAAe,QAAQ,IAAI;CAChD,IAAI,cAA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,UAAU;GAAE,GAAG;GAA4B;EAAiB;CAC7D;AACD;;;;;;AAOA,SAAS,oBACR,KACA,SACA,cACyB;CACzB,MAAM,UAAkC,CAAC;CACzC,KAAK,MAAM,OAAO,IAAI,iBAAiB,GAAG;EACzC,MAAM,OAAO,4BAA4B,IAAI,IAAI;EACjD,IAAI,QAAQ,MAAM;EAIlB,IAAI,IAAI,QACP,QAAQ,KAAK;GAAQ;GAAM,QAAQ,IAAI;GAAQ,UAAU,IAAI;EAAS,CAAC;OACjE,IAAI,IAAI,OACd,QAAQ,KAAK;GAAQ;GAAM,OAAO,IAAI;GAAO,UAAU,IAAI;EAAS,CAAC;CAEvE;CACA,IAAI,QAAQ,cAAc,MAAM,OAAO;CAEvC,MAAM,OAAO,iCAAiC,QAAQ,UAAU;CAChE,MAAM,SAAS,gBAAgB,QAAQ;CACvC,IAAI,QAAQ,QAAQ,CAAC,QAAQ,OAAO;CAMpC,MAAM,cAAc,OAAO,YAAY;CACvC,MAAM,WAAW,QAAQ,MAAK,MAAK;EAClC,IAAI,EAAE,SAAS,MAAM,OAAO;EAC5B,IAAI,EAAE,UAAU,MAAM,OAAO,EAAE,OAAO,YAAY,MAAM;EAGxD,IAAI,EAAE,OACL,IAAI;GACH,OAAO,IAAI,OAAO,EAAE,OAAO,GAAG,CAAC,CAAC,KAAK,WAAW;EACjD,QAAQ;GACP,OAAO;EACR;EAGD,OAAO;CACR,CAAC,CAAC,EAAE;CACJ,QAAQ,QAAQ;EAAQ;EAAc;EAAkB;CAAS,CAAC;CAClE,OAAO;AACR"}
1
+ {"version":3,"file":"resolveRepository.js","names":[],"sources":["../../../../../plus/integrations/src/reads/resolveRepository.ts"],"sourcesContent":["import type { RemoteProvider } from '@gitlens/git/models/remoteProvider.js';\nimport type { ResourceDescriptor } from '@gitlens/git/models/resourceDescriptor.js';\nimport type { RemoteProviderConfig } from '@gitlens/git/remotes/matcher.js';\nimport { createRemoteProviderMatcher } from '@gitlens/git/remotes/matcher.js';\nimport { parseGitRemoteUrl } from '@gitlens/git/utils/remote.utils.js';\nimport { trimTrailingSlashes } from '@gitlens/utils/path.js';\nimport type { ConfiguredIntegrationDescriptor } from '../authentication/models.js';\nimport { mergeAssessmentInto } from '../collectionMetadata.js';\nimport type { IntegrationIds } from '../constants.js';\nimport { GitCloudHostIntegrationId, GitSelfManagedHostIntegrationId } from '../constants.js';\nimport { AuthenticationError, RequestNotFoundError } from '../errors.js';\nimport { isIssuesIntegration } from '../models/issuesIntegration.js';\nimport { getAzureRepositoryIdentity } from '../providers/azure/azure.utils.js';\nimport type { ProviderRepository } from '../providers/models.js';\nimport { isAzureCloudDomain, isBitbucketCloudDomain, isGitHubDotCom, isGitLabDotCom } from '../providers/models.js';\nimport type { ProviderWarning, RepositoryIdentity, RepositoryResolution, ResolveRepositoryResult } from '../results.js';\nimport { toProviderWarning } from '../results.js';\nimport { decodePathSegment, getRemoteHostMatcher, hostFromDomain, isWebRemoteScheme } from '../utils/domain.utils.js';\nimport {\n\tgetIntegrationIdForRemote,\n\tgetSelfManagedBaseUrl,\n\tisGitCloudHostIntegrationId,\n\tisGitSelfManagedHostIntegrationId,\n\tremoteProviderTypeForConfig,\n\tremoteProviderTypeForIntegration,\n} from '../utils/integration.utils.js';\nimport type { RepositoryResolutionContext } from './context.js';\nimport { noConnectionWarning } from './warnings.js';\n\ntype ResolveRepositoryOptions = {\n\tproviderId?: IntegrationIds;\n\tremoteUrl: string;\n\thost?: string;\n\tconnectionId?: string;\n\t/**\n\t * Explicit self-managed host domain used to select the integration instance. Used only when the requested\n\t * connection has no configured domain; it must come from the trusted authentication configuration, not\n\t * repository or remote data.\n\t */\n\tdomain?: string;\n};\n\n/**\n * Resolution of a remote URL to a provider repository identity — the facade's equivalent of `gk repo resolve`.\n *\n * Unlike every other read here, this one's input is REPOSITORY data, so most of the code below is about not\n * letting that data choose the credentials: an explicit cloud `providerId` must agree with the remote's canonical\n * host, and a self-managed host resolves only against a domain the user already authenticated. The\n * `host-mismatch` returns are those guards, not edge cases — resolving `owner/repo` against the wrong account\n * would hand back a confidently wrong identity and seed the domain-keyed instance cache from remote data.\n */\nexport async function resolveRepository(\n\tctx: RepositoryResolutionContext,\n\toptions: ResolveRepositoryOptions,\n): Promise<ResolveRepositoryResult> {\n\tconst result = (status: RepositoryResolution['status']): ResolveRepositoryResult => ({\n\t\tresolution: { status: status },\n\t});\n\n\tconst [scheme, parsedDomain, parsedPath] = parseGitRemoteUrl(options.remoteUrl);\n\t// Git accepts a trailing slash but no provider's path carries one: GitLab wouldn't find it, and a host that does\n\t// would report the slashless name as a rename.\n\tconst path = trimTrailingSlashes(parsedPath);\n\t// An SSH remote's port belongs to its SSH daemon, not to the web authority a connection is keyed by.\n\tconst hostsMatch = getRemoteHostMatcher(scheme);\n\tconst parsedHost = hostFromDomain(parsedDomain);\n\tconst explicitHost = hostFromDomain(options.host);\n\tif (parsedHost != null && explicitHost != null && !hostsMatch(parsedHost, explicitHost)) {\n\t\treturn result('host-mismatch');\n\t}\n\n\tconst matcherDomain = parsedDomain || options.host || '';\n\n\t// An explicit cloud provider must agree with the remote's canonical cloud host. Without this guard the\n\t// synthetic matcher below can reinterpret, for example, a gitlab.com URL as GitHub and then resolve a\n\t// homonymous owner/repo through the wrong account. Match once without caller configs/synthetic entries;\n\t// Azure's matcher also normalizes ssh.dev.azure.com and vs-ssh.visualstudio.com to their web host.\n\tif (options.providerId != null && isGitCloudHostIntegrationId(options.providerId)) {\n\t\tconst nativeProvider = createRemoteProviderMatcher([])(options.remoteUrl, matcherDomain, path, scheme);\n\t\tconst nativeId = nativeProvider != null ? getIntegrationIdForRemote(nativeProvider) : undefined;\n\t\tconst nativeDomain = nativeProvider?.domain ?? matcherDomain;\n\t\tconst canonicalHost =\n\t\t\toptions.providerId === GitCloudHostIntegrationId.GitHub\n\t\t\t\t? isGitHubDotCom(nativeDomain)\n\t\t\t\t: options.providerId === GitCloudHostIntegrationId.GitLab\n\t\t\t\t\t? isGitLabDotCom(nativeDomain)\n\t\t\t\t\t: options.providerId === GitCloudHostIntegrationId.Bitbucket\n\t\t\t\t\t\t? isBitbucketCloudDomain(nativeDomain)\n\t\t\t\t\t\t: isAzureCloudDomain(nativeDomain);\n\t\tif (nativeId !== options.providerId || !canonicalHost) return result('host-mismatch');\n\t}\n\n\tlet provider = createRemoteProviderMatcher(buildMatcherConfigs(ctx, options, parsedDomain))(\n\t\toptions.remoteUrl,\n\t\tmatcherDomain,\n\t\tpath,\n\t\tscheme,\n\t);\n\tif (provider == null) return result('invalid-remote-url');\n\n\tlet id = options.providerId ?? getIntegrationIdForRemote(provider);\n\t// Custom Azure DevOps Server domains matched via getRemoteConfigs return undefined from\n\t// getIntegrationIdForRemote because the provider is marked custom; map them to the server id so the\n\t// project-scoped lookup uses that host's configured connection and API base URL.\n\tif (id == null && provider.id === 'azure-devops' && provider.custom) {\n\t\tid = GitSelfManagedHostIntegrationId.AzureDevOpsServer;\n\t}\n\tif (id == null) return result('unsupported-provider');\n\n\t// On a self-managed host, resolve only against a TRUSTED host: the pinned connection's configured\n\t// domain, the explicit `domain`, or — when neither was supplied — a configured host matching the\n\t// remote's. That last case keeps `remoteUrl` (repository-supplied) out of the trusted path: it selects\n\t// among hosts the user already authenticated and can never introduce a new one. Resolving `owner/repo`\n\t// against some other host's account would, if that host has the same owner/repo, return a confidently\n\t// wrong identity — and would seed the domain-keyed integration cache (never evicted before dispose) with\n\t// an entry derived from repository data.\n\tconst urlHost = hostFromDomain(provider.domain);\n\t// Normalize BOTH sides before comparing: a stored connection domain is usually a full URL\n\t// (`https://git.example.com`) while `urlHost` is already a bare host, so a raw compare would fail on\n\t// scheme/trailing-slash alone and wrongly reject a correctly-configured connection.\n\tlet trustedHost =\n\t\toptions.connectionId != null || options.domain != null\n\t\t\t? hostFromDomain(ctx.resolveDomainForRead(id, options.connectionId, options.domain))\n\t\t\t: undefined;\n\tlet connectionId = options.connectionId;\n\tlet providerRepo: ResourceDescriptor | undefined;\n\tif (isGitSelfManagedHostIntegrationId(id)) {\n\t\tif (path.split('/').some(segment => /^(?:\\.|%2e){1,2}$/i.test(segment) || /%2f|%5c|\\\\/i.test(segment))) {\n\t\t\treturn result('invalid-remote-url');\n\t\t}\n\n\t\tconst configured = ctx.getConfigured(id);\n\t\tconst configuredHosts = configured.map(c => hostFromDomain(c.domain));\n\t\tif (trustedHost == null && urlHost != null) {\n\t\t\tconst matchingHosts = new Set(configuredHosts.filter(host => hostsMatch(host, urlHost)));\n\t\t\tif (matchingHosts.size > 1) return result('host-mismatch');\n\n\t\t\ttrustedHost = matchingHosts.values().next().value;\n\t\t}\n\t\t// A configured host that doesn't match the remote's is a genuine mismatch. With nothing configured\n\t\t// there is no host to mismatch against — it's simply not connected, so fall through to the\n\t\t// `unauthorized` path below (still WITHOUT resolving by the URL domain, so repo data can't seed the\n\t\t// cache).\n\t\tif (trustedHost == null && configuredHosts.length !== 0) return result('host-mismatch');\n\t\tif (trustedHost != null && urlHost != null && !hostsMatch(trustedHost, urlHost)) {\n\t\t\treturn result('host-mismatch');\n\t\t}\n\n\t\tconst installation = matchInstallation(\n\t\t\tctx,\n\t\t\toptions,\n\t\t\tid,\n\t\t\tconfigured.filter(c => hostFromDomain(c.domain) === trustedHost),\n\t\t\t{ scheme: scheme, domain: parsedDomain, path: path },\n\t\t);\n\t\tif (typeof installation === 'string') return result(installation);\n\n\t\tif (installation != null) {\n\t\t\tprovider = installation.provider;\n\t\t\tconnectionId = installation.connectionId;\n\t\t\tproviderRepo = installation.repoDesc;\n\t\t}\n\t}\n\n\tconst owner = provider.owner;\n\tconst name = provider.repoName;\n\tif (owner == null || name == null) return result('invalid-remote-url');\n\n\tproviderRepo ??= provider.repoDesc;\n\n\tlet integration;\n\ttry {\n\t\t// Resolve the instance through the trusted target (as `getIntegrationForRead` does):\n\t\t// `resolveReadSession` looks the session up against the instance's domain-scoped descriptor, so\n\t\t// selecting the instance by the URL domain could miss the session and degrade to `no-connection`.\n\t\tintegration = isGitSelfManagedHostIntegrationId(id)\n\t\t\t? trustedHost != null\n\t\t\t\t? await ctx.getIntegrationForRead(id, connectionId, trustedHost)\n\t\t\t\t: undefined\n\t\t\t: await ctx.getIntegrationForDomain(id, provider.domain);\n\t} catch {\n\t\tintegration = undefined;\n\t}\n\tif (integration == null) {\n\t\t// Attach a warning, as the thrown-AuthenticationError branch below does: a consumer driving auth\n\t\t// recovery off `warning.kind` would otherwise get nothing for an unresolvable target.\n\t\treturn {\n\t\t\tresolution: {\n\t\t\t\tstatus: 'unauthorized',\n\t\t\t\twarning: noConnectionWarning(id, provider.domain, connectionId),\n\t\t\t},\n\t\t};\n\t}\n\t// Issue trackers have no `getRepo` client; a git host without `getRepoFn` leaves `getRepoInfo`\n\t// undefined. Either way this provider can't resolve repositories.\n\tif (isIssuesIntegration(integration) || integration.getRepoInfo == null) {\n\t\treturn result('unsupported-provider');\n\t}\n\n\t// Azure repos are org + project scoped; the remote provider exposes project as `providerDesc.repoDomain`.\n\tconst project = provider.id === 'azure-devops' ? provider.providerDesc?.repoDomain : undefined;\n\tconst domain = trustedHost ?? provider.domain;\n\n\t// Azure's lookup is project-scoped and returns `undefined` without one, which the connection-gap branch\n\t// below would misreport as `unauthorized` (driving a pointless reconnect). A remote URL that carries no\n\t// project simply can't address an Azure repo.\n\tif (provider.id === 'azure-devops' && project == null) return result('invalid-remote-url');\n\n\t// Azure names the repository bare and its project apart, where the remote names `{project}/_git/{repo}`.\n\tconst repositoryName =\n\t\tproject != null ? getAzureRepositoryIdentity({ owner: owner, name: name }).repositoryName : name;\n\n\ttry {\n\t\tconst repo = await integration.getRepoInfo({\n\t\t\t...providerRepo,\n\t\t\towner: owner,\n\t\t\tname: name,\n\t\t\tproject: project,\n\t\t\tconnectionId: connectionId,\n\t\t});\n\t\tif (repo == null) {\n\t\t\t// `getRepoInfo` returns undefined only when no session could be resolved (not connected, or the\n\t\t\t// requested connection is gone) — a real 404 throws below. So this is a connection gap. Attach a\n\t\t\t// warning so a consumer driving auth recovery off `warning.kind` sees the same signal it gets from\n\t\t\t// the thrown-AuthenticationError branch below; without it, the most common unauthorized case is\n\t\t\t// silent.\n\t\t\treturn {\n\t\t\t\tresolution: {\n\t\t\t\t\tstatus: 'unauthorized',\n\t\t\t\t\twarning: noConnectionWarning(id, domain, connectionId),\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\t// Prefer the provider's canonical namespace/name (GitHub's REST/GraphQL lookup follows the 301\n\t\t// rename redirect, so a stale old name resolves to the new canonical identity), falling back to where the\n\t\t// repository was read when the response omits them. `renamed` is a case-insensitive compare of that against\n\t\t// canonical, mirroring gkcli's `EqualFold`, so hosts that merely echo the input casing (e.g.\n\t\t// Bitbucket Server/Azure) don't get spuriously flagged. An Azure DevOps Server remote's path may be read as\n\t\t// another collection and project than the parser read (see `AzureDevOpsServerIntegration.getRepositoryTarget`),\n\t\t// which is no rename, so the compare is against where it was read. Owner and name are compared joined, because\n\t\t// the sides split a GitLab nested group differently: the remote at its first slash, the SDK at its last.\n\t\tconst readAt = repo.readAt ?? { owner: owner, name: repositoryName, project: project };\n\t\tconst canonicalOwner = repo.namespace || readAt.owner;\n\t\tconst canonicalName = repo.name || readAt.name;\n\t\tconst readAtProject = project != null ? readAt.project || project : undefined;\n\t\tconst canonicalProject = readAtProject != null ? repo.project || readAtProject : undefined;\n\t\tconst differs = (a: string | undefined, b: string | undefined) => a?.toLowerCase() !== b?.toLowerCase();\n\t\tconst renamed =\n\t\t\tdiffers(`${canonicalOwner}/${canonicalName}`, `${readAt.owner}/${readAt.name}`) ||\n\t\t\tdiffers(canonicalProject, readAtProject);\n\n\t\tconst identity: RepositoryIdentity = {\n\t\t\tproviderId: id,\n\t\t\tdomain: domain,\n\t\t\towner: canonicalOwner,\n\t\t\tname: canonicalName,\n\t\t\tproject: canonicalProject,\n\t\t\tremoteUrl: options.remoteUrl,\n\t\t\trenamed: renamed,\n\t\t\t...getForkInfo(repo),\n\t\t};\n\t\treturn { resolution: { status: 'resolved', identity: identity } };\n\t} catch (ex) {\n\t\t// Order matters: 404 throws RequestNotFoundError (not `undefined`), so check not-found before auth\n\t\t// and before the generic 5xx/unknown bucket — never classify a 401/403 as not-found.\n\t\tlet resolution: RepositoryResolution;\n\t\tif (ex instanceof RequestNotFoundError) {\n\t\t\tresolution = { status: 'not-found' };\n\t\t} else if (ex instanceof AuthenticationError) {\n\t\t\t// One repository refusing a credential that works (e.g. GitHub's OAuth App access restrictions) is that\n\t\t\t// repository's warning, scoped and with its cause, not a dead connection's.\n\t\t\tlet warning = toProviderWarning(id, domain, connectionId, ex);\n\t\t\ttry {\n\t\t\t\tconst failure = await integration.settleRepositoryRefusal(\n\t\t\t\t\t{\n\t\t\t\t\t\towner: owner,\n\t\t\t\t\t\tname: repositoryName,\n\t\t\t\t\t\tproject: project,\n\t\t\t\t\t\tconnectionId: connectionId,\n\t\t\t\t\t},\n\t\t\t\t\tex,\n\t\t\t\t);\n\t\t\t\tif (failure != null) {\n\t\t\t\t\tconst warnings: ProviderWarning[] = [];\n\t\t\t\t\tmergeAssessmentInto(warnings, id, domain, connectionId, {\n\t\t\t\t\t\tcompleteness: 'partial',\n\t\t\t\t\t\tfailures: [failure],\n\t\t\t\t\t});\n\t\t\t\t\twarning = warnings[0] ?? warning;\n\t\t\t\t}\n\t\t\t} catch (credentialError) {\n\t\t\t\tif (credentialError instanceof AuthenticationError) {\n\t\t\t\t\twarning = toProviderWarning(id, domain, connectionId, credentialError);\n\t\t\t\t}\n\t\t\t}\n\t\t\tresolution = {\n\t\t\t\tstatus: 'unauthorized',\n\t\t\t\twarning: warning,\n\t\t\t};\n\t\t} else {\n\t\t\tresolution = { status: 'undetermined', warning: toProviderWarning(id, domain, connectionId, ex) };\n\t\t}\n\t\treturn { resolution: resolution };\n\t}\n}\n\n/**\n * The fork fields of a provider repository. `namespace` is the owner, workspace, project key, Azure organization or\n * GitLab group path (`group/subgroup`), as the SDK uses it elsewhere. A named parent is itself a report of a fork, so\n * it settles an unreported `isFork` to `true`; one beside `isFork: false` contradicts the flag and is dropped. So is\n * one with an empty namespace or name: the type allows it, and GitLab's is split from a path the server sends, which\n * leaves no namespace when it has no `/`. It can't address a repository, but the fork is still reported.\n */\nfunction getForkInfo(repo: ProviderRepository): Pick<RepositoryIdentity, 'isFork' | 'parent'> {\n\tconst { isFork, parent } = repo;\n\tif (isFork === false || !parent?.namespace || !parent.name) return { isFork: isFork };\n\n\treturn {\n\t\tisFork: true,\n\t\tparent: {\n\t\t\towner: parent.namespace,\n\t\t\tname: parent.name,\n\t\t\t...(parent.project ? { project: parent.project } : {}),\n\t\t},\n\t};\n}\n\n/** Whether `path` is `{x}/_git/{repo}`, the Azure repository path the remote parser reads without a project segment. */\nfunction isProjectlessAzurePath(path: string | undefined): boolean {\n\tconst segments = path?.split('/');\n\treturn segments?.length === 3 && decodePathSegment(segments[1]).toLowerCase() === '_git';\n}\n\n/**\n * Narrows a web remote on a self-managed host to the configured installation it lives under: the pinned\n * connection's or, unpinned, the one whose installation path is the longest prefix of the remote's, so two\n * installations behind one host each resolve with their own credentials. The provider is re-matched against the\n * path relative to that installation, because the remote parsers expect the repository path to start at the\n * host root. An SSH remote carries no installation path, so it is left to the host-level checks.\n */\nfunction matchInstallation(\n\tctx: RepositoryResolutionContext,\n\toptions: ResolveRepositoryOptions,\n\tid: GitSelfManagedHostIntegrationId,\n\tconnections: ConfiguredIntegrationDescriptor[],\n\tremote: { scheme: string; domain: string; path: string },\n):\n\t| { provider: RemoteProvider; connectionId: string | undefined; repoDesc: ResourceDescriptor }\n\t| 'host-mismatch'\n\t| 'invalid-remote-url'\n\t| undefined {\n\tif (!isWebRemoteScheme(remote.scheme)) return undefined;\n\n\tconst installationPath = (connection: ConfiguredIntegrationDescriptor | undefined): string | undefined => {\n\t\tconst baseUrl = getSelfManagedBaseUrl(\n\t\t\tid,\n\t\t\tconnection != null ? (connection.baseUrl ?? connection.domain) : options.domain,\n\t\t);\n\t\treturn baseUrl != null ? trimTrailingSlashes(new URL(baseUrl).pathname) : undefined;\n\t};\n\n\t// The connection an unpinned read already targets comes first, so it wins a tie between installations.\n\tconst defaultConnection = connections.find(c => c.primary) ?? connections[0];\n\t// A cloud sync serves the host's cloud-scoped default instead, even over a local primary (see\n\t// `getStoredSession`), so an unpinned read reaches the default's installation only when both agree.\n\tconst cloudConnections = connections.filter(c => c.cloud);\n\tconst cloudDefault = cloudConnections.find(c => c.primary) ?? cloudConnections[0];\n\tconst isDefaultReadable =\n\t\tdefaultConnection?.cloud !== false ||\n\t\tcloudDefault == null ||\n\t\tinstallationPath(cloudDefault) === installationPath(defaultConnection);\n\t// Whether an unpinned read can reach this connection's session: the default one is read without an id, any\n\t// other only by a real cloud token id. Session lookup treats every connection id as one, and a local (PAT)\n\t// descriptor's or domain-derived legacy id is not (see `getConfiguredConnectionId`).\n\tconst isReadable = (connection: ConfiguredIntegrationDescriptor | undefined): boolean =>\n\t\toptions.connectionId != null ||\n\t\t(connection === defaultConnection\n\t\t\t? isDefaultReadable\n\t\t\t: connection?.cloud === true && hostFromDomain(connection.id) !== connection.domain);\n\n\tconst candidates: (ConfiguredIntegrationDescriptor | undefined)[] =\n\t\toptions.connectionId != null\n\t\t\t? connections.filter(c => c.id === options.connectionId)\n\t\t\t: [defaultConnection, ...connections.filter(c => c !== defaultConnection)];\n\t// With no configured candidate, the explicit (trusted) `domain` is the only installation address there is.\n\tif (!candidates.length) {\n\t\tcandidates.push(undefined);\n\t}\n\n\tconst remotePath = `/${remote.path}`;\n\tconst remoteSegments = remote.path.split('/');\n\t// The remote's path below an installation, or `undefined` when it isn't under it. Azure DevOps Server runs on\n\t// IIS, which serves its paths decoded and case-insensitively, so it compares segment by segment.\n\tconst relativeTo = (basePath: string): string | undefined => {\n\t\tif (id !== GitSelfManagedHostIntegrationId.AzureDevOpsServer) {\n\t\t\treturn remotePath.startsWith(`${basePath}/`) ? remotePath.slice(basePath.length + 1) : undefined;\n\t\t}\n\n\t\tconst baseSegments = basePath.split('/').filter(Boolean);\n\t\tconst isUnder =\n\t\t\tremoteSegments.length > baseSegments.length &&\n\t\t\tbaseSegments.every(\n\t\t\t\t(segment, i) =>\n\t\t\t\t\tdecodePathSegment(segment).toLowerCase() === decodePathSegment(remoteSegments[i]).toLowerCase(),\n\t\t\t);\n\t\treturn isUnder ? remoteSegments.slice(baseSegments.length).join('/') : undefined;\n\t};\n\tlet match: { connection: ConfiguredIntegrationDescriptor | undefined; basePath: string } | undefined;\n\tlet checked = false;\n\tfor (const connection of candidates) {\n\t\tconst basePath = installationPath(connection);\n\t\tif (basePath == null) continue;\n\n\t\tchecked = true;\n\t\tif (relativeTo(basePath) == null) continue;\n\n\t\t// The longest installation wins; on a tie, a readable connection replaces an unreadable one.\n\t\tconst isBetter =\n\t\t\tmatch == null ||\n\t\t\tbasePath.length > match.basePath.length ||\n\t\t\t(basePath.length === match.basePath.length && !isReadable(match.connection) && isReadable(connection));\n\t\tif (isBetter) {\n\t\t\tmatch = { connection: connection, basePath: basePath };\n\t\t}\n\t}\n\tif (match == null) return checked ? 'host-mismatch' : undefined;\n\t// Reading through the default connection instead would address its installation with a path relative to\n\t// another one, so an unreachable installation fails closed.\n\tif (!isReadable(match.connection)) return 'host-mismatch';\n\n\tconst connectionId =\n\t\toptions.connectionId ?? (match.connection !== defaultConnection ? match.connection?.id : undefined);\n\n\tconst matcher = createRemoteProviderMatcher(\n\t\tbuildMatcherConfigs(ctx, { ...options, providerId: id }, remote.domain),\n\t);\n\tconst rematch = (path: string) => matcher(options.remoteUrl, remote.domain, relativeTo(path) ?? '', remote.scheme);\n\tlet basePath = match.basePath;\n\tlet provider = rematch(basePath);\n\tif (id !== GitSelfManagedHostIntegrationId.AzureDevOpsServer) {\n\t\treturn provider != null\n\t\t\t? { provider: provider, connectionId: connectionId, repoDesc: provider.repoDesc }\n\t\t\t: 'invalid-remote-url';\n\t}\n\n\t// An Azure DevOps Server address may name the collection as well as the virtual directory; the parser expects\n\t// the collection in the path, so re-base on the address's parent when no project was found. A relative\n\t// `{x}/_git/{repo}` re-bases too: `x` is a collection only if the address is the installation rather than a\n\t// collection, which the path can't tell, so the integration settles it against the collections it discovers.\n\tif (basePath && (provider?.providerDesc?.repoDomain == null || isProjectlessAzurePath(relativeTo(basePath)))) {\n\t\tbasePath = basePath.slice(0, basePath.lastIndexOf('/'));\n\t\tprovider = rematch(basePath);\n\t}\n\tif (provider == null) return 'invalid-remote-url';\n\n\t// Requests address the repository's virtual directory from the host root, not from the installation the\n\t// re-match made it relative to; the absolute form also tells a directory apart from a collection of that name.\n\tconst repoDesc = provider.repoDesc;\n\tconst relative = typeof repoDesc.virtualDirectory === 'string' ? repoDesc.virtualDirectory : undefined;\n\tconst virtualDirectory =\n\t\t[...basePath.split('/').filter(Boolean).map(decodePathSegment), ...(relative?.split('/') ?? [])].join('/') ||\n\t\tundefined;\n\treturn {\n\t\tprovider: provider,\n\t\tconnectionId: connectionId,\n\t\trepoDesc: { ...repoDesc, virtualDirectory: virtualDirectory },\n\t};\n}\n\n/**\n * The remote-matcher configs for this resolution: the user's own host remote configs (self-managed/custom\n * domains), plus a synthetic exact-domain entry for an explicit `providerId` + host so a custom domain still maps\n * to the right provider for path parsing.\n */\nfunction buildMatcherConfigs(\n\tctx: RepositoryResolutionContext,\n\toptions: { providerId?: IntegrationIds; host?: string },\n\tparsedDomain: string,\n): RemoteProviderConfig[] {\n\tconst configs: RemoteProviderConfig[] = [];\n\tfor (const cfg of ctx.getRemoteConfigs()) {\n\t\tconst type = remoteProviderTypeForConfig(cfg.type);\n\t\tif (type == null) continue;\n\n\t\t// Forward both domain- and regex-based custom remotes (carrying any protocol override), so a\n\t\t// regex-configured host resolves instead of falling through to `unsupported`.\n\t\tif (cfg.domain) {\n\t\t\tconfigs.push({ type: type, domain: cfg.domain, protocol: cfg.protocol });\n\t\t} else if (cfg.regex) {\n\t\t\tconfigs.push({ type: type, regex: cfg.regex, protocol: cfg.protocol });\n\t\t}\n\t}\n\tif (options.providerId == null) return configs;\n\n\tconst type = remoteProviderTypeForIntegration(options.providerId);\n\tconst domain = parsedDomain || options.host;\n\tif (type == null || !domain) return configs;\n\n\t// The synthetic exact-domain entry is unshifted to the front, so it wins the match over the user's own\n\t// config for the same host. Carry that config's protocol override across (matched by domain or regex,\n\t// mirroring `ignoreSSLErrors`) so a self-managed host configured for a custom protocol — e.g. plain\n\t// `http` — isn't silently downgraded to the provider default here.\n\tconst lowerDomain = domain.toLowerCase();\n\tconst protocol = configs.find(c => {\n\t\tif (c.type !== type) return false;\n\t\tif (c.domain != null) return c.domain.toLowerCase() === lowerDomain;\n\n\t\t// Truthy (not just non-null): an empty regex would compile to a match-everything pattern.\n\t\tif (c.regex) {\n\t\t\ttry {\n\t\t\t\treturn new RegExp(c.regex, 'i').test(lowerDomain);\n\t\t\t} catch {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn false;\n\t})?.protocol;\n\tconfigs.unshift({ type: type, domain: domain, protocol: protocol });\n\treturn configs;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAmDA,eAAsB,kBACrB,KACA,SACmC;CACnC,MAAM,UAAU,YAAqE,EACpF,YAAY,EAAU,OAAO,EAC9B;CAEA,MAAM,CAAC,QAAQ,cAAc,cAAc,kBAAkB,QAAQ,SAAS;CAG9E,MAAM,OAAO,oBAAoB,UAAU;CAE3C,MAAM,aAAa,qBAAqB,MAAM;CAC9C,MAAM,aAAa,eAAe,YAAY;CAC9C,MAAM,eAAe,eAAe,QAAQ,IAAI;CAChD,IAAI,cAAc,QAAQ,gBAAgB,QAAQ,CAAC,WAAW,YAAY,YAAY,GACrF,OAAO,OAAO,eAAe;CAG9B,MAAM,gBAAgB,gBAAgB,QAAQ,QAAQ;CAMtD,IAAI,QAAQ,cAAc,QAAQ,4BAA4B,QAAQ,UAAU,GAAG;EAClF,MAAM,iBAAiB,4BAA4B,CAAC,CAAC,CAAC,CAAC,QAAQ,WAAW,eAAe,MAAM,MAAM;EACrG,MAAM,WAAW,kBAAkB,OAAO,0BAA0B,cAAc,IAAI,KAAA;EACtF,MAAM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