@gitkraken/core-gitlens 0.7.1 → 0.8.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 (188) hide show
  1. package/CHANGELOG.md +48 -1
  2. package/dist/git/cache.d.ts +18 -5
  3. package/dist/git/cache.js +26 -8
  4. package/dist/git/cache.js.map +1 -1
  5. package/dist/git/context.d.ts +5 -1
  6. package/dist/git/context.js.map +1 -1
  7. package/dist/git/errors.d.ts +28 -1
  8. package/dist/git/errors.js +45 -1
  9. package/dist/git/errors.js.map +1 -1
  10. package/dist/git/providers/branches.d.ts +5 -1
  11. package/dist/git/providers/commits.d.ts +24 -1
  12. package/dist/git/providers/config.d.ts +7 -1
  13. package/dist/git/providers/operations.d.ts +6 -0
  14. package/dist/git/providers/provider.d.ts +17 -0
  15. package/dist/git/providers/refs.d.ts +38 -3
  16. package/dist/git/providers/revision.d.ts +5 -1
  17. package/dist/git/providers/staging.d.ts +12 -0
  18. package/dist/git/providers/worktrees.d.ts +23 -3
  19. package/dist/git/run.types.d.ts +6 -0
  20. package/dist/git-cli/cliGitProvider.d.ts +17 -1
  21. package/dist/git-cli/cliGitProvider.js +37 -1
  22. package/dist/git-cli/cliGitProvider.js.map +1 -1
  23. package/dist/git-cli/exec/git.d.ts +12 -2
  24. package/dist/git-cli/exec/git.js +48 -17
  25. package/dist/git-cli/exec/git.js.map +1 -1
  26. package/dist/git-cli/exec/gitQueue.d.ts +4 -1
  27. package/dist/git-cli/exec/gitQueue.js +1 -1
  28. package/dist/git-cli/exec/gitQueue.js.map +1 -1
  29. package/dist/git-cli/providers/branches.d.ts +10 -1
  30. package/dist/git-cli/providers/branches.js +15 -8
  31. package/dist/git-cli/providers/branches.js.map +1 -1
  32. package/dist/git-cli/providers/commits.d.ts +23 -1
  33. package/dist/git-cli/providers/commits.js +57 -8
  34. package/dist/git-cli/providers/commits.js.map +1 -1
  35. package/dist/git-cli/providers/config.js +4 -3
  36. package/dist/git-cli/providers/config.js.map +1 -1
  37. package/dist/git-cli/providers/operations.d.ts +1 -0
  38. package/dist/git-cli/providers/operations.js +39 -3
  39. package/dist/git-cli/providers/operations.js.map +1 -1
  40. package/dist/git-cli/providers/patch.js +20 -41
  41. package/dist/git-cli/providers/patch.js.map +1 -1
  42. package/dist/git-cli/providers/pausedOperations.js +2 -2
  43. package/dist/git-cli/providers/pausedOperations.js.map +1 -1
  44. package/dist/git-cli/providers/refs.d.ts +15 -3
  45. package/dist/git-cli/providers/refs.js +115 -10
  46. package/dist/git-cli/providers/refs.js.map +1 -1
  47. package/dist/git-cli/providers/revision.d.ts +3 -1
  48. package/dist/git-cli/providers/revision.js +9 -5
  49. package/dist/git-cli/providers/revision.js.map +1 -1
  50. package/dist/git-cli/providers/staging.d.ts +8 -0
  51. package/dist/git-cli/providers/staging.js +59 -7
  52. package/dist/git-cli/providers/staging.js.map +1 -1
  53. package/dist/git-cli/providers/worktrees.d.ts +31 -2
  54. package/dist/git-cli/providers/worktrees.js +75 -7
  55. package/dist/git-cli/providers/worktrees.js.map +1 -1
  56. package/dist/ipc/discovery.js +1 -1
  57. package/dist/plus/agents/providers/claudeCodeTranscript.js +6 -6
  58. package/dist/plus/agents/providers/claudeCodeTranscript.js.map +1 -1
  59. package/dist/plus/ai/providers/openAICompatibleProviderBase.js +1 -1
  60. package/dist/plus/git-github/api/github.d.ts +64 -3
  61. package/dist/plus/git-github/api/github.js +237 -24
  62. package/dist/plus/git-github/api/github.js.map +1 -1
  63. package/dist/plus/git-github/providers/github/branches.d.ts +3 -1
  64. package/dist/plus/git-github/providers/github/branches.js +2 -1
  65. package/dist/plus/git-github/providers/github/branches.js.map +1 -1
  66. package/dist/plus/git-github/providers/github/refs.d.ts +10 -3
  67. package/dist/plus/git-github/providers/github/refs.js +4 -4
  68. package/dist/plus/git-github/providers/github/refs.js.map +1 -1
  69. package/dist/plus/git-github/providers/github/revision.d.ts +3 -1
  70. package/dist/plus/git-github/providers/github/revision.js +1 -1
  71. package/dist/plus/git-github/providers/github/revision.js.map +1 -1
  72. package/dist/plus/integrations/collectionMetadata.d.ts +48 -3
  73. package/dist/plus/integrations/collectionMetadata.js +138 -8
  74. package/dist/plus/integrations/collectionMetadata.js.map +1 -1
  75. package/dist/plus/integrations/errors.d.ts +3 -1
  76. package/dist/plus/integrations/errors.js +7 -3
  77. package/dist/plus/integrations/errors.js.map +1 -1
  78. package/dist/plus/integrations/index.d.ts +6 -3
  79. package/dist/plus/integrations/index.js.map +1 -1
  80. package/dist/plus/integrations/integrationService.d.ts +36 -10
  81. package/dist/plus/integrations/integrationService.js +16 -3
  82. package/dist/plus/integrations/integrationService.js.map +1 -1
  83. package/dist/plus/integrations/manager.d.ts +107 -37
  84. package/dist/plus/integrations/models/gitHostIntegration.d.ts +129 -14
  85. package/dist/plus/integrations/models/gitHostIntegration.js +142 -18
  86. package/dist/plus/integrations/models/gitHostIntegration.js.map +1 -1
  87. package/dist/plus/integrations/models/integration.d.ts +117 -11
  88. package/dist/plus/integrations/models/integration.js +175 -13
  89. package/dist/plus/integrations/models/integration.js.map +1 -1
  90. package/dist/plus/integrations/models/issuesIntegration.d.ts +18 -5
  91. package/dist/plus/integrations/models/issuesIntegration.js +42 -10
  92. package/dist/plus/integrations/models/issuesIntegration.js.map +1 -1
  93. package/dist/plus/integrations/providers/azure/azure.d.ts +1 -1
  94. package/dist/plus/integrations/providers/azure/azure.js +14 -18
  95. package/dist/plus/integrations/providers/azure/azure.js.map +1 -1
  96. package/dist/plus/integrations/providers/azure/models.d.ts +29 -0
  97. package/dist/plus/integrations/providers/azure/models.js +112 -1
  98. package/dist/plus/integrations/providers/azure/models.js.map +1 -1
  99. package/dist/plus/integrations/providers/azureDevOps.d.ts +73 -3
  100. package/dist/plus/integrations/providers/azureDevOps.js +117 -3
  101. package/dist/plus/integrations/providers/azureDevOps.js.map +1 -1
  102. package/dist/plus/integrations/providers/azureDevOpsServer.js +2 -1
  103. package/dist/plus/integrations/providers/azureDevOpsServer.js.map +1 -1
  104. package/dist/plus/integrations/providers/bitbucket/bitbucket.d.ts +61 -0
  105. package/dist/plus/integrations/providers/bitbucket/bitbucket.js +165 -23
  106. package/dist/plus/integrations/providers/bitbucket/bitbucket.js.map +1 -1
  107. package/dist/plus/integrations/providers/bitbucket/models.d.ts +6 -1
  108. package/dist/plus/integrations/providers/bitbucket/models.js +4 -3
  109. package/dist/plus/integrations/providers/bitbucket/models.js.map +1 -1
  110. package/dist/plus/integrations/providers/bitbucket-server/pullRequestSearch.js +2 -2
  111. package/dist/plus/integrations/providers/bitbucket-server/pullRequestSearch.js.map +1 -1
  112. package/dist/plus/integrations/providers/bitbucket-server.d.ts +48 -2
  113. package/dist/plus/integrations/providers/bitbucket-server.js +51 -1
  114. package/dist/plus/integrations/providers/bitbucket-server.js.map +1 -1
  115. package/dist/plus/integrations/providers/bitbucket.d.ts +45 -2
  116. package/dist/plus/integrations/providers/bitbucket.js +41 -2
  117. package/dist/plus/integrations/providers/bitbucket.js.map +1 -1
  118. package/dist/plus/integrations/providers/github.d.ts +49 -5
  119. package/dist/plus/integrations/providers/github.js +102 -7
  120. package/dist/plus/integrations/providers/github.js.map +1 -1
  121. package/dist/plus/integrations/providers/gitlab/gitlab.d.ts +35 -0
  122. package/dist/plus/integrations/providers/gitlab/gitlab.js +132 -15
  123. package/dist/plus/integrations/providers/gitlab/gitlab.js.map +1 -1
  124. package/dist/plus/integrations/providers/gitlab/models.d.ts +1 -0
  125. package/dist/plus/integrations/providers/gitlab/models.js +1 -1
  126. package/dist/plus/integrations/providers/gitlab/models.js.map +1 -1
  127. package/dist/plus/integrations/providers/gitlab.d.ts +49 -2
  128. package/dist/plus/integrations/providers/gitlab.js +80 -4
  129. package/dist/plus/integrations/providers/gitlab.js.map +1 -1
  130. package/dist/plus/integrations/providers/jira-server.d.ts +3 -3
  131. package/dist/plus/integrations/providers/jira-server.js +5 -8
  132. package/dist/plus/integrations/providers/jira-server.js.map +1 -1
  133. package/dist/plus/integrations/providers/jira.d.ts +9 -0
  134. package/dist/plus/integrations/providers/jira.js +13 -1
  135. package/dist/plus/integrations/providers/jira.js.map +1 -1
  136. package/dist/plus/integrations/providers/linear.js +1 -1
  137. package/dist/plus/integrations/providers/models.d.ts +13 -2
  138. package/dist/plus/integrations/providers/models.js +11 -1
  139. package/dist/plus/integrations/providers/models.js.map +1 -1
  140. package/dist/plus/integrations/providers/providerErrors.d.ts +9 -1
  141. package/dist/plus/integrations/providers/providerErrors.js +10 -1
  142. package/dist/plus/integrations/providers/providerErrors.js.map +1 -1
  143. package/dist/plus/integrations/providers/providersApi.d.ts +60 -1
  144. package/dist/plus/integrations/providers/providersApi.js +137 -2
  145. package/dist/plus/integrations/providers/providersApi.js.map +1 -1
  146. package/dist/plus/integrations/providers/utils/providerPaging.d.ts +42 -0
  147. package/dist/plus/integrations/providers/utils/providerPaging.js +58 -1
  148. package/dist/plus/integrations/providers/utils/providerPaging.js.map +1 -1
  149. package/dist/plus/integrations/providers/utils.d.ts +1 -1
  150. package/dist/plus/integrations/reads/broaden.js +1 -1
  151. package/dist/plus/integrations/reads/context.d.ts +1 -1
  152. package/dist/plus/integrations/reads/counts.js +1 -1
  153. package/dist/plus/integrations/reads/currentAccount.d.ts +35 -0
  154. package/dist/plus/integrations/reads/currentAccount.js +46 -0
  155. package/dist/plus/integrations/reads/currentAccount.js.map +1 -0
  156. package/dist/plus/integrations/reads/drains.d.ts +5 -2
  157. package/dist/plus/integrations/reads/drains.js +8 -4
  158. package/dist/plus/integrations/reads/drains.js.map +1 -1
  159. package/dist/plus/integrations/reads/hierarchy.js +1 -1
  160. package/dist/plus/integrations/reads/hierarchy.utils.js +1 -1
  161. package/dist/plus/integrations/reads/issueBatch.d.ts +72 -12
  162. package/dist/plus/integrations/reads/issueBatch.js +193 -48
  163. package/dist/plus/integrations/reads/issueBatch.js.map +1 -1
  164. package/dist/plus/integrations/reads/issueTracker.js +1 -1
  165. package/dist/plus/integrations/reads/issues.js +1 -1
  166. package/dist/plus/integrations/reads/pullRequestBatch.d.ts +57 -0
  167. package/dist/plus/integrations/reads/pullRequestBatch.js +80 -0
  168. package/dist/plus/integrations/reads/pullRequestBatch.js.map +1 -0
  169. package/dist/plus/integrations/reads/pullRequestBranches.d.ts +58 -0
  170. package/dist/plus/integrations/reads/pullRequestBranches.js +111 -0
  171. package/dist/plus/integrations/reads/pullRequestBranches.js.map +1 -0
  172. package/dist/plus/integrations/reads/pullRequests.js +3 -3
  173. package/dist/plus/integrations/reads/pullRequests.js.map +1 -1
  174. package/dist/plus/integrations/reads/resolveRepository.js +1 -1
  175. package/dist/plus/integrations/reads/sweeps.js +4 -4
  176. package/dist/plus/integrations/reads/sweeps.js.map +1 -1
  177. package/dist/plus/integrations/results.d.ts +87 -6
  178. package/dist/plus/integrations/results.js +9 -2
  179. package/dist/plus/integrations/results.js.map +1 -1
  180. package/dist/utils/env/node/exec.js +3 -3
  181. package/dist/utils/env/node/exec.js.map +1 -1
  182. package/docs/integrations.md +175 -35
  183. package/docs/kepler-git-write-api-parity.md +239 -0
  184. package/docs/kepler-read-api-parity.md +75 -28
  185. package/package.json +1 -1
  186. package/dist/plus/integrations/reads/trackerIssue.d.ts +0 -33
  187. package/dist/plus/integrations/reads/trackerIssue.js +0 -60
  188. package/dist/plus/integrations/reads/trackerIssue.js.map +0 -1
