better-review 0.7.2 → 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.
package/README.md CHANGED
@@ -53,6 +53,12 @@ filtres par groupe : Reviewer, Auteur, Lead ; par repo (liste avec recherche) ;
53
53
  Le tableau se recharge au retour sur la page ou dans l'onglet (au-delà de 30 s), toutes les 5 min, dès qu'un
54
54
  changement GitHub est détecté (sondage toutes les 60 s) et sur « Actualiser ».
55
55
 
56
+ PR empilées : badge « Stack 2/4 » sur la carte et dans l'en-tête de la PR. Il ouvre la liste des PR de la stack, de
57
+ la base vers le sommet, chacune ouvrable dans better-review. Stacks natives de GitHub (badge plein) d'abord. Sinon,
58
+ une stack est déduite des branches (badge contour) : une PR ouverte dont la base est la branche d'une autre PR ouverte
59
+ du même repo. Une branche de fork ne compte pas, la branche par défaut ne relie jamais deux PR, et la chaîne s'arrête
60
+ là où plusieurs PR partent de la même branche.
61
+
56
62
  Données chargées au plus juste : champs du tableau pour toutes les PR ; CI et threads en plus pour les PR approuvées
57
63
  (pour séparer « Approuvée » de « Prête à merger ») ; taille, fichiers vus, réponses attendues et dernière activité
58
64
  seulement pour les PR qui me concernent. Recherche GitHub limitée à 1000 résultats par repo / org suivi.
package/dist/cli.js CHANGED
@@ -26445,6 +26445,108 @@ var GitHub = class {
26445
26445
  }
26446
26446
  };
26447
26447
 
26448
+ // ../server/src/stack.ts
26449
+ var MAX_STACK = 20;
26450
+ var STACK_FIELDS = (
26451
+ /* GraphQL */
26452
+ `
26453
+ stackEntry {
26454
+ position
26455
+ }
26456
+ stack {
26457
+ number
26458
+ size
26459
+ baseRefName
26460
+ entries(first: ${MAX_STACK}) {
26461
+ nodes {
26462
+ position
26463
+ pullRequest {
26464
+ number
26465
+ title
26466
+ state
26467
+ isDraft
26468
+ }
26469
+ }
26470
+ }
26471
+ }
26472
+ `
26473
+ );
26474
+ function nativeStack(node2) {
26475
+ if (!node2.stack || !node2.stackEntry) return null;
26476
+ return {
26477
+ kind: "native",
26478
+ number: node2.stack.number,
26479
+ baseRefName: node2.stack.baseRefName,
26480
+ position: node2.stackEntry.position,
26481
+ size: node2.stack.size,
26482
+ entries: node2.stack.entries.nodes.flatMap((e) => e.pullRequest ? [{ position: e.position, ...e.pullRequest }] : []).sort((a, b) => a.position - b.position)
26483
+ };
26484
+ }
26485
+ var BranchIndex = class {
26486
+ constructor(defaultBranch, prs = []) {
26487
+ this.defaultBranch = defaultBranch;
26488
+ this.add(prs);
26489
+ }
26490
+ defaultBranch;
26491
+ prs = /* @__PURE__ */ new Map();
26492
+ byHead = /* @__PURE__ */ new Map();
26493
+ byBase = /* @__PURE__ */ new Map();
26494
+ add(prs) {
26495
+ for (const pr of prs) {
26496
+ if (this.prs.has(pr.number)) continue;
26497
+ this.prs.set(pr.number, pr);
26498
+ push(this.byHead, pr.headRefName, pr);
26499
+ push(this.byBase, pr.baseRefName, pr);
26500
+ }
26501
+ }
26502
+ parent(pr) {
26503
+ if (pr.baseRefName === this.defaultBranch) return null;
26504
+ const matches = (this.byHead.get(pr.baseRefName) ?? []).filter(
26505
+ (p) => !p.isCrossRepository && p.number !== pr.number
26506
+ );
26507
+ return matches.length === 1 ? matches[0] : null;
26508
+ }
26509
+ child(pr) {
26510
+ if (pr.isCrossRepository || pr.headRefName === this.defaultBranch) return null;
26511
+ const matches = (this.byBase.get(pr.headRefName) ?? []).filter((p) => p.number !== pr.number);
26512
+ return matches.length === 1 ? matches[0] : null;
26513
+ }
26514
+ /** The chain through `pr`, at most `MAX_STACK` PRs; null when `pr` is alone. */
26515
+ stackOf(pr) {
26516
+ const seen = /* @__PURE__ */ new Set([pr.number]);
26517
+ const below = [];
26518
+ for (let p = this.parent(pr); p && !seen.has(p.number) && below.length < MAX_STACK - 1; p = this.parent(p)) {
26519
+ seen.add(p.number);
26520
+ below.unshift(p);
26521
+ }
26522
+ const chain = [...below, pr];
26523
+ for (let c = this.child(pr); c && !seen.has(c.number) && chain.length < MAX_STACK; c = this.child(c)) {
26524
+ seen.add(c.number);
26525
+ chain.push(c);
26526
+ }
26527
+ if (chain.length < 2) return null;
26528
+ return {
26529
+ kind: "inferred",
26530
+ number: null,
26531
+ baseRefName: chain[0].baseRefName,
26532
+ position: below.length + 1,
26533
+ size: chain.length,
26534
+ entries: chain.map((p, i) => ({
26535
+ position: i + 1,
26536
+ number: p.number,
26537
+ title: p.title,
26538
+ state: "OPEN",
26539
+ isDraft: p.isDraft
26540
+ }))
26541
+ };
26542
+ }
26543
+ };
26544
+ function push(map2, key, pr) {
26545
+ const list2 = map2.get(key);
26546
+ if (list2) list2.push(pr);
26547
+ else map2.set(key, [pr]);
26548
+ }
26549
+
26448
26550
  // ../server/src/github/queries.ts
