@mark1russell7/site-pages 0.3.3 → 0.3.5

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
@@ -499,7 +499,7 @@ Two functions read a measure from GitHub at the build. Each result has the `at`
499
499
  | Function | Measure |
500
500
  | --- | --- |
501
501
  | `githubGreenRun({ owner, repo, token, workflow })` | The scheduled runs of a workflow that passed in a row, from the newest run |
502
- | `githubReleaseLag({ owner, repo, token, tagPrefix, branch })` | The age in days of the oldest commit of the branch that is not in the newest release of the tag prefix. Drafts and pre-releases do not count. |
502
+ | `githubReleaseLag({ owner, repo, token, tagPrefix, branch })` | The age in days of the oldest commit of the first-parent line of the branch that is not in the newest release of the tag prefix. A merge commit counts at its own date. Drafts and pre-releases do not count. |
503
503
 
504
504
  ## The shell of a site
505
505
 
@@ -573,6 +573,7 @@ The explorer obeys these rules:
573
573
 
574
574
  - **A bad record.** The explorer reads a record only through `parseResponseRecord`. It shows each fault with its path, and it does not throw.
575
575
  - **Conditions.** A dimension with `when` has its parent at a level inside `when`. The controls disable a choice that a view refuses, and they tell why.
576
+ - **Held values that do not apply.** A held dimension whose parent is at an other level goes in one closed fold, after the held values that change the view. The fold tells their count, and it stays open or closed when the view changes.
576
577
  - **The band.** The band shows `low` to `high`. It fades with the distance from the nearest measured point.
577
578
  - **The time of a surface.** The field `nearest` reads each point at each place. So `planSteps` bounds the grid from the point count before the call. After a surface that passes the budget, `nextStepsCap` makes the next grid smaller.
578
579
  - **A table model.** A table model has no smooth surface, so the view shows cells.
@@ -522,16 +522,50 @@ function releaseLagOf(oldest, now) {
522
522
  const days = (Date.parse(now) - Date.parse(oldest)) / DAY_MS$1;
523
523
  return Number.isFinite(days) ? Math.max(0, Math.round(days * 100) / 100) : NaN;
524
524
  }
525
+ /** The most pages of 100 commits that `githubReleaseLag` reads from one comparison. */
526
+ const COMPARE_PAGES = 20;
527
+ function compareCommit(value) {
528
+ const commit = object(value);
529
+ const parents = Array.isArray(commit["parents"]) ? commit["parents"].map((parent) => text(object(parent)["sha"])) : [];
530
+ return {
531
+ sha: text(commit["sha"]),
532
+ parents,
533
+ date: text(object(object(commit["commit"])["committer"])["date"])
534
+ };
535
+ }
536
+ /**
537
+ * This function follows the first-parent line of `commits` from its tip. `commits` are the commits of a branch that a tag does
538
+ * not contain. The function gives the commit date and the first parent of the oldest commit of that line. The tip is the one
539
+ * commit that is not a parent of another commit of the list. The function gives undefined for no commit, and null when the list
540
+ * has no single tip.
541
+ */
542
+ function oldestFirstParent(commits) {
543
+ if (commits.length === 0) return void 0;
544
+ const bySha = new Map(commits.map((commit) => [commit.sha, commit]));
545
+ const parents = new Set(commits.flatMap((commit) => commit.parents));
546
+ const tips = commits.filter((commit) => !parents.has(commit.sha));
547
+ if (tips.length !== 1 || tips[0] === void 0) return null;
548
+ let line = tips[0];
549
+ for (let next = bySha.get(line.parents[0] ?? ""); next !== void 0; next = bySha.get(next.parents[0] ?? "")) line = next;
550
+ return {
551
+ date: line.date,
552
+ parent: line.parents[0] ?? ""
553
+ };
554
+ }
525
555
  /**
526
- * This function reads how many days a branch is ahead of its newest release. That is the age of the oldest commit of the branch
527
- * that is not in the newest release of the tag prefix `tagPrefix`. It skips drafts and pre-releases, because
528
- * a pre-release is not the version that most users get. It gives `{ available: false, reason }` without a token, after an error,
556
+ * This function reads how many days a branch is ahead of its newest release. That is the age of the oldest commit of the
557
+ * first-parent line of the branch that the newest release of `tagPrefix` does not contain. It skips drafts and pre-releases,
558
+ * because a pre-release is not the version that most users get. It gives `{ available: false, reason }` without a token, after an error,
529
559
  * or with no such release.
530
560
  *
531
561
  * @remarks The function reads the releases until it finds one, at most `maxPages` pages of 100 (default 10). It then compares the
532
- * tag with the branch, with one commit on each page. GitHub gives the commits of a comparison from the oldest, so the first page
533
- * holds the oldest commit. A commit that is merged after the tag and before the release is published counts, because it is not
534
- * in the release. The time of the release does not decide.
562
+ * tag with the branch, and reads each commit of the comparison, at most 2,000. A change lands on the branch as a commit of its
563
+ * first-parent line: a squash, a merge commit, or a rebased commit.
564
+ *
565
+ * The function follows that line from the tip of the branch back to the tag, and takes the date of its oldest commit. A tag
566
+ * that is not on that line gives `{ available: false, reason }`. So a merge commit counts at the time of the merge, not at the older
567
+ * dates of the commits that it brings. A commit that lands after the tag and before the release is published counts, because it
568
+ * is not in the release. The time of the release does not decide.
535
569
  */
