@gitkraken/core-gitlens 0.43.0 → 0.44.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 (85) hide show
  1. package/CHANGELOG.md +23 -1
  2. package/dist/git/errors.d.ts +1 -0
  3. package/dist/git/errors.js +7 -1
  4. package/dist/git/errors.js.map +1 -1
  5. package/dist/git-cli/providers/config.js +2 -2
  6. package/dist/git-cli/providers/pausedOperations.js +2 -2
  7. package/dist/git-cli/providers/pausedOperations.js.map +1 -1
  8. package/dist/git-cli/providers/staging.js +1 -1
  9. package/dist/ipc/discovery.js +1 -1
  10. package/dist/plus/agents/providers/claudeCodeTranscript.js +6 -6
  11. package/dist/plus/agents/providers/claudeCodeTranscript.js.map +1 -1
  12. package/dist/plus/ai/providers/openAICompatibleProviderBase.js +1 -1
  13. package/dist/plus/git-github/api/aliasedQuery.d.ts +3 -2
  14. package/dist/plus/git-github/api/aliasedQuery.js +7 -3
  15. package/dist/plus/git-github/api/aliasedQuery.js.map +1 -1
  16. package/dist/plus/git-github/api/github.d.ts +5 -0
  17. package/dist/plus/git-github/api/github.js +100 -12
  18. package/dist/plus/git-github/api/github.js.map +1 -1
  19. package/dist/plus/git-github/api/issueWrites.d.ts +4 -1
  20. package/dist/plus/git-github/api/issueWrites.js +9 -4
  21. package/dist/plus/git-github/api/issueWrites.js.map +1 -1
  22. package/dist/plus/integrations/collectionMetadata.js +2 -1
  23. package/dist/plus/integrations/collectionMetadata.js.map +1 -1
  24. package/dist/plus/integrations/context.d.ts +3 -3
  25. package/dist/plus/integrations/errors.d.ts +4 -0
  26. package/dist/plus/integrations/errors.js +8 -1
  27. package/dist/plus/integrations/errors.js.map +1 -1
  28. package/dist/plus/integrations/index.d.ts +2 -1
  29. package/dist/plus/integrations/index.js.map +1 -1
  30. package/dist/plus/integrations/integrationService.d.ts +16 -0
  31. package/dist/plus/integrations/integrationService.js +6 -1
  32. package/dist/plus/integrations/integrationService.js.map +1 -1
  33. package/dist/plus/integrations/lite.js +11 -1
  34. package/dist/plus/integrations/lite.js.map +1 -1
  35. package/dist/plus/integrations/manager.d.ts +87 -2
  36. package/dist/plus/integrations/models/gitHostIntegration.d.ts +21 -2
  37. package/dist/plus/integrations/models/gitHostIntegration.js +182 -14
  38. package/dist/plus/integrations/models/gitHostIntegration.js.map +1 -1
  39. package/dist/plus/integrations/models/integration.d.ts +9 -1
  40. package/dist/plus/integrations/models/integration.js +43 -3
  41. package/dist/plus/integrations/models/integration.js.map +1 -1
  42. package/dist/plus/integrations/providers/apiClients.d.ts +1 -0
  43. package/dist/plus/integrations/providers/apiClients.js +3 -0
  44. package/dist/plus/integrations/providers/apiClients.js.map +1 -1
  45. package/dist/plus/integrations/providers/azure/azure.d.ts +3 -0
  46. package/dist/plus/integrations/providers/azure/azure.js +110 -19
  47. package/dist/plus/integrations/providers/azure/azure.js.map +1 -1
  48. package/dist/plus/integrations/providers/azureDevOps.d.ts +12 -0
  49. package/dist/plus/integrations/providers/azureDevOps.js +22 -0
  50. package/dist/plus/integrations/providers/azureDevOps.js.map +1 -1
  51. package/dist/plus/integrations/providers/bitbucket/bitbucket.d.ts +21 -2
  52. package/dist/plus/integrations/providers/bitbucket/bitbucket.js +59 -19
  53. package/dist/plus/integrations/providers/bitbucket/bitbucket.js.map +1 -1
  54. package/dist/plus/integrations/providers/bitbucket-server.d.ts +2 -0
  55. package/dist/plus/integrations/providers/bitbucket-server.js +11 -3
  56. package/dist/plus/integrations/providers/bitbucket-server.js.map +1 -1
  57. package/dist/plus/integrations/providers/bitbucket.d.ts +14 -0
  58. package/dist/plus/integrations/providers/bitbucket.js +30 -2
  59. package/dist/plus/integrations/providers/bitbucket.js.map +1 -1
  60. package/dist/plus/integrations/providers/github.d.ts +7 -0
  61. package/dist/plus/integrations/providers/github.js +12 -1
  62. package/dist/plus/integrations/providers/github.js.map +1 -1
  63. package/dist/plus/integrations/providers/gitlab/gitlab.d.ts +19 -1
  64. package/dist/plus/integrations/providers/gitlab/gitlab.js +116 -17
  65. package/dist/plus/integrations/providers/gitlab/gitlab.js.map +1 -1
  66. package/dist/plus/integrations/providers/gitlab.d.ts +15 -2
  67. package/dist/plus/integrations/providers/gitlab.js +34 -4
  68. package/dist/plus/integrations/providers/gitlab.js.map +1 -1
  69. package/dist/plus/integrations/providers/issueSorts.d.ts +1 -0
  70. package/dist/plus/integrations/providers/providerErrors.d.ts +8 -0
  71. package/dist/plus/integrations/providers/providerErrors.js +15 -2
  72. package/dist/plus/integrations/providers/providerErrors.js.map +1 -1
  73. package/dist/plus/integrations/reads/drains.d.ts +1 -0
  74. package/dist/plus/integrations/reads/pullRequestsForCommits.d.ts +45 -0
  75. package/dist/plus/integrations/reads/pullRequestsForCommits.js +97 -0
  76. package/dist/plus/integrations/reads/pullRequestsForCommits.js.map +1 -0
  77. package/dist/plus/integrations/utils/domain.utils.d.ts +1 -0
  78. package/dist/plus/integrations/utils/domain.utils.js +5 -1
  79. package/dist/plus/integrations/utils/domain.utils.js.map +1 -1
  80. package/dist/plus/integrations/utils/failureBackoff.d.ts +13 -0
  81. package/dist/plus/integrations/utils/failureBackoff.js +47 -0
  82. package/dist/plus/integrations/utils/failureBackoff.js.map +1 -0
  83. package/dist/utils/env/node/exec.js +2 -2
  84. package/docs/integrations.md +90 -6
  85. package/package.json +1 -1
