@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
@@ -12,8 +12,9 @@ export declare const aliasedQueryChunkSize = 25;
12
12
  /**
13
13
  * What an alias's own errors say about its slot in an aliased read: `'absent'` only when its node is null and every
14
14
  * error on it is NOT_FOUND; a rejection when a node arrived with an error, or on any other error (even a NOT_FOUND
15
- * nested under the node), since neither is trustworthy; `undefined` when the alias has no errors.
15
+ * nested under the node), since neither is trustworthy; `undefined` when the alias has no errors. `parent` names the
16
+ * top-level field the alias is selected under, for a document that aliases inside one selection.
16
17
  */
17
- export declare function getAliasErrorVerdict(errors: readonly GraphqlAliasError[], alias: string, node: unknown): 'absent' | PromiseRejectedResult | undefined;
18
+ export declare function getAliasErrorVerdict(errors: readonly GraphqlAliasError[], alias: string, node: unknown, parent?: string): 'absent' | PromiseRejectedResult | undefined;
18
19
  //#endregion
19
20
  //# sourceMappingURL=aliasedQuery.d.ts.map
@@ -3,10 +3,14 @@ const aliasedQueryChunkSize = 25;
3
3
  /**
4
4
  * What an alias's own errors say about its slot in an aliased read: `'absent'` only when its node is null and every
5
5
  * error on it is NOT_FOUND; a rejection when a node arrived with an error, or on any other error (even a NOT_FOUND
6
- * nested under the node), since neither is trustworthy; `undefined` when the alias has no errors.
6
+ * nested under the node), since neither is trustworthy; `undefined` when the alias has no errors. `parent` names the
7
+ * top-level field the alias is selected under, for a document that aliases inside one selection.
7
8
  */