@@ -2,17 +2,17 @@ import { PagedResult } from "../../../utils/paging.js";
2
2
  import { Emitter } from "../../../utils/event.js";
3
3
  import { IssueOrPullRequest, IssueOrPullRequestState, IssueOrPullRequestType } from "../../../git/models/issueOrPullRequest.js";
4
4
  import { Issue, IssueShape } from "../../../git/models/issue.js";
5
- import { PullRequest, PullRequestFilter, PullRequestMergeMethod, PullRequestSearchCriteria, PullRequestStateFilter } from "../../../git/models/pullRequest.js";
5
+ import { PullRequest, PullRequestFilter, PullRequestMergeMethod, PullRequestSearchCriteria, PullRequestShape, PullRequestStateFilter } from "../../../git/models/pullRequest.js";
6
6
  import { Account, UnidentifiedAuthor } from "../../../git/models/author.js";
7
7
  import { DefaultBranch } from "../../../git/models/defaultBranch.js";
8
8
  import { RepositoryMetadata } from "../../../git/models/repositoryMetadata.js";
9
9
  import { AuthenticationSessionLike, ProviderAuthenticationSession } from "../authentication/models.js";
10
10
  import { GitSelfManagedHostIntegrationId } from "../constants.js";
11
+ import { ProviderOrganization } from "../results.js";
11
12
  import { ProviderPullRequestCount, ProviderPullRequestSearchPage } from "../models/pullRequestReads.js";
12
13
  import { ProvidersApi } from "./providersApi.js";
13
14
  import { GitHostIntegration, SearchMyPullRequestsOptions, SearchPullRequestsOptions } from "../models/gitHostIntegration.js";
14
15
  import "../models/integration.js";
15
- import { ProviderOrganization } from "../results.js";
16
16
  import { ProviderHierarchyResult, ProviderPullRequest, ProviderRepoInput, ProviderRepository } from "./models.js";
17
17
  import { IntegrationConnectionChangeEvent } from "../integrationService.js";
18
18
  import { IntegrationAuthenticationService } from "../authentication/integrationAuthenticationService.js";
@@ -43,6 +43,43 @@ export declare class BitbucketServerIntegration extends GitHostIntegration<GitSe
43
43
  id: string;
44
44
  key: string;
45
45
  }, type: undefined | IssueOrPullRequestType): Promise<IssueOrPullRequest | undefined>;
46
+ /**
47
+ * One request per target, settled independently so one target's failure rejects only its own slot:
48
+ * provider-apis has no single pull request read for Bitbucket, so this uses our own.
49
+ */
50
+ protected getProviderPullRequestsBatch(session: ProviderAuthenticationSession, coordinates: readonly {
51
+ owner: string;
52
+ repo: string;
53
+ number: number;
54
+ project?: string;
55
+ }[], options: {
56
+ currentAccount?: {
57
+ id: string;
58
+ username?: string;
59
+ };
60
+ } | undefined, _cancellation?: AbortSignal): Promise<PromiseSettledResult<PullRequestShape | undefined>[] | undefined>;
61
+ /**
62
+ * One request per target, settled independently, through our own client: provider-apis' pull request list has
63
+ * no source-branch filter. Serves only a branch in the base repository — the manager read refuses a `headOwner`
64
+ * naming another owner here, since Bitbucket Data Center finds a branch's pull requests only through the
65
+ * repository the branch lives in, and a fork's slug can't be derived from its owner.
66
+ */
67
+ protected getProviderPullRequestsForBranches(session: ProviderAuthenticationSession, targets: readonly {
68
+ owner: string;
69
+ repo: string;
70
+ project?: string;
71
+ branch: string;
72
+ headOwner?: string;
73
+ }[], options: {
74
+ currentAccount?: {
75
+ id: string;
76
+ username?: string;
77
+ };
78
+ limit: number;
79
+ }, _cancellation?: AbortSignal): Promise<PromiseSettledResult<{
80
+ pullRequests: PullRequestShape[];
81
+ truncated: boolean;
82
+ }>[] | undefined>;
46
83
  protected getProviderIssue(_session: AuthenticationSessionLike, _repo: BitbucketRepositoryDescriptor, _id: string): Promise<Issue | undefined>;