@@ -1,3 +1,4 @@
1
+ import { chunk } from "../../../../utils/array.js";
1
2
  import { CancellationError, isCancellationError, raceWithSignal } from "../../../../utils/cancellation.js";
2
3
  import { Logger as _logger } from "../../../../utils/logger.js";
3
4
  import { getScopedLogger } from "../../../../utils/logger.scoped.js";
@@ -5,13 +6,13 @@ import { mapBounded } from "../../../../utils/promise.js";
5
6
  import { trace } from "../../../../utils/decorators/log.js";
6
7
  import { PromiseCache } from "../../../../utils/promiseCache.js";
7
8
  import __decorate from "../../../../_virtual/@oxc-project+runtime/helpers/esm/decorate.js";
8
- import { AuthenticationError, RequestClientError, RequestNotFoundError } from "../../../../git/errors.js";
9
+ import { AuthenticationError, RequestClientError, RequestNotFoundError, RequestRateLimitError, getDeferredRequestFailure, reportRequestFailure } from "../../../../git/errors.js";
10
+ import { sha256, uuid } from "../../../../utils/crypto.js";
9
11
  import { maybeStopWatch } from "../../../../utils/stopwatch.js";
10
12
  import { base64 } from "../../../../utils/base64.js";
11
- import { sha256, uuid } from "../../../../utils/crypto.js";
12
13
  import { effectiveIssueSort } from "../../../../git/utils/issue.utils.js";
