@gitkraken/core-gitlens 0.43.0 → 0.45.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 (92) hide show
  1. package/CHANGELOG.md +30 -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/plus/git-github/api/aliasedQuery.d.ts +3 -2
  6. package/dist/plus/git-github/api/aliasedQuery.js +7 -3
  7. package/dist/plus/git-github/api/aliasedQuery.js.map +1 -1
  8. package/dist/plus/git-github/api/github.d.ts +12 -0
  9. package/dist/plus/git-github/api/github.js +188 -41
  10. package/dist/plus/git-github/api/github.js.map +1 -1
  11. package/dist/plus/git-github/api/issueWrites.d.ts +7 -2
  12. package/dist/plus/git-github/api/issueWrites.js +9 -4
  13. package/dist/plus/git-github/api/issueWrites.js.map +1 -1
  14. package/dist/plus/git-github/api/pullRequestWrites.d.ts +95 -0
  15. package/dist/plus/git-github/api/pullRequestWrites.js +469 -0
  16. package/dist/plus/git-github/api/pullRequestWrites.js.map +1 -0
  17. package/dist/plus/integrations/authentication/configuredIntegrationService.d.ts +10 -9
  18. package/dist/plus/integrations/authentication/configuredIntegrationService.js +18 -12
  19. package/dist/plus/integrations/authentication/configuredIntegrationService.js.map +1 -1
  20. package/dist/plus/integrations/authentication/integrationAuthenticationProvider.d.ts +9 -4
  21. package/dist/plus/integrations/authentication/integrationAuthenticationProvider.js +26 -9
  22. package/dist/plus/integrations/authentication/integrationAuthenticationProvider.js.map +1 -1
  23. package/dist/plus/integrations/authentication/integrationAuthenticationService.d.ts +1 -0
  24. package/dist/plus/integrations/authentication/integrationAuthenticationService.js +3 -0
  25. package/dist/plus/integrations/authentication/integrationAuthenticationService.js.map +1 -1
  26. package/dist/plus/integrations/authentication/observedAuthenticationProvider.d.ts +1 -0
  27. package/dist/plus/integrations/authentication/observedAuthenticationProvider.js +14 -4
  28. package/dist/plus/integrations/authentication/observedAuthenticationProvider.js.map +1 -1
  29. package/dist/plus/integrations/authentication/rejectedTokenTracker.d.ts +2 -2
  30. package/dist/plus/integrations/authentication/rejectedTokenTracker.js +19 -5
  31. package/dist/plus/integrations/authentication/rejectedTokenTracker.js.map +1 -1
  32. package/dist/plus/integrations/collectionMetadata.js +2 -1
  33. package/dist/plus/integrations/collectionMetadata.js.map +1 -1
  34. package/dist/plus/integrations/context.d.ts +3 -3
  35. package/dist/plus/integrations/errors.d.ts +4 -0
  36. package/dist/plus/integrations/errors.js +8 -1
  37. package/dist/plus/integrations/errors.js.map +1 -1
  38. package/dist/plus/integrations/index.d.ts +4 -2
  39. package/dist/plus/integrations/index.js.map +1 -1
  40. package/dist/plus/integrations/integrationService.d.ts +22 -1
  41. package/dist/plus/integrations/integrationService.js +51 -2
  42. package/dist/plus/integrations/integrationService.js.map +1 -1
  43. package/dist/plus/integrations/lite.js +11 -1
  44. package/dist/plus/integrations/lite.js.map +1 -1
  45. package/dist/plus/integrations/manager.d.ts +96 -4
  46. package/dist/plus/integrations/models/gitHostIntegration.d.ts +21 -2
  47. package/dist/plus/integrations/models/gitHostIntegration.js +182 -14
  48. package/dist/plus/integrations/models/gitHostIntegration.js.map +1 -1
  49. package/dist/plus/integrations/models/integration.d.ts +10 -2
  50. package/dist/plus/integrations/models/integration.js +53 -8
  51. package/dist/plus/integrations/models/integration.js.map +1 -1
  52. package/dist/plus/integrations/providers/apiClients.d.ts +1 -0
  53. package/dist/plus/integrations/providers/apiClients.js +3 -0
  54. package/dist/plus/integrations/providers/apiClients.js.map +1 -1
  55. package/dist/plus/integrations/providers/azure/azure.d.ts +3 -0
  56. package/dist/plus/integrations/providers/azure/azure.js +109 -18
  57. package/dist/plus/integrations/providers/azure/azure.js.map +1 -1
  58. package/dist/plus/integrations/providers/azureDevOps.d.ts +12 -0
  59. package/dist/plus/integrations/providers/azureDevOps.js +22 -0
  60. package/dist/plus/integrations/providers/azureDevOps.js.map +1 -1
  61. package/dist/plus/integrations/providers/bitbucket/bitbucket.d.ts +21 -2
  62. package/dist/plus/integrations/providers/bitbucket/bitbucket.js +59 -19
  63. package/dist/plus/integrations/providers/bitbucket/bitbucket.js.map +1 -1
  64. package/dist/plus/integrations/providers/bitbucket-server.d.ts +2 -0
  65. package/dist/plus/integrations/providers/bitbucket-server.js +11 -3
  66. package/dist/plus/integrations/providers/bitbucket-server.js.map +1 -1
  67. package/dist/plus/integrations/providers/bitbucket.d.ts +14 -0
  68. package/dist/plus/integrations/providers/bitbucket.js +30 -2
  69. package/dist/plus/integrations/providers/bitbucket.js.map +1 -1
  70. package/dist/plus/integrations/providers/github.d.ts +12 -0
  71. package/dist/plus/integrations/providers/github.js +66 -2
  72. package/dist/plus/integrations/providers/github.js.map +1 -1
  73. package/dist/plus/integrations/providers/gitlab/gitlab.d.ts +19 -1
  74. package/dist/plus/integrations/providers/gitlab/gitlab.js +116 -17
  75. package/dist/plus/integrations/providers/gitlab/gitlab.js.map +1 -1
  76. package/dist/plus/integrations/providers/gitlab.d.ts +15 -2
  77. package/dist/plus/integrations/providers/gitlab.js +34 -4
  78. package/dist/plus/integrations/providers/gitlab.js.map +1 -1
  79. package/dist/plus/integrations/providers/providerErrors.d.ts +8 -0
  80. package/dist/plus/integrations/providers/providerErrors.js +15 -2
  81. package/dist/plus/integrations/providers/providerErrors.js.map +1 -1
  82. package/dist/plus/integrations/reads/pullRequestsForCommits.d.ts +45 -0
  83. package/dist/plus/integrations/reads/pullRequestsForCommits.js +97 -0
  84. package/dist/plus/integrations/reads/pullRequestsForCommits.js.map +1 -0
  85. package/dist/plus/integrations/utils/domain.utils.d.ts +1 -0
  86. package/dist/plus/integrations/utils/domain.utils.js +5 -1
  87. package/dist/plus/integrations/utils/domain.utils.js.map +1 -1
  88. package/dist/plus/integrations/utils/failureBackoff.d.ts +13 -0
  89. package/dist/plus/integrations/utils/failureBackoff.js +47 -0
  90. package/dist/plus/integrations/utils/failureBackoff.js.map +1 -0
  91. package/docs/integrations.md +126 -6
  92. package/package.json +1 -1
