@mark1russell7/site-pages 0.3.1 → 0.3.2

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
@@ -495,7 +495,7 @@ Two functions read a measure from GitHub at the build. Each result has the `at`
495
495
  | Function | Measure |
496
496
  | --- | --- |
497
497
  | `githubGreenRun({ owner, repo, token, workflow })` | The scheduled runs of a workflow that passed in a row, from the newest run |
498
- | `githubReleaseLag({ owner, repo, token, tagPrefix, branch })` | The age in days of the oldest commit of the branch after the newest release of the tag prefix. Drafts and pre-releases do not count. |
498
+ | `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. |
499
499
 
500
500
  ## The shell of a site
501
501
 
@@ -524,11 +524,14 @@ function releaseLagOf(oldest, now) {
524
524
  }
525
525
  /**
526
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
- * after the newest release whose tag starts with `tagPrefix`. It skips drafts and pre-releases, because a pre-release is not the
528
- * version that most users get. It gives `{ available: false, reason }` without a token, after an error, or with no such release.
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,
529
+ * or with no such release.
529
530
  *
530
- * @remarks The function reads the releases until it finds one, at most `maxPages` pages of 100 (default 10). It then reads one
531
- * commit on each page of the branch since that release, and asks GitHub for the last page only.
531
+ * @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.
532
535
  */
533
536
  async function githubReleaseLag(options) {
534
537
  const { owner, repo, token = "", tagPrefix, branch = "main", endpoint = GITHUB_API, timeoutMs = 15e3 } = options;
@@ -550,25 +553,23 @@ async function githubReleaseLag(options) {
550
553
  headers: restHeaders(token),
551
554
  signal: AbortSignal.timeout(timeoutMs)
552
555
  });
553
- const first = `${endpoint}/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/commits?sha=${encodeURIComponent(branch)}&since=${encodeURIComponent(release.publishedAt)}&per_page=1`;
556
+ const compare = `${endpoint}/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/compare/${encodeURIComponent(release.tag)}...${encodeURIComponent(branch)}?per_page=1`;
554
557
  try {
555
- let response = await read(first);
556
- const last = response.ok ? linkedPage(response.headers.get("link"), "last") : null;
557
- if (last !== null) response = await read(last);
558
+ const response = await read(compare);
558
559
  if (response.status === 404) return {
559
560
  available: false,
560
- reason: `GitHub has no branch ${branch} in ${owner}/${repo}`
561
+ reason: `GitHub has no tag ${release.tag} or no branch ${branch} in ${owner}/${repo}`
561
562
  };
562
563
  if (!response.ok) return {
563
564
  available: false,
564
565
  reason: `GitHub answered with HTTP ${response.status}`
565
566
  };
566
- const body = await response.json();
567
- if (!Array.isArray(body)) return {
567
+ const commits = object(await response.json())["commits"];
568
+ if (!Array.isArray(commits)) return {
568
569
  available: false,
569
570
  reason: "GitHub gave no list of commits"
570
571
  };
571
- const commit = body.length === 0 ? void 0 : text(object(object(object(body.at(-1))["commit"])["committer"])["date"]);
572
+ const commit = commits.length === 0 ? void 0 : text(object(object(object(commits[0])["commit"])["committer"])["date"]);
572
573
  if (commit === "") return {
573
574
  available: false,
574
575
  reason: "the oldest commit has no date"