@gitkraken/core-gitlens 0.26.0 → 0.27.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.
@@ -2575,19 +2575,26 @@ var GitHubApi = class {
2575
2575
  * {@link getPullRequestNumbersForBranch} settles such a target, though it can't see a deleted fork's pull
2576
2576
  * request, so its caller keeps the rows matched here as well.
2577
2577
  *
2578
+ * One alias per query, however many head owners ask it: the owner filter runs on the returned nodes, so
2579
+ * queries that differ only by owner would send identical subqueries. The caller names each query once, with
2580
+ * every owner it wants answered from it (`headOwners`, where `undefined` means the base repository), and
2581
+ * the answer holds one list per owner, in `headOwners` order. The caller must keep queries distinct (same
2582
+ * repository, case-insensitively, and branch), or it pays for the duplicates.
2583
+ *
2578
2584
  * Returns POSITIONALLY, with the same per-alias rules as {@link getPullRequestsBatch}: a missing base
2579
- * repository (NOT_FOUND on a null repository) is a PROVEN "none" — an empty list — while any other error on
2580
- * a target's alias rejects only that target, and a whole-request failure still throws.
2585
+ * repository (NOT_FOUND on a null repository) is a PROVEN "none" — an empty list per owner — while any other
2586
+ * error on a query's alias rejects that query (every owner of it), and a whole-request failure still throws.
2587
+ * `truncated` is a property of the query, so it is shared by every owner.
2581
2588
  */
2582
- async getPullRequestsForBranches(provider, token, targets, options, cancellation) {
2589
+ async getPullRequestsForBranches(provider, token, queries, options, cancellation) {
2583
2590
  const scope = getScopedLogger();
2584
- if (targets.length === 0) return [];
2591
+ if (queries.length === 0) return [];
2585
2592
  const query = `query getPullRequestsForBranches(
2586
- ${targets.map((_, i) => `$o${i}: String!\n\t\t\t\t$n${i}: String!\n\t\t\t\t$h${i}: String!`).join("\n ")}
2593
+ ${queries.map((_, i) => `$o${i}: String!\n\t\t\t\t$n${i}: String!\n\t\t\t\t$h${i}: String!`).join("\n ")}
2587
2594
  $limit: Int!
2588
2595
  $avatarSize: Int
2589
2596
  ) {
2590
- ${targets.map((_, i) => `b${i}: repository(owner: $o${i}, name: $n${i}) {
2597
+ ${queries.map((_, i) => `b${i}: repository(owner: $o${i}, name: $n${i}) {
2591
2598
  pullRequests(headRefName: $h${i}, states: [OPEN, CLOSED, MERGED], first: $limit, orderBy: {field: UPDATED_AT, direction: DESC}) {
2592
2599
  totalCount
2593
2600
  nodes {
@@ -2605,7 +2612,7 @@ var GitHubApi = class {
2605
2612
  avatarSize: options.avatarSize,
2606
2613
  limit: options.limit
2607
2614
  };
2608
- targets.forEach((t, i) => {
2615
+ queries.forEach((t, i) => {
2609
2616
  variables[`o${i}`] = t.owner;
2610
2617
  variables[`n${i}`] = t.repo;
2611
2618
  variables[`h${i}`] = t.branch;
@@ -2613,7 +2620,7 @@ var GitHubApi = class {
2613
2620
  try {
2614
2621
  const rsp = await this.graphql(provider, token, query, variables, scope, cancellation, "aliased");
2615
2622
  if (rsp?.data == null) throw new Error("GitHub returned no data for the pull requests by branch");
2616
- return targets.map((t, i) => {
2623
+ return queries.map((t, i) => {
2617
2624
  const alias = `b${i}`;
2618
2625
  const repository = rsp.data[alias];
2619
2626
  const verdict = getAliasErrorVerdict(rsp.errors, alias, repository);
@@ -2621,7 +2628,7 @@ var GitHubApi = class {
2621
2628
  if (repository == null) return {
2622
2629
  status: "fulfilled",
2623
2630
  value: {
2624
- pullRequests: [],
2631
+ pullRequests: t.headOwners.map(() => []),
2625
2632
  truncated: false
2626
2633
  }
2627
2634
  };
@@ -2630,15 +2637,25 @@ var GitHubApi = class {
2630
2637
  status: "rejected",
2631
2638
  reason: /* @__PURE__ */ new Error(`GitHub returned no pull requests for ${t.owner}/${t.repo}:${t.branch}`)
2632
2639
  };
2633
- const headOwner = t.headOwner?.toLowerCase();
2634
- const nodes = connection.nodes.filter((pr) => pr != null);
2635
- const matches = nodes.filter((pr) => pr.headRefName === t.branch && (headOwner == null ? !pr.isCrossRepository : pr.isCrossRepository && pr.headRepositoryOwner?.login.toLowerCase() === headOwner));
2640
+ const returned = connection.nodes.filter((pr) => pr != null);
2641
+ const nodes = returned.filter((pr) => pr.headRefName === t.branch);
2636
2642
  try {
2643
+ const mapped = /* @__PURE__ */ new Map();
2637
2644
  return {
2638
2645
  status: "fulfilled",
2639
2646
  value: {
2640
- pullRequests: matches.map((pr) => fromGitHubPullRequest(pr, provider)).sort((a, b) => b.updatedDate.getTime() - a.updatedDate.getTime()),
2641
- truncated: connection.totalCount > nodes.length
2647
+ pullRequests: t.headOwners.map((owner) => {
2648
+ const headOwner = owner?.toLowerCase();
2649
+ return nodes.filter((pr) => headOwner == null ? !pr.isCrossRepository : pr.isCrossRepository && pr.headRepositoryOwner?.login.toLowerCase() === headOwner).map((pr) => {
2650
+ let converted = mapped.get(pr);
2651
+ if (converted == null) {
2652
+ converted = fromGitHubPullRequest(pr, provider);
2653
+ mapped.set(pr, converted);
2654
+ }
2655
+ return converted;
2656
+ }).sort((a, b) => b.updatedDate.getTime() - a.updatedDate.getTime());
2657
+ }),
2658
+ truncated: connection.totalCount > returned.length
2642
2659
  }
2643
2660
  };
2644
2661
  } catch (ex) {