@@ -14,6 +14,7 @@ import { ProviderWarningCause, ProviderWarningScope } from "../results.js";
14
14
  import { ProviderRefusal, ProviderScopeFailure } from "../collectionMetadata.js";
15
15
  import { ProviderPullRequestCount, ProviderPullRequestSearchPage } from "./pullRequestReads.js";
16
16
  import { ProvidersApi } from "../providers/providersApi.js";
17
+ import { FailureBackoff } from "../utils/failureBackoff.js";
17
18
  import { AccountWideIssuesResult, ProviderIssueSearchPage, ProviderSearchCount, SearchMyIssuesOptions } from "./issueReads.js";
18
19
  import { GitHostIntegration } from "./gitHostIntegration.js";
19
20
  import { IssuesIntegration } from "./issuesIntegration.js";
@@ -214,7 +215,7 @@ type BatchTarget = {
214
215
  } | {
215
216
  resourceId: string;
216
217
  };
217
- type SyncReqUsecase = Exclude<'getAccountForCommit' | 'getAccountForEmail' | 'getAccountForResource' | 'getCurrentAccount' | 'getDefaultBranch' | 'getIssue' | 'getIssueOrPullRequest' | 'getIssuesBatch' | 'getIssuesEtagFields' | 'getIssuesForProject' | 'getIssuesForRepos' | 'getMyPullRequestsForUser' | 'getOrganizationsForUser' | 'getProjectsForOrg' | 'getProjectsForResources' | 'getPullRequest' | 'getPullRequestActivity' | 'getPullRequestCheckLogs' | 'getPullRequestsBatch' | 'getPullRequestsEtagFields' | 'getPullRequestsForBranches' | 'getRepositoriesForOrg' | 'getRepositoriesForUser' | 'getPullRequestForBranch' | 'getPullRequestForCommit' | 'getPullRequestsForRepos' | 'getRepositoryMetadata' | 'getResourcesForUser' | 'getSshSigningKeysForEmails' | 'countIssues' | 'countPullRequests' | 'dequeuePullRequest' | 'enqueuePullRequest' | 'mergePullRequest' | 'mutateIssue' | 'searchIssuesPage' | 'searchPullRequestsPage' | 'searchMyIssues' | 'searchMyPullRequests' | 'searchPullRequests', 'all'>;
218
+ type SyncReqUsecase = Exclude<'getAccountForCommit' | 'getAccountForEmail' | 'getAccountForResource' | 'getCurrentAccount' | 'getDefaultBranch' | 'getIssue' | 'getIssueOrPullRequest' | 'getIssuesBatch' | 'getIssuesEtagFields' | 'getIssuesForProject' | 'getIssuesForRepos' | 'getMyPullRequestsForUser' | 'getOrganizationsForUser' | 'getProjectsForOrg' | 'getProjectsForResources' | 'getPullRequest' | 'getPullRequestActivity' | 'getPullRequestCheckLogs' | 'getPullRequestsBatch' | 'getPullRequestsEtagFields' | 'getPullRequestsForBranches' | 'getPullRequestsForCommits' | 'getRepositoriesForOrg' | 'getRepositoriesForUser' | 'getPullRequestForBranch' | 'getPullRequestForCommit' | 'getPullRequestsForRepos' | 'getRepositoryMetadata' | 'getResourcesForUser' | 'getSshSigningKeysForEmails' | 'countIssues' | 'countPullRequests' | 'dequeuePullRequest' | 'enqueuePullRequest' | 'mergePullRequest' | 'mutateIssue' | 'writePullRequest' | 'searchIssuesPage' | 'searchPullRequestsPage' | 'searchMyIssues' | 'searchMyPullRequests' | 'searchPullRequests', 'all'>;
218
219
  export declare abstract class IntegrationBase<ID extends IntegrationIds = IntegrationIds, T extends ResourceDescriptor = ResourceDescriptor> implements Disposable {
219
220
  protected readonly ctx: IntegrationServiceContext;
220
221
  protected readonly authenticationService: IntegrationAuthenticationService;
@@ -320,6 +321,8 @@ export declare abstract class IntegrationBase<ID extends IntegrationIds = Integr
320
321
  * {@link resolveReadSession}; a rejection it declines belongs to {@link trackRequestException} instead.
321
322
  */
322
323
  private readonly _rejectedTokens;
324
+ protected readonly lookupBackoff: FailureBackoff;
325
+ protected clearLookupBackoff(): void;
323
326
  /**
324
327
  * Called by every path that replaces or removes the stored tokens — a disconnect, a forced re-sync, a
325
328
  * reauthentication, or the connection set changing. A rejection names a specific credential, so once that
@@ -470,6 +473,11 @@ export declare abstract class IntegrationBase<ID extends IntegrationIds = Integr
470
473
  protected settleBatchRefusals<T>(session: ProviderAuthenticationSession, targets: readonly BatchTarget[], slots: PromiseSettledResult<T>[], options?: {
471
474
  keepOtherFailures?: boolean;
472
475
  }): Promise<BatchSlot<T>[]>;
476
+ protected settleBatchCredential<T>(syncReqUsecase: SyncReqUsecase, settled: readonly BatchSlot<T>[], options: {
477
+ scope: ScopedLogger | undefined;
478
+ connectionId: string | undefined;
479
+ reset: boolean;
480
+ }): void;
473
481
  /**
474
482
  * Shows one notice, and spends at most one strike, for a batch read whose targets failed with a server error or a
475
483
  * timeout. Our own clients leave both to the batch (see `reportRequestFailure`) instead of spending them per
@@ -499,7 +507,7 @@ export declare abstract class IntegrationBase<ID extends IntegrationIds = Integr
499
507
  /** Names each scoped refusal's cause (see {@link describeRefusal}); only once the credential is proven. */
500
508
  private nameRefusalCauses;
501
509
  /** Returns whether it spent a strike (see {@link trackRequestException}). */
502
- protected handleConnectionAuthenticationRejection(connectionId: string, silent?: boolean): boolean;
510
+ protected handleConnectionAuthenticationRejection(connectionId: string, silent?: boolean, rejectedAccessToken?: string): boolean;
503
511
  /** Returns whether it spent a strike (see {@link trackRequestException}). */
504
512
  protected handleProviderException(syncReqUsecase: SyncReqUsecase, ex: Error, options?: {
505
513
  scope?: ScopedLogger | undefined;
@@ -5,7 +5,7 @@ import { debug, trace } from "../../../utils/decorators/log.js";
5
5
  import { Emitter } from "../../../utils/event.js";
6
6
  import { PromiseCache } from "../../../utils/promiseCache.js";
7
7
  import __decorate from "../../../_virtual/@oxc-project+runtime/helpers/esm/decorate.js";
8
- import { AuthenticationError, RequestClientError, getDeferredRequestFailure } from "../../../git/errors.js";
8
+ import { AuthenticationError, RequestClientError, takeDeferredRequestFailure } from "../../../git/errors.js";
9
9
  import { fnv1aHash64 } from "../../../utils/hash.js";
10
10
  import { gate } from "../../../utils/decorators/gate.js";
11
11
  import { isProviderUnreachableError, toError } from "../errors.js";
@@ -18,6 +18,7 @@ import { providersMetadata } from "../providers/models.js";
18
18
  import { isSelfManagedHostIntegrationId } from "../utils/integration.utils.js";
19
19
  import { getSessionIdentity } from "../authentication/models.js";
20
20
  import { RejectedTokenTracker } from "../authentication/rejectedTokenTracker.js";
21
+ import { FailureBackoff } from "../utils/failureBackoff.js";
21
22
  import { getCachedIssue } from "./issueCache.js";
22
23
  //#region ../plus/integrations/src/models/integration.ts
23
24
  /** A per-connection read's session that could not be resolved for a retryable reason (see `resolveReadSession`). */
@@ -100,6 +101,20 @@ const azureWorkItemViewerRule = 1;
100
101
  function linearSyncedWithEtagKeys(links) {
101
102
  return links.map((link) => link.owner != null ? `${link.id}:${link.owner}/${link.repo}#${link.number}` : `${link.id}:`).sort();
102
103
  }
104
+ function batchTargetRepository(target) {
105
+ if ("resourceId" in target) return void 0;
106
+ return [
107
+ target.owner,
108
+ target.project ?? "",
109
+ target.repo
110
+ ].join("/").toLowerCase();
111
+ }
112
+ function isRefusedCredential(reason) {
113
+ return reason instanceof AuthenticationError && reason.reason !== 3;
114
+ }
115
+ function findRefusedCredentialSlot(slots) {
116
+ return slots.find((slot) => slot.status === "rejected" && slot.failure == null && isRefusedCredential(slot.reason));
117
+ }
103
118
  /**
104
119
  * The scope a batch read records a refused target under. It is decided here rather than in the read, which has the
105
120
  * same targets, because naming the refusal's cause (`describeRefusal`) needs it too. Azure DevOps: the organization
@@ -241,7 +256,7 @@ var IntegrationBase = class IntegrationBase {
241
256
  async resolveReadSession(connectionId, scope, source) {
242
257
  if (this.ctx.config.isIntegrationsEnabled?.() === false || this.ctx.storage.getWorkspace(this.connectedKey) === false) return;
243
258
  if (connectionId) {
244
- const refreshRejectedToken = this._rejectedTokens.claimRefresh(connectionId);
259
+ const rejectedToken = this._rejectedTokens.claimRefresh(connectionId);
245
260
  try {
246
261
  const session = await (await this.authenticationService.get(this.authProvider.id)).getSession({
247
262
  ...this.authProviderDescriptor,
@@ -249,7 +264,8 @@ var IntegrationBase = class IntegrationBase {
249
264
  cloud: true
250
265
  }, {
251
266
  source,
252
- refreshRejectedToken
267
+ refreshRejectedToken: rejectedToken === true,
268
+ isRejectedToken: typeof rejectedToken === "function" ? rejectedToken : void 0
253
269
  });
254
270
  return session != null && this.isSessionForIntegrationHost(session) ? session : void 0;
255
271
  } catch (ex) {
@@ -363,6 +379,10 @@ var IntegrationBase = class IntegrationBase {
363
379
  * {@link resolveReadSession}; a rejection it declines belongs to {@link trackRequestException} instead.
364
380
  */
365
381
  _rejectedTokens = new RejectedTokenTracker();
382
+ lookupBackoff = new FailureBackoff();
383
+ clearLookupBackoff() {
384
+ this.lookupBackoff.clearAll();
385
+ }
366
386
  /**
367
387
  * Called by every path that replaces or removes the stored tokens — a disconnect, a forced re-sync, a
368
388
  * reauthentication, or the connection set changing. A rejection names a specific credential, so once that
@@ -376,6 +396,7 @@ var IntegrationBase = class IntegrationBase {
376
396
  */
377
397
  onStoredTokensReplaced() {
378
398
  this._rejectedTokens.clear();
399
+ this.clearLookupBackoff();
379
400
  this.invalidateDiscoveryCaches();
380
401
  }
381
402
  /**
@@ -451,6 +472,7 @@ var IntegrationBase = class IntegrationBase {
451
472
  this.connectionRequestExceptionCounts.clear();
452
473
  this._syncRequestsPerFailedUsecase.clear();
453
474
  this._rejectedTokens.clear();
475
+ this.clearLookupBackoff();
454
476
  }
455
477
  /**
456
478
  * Clears the strikes of the selected connection (the primary when omitted) after a successful request,
@@ -535,6 +557,7 @@ var IntegrationBase = class IntegrationBase {
535
557
  if (forceSync) {
536
558
  if (reason === "explicit") {
537
559
  this._rejectedTokens.clear();
560
+ this.clearLookupBackoff();
538
561
  this.beginForcedRefresh();
539
562
  }
540
563
  await this.ctx.storage.deleteWorkspace(this.connectedKey);
@@ -545,6 +568,7 @@ var IntegrationBase = class IntegrationBase {
545
568
  }
546
569
  let newSession;
547
570
  let refetchFailed = false;
571
+ const signOutMark = resyncing ? this.authenticationService.getSignOutMark() : void 0;
548
572
  try {
549
573
  newSession = await this.resolveSessionLocked({
550
574
  sync: forceSync,
@@ -556,7 +580,10 @@ var IntegrationBase = class IntegrationBase {
556
580
  failure = toError(ex);
557
581
  }
558
582
  if (oldSession && newSession && newSession === this._session && newSession.accessToken !== oldSession.accessToken) this.resetRecoveryAccounting();
559
- if (resyncing && newSession == null && !refetchFailed) await (await this.authenticationService.get(this.authProvider.id)).deleteSession(this.authProviderDescriptor, { preserveConfigured: false });
583
+ if (resyncing && newSession == null && !refetchFailed) await (await this.authenticationService.get(this.authProvider.id)).deleteSession(this.authProviderDescriptor, {
584
+ preserveConfigured: false,
585
+ signOutMark
586
+ });
560
587
  break;
561
588
  }
562
589
  case "disconnected": await this.disconnectLocked({ silent: true }, true);
@@ -622,7 +649,17 @@ var IntegrationBase = class IntegrationBase {
622
649
  */
623
650
  async settleBatchRefusals(session, targets, slots, options) {
624
651
  const keepOtherFailures = options?.keepOtherFailures ?? false;
625
- const failures = slots.map((slot, i) => slot.status === "rejected" && slot.reason instanceof AuthenticationError ? toCollectionScopeFailure(batchTargetScope(this.id, targets[i]), slot.reason) : void 0);
652
+ const answered = new Set(slots.flatMap((slot, i) => slot.status === "fulfilled" ? [batchTargetRepository(targets[i])] : []));
653
+ const credentialDied = slots.some((slot, i) => {
654
+ if (slot.status !== "rejected" || !isRefusedCredential(slot.reason)) return false;
655
+ const repository = batchTargetRepository(targets[i]);
656
+ return repository != null && answered.has(repository);
657
+ });
658
+ const failures = slots.map((slot, i) => {
659
+ if (slot.status !== "rejected" || !(slot.reason instanceof AuthenticationError)) return void 0;
660
+ if (credentialDied && isRefusedCredential(slot.reason)) return void 0;
661
+ return toCollectionScopeFailure(batchTargetScope(this.id, targets[i]), slot.reason);
662
+ });
626
663
  const refused = failures.filter((f) => f != null);
627
664
  if (!refused.length) {
628
665
  if (!keepOtherFailures) throwIfAllSettledFailed(slots);
@@ -650,6 +687,14 @@ var IntegrationBase = class IntegrationBase {
650
687
  } : slot;
651
688
  });
652
689
  }
690
+ settleBatchCredential(syncReqUsecase, settled, options) {
691
+ const refusal = findRefusedCredentialSlot(settled);
692
+ if (refusal != null) this.handleProviderException(syncReqUsecase, refusal.reason, {
693
+ scope: options.scope,
694
+ connectionId: options.connectionId
695
+ });
696
+ else if (options.reset) this.resetRequestExceptionCount(syncReqUsecase, options.connectionId);
697
+ }
653
698
  /**
654
699
  * Shows one notice, and spends at most one strike, for a batch read whose targets failed with a server error or a
655
700
  * timeout. Our own clients leave both to the batch (see `reportRequestFailure`) instead of spending them per
@@ -661,7 +706,7 @@ var IntegrationBase = class IntegrationBase {
661
706
  let notify;
662
707
  for (const slot of slots ?? []) {
663
708
  if (slot.status !== "rejected") continue;
664
- notify = getDeferredRequestFailure(slot.reason);
709
+ notify = takeDeferredRequestFailure(slot.reason);
665
710
  if (notify != null) break;
666
711
  }
667
712
  if (notify == null) return;
@@ -716,9 +761,9 @@ var IntegrationBase = class IntegrationBase {
716
761
  attributeScopedAuthFailures(metadata, (refusal, scope) => describeRefusal(session, refusal, scope));
717
762
  }
718
763
  /** Returns whether it spent a strike (see {@link trackRequestException}). */
719
- handleConnectionAuthenticationRejection(connectionId, silent) {
764
+ handleConnectionAuthenticationRejection(connectionId, silent, rejectedAccessToken) {
720
765
  this._validatedCredentials.clear();
721
- if (this._rejectedTokens.recordRejection(connectionId)) return false;
766
+ if (this._rejectedTokens.recordRejection(connectionId, rejectedAccessToken)) return false;
722
767
  this.trackRequestException({
723
768
  connectionId,
724
769
  silent