536
570
  async function githubReleaseLag(options) {
537
571
  const { owner, repo, token = "", tagPrefix, branch = "main", endpoint = GITHUB_API, timeoutMs = 15e3 } = options;
@@ -553,28 +587,61 @@ async function githubReleaseLag(options) {
553
587
  headers: restHeaders(token),
554
588
  signal: AbortSignal.timeout(timeoutMs)
555
589
  });
556
- const compare = `${endpoint}/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/compare/${encodeURIComponent(release.tag)}...${encodeURIComponent(branch)}?per_page=1`;
590
+ let url = `${endpoint}/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/compare/${encodeURIComponent(release.tag)}...${encodeURIComponent(branch)}?per_page=100`;
557
591
  try {
558
- const response = await read(compare);
559
- if (response.status === 404) return {
592
+ const commits = [];
593
+ let ahead = 0;
594
+ let base = "";
595
+ for (let page = 0; url !== null; page++) {
596
+ if (page === COMPARE_PAGES) return {
597
+ available: false,
598
+ reason: `the branch has more than 2000 commits after ${release.tag}`
599
+ };
600
+ const response = await read(url);
601
+ if (response.status === 404) return {
602
+ available: false,
603
+ reason: `GitHub has no tag ${release.tag} or no branch ${branch} in ${owner}/${repo}`
604
+ };
605
+ if (!response.ok) return {
606
+ available: false,
607
+ reason: `GitHub answered with HTTP ${response.status}`
608
+ };
609
+ const body = object(await response.json());
610
+ const listed = body["commits"];
611
+ if (!Array.isArray(listed)) return {
612
+ available: false,
613
+ reason: "GitHub gave no list of commits"
614
+ };
615
+ if (page === 0) {
616
+ const status = text(body["status"]);
617
+ if (status !== "ahead" && status !== "identical") return {
618
+ available: false,
619
+ reason: `the tag ${release.tag} is not on ${branch} (the comparison is ${status || "unknown"})`
620
+ };
621
+ ahead = typeof body["ahead_by"] === "number" ? body["ahead_by"] : 0;
622
+ base = text(object(body["merge_base_commit"])["sha"]);
623
+ }
624
+ for (const value of listed) commits.push(compareCommit(value));
625
+ url = linkedPage(response.headers.get("link"), "next");
626
+ }
627
+ if (commits.length < ahead) return {
560
628
  available: false,
561
- reason: `GitHub has no tag ${release.tag} or no branch ${branch} in ${owner}/${repo}`
629
+ reason: `GitHub listed ${commits.length} of the ${ahead} commits after ${release.tag}`
562
630
  };
563
- if (!response.ok) return {
631
+ const oldest = oldestFirstParent(commits);
632
+ if (oldest === null) return {
564
633
  available: false,
565
- reason: `GitHub answered with HTTP ${response.status}`
634
+ reason: `the commits after ${release.tag} have no single tip`
566
635
  };
567
- const commits = object(await response.json())["commits"];
568
- if (!Array.isArray(commits)) return {
636
+ if (oldest !== void 0 && oldest.parent !== base) return {
569
637
  available: false,
570
- reason: "GitHub gave no list of commits"
638
+ reason: `the tag ${release.tag} is not on the first-parent line of ${branch}`
571
639
  };
572
- const commit = commits.length === 0 ? void 0 : text(object(object(object(commits[0])["commit"])["committer"])["date"]);
573
- if (commit === "") return {
640
+ if (oldest?.date === "") return {
574
641
  available: false,
575
642
  reason: "the oldest commit has no date"
576
643
  };
577
- const value = releaseLagOf(commit, now);
644
+ const value = releaseLagOf(oldest?.date, now);
578
645
  if (!Number.isFinite(value)) return {
579
646
  available: false,
580
647
  reason: "the time of the read is not a date"