26449
26551
  var REACTION_FIELDS = (
26450
26552
  /* GraphQL */
@@ -26557,6 +26659,9 @@ var PR_QUERY = (
26557
26659
  rebaseMergeAllowed
26558
26660
  viewerDefaultMergeMethod
26559
26661
  autoMergeAllowed
26662
+ defaultBranchRef {
26663
+ name
26664
+ }
26560
26665
  pullRequest(number: $number) {
26561
26666
  id
26562
26667
  number
@@ -26574,6 +26679,8 @@ var PR_QUERY = (
26574
26679
  headRefName
26575
26680
  baseRefOid
26576
26681
  headRefOid
26682
+ isCrossRepository
26683
+ ${STACK_FIELDS}
26577
26684
  additions
26578
26685
  deletions
26579
26686
  changedFiles
@@ -26805,6 +26912,40 @@ var PR_FINGERPRINT_QUERY = (
26805
26912
  }
26806
26913
  `
26807
26914
  );
26915
+ var STACK_HOP_QUERY = (
26916
+ /* GraphQL */
26917
+ `
26918
+ query StackHop(
26919
+ $owner: String!
26920
+ $repo: String!
26921
+ $base: String!
26922
+ $head: String!
26923
+ $up: Boolean!
26924
+ $down: Boolean!
26925
+ ) {
26926
+ repository(owner: $owner, name: $repo) {
26927
+ below: pullRequests(headRefName: $base, states: OPEN, first: 5) @include(if: $up) {
26928
+ nodes {
26929
+ ...BranchPrFields
26930
+ }
26931
+ }
26932
+ above: pullRequests(baseRefName: $head, states: OPEN, first: 5) @include(if: $down) {
26933
+ nodes {
26934
+ ...BranchPrFields
26935
+ }
26936
+ }
26937
+ }
26938
+ }
26939
+ fragment BranchPrFields on PullRequest {
26940
+ number
26941
+ title
26942
+ isDraft
26943
+ baseRefName
26944
+ headRefName
26945
+ isCrossRepository
26946
+ }
26947
+ `
26948
+ );
26808
26949
 
26809
26950
  // ../server/src/github/blobs.ts
26810
26951
  var BATCH = 50;
@@ -26841,12 +26982,19 @@ var BOARD_FIELDS = (
26841
26982
  createdAt
26842
26983
  updatedAt
26843
26984
  headRefOid
26985
+ baseRefName
26986
+ headRefName
26987
+ isCrossRepository
26844
26988
  reviewDecision
26845
26989
  isInMergeQueue
26846
26990
  mergedAt
26847
26991
  repository {
26848
26992
  nameWithOwner
26993
+ defaultBranchRef {
26994
+ name
26995
+ }
26849
26996
  }
26997
+ ${STACK_FIELDS}
26850
26998
  author {
26851
26999
  login
26852
27000
  avatarUrl
@@ -27108,6 +27256,7 @@ function toInboxPr(node2, me, reads) {
27108
27256
  const name = r.requestedReviewer?.login ?? r.requestedReviewer?.slug;
27109
27257
  return name ? [name] : [];
27110
27258
  }),
27259
+ stack: nativeStack(node2),
27111
27260
  ...node2.commits ? { ci: node2.commits.nodes[0]?.commit.statusCheckRollup?.state ?? null } : {},
27112
27261
  ...threads ? { threads } : {},
27113
27262
  ...node2.additions !== void 0 ? { additions: node2.additions, deletions: node2.deletions ?? 0 } : {},
@@ -27141,8 +27290,10 @@ function stageOf(pr) {
27141
27290
  function buildBoard(sources, me, reads, staleBefore) {
27142
27291
  const nodes = /* @__PURE__ */ new Map();
27143
27292
  for (const node2 of [...sources.open, ...sources.merged]) nodes.set(node2.id, node2);
27293
+ const inferred = inferredStacks(sources.open);
27144
27294
  const prs = [...nodes.values()].map((node2) => {
27145
- const pr = toInboxPr(node2, me, reads);
27295
+ const summary = toInboxPr(node2, me, reads);
27296
+ const pr = { ...summary, stack: summary.stack ?? inferred.get(node2.id) ?? null };
27146
27297
  const stage = stageOf(pr);
27147
27298
  const mine = pr.author?.login === me;
27148
27299
  const tags = mine ? ["mine"] : [];
@@ -27161,6 +27312,24 @@ function buildBoard(sources, me, reads, staleBefore) {
27161
27312
  });
27162
27313
  return prs.sort((a, b) => b.updatedAt.localeCompare(a.updatedAt));
27163
27314
  }
27315
+ function inferredStacks(open2) {
27316
+ const byRepo = /* @__PURE__ */ new Map();
27317
+ for (const node2 of open2) {
27318
+ const repo = node2.repository.nameWithOwner.toLowerCase();
27319
+ const list2 = byRepo.get(repo);
27320
+ if (list2) list2.push(node2);
27321
+ else byRepo.set(repo, [node2]);
27322
+ }
27323
+ const stacks = /* @__PURE__ */ new Map();
27324
+ for (const nodes of byRepo.values()) {
27325
+ const index = new BranchIndex(nodes[0].repository.defaultBranchRef?.name ?? null, nodes);
27326
+ for (const node2 of nodes) {
27327
+ const stack = index.stackOf(node2);
27328
+ if (stack) stacks.set(node2.id, stack);
27329
+ }
27330
+ }
27331
+ return stacks;
27332
+ }
27164
27333
  var MAX_SEARCH_PAGES = 10;
27165
27334
  var BATCH2 = 25;
27166
27335
  var PARALLEL = 12;
@@ -27300,6 +27469,29 @@ async function inboxFingerprint(gh, config2, signal) {
27300
27469
  }
27301
27470
 
27302
27471
  // ../server/src/pr.ts
27472
+ async function inferStack(gh, vars, current, defaultBranch) {
27473
+ const index = new BranchIndex(defaultBranch, [current]);
27474
+ const seen = /* @__PURE__ */ new Set([current.number]);
27475
+ let bottom = current;
27476
+ let top = current;
27477
+ for (let hop = 1; hop < MAX_STACK && (bottom || top); hop++) {
27478
+ const data = await gh.graphql(STACK_HOP_QUERY, {
27479
+ ...vars,
27480
+ base: bottom?.baseRefName ?? "",
27481
+ head: top?.headRefName ?? "",
27482
+ up: bottom !== null,
27483
+ down: top !== null
27484
+ });
27485
+ index.add([...data.repository?.below?.nodes ?? [], ...data.repository?.above?.nodes ?? []]);
27486
+ const below = bottom && index.parent(bottom);
27487
+ const above = top && index.child(top);
27488
+ bottom = below && !seen.has(below.number) ? below : null;
27489
+ top = above && !seen.has(above.number) ? above : null;
27490
+ if (bottom) seen.add(bottom.number);
27491
+ if (top) seen.add(top.number);
27492
+ }
27493
+ return index.stackOf(current);
27494
+ }
27303
27495
  async function fetchAllPages(first, next) {
27304
27496
  const all = [...first.nodes];
27305
27497
  let page = first.pageInfo;
@@ -27317,7 +27509,8 @@ async function loadPr(gh, store, ref) {
27317
27509
  if (!pr) throw new GitHubError(`PR ${ref.owner}/${ref.repo}#${ref.number} introuvable`, 404);
27318
27510
  const me = data.viewer.login;
27319
27511
  const key = prKey(ref.owner, ref.repo, ref.number);
27320
- const [files, threadNodes] = await Promise.all([
27512
+ const native = nativeStack(pr);
27513
+ const [files, threadNodes, stack] = await Promise.all([
27321
27514
  fetchAllPages(
27322
27515
  pr.files,
27323
27516
  async (after) => (await gh.graphql(PR_FILES_PAGE_QUERY, { ...vars, after })).repository.pullRequest.files
@@ -27325,7 +27518,8 @@ async function loadPr(gh, store, ref) {
27325
27518
  fetchAllPages(
27326
27519
  pr.reviewThreads,
27327
27520
  async (after) => (await gh.graphql(PR_THREADS_PAGE_QUERY, { ...vars, after })).repository.pullRequest.reviewThreads
27328
- )
27521
+ ),
27522
+ native || pr.state !== "OPEN" ? native : inferStack(gh, vars, pr, data.repository?.defaultBranchRef?.name ?? null)
27329
27523
  ]);
27330
27524
  const reads = store.threadReads(threadNodes.map((t2) => t2.id));
27331
27525
  const entryIds = [...pr.comments.nodes.map((c) => c.id), ...pr.reviews.nodes.map((r) => r.id)];
@@ -27407,7 +27601,8 @@ async function loadPr(gh, store, ref) {
27407
27601
  author: pr.author,
27408
27602
  sameRepo: pr.headRepository?.nameWithOwner.toLowerCase() === `${ref.owner}/${ref.repo}`.toLowerCase(),
27409
27603
  canClose: pr.viewerCanClose,
27410
- canReopen: pr.viewerCanReopen
27604
+ canReopen: pr.viewerCanReopen,
27605
+ stack
27411
27606
  },
27412
27607
  merge: mergeInfo(data.repository, pr),
27413
27608
  reviewers: [...reviewers.values()],