@mark1russell7/site-pages 0.3.3 → 0.3.4
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 +1 -1
- package/build/chunks/build.js +85 -18
- package/build/chunks/build.js.map +1 -1
- package/build/index.d.ts +10 -6
- package/build/index.d.ts.map +1 -1
- package/package.json +1 -1
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
|
|
package/build/chunks/build.js
CHANGED
|
@@ -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
|
|
527
|
-
*
|
|
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,
|
|
533
|
-
*
|
|
534
|
-
*
|
|
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
|
-
|
|
590
|
+
let url = `${endpoint}/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/compare/${encodeURIComponent(release.tag)}...${encodeURIComponent(branch)}?per_page=100`;
|
|
557
591
|
try {
|
|
558
|
-
const
|
|
559
|
-
|
|
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
|
|
629
|
+
reason: `GitHub listed ${commits.length} of the ${ahead} commits after ${release.tag}`
|
|
562
630
|
};
|
|
563
|
-
|
|
631
|
+
const oldest = oldestFirstParent(commits);
|
|
632
|
+
if (oldest === null) return {
|
|
564
633
|
available: false,
|
|
565
|
-
reason: `
|
|
634
|
+
reason: `the commits after ${release.tag} have no single tip`
|
|
566
635
|
};
|
|
567
|
-
|
|
568
|
-
if (!Array.isArray(commits)) return {
|
|
636
|
+
if (oldest !== void 0 && oldest.parent !== base) return {
|
|
569
637
|
available: false,
|
|
570
|
-
reason:
|
|
638
|
+
reason: `the tag ${release.tag} is not on the first-parent line of ${branch}`
|
|
571
639
|
};
|
|
572
|
-
|
|
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(
|
|
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"
|