13
14
  import { ProviderFetchError, isRateLimitResponse, toRateLimitError } from "../../errors.js";
14
- import { throwProviderError } from "../providerErrors.js";
15
+ import { CommitReadRefusedError, isCommitReadRefusal, isNotFoundResponse, throwProviderError } from "../providerErrors.js";
15
16
  import { azureWorkItemSearchResultLimit, parseAzureWorkItemSearchCursor, toAzureSearchPageSize, toAzureWorkItemSearchCursorKey, toAzureWorkItemSearchQueries, toAzureWorkItemSearchWiql } from "./search.js";
16
17
  import { decodePathSegment } from "../../utils/domain.utils.js";
17
18
  import { azurePullRequestStatusToState, azureWorkItemsStateCategoryToState, encodeAzurePathSegment, fromAzurePullRequest, fromAzureWorkItem, getAzurePullRequestWebUrl, isClosedAzurePullRequestStatus, normalizeAzureBranchName, parseAzureWorkItemDate, sanitizeAzureRepositoryUrl } from "./models.js";
@@ -26,6 +27,9 @@ import { AzureDevOps } from "@gitkraken/provider-apis";
26
27
  //#region ../plus/integrations/src/providers/azure/azure.ts
27
28
  const forkRepositoryUrlCacheTtl = 3e5;
28
29
  const workItemMetadataConcurrency = 6;
30
+ /** KEEP: Azure DevOps documents no limit on a query's commits; 100 keeps a window to a few modest requests. */
31
+ const commitQueryChunkSize = 100;
32
+ const commitReadConcurrency = 6;
29
33
  /** How long a work-item search's id snapshot outlives the last page read from it, and the most it lives at all. */
30
34
  const workItemSearchSnapshotTtl = 3e5;
31
35
  const workItemSearchSnapshotMaxTtl = 18e5;
@@ -108,23 +112,96 @@ var AzureDevOpsApi = class {
108
112
  try {
109
113
  const encodedProject = encodeAzurePathSegment(projectName);
110
114
  const encodedRepo = encodeAzurePathSegment(repoName);
111
- const pr = (await this.request(provider, token, baseUrl, `${encodeAzurePathSegment(owner)}/${encodedProject}/_apis/git/repositories/${encodedRepo}/pullrequestquery?api-version=${resource.apiVersion}`, {
115
+ const answers = (await this.request(provider, token, baseUrl, `${encodeAzurePathSegment(owner)}/${encodedProject}/_apis/git/repositories/${encodedRepo}/pullrequestquery?api-version=${resource.apiVersion}`, {
112
116
  method: "POST",
113
117
  body: JSON.stringify({ queries: [{
114
118
  items: [rev],
115
119
  type: "commit"
116
120
  }] })
117
- }, scope, cancellation))?.results[0]?.[rev]?.[0];
121
+ }, scope, cancellation))?.results?.[0];
122
+ if (answers == null) throw new Error(`Azure DevOps returned no pull request query results for ${repo}`);
123
+ const pr = answers[rev]?.[0];
118
124
  if (pr == null) return void 0;
119
125
  const pullRequest = await this.request(provider, token, baseUrl, `${encodeAzurePathSegment(owner)}/${encodeAzurePathSegment(pr.repository.project.id)}/_apis/git/repositories/${encodeAzurePathSegment(pr.repository.id)}/pullRequests/${encodeAzurePathSegment(pr.pullRequestId.toString())}`, { method: "GET" }, scope, cancellation);
120
- if (pullRequest == null) return void 0;
126
+ if (pullRequest == null) throw new Error(`Azure DevOps returned no pull request ${pr.pullRequestId} for ${repo}`);
121
127
  return await this.toPullRequest(pullRequest, provider, token, owner, baseUrl, scope, cancellation);
122
128
  } catch (ex) {
123
- if (ex instanceof AuthenticationError) throw ex;
124
- scope?.error(ex);
125
- return;
129
+ if (isNotFoundResponse(ex)) return void 0;
130
+ if (isCommitReadRefusal(ex)) throw new CommitReadRefusedError(ex.message, ex);
131
+ throw ex;
126
132
  }
127
133
  }
