@mark1russell7/site-pages 0.2.21 → 0.2.23

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.
@@ -496,6 +496,73 @@ async function githubReleases(options) {
496
496
  return failure(error, timeoutMs);
497
497
  }
498
498
  }
499
+ /**
500
+ * This function counts the runs that passed in a row, from the newest run. A run that has not ended does not count and does not break the row.
501
+ * Each other conclusion breaks the row, a cancelled run too. It gives null when no run ended.
502
+ *
503
+ * @param runs - The runs, the newest first.
504
+ */
505
+ function greenRunOf(runs) {
506
+ const ended = runs.filter((run) => run.status === "completed");
507
+ const newest = ended[0];
508
+ if (newest === void 0) return null;
509
+ const broken = ended.findIndex((run) => run.conclusion !== "success");
510
+ return {
511
+ value: broken === -1 ? ended.length : broken,
512
+ at: newest.updated_at
513
+ };
514
+ }
515
+ /**
516
+ * This function reads the scheduled runs of a workflow with the REST API, and counts the runs that passed in a row.
517
+ * It gives `{ available: false, reason }` without a token, after an error, or when no scheduled run ended.
518
+ * A caller then leaves the measure out, because 0 says that a run failed.
519
+ *
520
+ * @remarks The function reads at most `limit` runs (default 30), so the count stops at that limit.
521
+ */
522
+ async function githubGreenRun(options) {
523
+ const stop = precheck(options);
524
+ if (stop) return stop;
525
+ const { owner, repo, token, workflow, endpoint = GITHUB_API, limit = 30, timeoutMs = 15e3 } = options;
526
+ const fetcher = options.fetch ?? globalThis.fetch;
527
+ const url = `${endpoint}/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/actions/workflows/${encodeURIComponent(workflow)}/runs?event=schedule&per_page=${limit}`;
528
+ try {
529
+ const response = await fetcher(url, {
530
+ headers: {
531
+ accept: "application/vnd.github+json",
532
+ authorization: `Bearer ${token}`,
533
+ "user-agent": USER_AGENT,
534
+ "x-github-api-version": "2022-11-28"
535
+ },
536
+ signal: AbortSignal.timeout(timeoutMs)
537
+ });
538
+ if (response.status === 404) return {
539
+ available: false,
540
+ reason: `GitHub has no workflow ${workflow} in ${owner}/${repo}`
541
+ };
542
+ if (!response.ok) return {
543
+ available: false,
544
+ reason: `GitHub answered with HTTP ${response.status}`
545
+ };
546
+ const green = greenRunOf(list(object(await response.json())["workflow_runs"]).map((value) => {
547
+ const run = object(value);
548
+ return {
549
+ status: text(run["status"]),
550
+ conclusion: typeof run["conclusion"] === "string" ? run["conclusion"] : null,
551
+ updated_at: text(run["updated_at"])
552
+ };
553
+ }));
554
+ if (green === null) return {
555
+ available: false,
556
+ reason: `the workflow ${workflow} has no scheduled run that ended`
557
+ };
558
+ return {
559
+ available: true,
560
+ ...green
561
+ };
562
+ } catch (error) {
563
+ return failure(error, timeoutMs);
564
+ }
565
+ }
499
566
  // src/data/glob.ts
500
567
  /**
501
568
  * A small glob for the changelog files. The syntax has `*` and `?` in one path segment, and `**` for
@@ -2505,6 +2572,6 @@ async function runCli(argv, io) {
2505
2572
  throw error;
2506
2573
  }
2507
2574
  }
2508
- export { changelogVersions as $, STATUS_CLASSES as A, DEFAULT_CHANGELOGS as B, pageShell as C, utcDay as D, shortDate as E, plainText as F, releaseReading as G, mergeReleases as H, readStatusBoard as I, GITHUB_GRAPHQL as J, globFiles as K, roadmapItems as L, linksOf as M, markdownTables as N, OPEN_CLASSES as O, parseRoadmap as P, changelogFaults as Q, splitRow as R, BASE_CSS as S, longDate as T, readChangelogs as U, ReleaseDataError as V, readReleases as W, githubOpenWork as X, checkStateOf as Y, githubReleases as Z, renderReleasesPage as _, runCli as a, releaseSummary as b, STATUS_SCRIPT as c, renderStatusPage as d, firstSentence as et, sectionsOf as f, releasesLead as g, RELEASES_SCRIPT as h, parseBuildArgs as i, sectionMarksBreak as it, buildStatusBoard as j, RoadmapParseError as k, classCounts as l, statusLead as m, UsageError as n, parseChangelog as nt, TYPESCRIPT_PROBE as o, slugOf as p, GITHUB_API as q, build as r, releaseBodyEntries as rt, probeScript as s, HELP as t, headingAnchor as tt, openGroups as u, laneCenter as v, dayRange as w, timelineLayout as x, oldestFirst as y, statusClassOf as z };
2575
+ export { greenRunOf as $, STATUS_CLASSES as A, DEFAULT_CHANGELOGS as B, pageShell as C, utcDay as D, shortDate as E, plainText as F, releaseReading as G, mergeReleases as H, readStatusBoard as I, GITHUB_GRAPHQL as J, globFiles as K, roadmapItems as L, linksOf as M, markdownTables as N, OPEN_CLASSES as O, parseRoadmap as P, githubReleases as Q, splitRow as R, BASE_CSS as S, longDate as T, readChangelogs as U, ReleaseDataError as V, readReleases as W, githubGreenRun as X, checkStateOf as Y, githubOpenWork as Z, renderReleasesPage as _, runCli as a, releaseBodyEntries as at, releaseSummary as b, STATUS_SCRIPT as c, renderStatusPage as d, changelogFaults as et, sectionsOf as f, releasesLead as g, RELEASES_SCRIPT as h, parseBuildArgs as i, parseChangelog as it, buildStatusBoard as j, RoadmapParseError as k, classCounts as l, statusLead as m, UsageError as n, firstSentence as nt, TYPESCRIPT_PROBE as o, sectionMarksBreak as ot, slugOf as p, GITHUB_API as q, build as r, headingAnchor as rt, probeScript as s, HELP as t, changelogVersions as tt, openGroups as u, laneCenter as v, dayRange as w, timelineLayout as x, oldestFirst as y, statusClassOf as z };
2509
2576
 
2510
2577
  //# sourceMappingURL=build.js.map