47
84
  protected getProviderPullRequestForBranch(session: ProviderAuthenticationSession, repo: BitbucketRepositoryDescriptor, branch: string, _options?: {
48
85
  avatarSize?: number;
@@ -63,6 +100,15 @@ export declare class BitbucketServerIntegration extends GitHostIntegration<GitSe
63
100
  private _accounts;
64
101
  /** The installation the session's reads address, plus the credential — what decides whose account it is. */
65
102
  private getAccountKey;
103
+ /**
104
+ * The account request the account cache would otherwise answer; see `IntegrationBase.validateCredential`. Needed
105
+ * without any discovery cache: a repo-scoped pull request read fans out across its repositories in the SDK with
106
+ * no request to the connection first, so a dead token comes back as one refused repository per request.
107
+ *
108
+ * A project access token never confirms: its bot user authenticates, but `/users` does not list it, so the SDK
109
+ * cannot find the current user and the check proves nothing.
110
+ */
111
+ protected validateCredential(session: ProviderAuthenticationSession): Promise<void>;
66
112
  protected getProviderCurrentAccount(session: ProviderAuthenticationSession): Promise<Account | undefined>;
67
113
  protected getProviderOrganizationsForUser(session: ProviderAuthenticationSession): Promise<ProviderHierarchyResult<ProviderOrganization>>;
68
114
  protected getProviderRepositoriesForOrg(session: ProviderAuthenticationSession, org: string, options?: {
@@ -1,7 +1,9 @@
1
1
  import { CancellationError, raceWithSignal } from "../../../utils/cancellation.js";
2
- import { nonnullSettled } from "../../../utils/promise.js";
2
+ import { mapSettledBounded, nonnullSettled } from "../../../utils/promise.js";
3
+ import { AuthenticationError } from "../../../git/errors.js";
3
4
  import { md5 } from "../../../utils/crypto.js";
4
5
  import "../../../git/models/pullRequest.js";
6
+ import { getResponseHeader } from "../errors.js";
5
7
  import "../constants.js";
6
8
  import { toTokenWithInfo } from "../authentication/models.js";
7
9
  import { collectProviderPagedResult, flatSettledOrThrow, parsePageCursor, toPageCursor } from "./utils/providerPaging.js";
@@ -48,6 +50,38 @@ var BitbucketServerIntegration = class extends GitHostIntegration {
48
50
  if (type === "issue") return;
49
51
  return (await this.authenticationService.apis.bitbucket)?.getServerPullRequestById(this, toTokenWithInfo(this.id, session), repo.owner, repo.name, id, this.apiBaseUrlFor(session));
50
52
  }
53
+ /**
54
+ * One request per target, settled independently so one target's failure rejects only its own slot:
55
+ * provider-apis has no single pull request read for Bitbucket, so this uses our own.
56
+ */
57
+ async getProviderPullRequestsBatch(session, coordinates, options, _cancellation) {
58
+ const api = await this.authenticationService.apis.bitbucket;
59
+ if (api == null) return void 0;
60
+ const tokenWithInfo = toTokenWithInfo(this.id, session);
61
+ return mapSettledBounded(coordinates, 6, (c) => api.getServerPullRequest(this, tokenWithInfo, c.owner, c.repo, String(c.number), this.apiBaseUrlFor(session), {
62
+ currentAccount: options?.currentAccount,
63
+ deferFailure: true
64
+ }));
65
+ }
66
+ /**
67
+ * One request per target, settled independently, through our own client: provider-apis' pull request list has
68
+ * no source-branch filter. Serves only a branch in the base repository — the manager read refuses a `headOwner`
69
+ * naming another owner here, since Bitbucket Data Center finds a branch's pull requests only through the
70
+ * repository the branch lives in, and a fork's slug can't be derived from its owner.
71
+ */
72
+ async getProviderPullRequestsForBranches(session, targets, options, _cancellation) {
73
+ const api = await this.authenticationService.apis.bitbucket;
74
+ if (api == null) return void 0;
75
+ const tokenWithInfo = toTokenWithInfo(this.id, session);
76
+ return mapSettledBounded(targets, 6, async (t) => {
77
+ if (t.headOwner != null) throw new Error(`Bitbucket Data Center can't find ${t.branch}'s pull requests in a fork by its owner`);
78
+ return api.getServerPullRequestsForBranch(this, tokenWithInfo, t.owner, t.repo, t.branch, this.apiBaseUrlFor(session), {
79
+ limit: options.limit,
80
+ currentAccount: options.currentAccount,
81
+ deferFailure: true
82
+ });
83
+ });
84
+ }
51
85
  async getProviderIssue(_session, _repo, _id) {
52
86
  return Promise.resolve(void 0);
53
87
  }
@@ -75,6 +109,22 @@ var BitbucketServerIntegration = class extends GitHostIntegration {
75
109
  getAccountKey(session) {
76
110
  return `${this.apiBaseUrlFor(session)}\n${session.accessToken}`;
77
111
  }
112
+ /**
113
+ * The account request the account cache would otherwise answer; see `IntegrationBase.validateCredential`. Needed
114
+ * without any discovery cache: a repo-scoped pull request read fans out across its repositories in the SDK with
115
+ * no request to the connection first, so a dead token comes back as one refused repository per request.
116
+ *
117
+ * A project access token never confirms: its bot user authenticates, but `/users` does not list it, so the SDK
118
+ * cannot find the current user and the check proves nothing.
119
+ */
120
+ async validateCredential(session) {
121
+ if (await (await this.getProvidersApi()).getCurrentUser(toTokenWithInfo(this.id, session), { baseUrl: this.apiBaseUrlFor(session) }).catch((ex) => {
122
+ if (!(ex instanceof AuthenticationError)) throw ex;
123
+ const response = ex.original?.response;
124
+ if (getResponseHeader(response?.headers, "x-ausername") || /not (?:a|currently) licensed/i.test(ex.original?.message ?? "")) throw new Error("Bitbucket Data Center could not confirm the credential", { cause: ex });
125
+ throw ex;
126
+ }) == null) throw new Error("Bitbucket Data Center did not confirm the credential");
127
+ }
78
128
  async getProviderCurrentAccount(session) {
79
129
  const key = this.getAccountKey(session);
80
130
  this._accounts ??= /* @__PURE__ */ new Map();
@@ -1 +1 @@
1
- {"version":3,"file":"bitbucket-server.js","names":[],"sources":["../../../../../plus/integrations/src/providers/bitbucket-server.ts"],"sourcesContent":["import type { Account, UnidentifiedAuthor } from '@gitlens/git/models/author.js';\nimport type { DefaultBranch } from '@gitlens/git/models/defaultBranch.js';\nimport type { Issue, IssueShape } from '@gitlens/git/models/issue.js';\nimport type { IssueOrPullRequest, IssueOrPullRequestType } from '@gitlens/git/models/issueOrPullRequest.js';\nimport type {\n\tPullRequest,\n\tPullRequestMergeMethod,\n\tPullRequestSearchCriteria,\n\tPullRequestState,\n\tPullRequestStateFilter,\n} from '@gitlens/git/models/pullRequest.js';\nimport type { GitRemote } from '@gitlens/git/models/remote.js';\nimport type { RepositoryMetadata } from '@gitlens/git/models/repositoryMetadata.js';\nimport { CancellationError, raceWithSignal } from '@gitlens/utils/cancellation.js';\nimport { md5 } from '@gitlens/utils/crypto.js';\nimport type { Emitter } from '@gitlens/utils/event.js';\nimport type { PagedResult } from '@gitlens/utils/paging.js';\nimport { nonnullSettled } from '@gitlens/utils/promise.js';\nimport type { IntegrationAuthenticationProviderDescriptor } from '../authentication/integrationAuthenticationProvider.js';\nimport type { IntegrationAuthenticationService } from '../authentication/integrationAuthenticationService.js';\nimport type {\n\tAuthenticationSessionLike as AuthenticationSession,\n\tProviderAuthenticationSession,\n} from '../authentication/models.js';\nimport { toTokenWithInfo } from '../authentication/models.js';\nimport { GitSelfManagedHostIntegrationId } from '../constants.js';\nimport type { IntegrationServiceContext } from '../context.js';\nimport type { IntegrationConnectionChangeEvent } from '../integrationService.js';\nimport type { SearchMyPullRequestsOptions, SearchPullRequestsOptions } from '../models/gitHostIntegration.js';\nimport { GitHostIntegration } from '../models/gitHostIntegration.js';\nimport type { IntegrationKey, ProviderPullRequestCount, ProviderPullRequestSearchPage } from '../models/integration.js';\nimport type { BitbucketServerSearchUser } from './bitbucket-server/pullRequestSearch.js';\nimport type { BitbucketRepositoryDescriptor } from './bitbucket/models.js';\nimport type {\n\tProviderHierarchyResult,\n\tProviderOrganization,\n\tProviderPullRequest,\n\tProviderRepoInput,\n\tProviderRepository,\n} from './models.js';\nimport {\n\tfromProviderPullRequest,\n\tproviderPullRequestMatchesSearch,\n\tProviderPullRequestReviewState,\n\tprovidersMetadata,\n\tPullRequestFilter,\n\ttoProviderPullRequestStates,\n} from './models.js';\nimport type { ProvidersApi } from './providersApi.js';\nimport {\n\tcollectProviderPagedResult,\n\tflatSettledOrThrow,\n\tparsePageCursor,\n\ttoPageCursor,\n} from './utils/providerPaging.js';\n\nconst metadata = providersMetadata[GitSelfManagedHostIntegrationId.BitbucketServer];\nconst authProvider = Object.freeze({ id: metadata.id, scopes: metadata.scopes });\n\nexport class BitbucketServerIntegration extends GitHostIntegration<\n\tGitSelfManagedHostIntegrationId.BitbucketServer,\n\tBitbucketRepositoryDescriptor\n> {\n\treadonly authProvider: IntegrationAuthenticationProviderDescriptor = authProvider;\n\treadonly id = GitSelfManagedHostIntegrationId.BitbucketServer;\n\tprotected readonly key =\n\t\t`${this.id}:${this.domain}` satisfies IntegrationKey<GitSelfManagedHostIntegrationId.BitbucketServer>;\n\treadonly name: string = 'Bitbucket Data Center';\n\n\tconstructor(\n\t\tctx: IntegrationServiceContext,\n\t\tauthenticationService: IntegrationAuthenticationService,\n\t\tgetProvidersApi: () => Promise<ProvidersApi>,\n\t\tdidChangeConnection: Emitter<IntegrationConnectionChangeEvent>,\n\t\tprivate readonly _domain: string,\n\t) {\n\t\tsuper(ctx, authenticationService, getProvidersApi, didChangeConnection);\n\t}\n\n\tget domain(): string {\n\t\treturn this._domain;\n\t}\n\n\tprotected apiBaseUrlFor(session: ProviderAuthenticationSession): string {\n\t\treturn this.getSelfManagedApiBaseUrl(session);\n\t}\n\n\tprotected override async mergeProviderPullRequest(\n\t\tsession: ProviderAuthenticationSession,\n\t\tpr: PullRequest,\n\t\toptions?: {\n\t\t\tmergeMethod?: PullRequestMergeMethod;\n\t\t},\n\t): Promise<boolean> {\n\t\tconst api = await this.getProvidersApi();\n\t\treturn api.mergePullRequest(toTokenWithInfo(this.id, session), pr, {\n\t\t\tmergeMethod: options?.mergeMethod,\n\t\t\tbaseUrl: this.apiBaseUrlFor(session),\n\t\t});\n\t}\n\n\tprotected override async getProviderAccountForCommit(\n\t\tsession: ProviderAuthenticationSession,\n\t\trepo: BitbucketRepositoryDescriptor,\n\t\trev: string,\n\t\toptions?: {\n\t\t\tavatarSize?: number;\n\t\t},\n\t): Promise<Account | UnidentifiedAuthor | undefined> {\n\t\treturn (await this.authenticationService.apis.bitbucket)?.getServerAccountForCommit(\n\t\t\tthis,\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\trepo.owner,\n\t\t\trepo.name,\n\t\t\trev,\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t\t{\n\t\t\t\tavatarSize: options?.avatarSize,\n\t\t\t},\n\t\t);\n\t}\n\n\tprotected override async getProviderAccountForEmail(\n\t\t_session: AuthenticationSession,\n\t\t_repo: BitbucketRepositoryDescriptor,\n\t\t_email: string,\n\t\t_options?: {\n\t\t\tavatarSize?: number;\n\t\t},\n\t): Promise<Account | undefined> {\n\t\treturn Promise.resolve(undefined);\n\t}\n\n\tprotected override async getProviderDefaultBranch(\n\t\t_session: AuthenticationSession,\n\t\t_repo: BitbucketRepositoryDescriptor,\n\t): Promise<DefaultBranch | undefined> {\n\t\treturn Promise.resolve(undefined);\n\t}\n\n\tprotected override async getProviderLinkedIssueOrPullRequest(\n\t\tsession: ProviderAuthenticationSession,\n\t\trepo: BitbucketRepositoryDescriptor,\n\t\t{ id }: { id: string; key: string },\n\t\ttype: undefined | IssueOrPullRequestType,\n\t): Promise<IssueOrPullRequest | undefined> {\n\t\tif (type === 'issue') {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn (await this.authenticationService.apis.bitbucket)?.getServerPullRequestById(\n\t\t\tthis,\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\trepo.owner,\n\t\t\trepo.name,\n\t\t\tid,\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t);\n\t}\n\n\tprotected override async getProviderIssue(\n\t\t_session: AuthenticationSession,\n\t\t_repo: BitbucketRepositoryDescriptor,\n\t\t_id: string,\n\t): Promise<Issue | undefined> {\n\t\treturn Promise.resolve(undefined);\n\t}\n\n\tprotected override async getProviderPullRequestForBranch(\n\t\tsession: ProviderAuthenticationSession,\n\t\trepo: BitbucketRepositoryDescriptor,\n\t\tbranch: string,\n\t\t_options?: {\n\t\t\tavatarSize?: number;\n\t\t\tinclude?: PullRequestState[];\n\t\t},\n\t): Promise<PullRequest | undefined> {\n\t\treturn (await this.authenticationService.apis.bitbucket)?.getServerPullRequestForBranch(\n\t\t\tthis,\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\trepo.owner,\n\t\t\trepo.name,\n\t\t\tbranch,\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t);\n\t}\n\n\tprotected override async getProviderPullRequestForCommit(\n\t\tsession: ProviderAuthenticationSession,\n\t\trepo: BitbucketRepositoryDescriptor,\n\t\trev: string,\n\t): Promise<PullRequest | undefined> {\n\t\treturn (await this.authenticationService.apis.bitbucket)?.getServerPullRequestForCommit(\n\t\t\tthis,\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\trepo.owner,\n\t\t\trepo.name,\n\t\t\trev,\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t);\n\t}\n\n\tpublic override async getRepoInfo(repo: {\n\t\towner: string;\n\t\tname: string;\n\t\tproject?: string;\n\t\tconnectionId?: string;\n\t}): Promise<ProviderRepository | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\t// `connectionId` targets a specific account (multi-account); omitted reads the primary.\n\t\tconst session = await this.resolveReadSession(repo.connectionId, undefined);\n\t\tif (session == null) return undefined;\n\n\t\treturn api.getRepo(toTokenWithInfo(this.id, session), repo.owner, repo.name, repo.project, {\n\t\t\tbaseUrl: this.apiBaseUrlFor(session),\n\t\t});\n\t}\n\n\tprotected override async getProviderRepositoryMetadata(\n\t\t_session: AuthenticationSession,\n\t\t_repo: BitbucketRepositoryDescriptor,\n\t\t_cancellation?: AbortSignal,\n\t): Promise<RepositoryMetadata | undefined> {\n\t\treturn Promise.resolve(undefined);\n\t}\n\n\t/**\n\t * Accounts by {@link getAccountKey}. One integration serves every installation on its host, and installations\n\t * mounted at different context paths are different servers whose users differ, even under the same token.\n\t */\n\tprivate _accounts: Map<string, Account | undefined> | undefined;\n\n\t/** The installation the session's reads address, plus the credential — what decides whose account it is. */\n\tprivate getAccountKey(session: ProviderAuthenticationSession): string {\n\t\treturn `${this.apiBaseUrlFor(session)}\\n${session.accessToken}`;\n\t}\n\n\tprotected override async getProviderCurrentAccount(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<Account | undefined> {\n\t\tconst key = this.getAccountKey(session);\n\t\tthis._accounts ??= new Map<string, Account | undefined>();\n\n\t\tconst cachedAccount = this._accounts.get(key);\n\t\tif (cachedAccount == null) {\n\t\t\tconst api = await this.getProvidersApi();\n\t\t\tconst user = await api.getCurrentUser(toTokenWithInfo(this.id, session), {\n\t\t\t\tbaseUrl: this.apiBaseUrlFor(session),\n\t\t\t});\n\t\t\tthis._accounts.set(\n\t\t\t\tkey,\n\t\t\t\tuser\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tprovider: this,\n\t\t\t\t\t\t\tid: user.id,\n\t\t\t\t\t\t\tname: user.name ?? undefined,\n\t\t\t\t\t\t\temail: user.email ?? undefined,\n\t\t\t\t\t\t\tavatarUrl: user.avatarUrl ?? undefined,\n\t\t\t\t\t\t\tusername: user.username ?? undefined,\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined,\n\t\t\t);\n\t\t}\n\n\t\treturn this._accounts.get(key);\n\t}\n\n\tprotected override async getProviderOrganizationsForUser(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<ProviderHierarchyResult<ProviderOrganization>> {\n\t\tconst api = await this.getProvidersApi();\n\t\treturn api.getBitbucketServerProjects(\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t\tsession.id,\n\t\t);\n\t}\n\n\tprotected override async getProviderRepositoriesForOrg(\n\t\tsession: ProviderAuthenticationSession,\n\t\torg: string,\n\t\toptions?: { cursor?: string },\n\t): Promise<ProviderHierarchyResult<ProviderRepository>> {\n\t\tconst api = await this.getProvidersApi();\n\t\treturn api.getBitbucketServerRepositories(\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t\tsession.id,\n\t\t\t{\n\t\t\t\tproject: org,\n\t\t\t\tcursor: options?.cursor,\n\t\t\t},\n\t\t);\n\t}\n\n\tprotected override async getProviderRepositoriesForUser(\n\t\tsession: ProviderAuthenticationSession,\n\t\toptions?: { cursor?: string },\n\t): Promise<ProviderHierarchyResult<ProviderRepository>> {\n\t\tconst api = await this.getProvidersApi();\n\t\treturn api.getBitbucketServerRepositories(\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t\tsession.id,\n\t\t\toptions,\n\t\t);\n\t}\n\n\tprotected override async searchProviderMyPullRequests(\n\t\tsession: ProviderAuthenticationSession,\n\t\trepos?: BitbucketRepositoryDescriptor[],\n\t\t_cancellation?: AbortSignal,\n\t\toptions?: SearchMyPullRequestsOptions,\n\t): Promise<PullRequest[] | undefined> {\n\t\tif (repos != null) {\n\t\t\t// TODO: implement repos version\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst api = await this.getProvidersApi();\n\t\tif (!api) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst prs = await api.getBitbucketServerPullRequestsForCurrentUser(\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t\t{ states: toProviderPullRequestStates(options?.state) },\n\t\t);\n\t\treturn prs?.data.map(pr => fromProviderPullRequest(pr, this));\n\t}\n\n\tprotected override async getProviderMyPullRequestsForUser(\n\t\tsession: ProviderAuthenticationSession,\n\t\toptions?: { state?: PullRequestStateFilter[]; cursor?: string; filters?: PullRequestFilter[] },\n\t): Promise<PagedResult<ProviderPullRequest> | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst states = toProviderPullRequestStates(options?.state);\n\t\t// provider-apis translates the public 1-based `page` to Bitbucket Server's `start` offset and normalizes\n\t\t// `nextPageStart` back to the next page number. Thread that number inside our opaque cursor so the\n\t\t// ProviderBackend sweep drives the drain (bounded by its maxPages).\n\t\tconst page = parsePageCursor(options?.cursor);\n\t\tconst result = await api.getBitbucketServerPullRequestsForCurrentUser(\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t\t{ states: states, page: page },\n\t\t);\n\t\tif (result == null) return undefined;\n\n\t\tconst account = options?.filters?.length ? await this.getProviderCurrentAccount(session) : undefined;\n\t\tconst identifiers = new Set([account?.id, account?.username].filter((id): id is string => id != null));\n\t\tif (options?.filters?.length && identifiers.size === 0) {\n\t\t\tthrow new Error(\n\t\t\t\t'Unable to resolve the current Bitbucket Data Center account for the requested pull request filters.',\n\t\t\t);\n\t\t}\n\n\t\tconst values = options?.filters?.length\n\t\t\t? result.data.filter(pr => {\n\t\t\t\t\tconst isCurrentUser = (user: { id?: string | null; username?: string | null } | null | undefined) =>\n\t\t\t\t\t\tuser != null &&\n\t\t\t\t\t\t((user.id != null && identifiers.has(user.id)) ||\n\t\t\t\t\t\t\t(user.username != null && identifiers.has(user.username)));\n\t\t\t\t\tconst isAuthor = isCurrentUser(pr.author);\n\t\t\t\t\tconst isRequestedReviewer = pr.reviews?.some(\n\t\t\t\t\t\treview =>\n\t\t\t\t\t\t\tisCurrentUser(review.reviewer) &&\n\t\t\t\t\t\t\treview.state === ProviderPullRequestReviewState.ReviewRequested,\n\t\t\t\t\t);\n\t\t\t\t\treturn (\n\t\t\t\t\t\t(options.filters!.includes(PullRequestFilter.Author) && isAuthor) ||\n\t\t\t\t\t\t(options.filters!.includes(PullRequestFilter.ReviewRequested) && isRequestedReviewer)\n\t\t\t\t\t);\n\t\t\t\t})\n\t\t\t: result.data;\n\n\t\treturn {\n\t\t\tvalues: values,\n\t\t\tpaging: {\n\t\t\t\tmore: result.hasMore,\n\t\t\t\tcursor: result.hasMore && result.nextPage != null ? toPageCursor(result.nextPage) : '{}',\n\t\t\t},\n\t\t};\n\t}\n\n\tprotected override async searchProviderPullRequests(\n\t\tsession: ProviderAuthenticationSession,\n\t\tsearchQuery: string,\n\t\trepos?: BitbucketRepositoryDescriptor[],\n\t\tcancellation?: AbortSignal,\n\t\toptions?: SearchPullRequestsOptions,\n\t): Promise<PullRequest[] | undefined> {\n\t\tif (cancellation?.aborted) throw new CancellationError();\n\n\t\tconst api = await this.getProvidersApi();\n\t\tif (!api) return undefined;\n\n\t\tconst repoInputs =\n\t\t\trepos != null\n\t\t\t\t? repos.map(r => ({ name: r.name, namespace: r.owner }))\n\t\t\t\t: await this.getWorkspaceRepoInputs();\n\t\tif (cancellation?.aborted) throw new CancellationError();\n\t\t// An explicitly-empty `repos` means \"search these zero repos\" -> no results; reserve `undefined`\n\t\t// (\"scope couldn't be determined\") for when no repos were requested and none were discovered.\n\t\tif (repoInputs.length === 0) return repos != null ? [] : undefined;\n\n\t\tconst token = toTokenWithInfo(this.id, session);\n\t\tconst states = toProviderPullRequestStates(options?.include);\n\t\tconst providerPullRequests = await flatSettledOrThrow(\n\t\t\trepoInputs.map(async repo => {\n\t\t\t\tconst result = await collectProviderPagedResult(cursor => {\n\t\t\t\t\tif (cancellation?.aborted) throw new CancellationError();\n\n\t\t\t\t\treturn api.getPullRequestsForRepo(token, repo, {\n\t\t\t\t\t\tbaseUrl: this.apiBaseUrlFor(session),\n\t\t\t\t\t\tcursor: cursor,\n\t\t\t\t\t\tstates: states,\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t\treturn result.values;\n\t\t\t}),\n\t\t);\n\t\tif (cancellation?.aborted) throw new CancellationError();\n\n\t\treturn providerPullRequests\n\t\t\t.filter(pr => providerPullRequestMatchesSearch(pr, searchQuery))\n\t\t\t.map(pr => fromProviderPullRequest(pr, this));\n\t}\n\n\t/**\n\t * The filtered pull-request search, read by this module's own requests rather than the SDK's: the SDK's list\n\t * reads carry no text, draft or participant-status filter and no per-facet continuation. Every request goes to\n\t * the session's own address, context path included, so one connection's cursor can't be replayed on another.\n\t */\n\tprotected override async searchProviderPullRequestsPage(\n\t\tsession: ProviderAuthenticationSession,\n\t\toptions: {\n\t\t\trepos?: ProviderRepoInput[];\n\t\t\torg?: string;\n\t\t\tcriteria?: PullRequestSearchCriteria;\n\t\t\tcursor?: string;\n\t\t\tpageSize?: number;\n\t\t\tsummary?: boolean;\n\t\t},\n\t\tcancellation?: AbortSignal,\n\t): Promise<ProviderPullRequestSearchPage | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\treturn api.searchBitbucketServerPullRequestsPage(\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\t{\n\t\t\t\tbaseUrl: this.apiBaseUrlFor(session),\n\t\t\t\tconnectionId: session.id,\n\t\t\t\tprovider: this,\n\t\t\t\trepos: options.repos,\n\t\t\t\torg: options.org,\n\t\t\t\tcriteria: options.criteria,\n\t\t\t\tcurrentUser: await this.getSearchUser(session, options.criteria, cancellation),\n\t\t\t\tcursor: options.cursor,\n\t\t\t\tpageSize: options.pageSize,\n\t\t\t},\n\t\t\tcancellation,\n\t\t);\n\t}\n\n\t/**\n\t * Counts each scope by reading it, since Bitbucket Data Center has neither a count query nor a total on its\n\t * pages. The facade hands over one scope per call and runs those calls concurrently (see `countPullRequests`),\n\t * so scopes here are counted one after another rather than multiplying that concurrency.\n\t */\n\tprotected override async countProviderPullRequests(\n\t\tsession: ProviderAuthenticationSession,\n\t\tscopes: readonly { repos?: ProviderRepoInput[]; org?: string; criteria?: PullRequestSearchCriteria }[],\n\t\tcancellation?: AbortSignal,\n\t): Promise<ProviderPullRequestCount[] | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst token = toTokenWithInfo(this.id, session);\n\t\tconst counts: ProviderPullRequestCount[] = [];\n\t\tfor (const scope of scopes) {\n\t\t\tcounts.push(\n\t\t\t\tawait api.countBitbucketServerPullRequests(\n\t\t\t\t\ttoken,\n\t\t\t\t\t{\n\t\t\t\t\t\tbaseUrl: this.apiBaseUrlFor(session),\n\t\t\t\t\t\trepos: scope.repos,\n\t\t\t\t\t\torg: scope.org,\n\t\t\t\t\t\tcriteria: scope.criteria,\n\t\t\t\t\t\tcurrentUser: await this.getSearchUser(session, scope.criteria, cancellation),\n\t\t\t\t\t},\n\t\t\t\t\tcancellation,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\treturn counts;\n\t}\n\n\t/**\n\t * The session's own user, which a relationship facet filters by. Resolved per session rather than from the\n\t * primary connection, so a read pinned to one account never filters by another's identity; an account that\n\t * can't be resolved refuses the read instead of widening it to everyone's pull requests.\n\t *\n\t * The lookup is raced against `cancellation` so a cancelled read settles at once. The SDK's current-user read\n\t * takes no signal, so the request itself runs on; its answer still lands in the per-token account cache, so a\n\t * cold lookup a cancellation abandoned isn't wasted on the next read.\n\t */\n\tprivate async getSearchUser(\n\t\tsession: ProviderAuthenticationSession,\n\t\tcriteria: PullRequestSearchCriteria | undefined,\n\t\tcancellation: AbortSignal | undefined,\n\t): Promise<BitbucketServerSearchUser | undefined> {\n\t\tif (!criteria?.relationships?.length) return undefined;\n\n\t\tconst lookup = this.getProviderCurrentAccount(session);\n\t\tconst account = await (cancellation != null ? raceWithSignal(lookup, cancellation) : lookup);\n\t\tif (account?.id == null || account.username == null) {\n\t\t\tthrow new Error('Unable to resolve the current Bitbucket Data Center account for a relationship search.');\n\t\t}\n\n\t\treturn { id: account.id, username: account.username };\n\t}\n\n\tprivate async getWorkspaceRepoInputs(): Promise<{ name: string; namespace: string }[]> {\n\t\tconst remotes = await this.ctx.repositories.getOpenRemotes();\n\t\tconst inputs = await nonnullSettled(\n\t\t\tremotes.map(async (r: GitRemote) => {\n\t\t\t\tconst integration = await this.authenticationService.getByRemote(r);\n\t\t\t\tif (integration !== this) return undefined;\n\n\t\t\t\t// Use the remote provider's parsing so the Bitbucket Server `scm/<project>/<repo>` prefix is\n\t\t\t\t// stripped; a raw `path.split('/')` would yield namespace=`scm`, name=`<project>`.\n\t\t\t\tconst namespace = r.provider?.owner;\n\t\t\t\tconst name = r.provider?.repoName;\n\t\t\t\treturn namespace != null && name != null ? { name: name, namespace: namespace } : undefined;\n\t\t\t}),\n\t\t);\n\t\t// Dedupe: a repo with multiple remotes (e.g. `origin` + `upstream`) can map to the same input,\n\t\t// which would otherwise fetch and return the same PRs more than once.\n\t\treturn [...new Map(inputs.map(i => [`${i.namespace}/${i.name}`, i])).values()];\n\t}\n\n\tprotected override async searchProviderMyIssues(\n\t\t_session: AuthenticationSession,\n\t\t_repos?: BitbucketRepositoryDescriptor[],\n\t): Promise<IssueShape[] | undefined> {\n\t\treturn Promise.resolve(undefined);\n\t}\n\n\t/**\n\t * Bitbucket Data Center exposes no issue tracker at all (issues live in Jira), so — like Bitbucket Cloud,\n\t * whose own tracker is deprecated — it is not an issue provider on the ProviderBackend surface. Without this\n\t * the facade would take `supportsIssues`' default `true` and route the read to a provider that registers no\n\t * issue client: the repo-scoped path fails with the SDK's `does not support function: getIssuesForReposFn`\n\t * as an opaque `kind: 'other'` warning, and `broadenIssues` first drains every repo of the org before hitting\n\t * the same failure. Its metadata already declares no issue filters, so this keeps both halves of the\n\t * capability answer consistent.\n\t */\n\toverride get supportsIssues(): boolean {\n\t\treturn false;\n\t}\n\n\tprivate readonly storagePrefix = 'bitbucket-server';\n\tprotected override async providerOnConnect(): Promise<void> {\n\t\tif (this._session == null) return;\n\n\t\tconst accountKey = this.getAccountKey(this._session);\n\t\tconst accountStorageKey = md5(accountKey);\n\n\t\tconst storedAccount = this.ctx.storage.get(`${this.storagePrefix}:${accountStorageKey}:account`);\n\n\t\tlet account: Account | undefined = storedAccount?.data ? { ...storedAccount.data, provider: this } : undefined;\n\n\t\tif (storedAccount == null) {\n\t\t\taccount = await this.getProviderCurrentAccount(this._session);\n\t\t\tif (account != null) {\n\t\t\t\t// Clear all other stored workspaces and repositories and accounts when our session changes\n\t\t\t\tawait this.ctx.storage.deleteWithPrefix(this.storagePrefix);\n\t\t\t\tawait this.ctx.storage.store(`${this.storagePrefix}:${accountStorageKey}:account`, {\n\t\t\t\t\tv: 1,\n\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tid: account.id,\n\t\t\t\t\t\tname: account.name,\n\t\t\t\t\t\temail: account.email,\n\t\t\t\t\t\tavatarUrl: account.avatarUrl,\n\t\t\t\t\t\tusername: account.username,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tthis._accounts ??= new Map<string, Account | undefined>();\n\t\tthis._accounts.set(accountKey, account);\n\t}\n\n\tprotected override providerOnDisconnect(): void {\n\t\tthis._accounts = undefined;\n\t}\n}\n"],"mappings":";;;;;;;;;;AAwDA,MAAM,WAAW,kBAAA;AACjB,MAAM,eAAe,OAAO,OAAO;CAAE,IAAI,SAAS;CAAI,QAAQ,SAAS;AAAO,CAAC;AAE/E,IAAa,6BAAb,cAAgD,mBAG9C;CAYiB;CAXlB,eAAqE;CACrE,KAAS;CACT,MACC,GAAG,KAAK,GAAG,GAAG,KAAK;CACpB,OAAwB;CAExB,YACC,KACA,uBACA,iBACA,qBACA,SACC;EACD,MAAM,KAAK,uBAAuB,iBAAiB,mBAAmB;EAFrD,KAAA,UAAA;CAGlB;CAEA,IAAI,SAAiB;EACpB,OAAO,KAAK;CACb;CAEA,cAAwB,SAAgD;EACvE,OAAO,KAAK,yBAAyB,OAAO;CAC7C;CAEA,MAAyB,yBACxB,SACA,IACA,SAGmB;EAEnB,QAAO,MADW,KAAK,gBAAgB,EAAA,CAC5B,iBAAiB,gBAAgB,KAAK,IAAI,OAAO,GAAG,IAAI;GAClE,aAAa,SAAS;GACtB,SAAS,KAAK,cAAc,OAAO;EACpC,CAAC;CACF;CAEA,MAAyB,4BACxB,SACA,MACA,KACA,SAGoD;EACpD,QAAQ,MAAM,KAAK,sBAAsB,KAAK,UAAA,EAAY,0BACzD,MACA,gBAAgB,KAAK,IAAI,OAAO,GAChC,KAAK,OACL,KAAK,MACL,KACA,KAAK,cAAc,OAAO,GAC1B,EACC,YAAY,SAAS,WACtB,CACD;CACD;CAEA,MAAyB,2BACxB,UACA,OACA,QACA,UAG+B;EAC/B,OAAO,QAAQ,QAAQ,KAAA,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,GAAG,EAAE,UAAU,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;CAC9E;CAEA,MAAyB,uBACxB,UACA,QACoC;EACpC,OAAO,QAAQ,QAAQ,KAAA,CAAS;CACjC;;;;;;;;;;CAWA,IAAa,iBAA0B;EACtC,OAAO;CACR;CAEA,gBAAiC;CACjC,MAAyB,oBAAmC;EAC3D,IAAI,KAAK,YAAY,MAAM;EAE3B,MAAM,aAAa,KAAK,cAAc,KAAK,QAAQ;EACnD,MAAM,oBAAoB,IAAI,UAAU;EAExC,MAAM,gBAAgB,KAAK,IAAI,QAAQ,IAAI,GAAG,KAAK,cAAc,GAAG,kBAAkB,SAAS;EAE/F,IAAI,UAA+B,eAAe,OAAO;GAAE,GAAG,cAAc;GAAM,UAAU;EAAK,IAAI,KAAA;EAErG,IAAI,iBAAiB,MAAM;GAC1B,UAAU,MAAM,KAAK,0BAA0B,KAAK,QAAQ;GAC5D,IAAI,WAAW,MAAM;IAEpB,MAAM,KAAK,IAAI,QAAQ,iBAAiB,KAAK,aAAa;IAC1D,MAAM,KAAK,IAAI,QAAQ,MAAM,GAAG,KAAK,cAAc,GAAG,kBAAkB,WAAW;KAClF,GAAG;KACH,WAAW,KAAK,IAAI;KACpB,MAAM;MACL,IAAI,QAAQ;MACZ,MAAM,QAAQ;MACd,OAAO,QAAQ;MACf,WAAW,QAAQ;MACnB,UAAU,QAAQ;KACnB;IACD,CAAC;GACF;EACD;EACA,KAAK,8BAAc,IAAI,IAAiC;EACxD,KAAK,UAAU,IAAI,YAAY,OAAO;CACvC;CAEA,uBAAgD;EAC/C,KAAK,YAAY,KAAA;CAClB;AACD"}
1
+ {"version":3,"file":"bitbucket-server.js","names":[],"sources":["../../../../../plus/integrations/src/providers/bitbucket-server.ts"],"sourcesContent":["import type { Account, UnidentifiedAuthor } from '@gitlens/git/models/author.js';\nimport type { DefaultBranch } from '@gitlens/git/models/defaultBranch.js';\nimport type { Issue, IssueShape } from '@gitlens/git/models/issue.js';\nimport type { IssueOrPullRequest, IssueOrPullRequestType } from '@gitlens/git/models/issueOrPullRequest.js';\nimport type {\n\tPullRequest,\n\tPullRequestMergeMethod,\n\tPullRequestSearchCriteria,\n\tPullRequestShape,\n\tPullRequestState,\n\tPullRequestStateFilter,\n} from '@gitlens/git/models/pullRequest.js';\nimport type { GitRemote } from '@gitlens/git/models/remote.js';\nimport type { RepositoryMetadata } from '@gitlens/git/models/repositoryMetadata.js';\nimport { CancellationError, raceWithSignal } from '@gitlens/utils/cancellation.js';\nimport { md5 } from '@gitlens/utils/crypto.js';\nimport type { Emitter } from '@gitlens/utils/event.js';\nimport type { PagedResult } from '@gitlens/utils/paging.js';\nimport { mapSettledBounded, nonnullSettled } from '@gitlens/utils/promise.js';\nimport type { IntegrationAuthenticationProviderDescriptor } from '../authentication/integrationAuthenticationProvider.js';\nimport type { IntegrationAuthenticationService } from '../authentication/integrationAuthenticationService.js';\nimport type {\n\tAuthenticationSessionLike as AuthenticationSession,\n\tProviderAuthenticationSession,\n} from '../authentication/models.js';\nimport { toTokenWithInfo } from '../authentication/models.js';\nimport { GitSelfManagedHostIntegrationId, providerFanOutConcurrency } from '../constants.js';\nimport type { IntegrationServiceContext } from '../context.js';\nimport type { ResponseHeaders } from '../errors.js';\nimport { AuthenticationError, getResponseHeader } from '../errors.js';\nimport type { IntegrationConnectionChangeEvent } from '../integrationService.js';\nimport type { SearchMyPullRequestsOptions, SearchPullRequestsOptions } from '../models/gitHostIntegration.js';\nimport { GitHostIntegration } from '../models/gitHostIntegration.js';\nimport type { IntegrationKey, ProviderPullRequestCount, ProviderPullRequestSearchPage } from '../models/integration.js';\nimport type { BitbucketServerSearchUser } from './bitbucket-server/pullRequestSearch.js';\nimport type { BitbucketRepositoryDescriptor } from './bitbucket/models.js';\nimport type {\n\tProviderHierarchyResult,\n\tProviderOrganization,\n\tProviderPullRequest,\n\tProviderRepoInput,\n\tProviderRepository,\n} from './models.js';\nimport {\n\tfromProviderPullRequest,\n\tproviderPullRequestMatchesSearch,\n\tProviderPullRequestReviewState,\n\tprovidersMetadata,\n\tPullRequestFilter,\n\ttoProviderPullRequestStates,\n} from './models.js';\nimport type { ProvidersApi } from './providersApi.js';\nimport {\n\tcollectProviderPagedResult,\n\tflatSettledOrThrow,\n\tparsePageCursor,\n\ttoPageCursor,\n} from './utils/providerPaging.js';\n\nconst metadata = providersMetadata[GitSelfManagedHostIntegrationId.BitbucketServer];\nconst authProvider = Object.freeze({ id: metadata.id, scopes: metadata.scopes });\n\nexport class BitbucketServerIntegration extends GitHostIntegration<\n\tGitSelfManagedHostIntegrationId.BitbucketServer,\n\tBitbucketRepositoryDescriptor\n> {\n\treadonly authProvider: IntegrationAuthenticationProviderDescriptor = authProvider;\n\treadonly id = GitSelfManagedHostIntegrationId.BitbucketServer;\n\tprotected readonly key =\n\t\t`${this.id}:${this.domain}` satisfies IntegrationKey<GitSelfManagedHostIntegrationId.BitbucketServer>;\n\treadonly name: string = 'Bitbucket Data Center';\n\n\tconstructor(\n\t\tctx: IntegrationServiceContext,\n\t\tauthenticationService: IntegrationAuthenticationService,\n\t\tgetProvidersApi: () => Promise<ProvidersApi>,\n\t\tdidChangeConnection: Emitter<IntegrationConnectionChangeEvent>,\n\t\tprivate readonly _domain: string,\n\t) {\n\t\tsuper(ctx, authenticationService, getProvidersApi, didChangeConnection);\n\t}\n\n\tget domain(): string {\n\t\treturn this._domain;\n\t}\n\n\tprotected apiBaseUrlFor(session: ProviderAuthenticationSession): string {\n\t\treturn this.getSelfManagedApiBaseUrl(session);\n\t}\n\n\tprotected override async mergeProviderPullRequest(\n\t\tsession: ProviderAuthenticationSession,\n\t\tpr: PullRequest,\n\t\toptions?: {\n\t\t\tmergeMethod?: PullRequestMergeMethod;\n\t\t},\n\t): Promise<boolean> {\n\t\tconst api = await this.getProvidersApi();\n\t\treturn api.mergePullRequest(toTokenWithInfo(this.id, session), pr, {\n\t\t\tmergeMethod: options?.mergeMethod,\n\t\t\tbaseUrl: this.apiBaseUrlFor(session),\n\t\t});\n\t}\n\n\tprotected override async getProviderAccountForCommit(\n\t\tsession: ProviderAuthenticationSession,\n\t\trepo: BitbucketRepositoryDescriptor,\n\t\trev: string,\n\t\toptions?: {\n\t\t\tavatarSize?: number;\n\t\t},\n\t): Promise<Account | UnidentifiedAuthor | undefined> {\n\t\treturn (await this.authenticationService.apis.bitbucket)?.getServerAccountForCommit(\n\t\t\tthis,\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\trepo.owner,\n\t\t\trepo.name,\n\t\t\trev,\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t\t{\n\t\t\t\tavatarSize: options?.avatarSize,\n\t\t\t},\n\t\t);\n\t}\n\n\tprotected override async getProviderAccountForEmail(\n\t\t_session: AuthenticationSession,\n\t\t_repo: BitbucketRepositoryDescriptor,\n\t\t_email: string,\n\t\t_options?: {\n\t\t\tavatarSize?: number;\n\t\t},\n\t): Promise<Account | undefined> {\n\t\treturn Promise.resolve(undefined);\n\t}\n\n\tprotected override async getProviderDefaultBranch(\n\t\t_session: AuthenticationSession,\n\t\t_repo: BitbucketRepositoryDescriptor,\n\t): Promise<DefaultBranch | undefined> {\n\t\treturn Promise.resolve(undefined);\n\t}\n\n\tprotected override async getProviderLinkedIssueOrPullRequest(\n\t\tsession: ProviderAuthenticationSession,\n\t\trepo: BitbucketRepositoryDescriptor,\n\t\t{ id }: { id: string; key: string },\n\t\ttype: undefined | IssueOrPullRequestType,\n\t): Promise<IssueOrPullRequest | undefined> {\n\t\tif (type === 'issue') {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn (await this.authenticationService.apis.bitbucket)?.getServerPullRequestById(\n\t\t\tthis,\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\trepo.owner,\n\t\t\trepo.name,\n\t\t\tid,\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t);\n\t}\n\n\t/**\n\t * One request per target, settled independently so one target's failure rejects only its own slot:\n\t * provider-apis has no single pull request read for Bitbucket, so this uses our own.\n\t */\n\tprotected override async getProviderPullRequestsBatch(\n\t\tsession: ProviderAuthenticationSession,\n\t\tcoordinates: readonly { owner: string; repo: string; number: number; project?: string }[],\n\t\toptions: { currentAccount?: { id: string; username?: string } } | undefined,\n\t\t_cancellation?: AbortSignal,\n\t): Promise<PromiseSettledResult<PullRequestShape | undefined>[] | undefined> {\n\t\tconst api = await this.authenticationService.apis.bitbucket;\n\t\tif (api == null) return undefined;\n\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\t\treturn mapSettledBounded(coordinates, providerFanOutConcurrency, c =>\n\t\t\tapi.getServerPullRequest(\n\t\t\t\tthis,\n\t\t\t\ttokenWithInfo,\n\t\t\t\tc.owner,\n\t\t\t\tc.repo,\n\t\t\t\tString(c.number),\n\t\t\t\tthis.apiBaseUrlFor(session),\n\t\t\t\t{\n\t\t\t\t\tcurrentAccount: options?.currentAccount,\n\t\t\t\t\tdeferFailure: true,\n\t\t\t\t},\n\t\t\t),\n\t\t);\n\t}\n\n\t/**\n\t * One request per target, settled independently, through our own client: provider-apis' pull request list has\n\t * no source-branch filter. Serves only a branch in the base repository — the manager read refuses a `headOwner`\n\t * naming another owner here, since Bitbucket Data Center finds a branch's pull requests only through the\n\t * repository the branch lives in, and a fork's slug can't be derived from its owner.\n\t */\n\tprotected override async getProviderPullRequestsForBranches(\n\t\tsession: ProviderAuthenticationSession,\n\t\ttargets: readonly { owner: string; repo: string; project?: string; branch: string; headOwner?: string }[],\n\t\toptions: { currentAccount?: { id: string; username?: string }; limit: number },\n\t\t_cancellation?: AbortSignal,\n\t): Promise<PromiseSettledResult<{ pullRequests: PullRequestShape[]; truncated: boolean }>[] | undefined> {\n\t\tconst api = await this.authenticationService.apis.bitbucket;\n\t\tif (api == null) return undefined;\n\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\t\treturn mapSettledBounded(targets, providerFanOutConcurrency, async t => {\n\t\t\tif (t.headOwner != null) {\n\t\t\t\tthrow new Error(`Bitbucket Data Center can't find ${t.branch}'s pull requests in a fork by its owner`);\n\t\t\t}\n\n\t\t\treturn api.getServerPullRequestsForBranch(\n\t\t\t\tthis,\n\t\t\t\ttokenWithInfo,\n\t\t\t\tt.owner,\n\t\t\t\tt.repo,\n\t\t\t\tt.branch,\n\t\t\t\tthis.apiBaseUrlFor(session),\n\t\t\t\t{\n\t\t\t\t\tlimit: options.limit,\n\t\t\t\t\tcurrentAccount: options.currentAccount,\n\t\t\t\t\tdeferFailure: true,\n\t\t\t\t},\n\t\t\t);\n\t\t});\n\t}\n\n\tprotected override async getProviderIssue(\n\t\t_session: AuthenticationSession,\n\t\t_repo: BitbucketRepositoryDescriptor,\n\t\t_id: string,\n\t): Promise<Issue | undefined> {\n\t\treturn Promise.resolve(undefined);\n\t}\n\n\tprotected override async getProviderPullRequestForBranch(\n\t\tsession: ProviderAuthenticationSession,\n\t\trepo: BitbucketRepositoryDescriptor,\n\t\tbranch: string,\n\t\t_options?: {\n\t\t\tavatarSize?: number;\n\t\t\tinclude?: PullRequestState[];\n\t\t},\n\t): Promise<PullRequest | undefined> {\n\t\treturn (await this.authenticationService.apis.bitbucket)?.getServerPullRequestForBranch(\n\t\t\tthis,\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\trepo.owner,\n\t\t\trepo.name,\n\t\t\tbranch,\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t);\n\t}\n\n\tprotected override async getProviderPullRequestForCommit(\n\t\tsession: ProviderAuthenticationSession,\n\t\trepo: BitbucketRepositoryDescriptor,\n\t\trev: string,\n\t): Promise<PullRequest | undefined> {\n\t\treturn (await this.authenticationService.apis.bitbucket)?.getServerPullRequestForCommit(\n\t\t\tthis,\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\trepo.owner,\n\t\t\trepo.name,\n\t\t\trev,\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t);\n\t}\n\n\tpublic override async getRepoInfo(repo: {\n\t\towner: string;\n\t\tname: string;\n\t\tproject?: string;\n\t\tconnectionId?: string;\n\t}): Promise<ProviderRepository | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\t// `connectionId` targets a specific account (multi-account); omitted reads the primary.\n\t\tconst session = await this.resolveReadSession(repo.connectionId, undefined);\n\t\tif (session == null) return undefined;\n\n\t\treturn api.getRepo(toTokenWithInfo(this.id, session), repo.owner, repo.name, repo.project, {\n\t\t\tbaseUrl: this.apiBaseUrlFor(session),\n\t\t});\n\t}\n\n\tprotected override async getProviderRepositoryMetadata(\n\t\t_session: AuthenticationSession,\n\t\t_repo: BitbucketRepositoryDescriptor,\n\t\t_cancellation?: AbortSignal,\n\t): Promise<RepositoryMetadata | undefined> {\n\t\treturn Promise.resolve(undefined);\n\t}\n\n\t/**\n\t * Accounts by {@link getAccountKey}. One integration serves every installation on its host, and installations\n\t * mounted at different context paths are different servers whose users differ, even under the same token.\n\t */\n\tprivate _accounts: Map<string, Account | undefined> | undefined;\n\n\t/** The installation the session's reads address, plus the credential — what decides whose account it is. */\n\tprivate getAccountKey(session: ProviderAuthenticationSession): string {\n\t\treturn `${this.apiBaseUrlFor(session)}\\n${session.accessToken}`;\n\t}\n\n\t/**\n\t * The account request the account cache would otherwise answer; see `IntegrationBase.validateCredential`. Needed\n\t * without any discovery cache: a repo-scoped pull request read fans out across its repositories in the SDK with\n\t * no request to the connection first, so a dead token comes back as one refused repository per request.\n\t *\n\t * A project access token never confirms: its bot user authenticates, but `/users` does not list it, so the SDK\n\t * cannot find the current user and the check proves nothing.\n\t */\n\tprotected override async validateCredential(session: ProviderAuthenticationSession): Promise<void> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst user = await api\n\t\t\t.getCurrentUser(toTokenWithInfo(this.id, session), { baseUrl: this.apiBaseUrlFor(session) })\n\t\t\t.catch((ex: unknown) => {\n\t\t\t\tif (!(ex instanceof AuthenticationError)) throw ex;\n\n\t\t\t\t// Bitbucket Data Center names the user it authenticated in `X-AUSERNAME`, and answers a dead token\n\t\t\t\t// exactly as it answers no credential: the same 401 and body, without that header. So a refusal that\n\t\t\t\t// names a user, or says the user holds no license, came from a credential that authenticated, and\n\t\t\t\t// proves nothing about the scopes' refusals.\n\t\t\t\tconst response = (ex.original as { response?: { headers?: ResponseHeaders } } | undefined)?.response;\n\t\t\t\tif (\n\t\t\t\t\tgetResponseHeader(response?.headers, 'x-ausername') ||\n\t\t\t\t\t/not (?:a|currently) licensed/i.test(ex.original?.message ?? '')\n\t\t\t\t) {\n\t\t\t\t\tthrow new Error('Bitbucket Data Center could not confirm the credential', { cause: ex });\n\t\t\t\t}\n\t\t\t\tthrow ex;\n\t\t\t});\n\t\tif (user == null) {\n\t\t\tthrow new Error('Bitbucket Data Center did not confirm the credential');\n\t\t}\n\t}\n\n\tprotected override async getProviderCurrentAccount(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<Account | undefined> {\n\t\tconst key = this.getAccountKey(session);\n\t\tthis._accounts ??= new Map<string, Account | undefined>();\n\n\t\tconst cachedAccount = this._accounts.get(key);\n\t\tif (cachedAccount == null) {\n\t\t\tconst api = await this.getProvidersApi();\n\t\t\tconst user = await api.getCurrentUser(toTokenWithInfo(this.id, session), {\n\t\t\t\tbaseUrl: this.apiBaseUrlFor(session),\n\t\t\t});\n\t\t\tthis._accounts.set(\n\t\t\t\tkey,\n\t\t\t\tuser\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tprovider: this,\n\t\t\t\t\t\t\tid: user.id,\n\t\t\t\t\t\t\tname: user.name ?? undefined,\n\t\t\t\t\t\t\temail: user.email ?? undefined,\n\t\t\t\t\t\t\tavatarUrl: user.avatarUrl ?? undefined,\n\t\t\t\t\t\t\tusername: user.username ?? undefined,\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined,\n\t\t\t);\n\t\t}\n\n\t\treturn this._accounts.get(key);\n\t}\n\n\tprotected override async getProviderOrganizationsForUser(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<ProviderHierarchyResult<ProviderOrganization>> {\n\t\tconst api = await this.getProvidersApi();\n\t\treturn api.getBitbucketServerProjects(\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t\tsession.id,\n\t\t);\n\t}\n\n\tprotected override async getProviderRepositoriesForOrg(\n\t\tsession: ProviderAuthenticationSession,\n\t\torg: string,\n\t\toptions?: { cursor?: string },\n\t): Promise<ProviderHierarchyResult<ProviderRepository>> {\n\t\tconst api = await this.getProvidersApi();\n\t\treturn api.getBitbucketServerRepositories(\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t\tsession.id,\n\t\t\t{\n\t\t\t\tproject: org,\n\t\t\t\tcursor: options?.cursor,\n\t\t\t},\n\t\t);\n\t}\n\n\tprotected override async getProviderRepositoriesForUser(\n\t\tsession: ProviderAuthenticationSession,\n\t\toptions?: { cursor?: string },\n\t): Promise<ProviderHierarchyResult<ProviderRepository>> {\n\t\tconst api = await this.getProvidersApi();\n\t\treturn api.getBitbucketServerRepositories(\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t\tsession.id,\n\t\t\toptions,\n\t\t);\n\t}\n\n\tprotected override async searchProviderMyPullRequests(\n\t\tsession: ProviderAuthenticationSession,\n\t\trepos?: BitbucketRepositoryDescriptor[],\n\t\t_cancellation?: AbortSignal,\n\t\toptions?: SearchMyPullRequestsOptions,\n\t): Promise<PullRequest[] | undefined> {\n\t\tif (repos != null) {\n\t\t\t// TODO: implement repos version\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst api = await this.getProvidersApi();\n\t\tif (!api) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst prs = await api.getBitbucketServerPullRequestsForCurrentUser(\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t\t{ states: toProviderPullRequestStates(options?.state) },\n\t\t);\n\t\treturn prs?.data.map(pr => fromProviderPullRequest(pr, this));\n\t}\n\n\tprotected override async getProviderMyPullRequestsForUser(\n\t\tsession: ProviderAuthenticationSession,\n\t\toptions?: { state?: PullRequestStateFilter[]; cursor?: string; filters?: PullRequestFilter[] },\n\t): Promise<PagedResult<ProviderPullRequest> | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst states = toProviderPullRequestStates(options?.state);\n\t\t// provider-apis translates the public 1-based `page` to Bitbucket Server's `start` offset and normalizes\n\t\t// `nextPageStart` back to the next page number. Thread that number inside our opaque cursor so the\n\t\t// ProviderBackend sweep drives the drain (bounded by its maxPages).\n\t\tconst page = parsePageCursor(options?.cursor);\n\t\tconst result = await api.getBitbucketServerPullRequestsForCurrentUser(\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t\t{ states: states, page: page },\n\t\t);\n\t\tif (result == null) return undefined;\n\n\t\tconst account = options?.filters?.length ? await this.getProviderCurrentAccount(session) : undefined;\n\t\tconst identifiers = new Set([account?.id, account?.username].filter((id): id is string => id != null));\n\t\tif (options?.filters?.length && identifiers.size === 0) {\n\t\t\tthrow new Error(\n\t\t\t\t'Unable to resolve the current Bitbucket Data Center account for the requested pull request filters.',\n\t\t\t);\n\t\t}\n\n\t\tconst values = options?.filters?.length\n\t\t\t? result.data.filter(pr => {\n\t\t\t\t\tconst isCurrentUser = (user: { id?: string | null; username?: string | null } | null | undefined) =>\n\t\t\t\t\t\tuser != null &&\n\t\t\t\t\t\t((user.id != null && identifiers.has(user.id)) ||\n\t\t\t\t\t\t\t(user.username != null && identifiers.has(user.username)));\n\t\t\t\t\tconst isAuthor = isCurrentUser(pr.author);\n\t\t\t\t\tconst isRequestedReviewer = pr.reviews?.some(\n\t\t\t\t\t\treview =>\n\t\t\t\t\t\t\tisCurrentUser(review.reviewer) &&\n\t\t\t\t\t\t\treview.state === ProviderPullRequestReviewState.ReviewRequested,\n\t\t\t\t\t);\n\t\t\t\t\treturn (\n\t\t\t\t\t\t(options.filters!.includes(PullRequestFilter.Author) && isAuthor) ||\n\t\t\t\t\t\t(options.filters!.includes(PullRequestFilter.ReviewRequested) && isRequestedReviewer)\n\t\t\t\t\t);\n\t\t\t\t})\n\t\t\t: result.data;\n\n\t\treturn {\n\t\t\tvalues: values,\n\t\t\tpaging: {\n\t\t\t\tmore: result.hasMore,\n\t\t\t\tcursor: result.hasMore && result.nextPage != null ? toPageCursor(result.nextPage) : '{}',\n\t\t\t},\n\t\t};\n\t}\n\n\tprotected override async searchProviderPullRequests(\n\t\tsession: ProviderAuthenticationSession,\n\t\tsearchQuery: string,\n\t\trepos?: BitbucketRepositoryDescriptor[],\n\t\tcancellation?: AbortSignal,\n\t\toptions?: SearchPullRequestsOptions,\n\t): Promise<PullRequest[] | undefined> {\n\t\tif (cancellation?.aborted) throw new CancellationError();\n\n\t\tconst api = await this.getProvidersApi();\n\t\tif (!api) return undefined;\n\n\t\tconst repoInputs =\n\t\t\trepos != null\n\t\t\t\t? repos.map(r => ({ name: r.name, namespace: r.owner }))\n\t\t\t\t: await this.getWorkspaceRepoInputs();\n\t\tif (cancellation?.aborted) throw new CancellationError();\n\t\t// An explicitly-empty `repos` means \"search these zero repos\" -> no results; reserve `undefined`\n\t\t// (\"scope couldn't be determined\") for when no repos were requested and none were discovered.\n\t\tif (repoInputs.length === 0) return repos != null ? [] : undefined;\n\n\t\tconst token = toTokenWithInfo(this.id, session);\n\t\tconst states = toProviderPullRequestStates(options?.include);\n\t\tconst providerPullRequests = await flatSettledOrThrow(\n\t\t\trepoInputs.map(async repo => {\n\t\t\t\tconst result = await collectProviderPagedResult(cursor => {\n\t\t\t\t\tif (cancellation?.aborted) throw new CancellationError();\n\n\t\t\t\t\treturn api.getPullRequestsForRepo(token, repo, {\n\t\t\t\t\t\tbaseUrl: this.apiBaseUrlFor(session),\n\t\t\t\t\t\tcursor: cursor,\n\t\t\t\t\t\tstates: states,\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t\treturn result.values;\n\t\t\t}),\n\t\t);\n\t\tif (cancellation?.aborted) throw new CancellationError();\n\n\t\treturn providerPullRequests\n\t\t\t.filter(pr => providerPullRequestMatchesSearch(pr, searchQuery))\n\t\t\t.map(pr => fromProviderPullRequest(pr, this));\n\t}\n\n\t/**\n\t * The filtered pull-request search, read by this module's own requests rather than the SDK's: the SDK's list\n\t * reads carry no text, draft or participant-status filter and no per-facet continuation. Every request goes to\n\t * the session's own address, context path included, so one connection's cursor can't be replayed on another.\n\t */\n\tprotected override async searchProviderPullRequestsPage(\n\t\tsession: ProviderAuthenticationSession,\n\t\toptions: {\n\t\t\trepos?: ProviderRepoInput[];\n\t\t\torg?: string;\n\t\t\tcriteria?: PullRequestSearchCriteria;\n\t\t\tcursor?: string;\n\t\t\tpageSize?: number;\n\t\t\tsummary?: boolean;\n\t\t},\n\t\tcancellation?: AbortSignal,\n\t): Promise<ProviderPullRequestSearchPage | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\treturn api.searchBitbucketServerPullRequestsPage(\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\t{\n\t\t\t\tbaseUrl: this.apiBaseUrlFor(session),\n\t\t\t\tconnectionId: session.id,\n\t\t\t\tprovider: this,\n\t\t\t\trepos: options.repos,\n\t\t\t\torg: options.org,\n\t\t\t\tcriteria: options.criteria,\n\t\t\t\tcurrentUser: await this.getSearchUser(session, options.criteria, cancellation),\n\t\t\t\tcursor: options.cursor,\n\t\t\t\tpageSize: options.pageSize,\n\t\t\t},\n\t\t\tcancellation,\n\t\t);\n\t}\n\n\t/**\n\t * Counts each scope by reading it, since Bitbucket Data Center has neither a count query nor a total on its\n\t * pages. The facade hands over one scope per call and runs those calls concurrently (see `countPullRequests`),\n\t * so scopes here are counted one after another rather than multiplying that concurrency.\n\t */\n\tprotected override async countProviderPullRequests(\n\t\tsession: ProviderAuthenticationSession,\n\t\tscopes: readonly { repos?: ProviderRepoInput[]; org?: string; criteria?: PullRequestSearchCriteria }[],\n\t\tcancellation?: AbortSignal,\n\t): Promise<ProviderPullRequestCount[] | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst token = toTokenWithInfo(this.id, session);\n\t\tconst counts: ProviderPullRequestCount[] = [];\n\t\tfor (const scope of scopes) {\n\t\t\tcounts.push(\n\t\t\t\tawait api.countBitbucketServerPullRequests(\n\t\t\t\t\ttoken,\n\t\t\t\t\t{\n\t\t\t\t\t\tbaseUrl: this.apiBaseUrlFor(session),\n\t\t\t\t\t\trepos: scope.repos,\n\t\t\t\t\t\torg: scope.org,\n\t\t\t\t\t\tcriteria: scope.criteria,\n\t\t\t\t\t\tcurrentUser: await this.getSearchUser(session, scope.criteria, cancellation),\n\t\t\t\t\t},\n\t\t\t\t\tcancellation,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\treturn counts;\n\t}\n\n\t/**\n\t * The session's own user, which a relationship facet filters by. Resolved per session rather than from the\n\t * primary connection, so a read pinned to one account never filters by another's identity; an account that\n\t * can't be resolved refuses the read instead of widening it to everyone's pull requests.\n\t *\n\t * The lookup is raced against `cancellation` so a cancelled read settles at once. The SDK's current-user read\n\t * takes no signal, so the request itself runs on; its answer still lands in the per-token account cache, so a\n\t * cold lookup a cancellation abandoned isn't wasted on the next read.\n\t */\n\tprivate async getSearchUser(\n\t\tsession: ProviderAuthenticationSession,\n\t\tcriteria: PullRequestSearchCriteria | undefined,\n\t\tcancellation: AbortSignal | undefined,\n\t): Promise<BitbucketServerSearchUser | undefined> {\n\t\tif (!criteria?.relationships?.length) return undefined;\n\n\t\tconst lookup = this.getProviderCurrentAccount(session);\n\t\tconst account = await (cancellation != null ? raceWithSignal(lookup, cancellation) : lookup);\n\t\tif (account?.id == null || account.username == null) {\n\t\t\tthrow new Error('Unable to resolve the current Bitbucket Data Center account for a relationship search.');\n\t\t}\n\n\t\treturn { id: account.id, username: account.username };\n\t}\n\n\tprivate async getWorkspaceRepoInputs(): Promise<{ name: string; namespace: string }[]> {\n\t\tconst remotes = await this.ctx.repositories.getOpenRemotes();\n\t\tconst inputs = await nonnullSettled(\n\t\t\tremotes.map(async (r: GitRemote) => {\n\t\t\t\tconst integration = await this.authenticationService.getByRemote(r);\n\t\t\t\tif (integration !== this) return undefined;\n\n\t\t\t\t// Use the remote provider's parsing so the Bitbucket Server `scm/<project>/<repo>` prefix is\n\t\t\t\t// stripped; a raw `path.split('/')` would yield namespace=`scm`, name=`<project>`.\n\t\t\t\tconst namespace = r.provider?.owner;\n\t\t\t\tconst name = r.provider?.repoName;\n\t\t\t\treturn namespace != null && name != null ? { name: name, namespace: namespace } : undefined;\n\t\t\t}),\n\t\t);\n\t\t// Dedupe: a repo with multiple remotes (e.g. `origin` + `upstream`) can map to the same input,\n\t\t// which would otherwise fetch and return the same PRs more than once.\n\t\treturn [...new Map(inputs.map(i => [`${i.namespace}/${i.name}`, i])).values()];\n\t}\n\n\tprotected override async searchProviderMyIssues(\n\t\t_session: AuthenticationSession,\n\t\t_repos?: BitbucketRepositoryDescriptor[],\n\t): Promise<IssueShape[] | undefined> {\n\t\treturn Promise.resolve(undefined);\n\t}\n\n\t/**\n\t * Bitbucket Data Center exposes no issue tracker at all (issues live in Jira), so — like Bitbucket Cloud,\n\t * whose own tracker is deprecated — it is not an issue provider on the ProviderBackend surface. Without this\n\t * the facade would take `supportsIssues`' default `true` and route the read to a provider that registers no\n\t * issue client: the repo-scoped path fails with the SDK's `does not support function: getIssuesForReposFn`\n\t * as an opaque `kind: 'other'` warning, and `broadenIssues` first drains every repo of the org before hitting\n\t * the same failure. Its metadata already declares no issue filters, so this keeps both halves of the\n\t * capability answer consistent.\n\t */\n\toverride get supportsIssues(): boolean {\n\t\treturn false;\n\t}\n\n\tprivate readonly storagePrefix = 'bitbucket-server';\n\tprotected override async providerOnConnect(): Promise<void> {\n\t\tif (this._session == null) return;\n\n\t\tconst accountKey = this.getAccountKey(this._session);\n\t\tconst accountStorageKey = md5(accountKey);\n\n\t\tconst storedAccount = this.ctx.storage.get(`${this.storagePrefix}:${accountStorageKey}:account`);\n\n\t\tlet account: Account | undefined = storedAccount?.data ? { ...storedAccount.data, provider: this } : undefined;\n\n\t\tif (storedAccount == null) {\n\t\t\taccount = await this.getProviderCurrentAccount(this._session);\n\t\t\tif (account != null) {\n\t\t\t\t// Clear all other stored workspaces and repositories and accounts when our session changes\n\t\t\t\tawait this.ctx.storage.deleteWithPrefix(this.storagePrefix);\n\t\t\t\tawait this.ctx.storage.store(`${this.storagePrefix}:${accountStorageKey}:account`, {\n\t\t\t\t\tv: 1,\n\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tid: account.id,\n\t\t\t\t\t\tname: account.name,\n\t\t\t\t\t\temail: account.email,\n\t\t\t\t\t\tavatarUrl: account.avatarUrl,\n\t\t\t\t\t\tusername: account.username,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tthis._accounts ??= new Map<string, Account | undefined>();\n\t\tthis._accounts.set(accountKey, account);\n\t}\n\n\tprotected override providerOnDisconnect(): void {\n\t\tthis._accounts = undefined;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;AA2DA,MAAM,WAAW,kBAAA;AACjB,MAAM,eAAe,OAAO,OAAO;CAAE,IAAI,SAAS;CAAI,QAAQ,SAAS;AAAO,CAAC;AAE/E,IAAa,6BAAb,cAAgD,mBAG9C;CAYiB;CAXlB,eAAqE;CACrE,KAAS;CACT,MACC,GAAG,KAAK,GAAG,GAAG,KAAK;CACpB,OAAwB;CAExB,YACC,KACA,uBACA,iBACA,qBACA,SACC;EACD,MAAM,KAAK,uBAAuB,iBAAiB,mBAAmB;EAFrD,KAAA,UAAA;CAGlB;CAEA,IAAI,SAAiB;EACpB,OAAO,KAAK;CACb;CAEA,cAAwB,SAAgD;EACvE,OAAO,KAAK,yBAAyB,OAAO;CAC7C;CAEA,MAAyB,yBACxB,SACA,IACA,SAGmB;EAEnB,QAAO,MADW,KAAK,gBAAgB,EAAA,CAC5B,iBAAiB,gBAAgB,KAAK,IAAI,OAAO,GA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AAM;MACL,IAAI,QAAQ;MACZ,MAAM,QAAQ;MACd,OAAO,QAAQ;MACf,WAAW,QAAQ;MACnB,UAAU,QAAQ;KACnB;IACD,CAAC;GACF;EACD;EACA,KAAK,8BAAc,IAAI,IAAiC;EACxD,KAAK,UAAU,IAAI,YAAY,OAAO;CACvC;CAEA,uBAAgD;EAC/C,KAAK,YAAY,KAAA;CAClB;AACD"}
@@ -1,13 +1,14 @@
1
1
  import { IssueOrPullRequest, IssueOrPullRequestState, IssueOrPullRequestType } from "../../../git/models/issueOrPullRequest.js";
2
2
  import { Issue, IssueShape } from "../../../git/models/issue.js";
3
- import { PullRequest, PullRequestFilter, PullRequestMergeMethod, PullRequestStateFilter } from "../../../git/models/pullRequest.js";
3
+ import { PullRequest, PullRequestFilter, PullRequestMergeMethod, PullRequestShape, PullRequestStateFilter } from "../../../git/models/pullRequest.js";
4
4
  import { Account, UnidentifiedAuthor } from "../../../git/models/author.js";
5
5
  import { DefaultBranch } from "../../../git/models/defaultBranch.js";
6
6
  import { RepositoryMetadata } from "../../../git/models/repositoryMetadata.js";
7
7
  import { AuthenticationSessionLike, ProviderAuthenticationSession } from "../authentication/models.js";
8
8
  import { GitCloudHostIntegrationId } from "../constants.js";
9
- import { GitHostIntegration, SearchMyPullRequestsOptions, SearchPullRequestsOptions } from "../models/gitHostIntegration.js";
10
9
  import { ProviderOrganization } from "../results.js";
10
+ import { ProviderRefusal } from "../collectionMetadata.js";
11
+ import { GitHostIntegration, SearchMyPullRequestsOptions, SearchPullRequestsOptions } from "../models/gitHostIntegration.js";
11
12
  import { ProviderApiPagedResult, ProviderHierarchyResult, ProviderPullRequest, ProviderRepository } from "./models.js";
12
13
  import { IntegrationAuthenticationProviderDescriptor } from "../authentication/integrationAuthenticationProvider.js";
13
14
  import { BitbucketRepositoryDescriptor } from "./bitbucket/models.js";
@@ -39,6 +40,41 @@ export declare class BitbucketIntegration extends GitHostIntegration<GitCloudHos
39
40
  id: string;
40
41
  key: string;
41
42
  }, type: undefined | IssueOrPullRequestType): Promise<IssueOrPullRequest | undefined>;
43
+ /**
44
+ * One request per target, settled independently so one target's failure rejects only its own slot:
45
+ * provider-apis has no single pull request read for Bitbucket, so this uses our own.
46
+ */
47
+ protected getProviderPullRequestsBatch(session: ProviderAuthenticationSession, coordinates: readonly {
48
+ owner: string;
49
+ repo: string;
50
+ number: number;
51
+ project?: string;
52
+ }[], options: {
53
+ currentAccount?: {
54
+ id: string;
55
+ username?: string;
56
+ };
57
+ } | undefined, _cancellation?: AbortSignal): Promise<PromiseSettledResult<PullRequestShape | undefined>[] | undefined>;
58
+ /**
59
+ * One request per target, settled independently, through our own client: provider-apis' pull request list has
60
+ * no source-branch filter.
61
+ */
62
+ protected getProviderPullRequestsForBranches(session: ProviderAuthenticationSession, targets: readonly {
63
+ owner: string;
64
+ repo: string;
65
+ project?: string;
66
+ branch: string;
67
+ headOwner?: string;
68
+ }[], options: {
69
+ currentAccount?: {
70
+ id: string;
71
+ username?: string;
72
+ };
73
+ limit: number;
74
+ }, _cancellation?: AbortSignal): Promise<PromiseSettledResult<{
75
+ pullRequests: PullRequestShape[];
76
+ truncated: boolean;
77
+ }>[] | undefined>;
42
78
  protected getProviderIssue(session: ProviderAuthenticationSession, repo: BitbucketRepositoryDescriptor, id: string): Promise<Issue | undefined>;
43
79
  protected getProviderPullRequestForBranch(session: ProviderAuthenticationSession, repo: BitbucketRepositoryDescriptor, branch: string, _options?: {
44
80
  avatarSize?: number;
@@ -48,6 +84,13 @@ export declare class BitbucketIntegration extends GitHostIntegration<GitCloudHos
48
84
  protected getProviderRepositoryMetadata(session: ProviderAuthenticationSession, repo: BitbucketRepositoryDescriptor, cancellation?: AbortSignal): Promise<RepositoryMetadata | undefined>;
49
85
  private _accounts;
50
86
  protected getProviderCurrentAccount(session: ProviderAuthenticationSession): Promise<Account | undefined>;
87
+ /** The profile request the account cache would otherwise answer; see `IntegrationBase.validateCredential`. */
88
+ protected validateCredential(session: ProviderAuthenticationSession): Promise<void>;
89
+ /**
90
+ * Bitbucket's `403` for a token missing the OAuth scopes a request needs, which a reconnect fixes by consenting to
91
+ * them again; see `IntegrationBase.isCredentialRefusal`.
92
+ */
93
+ protected isCredentialRefusal(refusal: ProviderRefusal): boolean;
51
94
  private _workspaces;
52
95
  private getProviderResourcesForCurrentUser;
53
96
  protected getProviderOrganizationsForUser(session: ProviderAuthenticationSession): Promise<ProviderHierarchyResult<ProviderOrganization> | undefined>;
@@ -1,10 +1,10 @@
1
1
  import { uniqueBy } from "../../../utils/iterable.js";
2
2
  import { CancellationError } from "../../../utils/cancellation.js";
3
- import { batchResults, flatSettled, nonnullSettled } from "../../../utils/promise.js";
3
+ import { batchResults, flatSettled, mapSettledBounded, nonnullSettled } from "../../../utils/promise.js";
4
4
  import { md5 } from "../../../utils/crypto.js";
5
5
  import "../../../git/models/pullRequest.js";
6
- import { toCollectionScopeFailure } from "../collectionMetadata.js";
7
6
  import "../constants.js";
7
+ import { toCollectionScopeFailure } from "../collectionMetadata.js";
8
8
  import { toTokenWithInfo } from "../authentication/models.js";
9
9
  import { collectProviderPagedResult, flatSettledOrThrow, mergeCollectionMetadata, parsePageCursor, toPageCursor } from "./utils/providerPaging.js";
10
10
  import { fromProviderPullRequest, getProviderPullRequestIdentity, providersMetadata, toProviderPullRequestStates } from "./models.js";
@@ -47,6 +47,34 @@ var BitbucketIntegration = class extends GitHostIntegration {
47
47
  async getProviderLinkedIssueOrPullRequest(session, repo, { id }, type) {
48
48
  return (await this.authenticationService.apis.bitbucket)?.getIssueOrPullRequest(this, toTokenWithInfo(this.id, session), repo.owner, repo.name, id, this.apiBaseUrl, { type });
49
49
  }
50
+ /**
51
+ * One request per target, settled independently so one target's failure rejects only its own slot:
52
+ * provider-apis has no single pull request read for Bitbucket, so this uses our own.
53
+ */
54
+ async getProviderPullRequestsBatch(session, coordinates, options, _cancellation) {
55
+ const api = await this.authenticationService.apis.bitbucket;
56
+ if (api == null) return void 0;
57
+ const tokenWithInfo = toTokenWithInfo(this.id, session);
58
+ return mapSettledBounded(coordinates, 6, (c) => api.getPullRequest(this, tokenWithInfo, c.owner, c.repo, String(c.number), this.apiBaseUrl, {
59
+ currentAccount: options?.currentAccount,
60
+ deferFailure: true
61
+ }));
62
+ }
63
+ /**
64
+ * One request per target, settled independently, through our own client: provider-apis' pull request list has
65
+ * no source-branch filter.
66
+ */
67
+ async getProviderPullRequestsForBranches(session, targets, options, _cancellation) {
68
+ const api = await this.authenticationService.apis.bitbucket;
69
+ if (api == null) return void 0;
70
+ const tokenWithInfo = toTokenWithInfo(this.id, session);
71
+ return mapSettledBounded(targets, 6, (t) => api.getPullRequestsForBranch(this, tokenWithInfo, t.owner, t.repo, t.branch, this.apiBaseUrl, {
72
+ headOwner: t.headOwner,
73
+ limit: options.limit,
74
+ currentAccount: options.currentAccount,
75
+ deferFailure: true
76
+ }));
77
+ }
50
78
  async getProviderIssue(session, repo, id) {
51
79
  return (await this.authenticationService.apis.bitbucket)?.getIssue(this, toTokenWithInfo(this.id, session), repo.owner, repo.name, id, this.apiBaseUrl);
52
80
  }
@@ -76,6 +104,17 @@ var BitbucketIntegration = class extends GitHostIntegration {
76
104
  }
77
105
  return this._accounts.get(accessToken);
78
106
  }
107
+ /** The profile request the account cache would otherwise answer; see `IntegrationBase.validateCredential`. */
108
+ async validateCredential(session) {
109
+ if (await (await this.getProvidersApi()).getCurrentUser(toTokenWithInfo(this.id, session)) == null) throw new Error("Bitbucket did not confirm the credential");
110
+ }
111
+ /**
112
+ * Bitbucket's `403` for a token missing the OAuth scopes a request needs, which a reconnect fixes by consenting to
113
+ * them again; see `IntegrationBase.isCredentialRefusal`.
114
+ */
115
+ isCredentialRefusal(refusal) {
116
+ return refusal.status === 403 && /required privilege scopes/i.test(refusal.detail ?? "");
117
+ }
79
118
  _workspaces;
80
119
  async getProviderResourcesForCurrentUser(session, force = false) {
81
120
  this._workspaces ??= /* @__PURE__ */ new Map();