134
+ async getPullRequestsForCommits(provider, token, owner, repo, revs, baseUrl, options, cancellation) {
135
+ const scope = getScopedLogger();
136
+ const gate = options?.gate ?? ((send) => send());
137
+ const slots = revs.map(() => ({
138
+ status: "fulfilled",
139
+ value: void 0
140
+ }));
141
+ if (revs.length === 0) return slots;
142
+ const reject = (indexes, reason) => {
143
+ for (const index of indexes) slots[index] = {
144
+ status: "rejected",
145
+ reason
146
+ };
147
+ };
148
+ const { projectName, repoName } = parseAzureRepositoryDescriptor(repo);
149
+ const resource = await this.requireRestResource(provider, token, owner, baseUrl, "pullRequestQuery", "4.1", cancellation);
150
+ const route = `${encodeAzurePathSegment(owner)}/${encodeAzurePathSegment(projectName)}/_apis/git/repositories/${encodeAzurePathSegment(repoName)}/pullrequestquery?api-version=${resource.apiVersion}`;
151
+ const found = /* @__PURE__ */ new Map();
152
+ const forkFailures = [];
153
+ await mapBounded(chunk(revs.map((_, index) => index), commitQueryChunkSize), commitReadConcurrency, async (indexes) => {
154
+ let answers;
155
+ try {
156
+ answers = (await gate(() => this.request(provider, token, baseUrl, route, {
157
+ method: "POST",
158
+ body: JSON.stringify({ queries: [{
159
+ items: indexes.map((index) => revs[index]),
160
+ type: "commit"
161
+ }] })
162
+ }, scope, cancellation, true)))?.results?.[0];
163
+ } catch (ex) {
164
+ if (isNotFoundResponse(ex)) return;
165
+ reject(indexes, ex);
166
+ return;
167
+ }
168
+ if (answers == null) {
169
+ reject(indexes, /* @__PURE__ */ new Error(`Azure DevOps returned no pull request query results for ${repo}`));
170
+ return;
171
+ }
172
+ for (const index of indexes) {
173
+ const pr = answers[revs[index]]?.[0];
174
+ if (pr == null) continue;
175
+ let match = found.get(pr.pullRequestId);
176
+ if (match == null) {
177
+ match = {
178
+ pr,
179
+ indexes: []
180
+ };
181
+ found.set(pr.pullRequestId, match);
182
+ }
183
+ match.indexes.push(index);
184
+ }
185
+ });
186
+ await mapBounded([...found.values()], commitReadConcurrency, async ({ pr, indexes }) => {
187
+ try {
188
+ const pullRequest = await gate(() => this.request(provider, token, baseUrl, `${encodeAzurePathSegment(owner)}/${encodeAzurePathSegment(pr.repository.project.id)}/_apis/git/repositories/${encodeAzurePathSegment(pr.repository.id)}/pullRequests/${encodeAzurePathSegment(pr.pullRequestId.toString())}`, { method: "GET" }, scope, cancellation, true));
189
+ if (pullRequest == null) throw new Error(`Azure DevOps returned no pull request ${pr.pullRequestId} for ${repo}`);
190
+ const value = await this.toPullRequest(pullRequest, provider, token, owner, baseUrl, scope, cancellation, {
191
+ gate,
192
+ failures: forkFailures
193
+ });
194
+ for (const index of indexes) slots[index] = {
195
+ status: "fulfilled",
196
+ value
197
+ };
198
+ } catch (ex) {
199
+ reject(indexes, ex);
200
+ }
201
+ });
202
+ if (!slots.some((slot) => slot.status === "rejected" && getDeferredRequestFailure(slot.reason) != null)) forkFailures.map(getDeferredRequestFailure).find((notify) => notify != null)?.();
203
+ return slots;
204
+ }
128
205
  async getPullRequest(provider, token, owner, projectOrName, id, options) {
129
206
  const scope = getScopedLogger();
130
207
  const projectName = projectOrName.split("/")[0];
@@ -520,8 +597,8 @@ var AzureDevOpsApi = class {
520
597
  const encodedRepo = encodeAzurePathSegment(repoName);
521
598
  return this.request(provider, token, baseUrl, `${encodeAzurePathSegment(owner)}/${encodedProject}/_apis/git/repositories/${encodedRepo}?api-version=${apiVersion}`, { method: "GET" }, scope, cancellation);
522
599
  }
523
- async toPullRequest(pr, provider, token, owner, baseUrl, scope, cancellation) {
524
- const forkRepositoryUrls = await this.getForkRepositoryUrls(provider, token, owner, baseUrl, pr.forkSource?.repository, scope, cancellation);
600
+ async toPullRequest(pr, provider, token, owner, baseUrl, scope, cancellation, batch) {
601
+ const forkRepositoryUrls = await this.getForkRepositoryUrls(provider, token, owner, baseUrl, pr.forkSource?.repository, scope, cancellation, batch);
525
602
  return fromAzurePullRequest(pr, provider, owner, baseUrl, forkRepositoryUrls, "point");
526
603
  }
527
604
  /**
@@ -533,7 +610,7 @@ var AzureDevOpsApi = class {
533
610
  * leaves the head ref without a URL. It must never cost the pull request itself, which is what makes swallowing
534
611
  * the failure here the right call rather than a shortcut.
535
612
  */
536
- async getForkRepositoryUrls(provider, token, owner, baseUrl, repository, scope, cancellation) {
613
+ async getForkRepositoryUrls(provider, token, owner, baseUrl, repository, scope, cancellation, batch) {
537
614
  if (repository == null) return void 0;
538
615
  let tokenHash;
539
616
  try {
@@ -547,13 +624,14 @@ var AzureDevOpsApi = class {
547
624
  owner,
548
625
  repository.id
549
626
  ]);
550
- return this._forkRepositoryUrls.getOrCreate(cacheKey, (cacheable, aggregate) => this.fetchForkRepositoryUrls(provider, token, owner, baseUrl, repository.id, cacheable, scope, aggregate), { cancellation });
627
+ return this._forkRepositoryUrls.getOrCreate(cacheKey, (cacheable, aggregate) => this.fetchForkRepositoryUrls(provider, token, owner, baseUrl, repository.id, cacheable, scope, aggregate, batch), { cancellation });
551
628
  }
552
- async fetchForkRepositoryUrls(provider, token, owner, baseUrl, repositoryId, cacheable, scope, cancellation) {
629
+ async fetchForkRepositoryUrls(provider, token, owner, baseUrl, repositoryId, cacheable, scope, cancellation, batch) {
630
+ const send = batch?.gate ?? ((request) => request());
553
631
  try {
554
632
  encodeAzurePathSegment(repositoryId);
555
633
  const resource = await this.requireRestResource(provider, token, owner, baseUrl, "repositories", "4.1", cancellation);
556
- const response = await this.request(provider, token, baseUrl, `${encodeAzurePathSegment(owner)}/_apis/git/repositories/${encodeAzurePathSegment(repositoryId)}?api-version=${resource.apiVersion}`, { method: "GET" }, scope, cancellation);
634
+ const response = await send(() => this.request(provider, token, baseUrl, `${encodeAzurePathSegment(owner)}/_apis/git/repositories/${encodeAzurePathSegment(repositoryId)}?api-version=${resource.apiVersion}`, { method: "GET" }, scope, cancellation, batch != null), (reason) => reason instanceof RequestRateLimitError);
557
635
  const webUrl = sanitizeAzureRepositoryUrl(response?.webUrl, baseUrl, owner);
558
636
  const cloneHttps = sanitizeAzureRepositoryUrl(response?.remoteUrl, baseUrl, owner);
559
637
  const url = webUrl ?? cloneHttps;
@@ -567,6 +645,7 @@ var AzureDevOpsApi = class {
567
645
  };
568
646
  } catch (ex) {
569
647
  if (!(ex instanceof RequestNotFoundError) && !(ex instanceof AuthenticationError)) cacheable.invalidate();
648
+ batch?.failures.push(ex);
570
649
  const status = ex instanceof ProviderFetchError ? ` (${ex.status})` : "";
571
650
  scope?.warn(`Unable to resolve the fork repository URLs${status}`);
572
651
  return;
@@ -632,7 +711,7 @@ var AzureDevOpsApi = class {
632
711
  if (result == null) throw new Error(`Azure DevOps REST resource ${resource} is unavailable`);
633
712
  return result;
634
713
  }
635
- async request(provider, token, baseUrl, route, options, scope, cancellation) {
714
+ async request(provider, token, baseUrl, route, options, scope, cancellation, deferFailure) {
636
715
  const { accessToken } = token;
637
716
  const url = baseUrl ? `${baseUrl}/${route}` : route;
638
717
  let rsp;
@@ -661,12 +740,12 @@ var AzureDevOpsApi = class {
661
740
  sw?.stop();
662
741
  }
663
742
  } catch (ex) {
664
- if (ex instanceof ProviderFetchError || ex.name === "AbortError") this.handleRequestError(provider, token, ex, scope);
743
+ if (ex instanceof ProviderFetchError || ex.name === "AbortError") this.handleRequestError(provider, token, ex, scope, deferFailure);
665
744
  else if (_logger.isDebugging) this.config.onError?.(`AzureDevOps request failed: ${ex.message}`);
666
745
  throw ex;
667
746
  }
668
747
  }
669
- handleRequestError(provider, token, ex, scope) {
748
+ handleRequestError(provider, token, ex, scope, deferFailure) {
670
749
  if (ex.name === "AbortError" || !(ex instanceof ProviderFetchError)) throw new CancellationError(ex);
671
750
  const { accessToken, ...tokenInfo } = token;
672
751
  switch (ex.status) {
@@ -680,7 +759,11 @@ var AzureDevOpsApi = class {
680
759
  throw new AuthenticationError(tokenInfo, 3, ex);
681
760
  case 500:
682
761
  scope?.error(ex);
683
- if (ex.response != null) this.config.onRequestFailed?.(provider == null || provider.id === "azure" ? l10n.t("{0} failed to respond and might be experiencing issues. Please visit the [AzureDevOps status page](https://status.dev.azure.com) for more information.", provider?.name ?? "AzureDevOps") : l10n.t("{0} failed to respond and might be experiencing issues.", provider.name));
762
+ if (ex.response != null) {
763
+ const notify = () => this.config.onRequestFailed?.(provider == null || provider.id === "azure" ? l10n.t("{0} failed to respond and might be experiencing issues. Please visit the [AzureDevOps status page](https://status.dev.azure.com) for more information.", provider?.name ?? "AzureDevOps") : l10n.t("{0} failed to respond and might be experiencing issues.", provider.name));
764
+ if (deferFailure) reportRequestFailure(provider, ex, notify, true, token.connectionId);
765
+ else notify();
766
+ }
684
767
  return;
685
768
  case 502:
686
769
  scope?.error(ex);
@@ -706,6 +789,14 @@ __decorate([trace({ args: (provider, token, owner, repo, rev, baseUrl) => ({
706
789
  rev,
707
790
  baseUrl
708
791
  }) })], AzureDevOpsApi.prototype, "getPullRequestForCommit", null);
792
+ __decorate([trace({ args: (provider, token, owner, repo, revs, baseUrl) => ({
793
+ provider: provider.name,
794
+ token: `<token:${token.microHash}>`,
795
+ owner,
796
+ repo,
797
+ revs: revs.length,
798
+ baseUrl
799
+ }) })], AzureDevOpsApi.prototype, "getPullRequestsForCommits", null);
709
800
  __decorate([trace({ args: (provider, token, owner, projectOrName, id) => ({
710
801
  provider: provider.name,
711
802
  token: `<token:${token.microHash}>`,