8
- function getAliasErrorVerdict(errors, alias, node) {
9
- const aliasErrors = errors.filter((e) => e.path?.[0] === alias);
9
+ function getAliasErrorVerdict(errors, alias, node, parent) {
10
+ const aliasErrors = errors.filter((e) => {
11
+ const path = e.path;
12
+ return parent == null ? path?.[0] === alias : path?.[0] === parent && path[1] === alias;
13
+ });
10
14
  if (aliasErrors.length === 0) return void 0;
11
15
  if (node == null && aliasErrors.every((e) => e.type === "NOT_FOUND")) return "absent";
12
16
  const primary = aliasErrors.find((e) => e.type !== "NOT_FOUND") ?? aliasErrors[0];
@@ -1 +1 @@
1
- {"version":3,"file":"aliasedQuery.js","names":[],"sources":["../../../../../plus/git-github/src/api/aliasedQuery.ts"],"sourcesContent":["import type { GraphqlResponseError } from '@octokit/graphql';\nimport type { RequestParameters } from '@octokit/types';\n\n/** One field-level error GitHub attaches to a GraphQL response, as thrown via {@link GraphqlResponseError}. */\nexport type GraphqlAliasError = NonNullable<GraphqlResponseError<unknown>['errors']>[number];\n\n/** An aliased GraphQL read: the (possibly partial) `data` alongside the field-level errors GitHub attached to it. */\nexport type AliasedGraphql = <T>(\n\tquery: string,\n\tvariables: RequestParameters,\n) => Promise<{ readonly data: T; readonly errors: readonly GraphqlAliasError[] } | undefined>;\n\nexport const aliasedQueryChunkSize = 25;\n\n/**\n * What an alias's own errors say about its slot in an aliased read: `'absent'` only when its node is null and every\n * error on it is NOT_FOUND; a rejection when a node arrived with an error, or on any other error (even a NOT_FOUND\n * nested under the node), since neither is trustworthy; `undefined` when the alias has no errors.\n */\nexport function getAliasErrorVerdict(\n\terrors: readonly GraphqlAliasError[],\n\talias: string,\n\tnode: unknown,\n): 'absent' | PromiseRejectedResult | undefined {\n\tconst aliasErrors = errors.filter(e => e.path?.[0] === alias);\n\tif (aliasErrors.length === 0) return undefined;\n\tif (node == null && aliasErrors.every(e => e.type === 'NOT_FOUND')) return 'absent';\n\n\tconst primary = aliasErrors.find(e => e.type !== 'NOT_FOUND') ?? aliasErrors[0];\n\treturn { status: 'rejected', reason: new Error(primary.message) };\n}\n"],"mappings":";AAYA,MAAa,wBAAwB;;;;;;AAOrC,SAAgB,qBACf,QACA,OACA,MAC+C;CAC/C,MAAM,cAAc,OAAO,QAAO,MAAK,EAAE,OAAO,OAAO,KAAK;CAC5D,IAAI,YAAY,WAAW,GAAG,OAAO,KAAA;CACrC,IAAI,QAAQ,QAAQ,YAAY,OAAM,MAAK,EAAE,SAAS,WAAW,GAAG,OAAO;CAE3E,MAAM,UAAU,YAAY,MAAK,MAAK,EAAE,SAAS,WAAW,KAAK,YAAY;CAC7E,OAAO;EAAE,QAAQ;EAAY,QAAQ,IAAI,MAAM,QAAQ,OAAO;CAAE;AACjE"}
1
+ {"version":3,"file":"aliasedQuery.js","names":[],"sources":["../../../../../plus/git-github/src/api/aliasedQuery.ts"],"sourcesContent":["import type { GraphqlResponseError } from '@octokit/graphql';\nimport type { RequestParameters } from '@octokit/types';\n\n/** One field-level error GitHub attaches to a GraphQL response, as thrown via {@link GraphqlResponseError}. */\nexport type GraphqlAliasError = NonNullable<GraphqlResponseError<unknown>['errors']>[number];\n\n/** An aliased GraphQL read: the (possibly partial) `data` alongside the field-level errors GitHub attached to it. */\nexport type AliasedGraphql = <T>(\n\tquery: string,\n\tvariables: RequestParameters,\n) => Promise<{ readonly data: T; readonly errors: readonly GraphqlAliasError[] } | undefined>;\n\nexport const aliasedQueryChunkSize = 25;\n\n/**\n * What an alias's own errors say about its slot in an aliased read: `'absent'` only when its node is null and every\n * error on it is NOT_FOUND; a rejection when a node arrived with an error, or on any other error (even a NOT_FOUND\n * nested under the node), since neither is trustworthy; `undefined` when the alias has no errors. `parent` names the\n * top-level field the alias is selected under, for a document that aliases inside one selection.\n */\nexport function getAliasErrorVerdict(\n\terrors: readonly GraphqlAliasError[],\n\talias: string,\n\tnode: unknown,\n\tparent?: string,\n): 'absent' | PromiseRejectedResult | undefined {\n\tconst aliasErrors = errors.filter(e => {\n\t\t// KEEP: typed as a one-segment tuple, but a nested field's error carries its whole path.\n\t\tconst path: readonly unknown[] | undefined = e.path;\n\t\treturn parent == null ? path?.[0] === alias : path?.[0] === parent && path[1] === alias;\n\t});\n\tif (aliasErrors.length === 0) return undefined;\n\tif (node == null && aliasErrors.every(e => e.type === 'NOT_FOUND')) return 'absent';\n\n\tconst primary = aliasErrors.find(e => e.type !== 'NOT_FOUND') ?? aliasErrors[0];\n\treturn { status: 'rejected', reason: new Error(primary.message) };\n}\n"],"mappings":";AAYA,MAAa,wBAAwB;;;;;;;AAQrC,SAAgB,qBACf,QACA,OACA,MACA,QAC+C;CAC/C,MAAM,cAAc,OAAO,QAAO,MAAK;EAEtC,MAAM,OAAuC,EAAE;EAC/C,OAAO,UAAU,OAAO,OAAO,OAAO,QAAQ,OAAO,OAAO,UAAU,KAAK,OAAO;CACnF,CAAC;CACD,IAAI,YAAY,WAAW,GAAG,OAAO,KAAA;CACrC,IAAI,QAAQ,QAAQ,YAAY,OAAM,MAAK,EAAE,SAAS,WAAW,GAAG,OAAO;CAE3E,MAAM,UAAU,YAAY,MAAK,MAAK,EAAE,SAAS,WAAW,KAAK,YAAY;CAC7E,OAAO;EAAE,QAAQ;EAAY,QAAQ,IAAI,MAAM,QAAQ,OAAO;CAAE;AACjE"}
@@ -15,6 +15,7 @@ import { GitHubBlame, GitHubBranch, GitHubCheckRunRef, GitHubCommit, GitHubCommi
15
15
  import { GitHubApiConfig } from "./config.js";
16
16
  import { GitHubIssueMutation, IssueWriteResult } from "./issueWrites.js";
17
17
  import { GitHubPullRequestActivityTarget } from "./pullRequestActivity.js";
18
+ import { GitHubPullRequestCreateTarget, GitHubPullRequestWrite, GitHubPullRequestWriteTarget, PullRequestCreateCapabilityResult, PullRequestWriteResult, PullRequestWriteTargetResult } from "./pullRequestWrites.js";
18
19
  import { GitHubTokenInfo } from "./token.js";
19
20
  import { Endpoints } from "@octokit/types";
20
21
  //#region ../plus/git-github/src/api/github.d.ts
@@ -135,6 +136,11 @@ export declare class GitHubApi {
135
136
  */
136
137
  mergeQueue?: boolean;
137
138
  }, cancellation?: AbortSignal): Promise<PullRequest | undefined>;
139
+ getPullRequestsForCommits(provider: Provider, token: GitHubTokenInfo, owner: string, repo: string, shas: readonly string[], options?: {
140
+ baseUrl?: string;
141
+ avatarSize?: number;
142
+ mergeQueue?: boolean;
143
+ }, cancellation?: AbortSignal): Promise<PromiseSettledResult<PullRequest | undefined>[]>;
138
144
  getRepositoryMetadata(provider: Provider, token: GitHubTokenInfo, owner: string, repo: string, options?: {
139
145
  baseUrl?: string;
140
146
  }, cancellation?: AbortSignal): Promise<RepositoryMetadata | undefined>;
@@ -241,6 +247,10 @@ export declare class GitHubApi {
241
247
  private requestWithRetries;
242
248
  private delayWithAbort;
243
249
  mutateIssue(provider: Provider, token: GitHubTokenInfo, input: GitHubIssueMutation): Promise<IssueWriteResult>;
250
+ resolvePullRequestWriteTarget(provider: Provider, token: GitHubTokenInfo, input: GitHubPullRequestWriteTarget, onUnauthorized: () => void): Promise<PullRequestWriteTargetResult>;
251
+ getPullRequestCreateCapability(provider: Provider, token: GitHubTokenInfo, input: GitHubPullRequestCreateTarget, onUnauthorized: () => void): Promise<PullRequestCreateCapabilityResult>;
252
+ writePullRequest(provider: Provider, token: GitHubTokenInfo, input: GitHubPullRequestWrite, isSessionCurrent: () => Promise<boolean>, onUnauthorized: () => void): Promise<PullRequestWriteResult>;
253
+ private writeGraphql;
244
254
  private readonly _pendingGraphQL;
245
255
  private graphql;
246
256
  private request;
@@ -756,6 +766,8 @@ export declare class GitHubApi {
756
766
  enqueuePullRequest(provider: Provider, token: GitHubTokenInfo, nodeId: string, expectedHeadSha: string, options?: {
757
767
  baseUrl?: string;
758
768
  }, cancellation?: AbortSignal): Promise<PullRequestMergeQueueActionResult>;
769
+ private enqueuePullRequestCore;
770
+ private enqueuePullRequestForWrite;
759
771
  /**
760
772
  * Removes a pull request from its base branch's merge queue, losing its place there. Fails and throws as
761
773
  * {@link enqueuePullRequest} does, and is github.com only like it.
@@ -27,6 +27,7 @@ import { gitHubIssueSearchRelationships, toGitHubIssueSearchQualifiers, toGitHub
27
27
  import { mutateGitHubIssue } from "./issueWrites.js";
28
28
  import { readGitHubPullRequestActivity } from "./pullRequestActivity.js";
29
29
  import { toGitHubPullRequestSearchFacets } from "./pullRequestSearchQuery.js";
30
+ import { getGitHubPullRequestCreateCapability, resolveGitHubPullRequestWriteTarget, writeGitHubPullRequest } from "./pullRequestWrites.js";
30
31
  import * as l10n from "@vscode/l10n";
31
32
  import { captureReadNodes, copyReadProvenance, createReadCapture } from "@gitkraken/provider-apis/read-provenance";
32
33
  import { GraphqlResponseError, graphql } from "@octokit/graphql";
@@ -465,6 +466,23 @@ reactions(content: THUMBS_UP) {
465
466
  function isByteStream(value) {
466
467
  return typeof value === "object" && value != null && "getReader" in value && typeof value.getReader === "function";
467
468
  }
469
+ function gqlCommitAssociatedPullRequests(options, config) {
470
+ return `associatedPullRequests(first: 2, orderBy: {field: UPDATED_AT, direction: DESC}) {
471
+ nodes {
472
+ ${gqlPullRequestLiteFragment}
473
+ ${gqlPullRequestStackFragmentFor(options)}
474
+ ${gqlPullRequestMergeQueueFragmentFor(options, config)}
475
+ }
476
+ }`;
477
+ }
478
+ function selectCommitPullRequest(nodes, owner) {
479
+ const ownerKey = owner.toLowerCase();
480
+ const isOwners = (pr) => pr.repository.owner.login.toLowerCase() === ownerKey;
481
+ const prs = nodes?.filter((pr) => pr != null && (!pr.repository.isFork || isOwners(pr)));
482
+ if (prs == null || prs.length === 0) return void 0;
483
+ if (prs.length > 1) prs.sort((a, b) => (isOwners(a) ? -1 : 1) - (isOwners(b) ? -1 : 1) || (a.state === "MERGED" ? -1 : 1) - (b.state === "MERGED" ? -1 : 1) || new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime());
484
+ return prs[0];
485
+ }
468
486
  var GitHubApi = class {
469
487
  config;
470
488
  _onDidReauthenticate = new Emitter();
@@ -807,31 +825,98 @@ var GitHubApi = class {
807
825
  repository(name: $repo, owner: $owner) {
808
826
  object(oid: $rev) {
809
827
  ... on Commit {
810
- associatedPullRequests(first: 2, orderBy: {field: UPDATED_AT, direction: DESC}) {
811
- nodes {
812
- ${gqlPullRequestLiteFragment}
813
- ${gqlPullRequestStackFragmentFor(options)}
814
- ${gqlPullRequestMergeQueueFragmentFor(options, this.config)}
815
- }
816
- }
828
+ ${gqlCommitAssociatedPullRequests(options, this.config)}
817
829
  }
818
830
  }
819
831
  }
820
832
  }`;
821
- const prs = (await this.graphql(provider, token, query, {
833
+ const pr = selectCommitPullRequest((await this.graphql(provider, token, query, {
822
834
  ...options,
823
835
  owner,
824
836
  repo,
825
837
  rev
826
- }, scope, cancellation))?.repository?.object?.associatedPullRequests?.nodes?.filter((pr) => pr != null && (!pr.repository.isFork || pr.repository.owner.login === owner));
827
- if (prs == null || prs.length === 0) return void 0;
828
- if (prs.length > 1) prs.sort((a, b) => (a.repository.owner.login === owner ? -1 : 1) - (b.repository.owner.login === owner ? -1 : 1) || (a.state === "MERGED" ? -1 : 1) - (b.state === "MERGED" ? -1 : 1) || new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime());
829
- return fromGitHubPullRequestLite(prs[0], provider, "point");
838
+ }, scope, cancellation))?.repository?.object?.associatedPullRequests?.nodes, owner);
839
+ return pr != null ? fromGitHubPullRequestLite(pr, provider, "point") : void 0;
830
840
  } catch (ex) {
831
841
  if (ex instanceof RequestNotFoundError) return void 0;
832
842
  throw this.handleException(ex, provider, scope);
833
843
  }
834
844
  }
845
+ async getPullRequestsForCommits(provider, token, owner, repo, shas, options, cancellation) {
846
+ const scope = getScopedLogger();
847
+ const slots = shas.map(() => ({
848
+ status: "fulfilled",
849
+ value: void 0
850
+ }));
851
+ if (shas.length === 0) return slots;
852
+ const asked = shas.map((sha, index) => ({
853
+ sha,
854
+ index
855
+ }));
856
+ const query = `query getPullRequestsForCommits(
857
+ $owner: String!
858
+ $repo: String!
859
+ ${asked.map((_, i) => `$sha${i}: GitObjectID!`).join("\n ")}
860
+ $avatarSize: Int
861
+ ) {
862
+ repository(name: $repo, owner: $owner) {
863
+ ${asked.map((_, i) => `c${i}: object(oid: $sha${i}) {
864
+ ... on Commit {
865
+ ${gqlCommitAssociatedPullRequests(options, this.config)}
866
+ }
867
+ }`).join("\n ")}
868
+ }
869
+ }`;
870
+ const variables = {
871
+ baseUrl: options?.baseUrl,
872
+ avatarSize: options?.avatarSize,
873
+ owner,
874
+ repo
875
+ };
876
+ asked.forEach((a, i) => {
877
+ variables[`sha${i}`] = a.sha;
878
+ });
879
+ try {
880
+ const rsp = await this.graphql(provider, token, query, variables, scope, cancellation, "aliased");
881
+ if (rsp?.data == null) throw new Error("GitHub returned no data for the pull requests by commit");
882
+ const repository = rsp.data.repository;
883
+ if (repository == null) {
884
+ const forbidden = rsp.errors.find((e) => e.path?.[0] === "repository" && e.type === "FORBIDDEN");
885
+ if (forbidden != null) {
886
+ const { accessToken: _accessToken, ...tokenInfo } = token;
887
+ throw new AuthenticationError(tokenInfo, 3, new Error(forbidden.message));
888
+ }
889
+ const verdict = getAliasErrorVerdict(rsp.errors, "repository", repository);
890
+ if (verdict != null && verdict !== "absent") for (const a of asked) slots[a.index] = verdict;
891
+ return slots;
892
+ }
893
+ asked.forEach((a, i) => {
894
+ const alias = `c${i}`;
895
+ const node = repository[alias];
896
+ const verdict = getAliasErrorVerdict(rsp.errors, alias, node, "repository");
897
+ if (verdict != null && verdict !== "absent") {
898
+ slots[a.index] = verdict;
899
+ return;
900
+ }
901
+ try {
902
+ const pr = selectCommitPullRequest(node?.associatedPullRequests?.nodes, owner);
903
+ slots[a.index] = {
904
+ status: "fulfilled",
905
+ value: pr != null ? fromGitHubPullRequestLite(pr, provider, "point") : void 0
906
+ };
907
+ } catch (ex) {
908
+ scope?.warn(`failed to map pull request; ${owner}/${repo}@${a.sha}, ex=${ex}`);
909
+ slots[a.index] = {
910
+ status: "rejected",
911
+ reason: ex
912
+ };
913
+ }
914
+ });
915
+ return slots;
916
+ } catch (ex) {
917
+ throw this.handleException(ex, provider, scope, true);
918
+ }
919
+ }
835
920
  async getRepositoryMetadata(provider, token, owner, repo, options, cancellation) {
836
921
  const scope = getScopedLogger();
837
922
  try {
@@ -1935,19 +2020,50 @@ var GitHubApi = class {
1935
2020
  });
1936
2021
  }
1937
2022
  async mutateIssue(provider, token, input) {
1938
- return mutateGitHubIssue(input, (query, variables) => this.requestWithRetries(() => this.config.wrapForForcedInsecureSSL(provider.getIgnoreSSLErrors(), () => this.getDefaults(token.accessToken, graphql)(query, {
1939
- ...variables,
1940
- headers: { "x-github-next-global-id": "1" }
1941
- })), graphqlReadQueryRegex.test(query), void 0, void 0));
2023
+ return mutateGitHubIssue(input, (query, variables) => this.writeGraphql(provider, token, query, variables));
2024
+ }
2025
+ async resolvePullRequestWriteTarget(provider, token, input, onUnauthorized) {
2026
+ return resolveGitHubPullRequestWriteTarget(input, (query, variables) => this.writeGraphql(provider, token, query, variables, onUnauthorized));
2027
+ }
2028
+ async getPullRequestCreateCapability(provider, token, input, onUnauthorized) {
2029
+ return getGitHubPullRequestCreateCapability(input, (query, variables) => this.writeGraphql(provider, token, query, variables, onUnauthorized));
2030
+ }
2031
+ async writePullRequest(provider, token, input, isSessionCurrent, onUnauthorized) {
2032
+ const request = (query, variables) => this.writeGraphql(provider, token, query, variables, onUnauthorized);
2033
+ return writeGitHubPullRequest(input, {
2034
+ graphql: request,
2035
+ isSessionCurrent,
2036
+ enqueue: (nodeId, headSha) => this.enqueuePullRequestForWrite(nodeId, headSha, request)
2037
+ });
2038
+ }
2039
+ async writeGraphql(provider, token, query, variables, onUnauthorized) {
2040
+ try {
2041
+ return await this.requestWithRetries(() => this.config.wrapForForcedInsecureSSL(provider.getIgnoreSSLErrors(), () => this.getDefaults(token.accessToken, graphql)(query, {
2042
+ ...variables,
2043
+ headers: { "x-github-next-global-id": "1" }
2044
+ })), graphqlReadQueryRegex.test(query), void 0, void 0);
2045
+ } catch (ex) {
2046
+ if (ex instanceof RequestError && ex.status === 401) onUnauthorized?.();
2047
+ throw ex;
2048
+ }
1942
2049
  }
1943
2050
  _pendingGraphQL = /* @__PURE__ */ new Map();
1944
2051
  async graphql(provider, token, query, variables, scope, cancellation, allowPartialNotFound, gatewayFailures) {
1945
2052
  const { accessToken, ...tokenInfo } = token;
1946
- const dedupable = cancellation == null && variables?.request == null;
2053
+ const readQuery = graphqlReadQueryRegex.test(query);
2054
+ const dedupable = readQuery && cancellation == null && variables?.request == null;
1947
2055
  let dedupeKey;
1948
2056
  if (dedupable) {
1949
2057
  try {
1950
- dedupeKey = `${token.microHash}|${provider?.id ?? ""}|${allowPartialNotFound ?? ""}|${gatewayFailures ?? ""}|${query}|${JSON.stringify(variables ?? null)}`;
2058
+ dedupeKey = JSON.stringify([
2059
+ accessToken,
2060
+ token.connectionId,
2061
+ provider?.id,
2062
+ allowPartialNotFound,
2063
+ gatewayFailures,
2064
+ query,
2065
+ variables
2066
+ ]);
1951
2067
  } catch {
1952
2068
  dedupeKey = void 0;
1953
2069
  }
@@ -1968,7 +2084,6 @@ var GitHubApi = class {
1968
2084
  }
1969
2085
  };
1970
2086
  }
1971
- const retryable = graphqlReadQueryRegex.test(query);
1972
2087
  const data = await this.requestWithRetries(() => this.config.wrapForForcedInsecureSSL(provider?.getIgnoreSSLErrors() ?? false, async () => {
1973
2088
  const capture = createReadCapture();
1974
2089
  try {
@@ -1977,7 +2092,7 @@ var GitHubApi = class {
1977
2092
  if (ex instanceof GraphqlResponseError) captureReadNodes(ex.data, capture);
1978
2093
  throw ex;
1979
2094
  }
1980
- }), retryable, cancellation, scope, gatewayFailures != null);
2095
+ }), readQuery, cancellation, scope, gatewayFailures != null);
1981
2096
  return allowPartialNotFound === "aliased" ? {
1982
2097
  data,
1983
2098
  errors: []
@@ -3609,25 +3724,10 @@ var GitHubApi = class {
3609
3724
  reason: "unsupported"
3610
3725
  };
3611
3726
  try {
3612
- const query = `mutation enqueuePullRequest(
3613
- $id: ID!
3614
- $expectedHeadOid: GitObjectID!
3615
- ) {
3616
- enqueuePullRequest(input: { pullRequestId: $id, expectedHeadOid: $expectedHeadOid }) {
3617
- mergeQueueEntry {
3618
- ${gqlMergeQueueEntryFields}
3619
- }
3620
- }
3621
- }`;
3622
- const entry = (await this.graphql(provider, token, query, {
3623
- id: nodeId,
3624
- expectedHeadOid: expectedHeadSha,
3727
+ return await this.enqueuePullRequestCore(nodeId, expectedHeadSha, (query, variables) => this.graphql(provider, token, query, {
3728
+ ...variables,
3625
3729
  baseUrl: options?.baseUrl
3626
- }, scope, cancellation))?.enqueuePullRequest?.mergeQueueEntry;
3627
- return {
3628
- status: "queued",
3629
- entry: entry != null ? fromGitHubMergeQueueEntry(entry) : void 0
3630
- };
3730
+ }, scope, cancellation));
3631
3731
  } catch (ex) {
3632
3732
  if (isCancellationError(ex)) throw ex;
3633
3733
  const failure = toGitHubMergeQueueActionFailure(ex);
@@ -3641,6 +3741,47 @@ var GitHubApi = class {
3641
3741
  throw this.handleException(ex, provider, scope);
3642
3742
  }
3643
3743
  }
3744
+ async enqueuePullRequestCore(nodeId, expectedHeadSha, request) {
3745
+ const entry = (await request(`mutation enqueuePullRequest(
3746
+ $id: ID!
3747
+ $expectedHeadOid: GitObjectID!
3748
+ ) {
3749
+ enqueuePullRequest(input: { pullRequestId: $id, expectedHeadOid: $expectedHeadOid }) {
3750
+ mergeQueueEntry {
3751
+ ${gqlMergeQueueEntryFields}
3752
+ }
3753
+ }
3754
+ }`, {
3755
+ id: nodeId,
3756
+ expectedHeadOid: expectedHeadSha
3757
+ }))?.enqueuePullRequest?.mergeQueueEntry;
3758
+ return {
3759
+ status: "queued",
3760
+ entry: entry != null ? fromGitHubMergeQueueEntry(entry) : void 0
3761
+ };
3762
+ }
3763
+ async enqueuePullRequestForWrite(nodeId, expectedHeadSha, request) {
3764
+ try {
3765
+ return await this.enqueuePullRequestCore(nodeId, expectedHeadSha, request);
3766
+ } catch (ex) {
3767
+ const graphqlError = getGraphqlResponseError(ex);
3768
+ const partial = (graphqlError?.data)?.enqueuePullRequest?.mergeQueueEntry;
3769
+ if (partial?.state != null && partial.enqueuedAt != null) return {
3770
+ status: "queued",
3771
+ entry: fromGitHubMergeQueueEntry(partial)
3772
+ };
3773
+ if (graphqlError?.errors?.some((error) => error.path?.[0] === "enqueuePullRequest" && error.path.length > 1)) return {
3774
+ status: "failed",
3775
+ reason: "unknown"
3776
+ };
3777
+ const failure = toGitHubMergeQueueActionFailure(ex);
3778
+ if (failure != null && failure.reason !== "unknown") return {
3779
+ status: "failed",
3780
+ ...failure
3781
+ };
3782
+ throw ex;
3783
+ }
3784
+ }
3644
3785
  /**
3645
3786
  * Removes a pull request from its base branch's merge queue, losing its place there. Fails and throws as
3646
3787
  * {@link enqueuePullRequest} does, and is github.com only like it.
@@ -3736,6 +3877,10 @@ __decorate([trace({ args: (provider, token, owner, repo, rev) => ({
3736
3877
  repo,
3737
3878
  rev
3738
3879
  }) })], GitHubApi.prototype, "getPullRequestForCommit", null);
3880
+ __decorate([trace({ args: (provider, token) => ({
3881
+ provider: provider.name,
3882
+ token: `<token:${token.microHash}>`
3883
+ }) })], GitHubApi.prototype, "getPullRequestsForCommits", null);
3739
3884
  __decorate([trace({ args: (provider, token, owner, repo) => ({
3740
3885
  provider: provider.name,
3741
3886
  token: `<token:${token.microHash}>`,
@@ -4014,6 +4159,10 @@ const mergeQueueActionFailurePatterns = [
4014
4159
  ["head-changed", /\bexpected head oid does not match\b/],
4015
4160
  ["not-allowed", /^pull request is (?:closed|in draft)\b/]
4016
4161
  ];
4162
+ function getGraphqlResponseError(ex) {
4163
+ const original = ex instanceof AuthenticationError || ex instanceof RequestNotFoundError ? ex.original : ex;
4164
+ return original instanceof GraphqlResponseError ? original : void 0;
4165
+ }
4017
4166
  /**
4018
4167
  * Why GitHub refused to add a pull request to its merge queue or remove it, from the error its GraphQL answer carried
4019
4168
  * (`errors[]`, which `graphql` throws as a `GraphqlResponseError`, or wraps in an `AuthenticationError` for FORBIDDEN
@@ -4027,9 +4176,7 @@ const mergeQueueActionFailurePatterns = [
4027
4176
  * The message is GitHub's own, for logs, never for display.
4028
4177
  */
4029
4178
  function toGitHubMergeQueueActionFailure(ex) {
4030
- const original = ex instanceof AuthenticationError || ex instanceof RequestNotFoundError ? ex.original : ex;
4031
- if (!(original instanceof GraphqlResponseError)) return void 0;
4032
- const error = original.errors?.[0];
4179
+ const error = getGraphqlResponseError(ex)?.errors?.[0];
4033
4180
  if (error == null) return void 0;
4034
4181
  const message = error.message ?? "";
4035
4182
  const text = message.toLowerCase();