paseo-plugin-genui 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/OVERVIEW.md +21 -0
- package/README.md +77 -2
- package/assets/fonts/Excalifont-OFL.txt +109 -0
- package/assets/fonts/Excalifont-Regular-latin.woff2 +0 -0
- package/assets/icon.png +0 -0
- package/assets/icon.svg +1 -0
- package/assets/screenshot-chat.png +0 -0
- package/assets/screenshot-gallery.png +0 -0
- package/assets/screenshot-playground.png +0 -0
- package/client/components/content.tsx +468 -0
- package/client/components/data.tsx +967 -0
- package/client/components/dev.tsx +998 -0
- package/client/components/diagram.tsx +513 -0
- package/client/components/inputs.tsx +994 -0
- package/client/components/layout.tsx +239 -0
- package/client/components/media.tsx +428 -0
- package/client/components/project.tsx +641 -0
- package/client/components/widgets.tsx +836 -0
- package/client/gallery.tsx +449 -0
- package/client/live-ui.tsx +525 -0
- package/client/loaders.ts +342 -0
- package/client/markdown.tsx +172 -0
- package/client/node-renderer.tsx +149 -0
- package/client/render.tsx +186 -0
- package/client/runtime.ts +103 -0
- package/client/settings.tsx +57 -0
- package/client/web.ts +186 -0
- package/gallery/Acceptance-baseline.ui +1 -0
- package/gallery/Acceptance-checklist.ui +14 -0
- package/gallery/Acceptance-evidence.ui +9 -0
- package/gallery/Acceptance.ui +1 -0
- package/gallery/Badge.ui +3 -0
- package/gallery/Benchmark-context.ui +8 -0
- package/gallery/Benchmark-hyperfine.ui +1 -0
- package/gallery/Benchmark-runs-list.ui +9 -0
- package/gallery/Benchmark-runs.ui +1 -0
- package/gallery/Benchmark-vitest.ui +1 -0
- package/gallery/Benchmark.ui +9 -0
- package/gallery/Board-bb-tasks.ui +1 -0
- package/gallery/Board-gh-issues.ui +1 -0
- package/gallery/Board-gh-prs.ui +1 -0
- package/gallery/Board.ui +12 -0
- package/gallery/Button-destructive.ui +4 -0
- package/gallery/Button.ui +5 -0
- package/gallery/Calendar.ui +15 -0
- package/gallery/CalendarHeatmap-short.ui +11 -0
- package/gallery/CalendarHeatmap.ui +4 -0
- package/gallery/Callout.ui +4 -0
- package/gallery/Card.ui +4 -0
- package/gallery/Carousel.ui +8 -0
- package/gallery/Changes-paths.ui +1 -0
- package/gallery/Changes-uncommitted.ui +1 -0
- package/gallery/Changes.ui +1 -0
- package/gallery/Chart-area.ui +3 -0
- package/gallery/Chart-funnel.ui +3 -0
- package/gallery/Chart-heatmap.ui +11 -0
- package/gallery/Chart-pie.ui +3 -0
- package/gallery/Chart-radar.ui +3 -0
- package/gallery/Chart-scatter.ui +4 -0
- package/gallery/Chart-stacked.ui +5 -0
- package/gallery/Chart.ui +3 -0
- package/gallery/Checklist.ui +6 -0
- package/gallery/Choice.ui +8 -0
- package/gallery/Code.ui +3 -0
- package/gallery/Commits-limit.ui +1 -0
- package/gallery/Commits.ui +1 -0
- package/gallery/Compare-conditions.ui +4 -0
- package/gallery/Compare-three.ui +7 -0
- package/gallery/Compare.ui +4 -0
- package/gallery/Coverage-go.ui +1 -0
- package/gallery/Coverage-lcov.ui +1 -0
- package/gallery/Coverage-python.ui +1 -0
- package/gallery/Coverage.ui +1 -0
- package/gallery/DateInput.ui +5 -0
- package/gallery/Decision-percent.ui +10 -0
- package/gallery/Decision.ui +12 -0
- package/gallery/Dependencies-audit.ui +1 -0
- package/gallery/Dependencies-both.ui +1 -0
- package/gallery/Dependencies-list.ui +7 -0
- package/gallery/Dependencies-pip.ui +1 -0
- package/gallery/Dependencies-pnpm.ui +1 -0
- package/gallery/Dependencies.ui +1 -0
- package/gallery/Details.ui +4 -0
- package/gallery/Diagram-flow.ui +16 -0
- package/gallery/Diagram-sequence.ui +15 -0
- package/gallery/Diagram.ui +16 -0
- package/gallery/Diff.ui +3 -0
- package/gallery/Divider.ui +5 -0
- package/gallery/EditableTable.ui +9 -0
- package/gallery/Entity-list.ui +6 -0
- package/gallery/Entity.ui +8 -0
- package/gallery/Environments.ui +1 -0
- package/gallery/Estimate-points.ui +6 -0
- package/gallery/Estimate.ui +8 -0
- package/gallery/File.ui +4 -0
- package/gallery/Findings-biome.ui +1 -0
- package/gallery/Findings-eslint.ui +1 -0
- package/gallery/Findings-oxlint.ui +1 -0
- package/gallery/Findings-review.ui +1 -0
- package/gallery/Findings-ruff.ui +1 -0
- package/gallery/Findings-sarif.ui +1 -0
- package/gallery/Findings-ship.ui +11 -0
- package/gallery/Findings-tsc.ui +1 -0
- package/gallery/Findings.ui +7 -0
- package/gallery/Flashcards.ui +3 -0
- package/gallery/FollowUps.ui +4 -0
- package/gallery/Form.ui +8 -0
- package/gallery/Gallery-links.ui +8 -0
- package/gallery/Gallery-strip.ui +14 -0
- package/gallery/Gallery.ui +10 -0
- package/gallery/Gauge.ui +7 -0
- package/gallery/Grid.ui +8 -0
- package/gallery/Hotspots-photo.ui +8 -0
- package/gallery/Hotspots.ui +11 -0
- package/gallery/Icon.ui +5 -0
- package/gallery/Image.ui +4 -0
- package/gallery/ImageSearch-aspects.ui +6 -0
- package/gallery/ImageSearch.ui +4 -0
- package/gallery/Input.ui +5 -0
- package/gallery/Json-api.ui +1 -0
- package/gallery/Json.ui +8 -0
- package/gallery/KeyValue.ui +3 -0
- package/gallery/List-dots.ui +8 -0
- package/gallery/List.ui +8 -0
- package/gallery/ListEditor.ui +5 -0
- package/gallery/Logs-jsonl.ui +1 -0
- package/gallery/Logs-lines.ui +11 -0
- package/gallery/Logs-python.ui +1 -0
- package/gallery/Logs.ui +1 -0
- package/gallery/Map-city.ui +8 -0
- package/gallery/Map.ui +8 -0
- package/gallery/Metric.ui +3 -0
- package/gallery/OptionCards-multi.ui +10 -0
- package/gallery/OptionCards.ui +10 -0
- package/gallery/Pipeline-checks.ui +1 -0
- package/gallery/Pipeline-passed.ui +1 -0
- package/gallery/Pipeline-running.ui +1 -0
- package/gallery/Pipeline-stages.ui +13 -0
- package/gallery/Pipeline.ui +1 -0
- package/gallery/Plan.ui +9 -0
- package/gallery/Progress.ui +4 -0
- package/gallery/Provenance-deploy.ui +6 -0
- package/gallery/Provenance-no-receipt.ui +1 -0
- package/gallery/Provenance.ui +1 -0
- package/gallery/PullRequest.ui +1 -0
- package/gallery/Quiz.ui +6 -0
- package/gallery/Radio.ui +5 -0
- package/gallery/Rating.ui +5 -0
- package/gallery/Roadmap-sprint.ui +8 -0
- package/gallery/Roadmap-year.ui +9 -0
- package/gallery/Roadmap.ui +12 -0
- package/gallery/Row.ui +3 -0
- package/gallery/SegmentedBar-status.ui +8 -0
- package/gallery/SegmentedBar.ui +8 -0
- package/gallery/Select.ui +5 -0
- package/gallery/Slider.ui +7 -0
- package/gallery/Snippet.ui +3 -0
- package/gallery/Sources-chips.ui +4 -0
- package/gallery/Sources.ui +8 -0
- package/gallery/Sparkline.ui +6 -0
- package/gallery/Stack.ui +7 -0
- package/gallery/StackTrace-aggregate.ui +1 -0
- package/gallery/StackTrace-browser.ui +1 -0
- package/gallery/StackTrace-go.ui +1 -0
- package/gallery/StackTrace-java.ui +1 -0
- package/gallery/StackTrace-python.ui +1 -0
- package/gallery/StackTrace-rust.ui +1 -0
- package/gallery/StackTrace.ui +1 -0
- package/gallery/Status.ui +9 -0
- package/gallery/Stepper.ui +5 -0
- package/gallery/Steps.ui +8 -0
- package/gallery/Swatches-long-names.ui +4 -0
- package/gallery/Swatches-picker.ui +5 -0
- package/gallery/Swatches.ui +10 -0
- package/gallery/Table.ui +7 -0
- package/gallery/Tabs.ui +8 -0
- package/gallery/Tests-junit.ui +1 -0
- package/gallery/Tests-vitest-junit.ui +1 -0
- package/gallery/Tests-vitest.ui +1 -0
- package/gallery/Tests.ui +9 -0
- package/gallery/Text.ui +4 -0
- package/gallery/TextArea.ui +5 -0
- package/gallery/Threads-ids.ui +1 -0
- package/gallery/Threads.ui +1 -0
- package/gallery/Timeline.ui +8 -0
- package/gallery/Timer.ui +4 -0
- package/gallery/Toggle.ui +5 -0
- package/gallery/Transcript-text.ui +1 -0
- package/gallery/Transcript-untimed.ui +1 -0
- package/gallery/Transcript-whisper.ui +1 -0
- package/gallery/Transcript.ui +1 -0
- package/gallery/Tree.ui +3 -0
- package/gallery/Treemap-du.ui +1 -0
- package/gallery/Treemap-esbuild.ui +1 -0
- package/gallery/Treemap-tree.ui +7 -0
- package/gallery/Treemap.ui +18 -0
- package/gallery/Walkthrough.ui +9 -0
- package/gallery/Waterfall-har.ui +1 -0
- package/gallery/Waterfall-trace.ui +1 -0
- package/gallery/Waterfall.ui +11 -0
- package/gallery/data/acceptance/coil/viewport-lifecycle.json +25 -0
- package/gallery/data/acceptance/coil-gate.json +153 -0
- package/gallery/data/acceptance/orbit-baseline.json +163 -0
- package/gallery/data/acceptance/shots/gate-cell-opened.png +0 -0
- package/gallery/data/acceptance/shots/gate-light.png +0 -0
- package/gallery/data/acceptance/shots/gate-phone-dark.png +0 -0
- package/gallery/data/activity.json +1 -0
- package/gallery/data/bb-tasks-orb.json +420 -0
- package/gallery/data/biome.json +229 -0
- package/gallery/data/compare/status-after.png +0 -0
- package/gallery/data/compare/status-before.png +0 -0
- package/gallery/data/compare/status-dark-2x.png +0 -0
- package/gallery/data/compare/status-rerender.png +0 -0
- package/gallery/data/coverage-py.json +1 -0
- package/gallery/data/coverage-summary.json +1 -0
- package/gallery/data/coverage.out +23 -0
- package/gallery/data/deploys.json +1 -0
- package/gallery/data/device-runs.json +285 -0
- package/gallery/data/du-node-modules.txt +359 -0
- package/gallery/data/esbuild-meta.json +292 -0
- package/gallery/data/eslint.json +266 -0
- package/gallery/data/eslint.sarif +343 -0
- package/gallery/data/findings-review.json +76 -0
- package/gallery/data/gh-issues-nextjs.json +293 -0
- package/gallery/data/gh-pr-checks.json +272 -0
- package/gallery/data/gh-prs-nextjs.json +419 -0
- package/gallery/data/gh-run-failed.json +1 -0
- package/gallery/data/gh-run-passed.json +1 -0
- package/gallery/data/gh-run-running.json +1 -0
- package/gallery/data/github-release.json +57 -0
- package/gallery/data/hyperfine-startup.json +187 -0
- package/gallery/data/lcov.info +234 -0
- package/gallery/data/logs/media-sync.log +127 -0
- package/gallery/data/logs/thumbnailer.jsonl +17 -0
- package/gallery/data/logs/vitest-run.log +89 -0
- package/gallery/data/npm-audit.json +672 -0
- package/gallery/data/npm-outdated.json +179 -0
- package/gallery/data/oxlint.json +156 -0
- package/gallery/data/pip-outdated.json +68 -0
- package/gallery/data/pnpm-outdated.json +58 -0
- package/gallery/data/provenance/devicectl-install.json +35 -0
- package/gallery/data/provenance/install-timeout.log +4 -0
- package/gallery/data/provenance/iphone-install.json +72 -0
- package/gallery/data/provenance/iphone-no-receipt.json +57 -0
- package/gallery/data/provenance/live-home.jpg +0 -0
- package/gallery/data/provenance/live-probe.txt +10 -0
- package/gallery/data/provenance/xcodebuild-2811.log +19 -0
- package/gallery/data/provenance/xcodebuild-4712.log +19 -0
- package/gallery/data/pytest-junit.xml +64 -0
- package/gallery/data/python-org-trace.json +35 -0
- package/gallery/data/python-org.har +31 -0
- package/gallery/data/retry.ts +13 -0
- package/gallery/data/ruff.json +261 -0
- package/gallery/data/src/durations.py +63 -0
- package/gallery/data/src/json-logic.ts +156 -0
- package/gallery/data/src/mapMath.ts +135 -0
- package/gallery/data/src/semver/bump.go +73 -0
- package/gallery/data/traces/browser-error.json +5 -0
- package/gallery/data/traces/go/main.go +27 -0
- package/gallery/data/traces/go-panic.txt +16 -0
- package/gallery/data/traces/java-caused-by.txt +15 -0
- package/gallery/data/traces/node-aggregate.txt +30 -0
- package/gallery/data/traces/node-cause.txt +21 -0
- package/gallery/data/traces/py/deploy.json +5 -0
- package/gallery/data/traces/py/deploy.py +17 -0
- package/gallery/data/traces/py/settings.py +19 -0
- package/gallery/data/traces/python-chain.txt +30 -0
- package/gallery/data/traces/rust/main.rs +11 -0
- package/gallery/data/traces/rust-panic.txt +16 -0
- package/gallery/data/traces/shop/cart.mjs +19 -0
- package/gallery/data/traces/shop/pricing.mjs +12 -0
- package/gallery/data/traces/shop/status.mjs +9 -0
- package/gallery/data/traces/web/app.js +11 -0
- package/gallery/data/traces/web/index.html +1 -0
- package/gallery/data/traces/web/search.js +10 -0
- package/gallery/data/transcript/call-noisy.wav +0 -0
- package/gallery/data/transcript/call.json +362 -0
- package/gallery/data/transcript/call.wav +0 -0
- package/gallery/data/transcript/mlx-whisper-tiny.en-noisy.json +1 -0
- package/gallery/data/transcript/whisper-cpp-base.en-noisy.json +658 -0
- package/gallery/data/transcript/whisper-cpp-base.en.json +658 -0
- package/gallery/data/transcript/whisper-cpp-base.en.srt +16 -0
- package/gallery/data/transcript/whisper-cpp-tiny.en-noisy.json +619 -0
- package/gallery/data/tsc.txt +4 -0
- package/gallery/data/vitest-bench.json +119 -0
- package/gallery/data/vitest-junit.xml +133 -0
- package/gallery/data/vitest-report.json +612 -0
- package/gallery/images/bell.svg +10 -0
- package/gallery/images/bike.svg +47 -0
- package/gallery/images/footer-planet.webp +0 -0
- package/gallery/images/front-light.svg +13 -0
- package/gallery/images/golden-hour.webp +0 -0
- package/gallery/images/option-flowers.webp +0 -0
- package/gallery/images/option-hilltop.webp +0 -0
- package/gallery/images/option-meadow.webp +0 -0
- package/gallery/images/option-sky.webp +0 -0
- package/gallery/images/u-lock.svg +10 -0
- package/index.client.tsx +164 -0
- package/index.server.ts +216 -0
- package/package.json +50 -4
- package/paseo-plugin.json +14 -0
- package/server/data-source.ts +407 -0
- package/server/project.ts +981 -0
- package/server/web/address.ts +57 -0
- package/server/web/cache.ts +85 -0
- package/server/web/commons.ts +126 -0
- package/server/web/geocode.ts +40 -0
- package/server/web/image.ts +35 -0
- package/server/web/lookups.ts +248 -0
- package/server/web/net.ts +210 -0
- package/shared/core/acceptance.ts +744 -0
- package/shared/core/ast.ts +76 -0
- package/shared/core/benchmark.ts +743 -0
- package/shared/core/catalog.ts +733 -0
- package/shared/core/compare.ts +225 -0
- package/shared/core/coverage.ts +456 -0
- package/shared/core/data.ts +334 -0
- package/shared/core/decisions.ts +527 -0
- package/shared/core/dependencies.ts +604 -0
- package/shared/core/diagnostics.ts +24 -0
- package/shared/core/environments.ts +212 -0
- package/shared/core/evaluate.ts +737 -0
- package/shared/core/fields.ts +66 -0
- package/shared/core/findings.ts +1172 -0
- package/shared/core/form.ts +69 -0
- package/shared/core/index.ts +44 -0
- package/shared/core/junit.ts +252 -0
- package/shared/core/lexer.ts +275 -0
- package/shared/core/logs.ts +496 -0
- package/shared/core/markdown.ts +2374 -0
- package/shared/core/parser.ts +355 -0
- package/shared/core/perf-units.ts +228 -0
- package/shared/core/pipeline.ts +679 -0
- package/shared/core/project.ts +472 -0
- package/shared/core/provenance.ts +725 -0
- package/shared/core/stack-trace.ts +718 -0
- package/shared/core/streaming.ts +136 -0
- package/shared/core/test-results.ts +562 -0
- package/shared/core/thread-activity.ts +203 -0
- package/shared/core/tracking.ts +887 -0
- package/shared/core/transcript.ts +1364 -0
- package/shared/core/treemap.ts +446 -0
- package/shared/core/types.ts +70 -0
- package/shared/core/validate.ts +574 -0
- package/shared/core/waterfall.ts +536 -0
- package/shared/diagram/flowchart.ts +205 -0
- package/shared/diagram/layout.ts +440 -0
- package/shared/diagram/markdown.ts +135 -0
- package/shared/diagram/sequence.ts +122 -0
- package/shared/diagram/zoom.ts +114 -0
- package/shared/fallback.ts +120 -0
- package/shared/genui.test.ts +122 -0
- package/shared/instructions.ts +144 -0
- package/shared/logic/calendarMath.ts +130 -0
- package/shared/logic/chartMath.ts +289 -0
- package/shared/logic/choose-logic.ts +196 -0
- package/shared/logic/compare-logic.ts +270 -0
- package/shared/logic/content-model.ts +227 -0
- package/shared/logic/environments-logic.ts +53 -0
- package/shared/logic/explain-logic.ts +315 -0
- package/shared/logic/fieldLogic.ts +138 -0
- package/shared/logic/gallery-search.ts +71 -0
- package/shared/logic/icons.ts +322 -0
- package/shared/logic/json-logic.ts +153 -0
- package/shared/logic/mapMath.ts +133 -0
- package/shared/logic/project-logic.ts +39 -0
- package/shared/logic/references-model.ts +201 -0
- package/shared/logic/sketch.ts +165 -0
- package/shared/logic/supersession.ts +77 -0
- package/shared/logic/values.ts +133 -0
- package/shared/logic/widget-logic.ts +163 -0
- package/shared/rpc.ts +252 -0
- package/shared/segment.ts +81 -0
- package/shared/settings.ts +12 -0
|
@@ -0,0 +1,679 @@
|
|
|
1
|
+
// What `Pipeline` shows, from the three shapes it takes: `gh run view --json
|
|
2
|
+
// name,displayTitle,status,conclusion,event,headBranch,headSha,url,createdAt,updatedAt,jobs`
|
|
3
|
+
// (or any subset that has `jobs`), `gh pr checks --json
|
|
4
|
+
// name,state,bucket,link,startedAt,completedAt,workflow`, and a hand-written
|
|
5
|
+
// list of stages `{name, status, duration?, url?, jobs?: [{name, status,
|
|
6
|
+
// duration?, url?, steps?}]}`. Pure: no React, no DOM.
|
|
7
|
+
import type { Value } from "./types";
|
|
8
|
+
|
|
9
|
+
export type PipelineStatus = "failure" | "in_progress" | "queued" | "cancelled" | "success" | "neutral" | "skipped";
|
|
10
|
+
|
|
11
|
+
export interface PipelineStep {
|
|
12
|
+
readonly name: string;
|
|
13
|
+
readonly number: number | null;
|
|
14
|
+
readonly status: PipelineStatus;
|
|
15
|
+
/** The tool's own word where it says more than the status: "timed out", "waiting". */
|
|
16
|
+
readonly detail: string | null;
|
|
17
|
+
readonly ms: number | null;
|
|
18
|
+
/** What a hand-written list says went wrong. */
|
|
19
|
+
readonly message: string | null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface PipelineJob {
|
|
23
|
+
readonly name: string;
|
|
24
|
+
readonly status: PipelineStatus;
|
|
25
|
+
readonly detail: string | null;
|
|
26
|
+
readonly url: string | null;
|
|
27
|
+
/** Epoch ms; null when the job has not started or the data has no times. */
|
|
28
|
+
readonly startedAt: number | null;
|
|
29
|
+
/** How long it ran (so far, for a running job, up to the newest time in the data); null when unknown. */
|
|
30
|
+
readonly ms: number | null;
|
|
31
|
+
/** Where its bar starts, in ms from the run's first start; null when the data has no timeline. */
|
|
32
|
+
readonly offset: number | null;
|
|
33
|
+
readonly steps: readonly PipelineStep[];
|
|
34
|
+
/** Index in `steps` of the first failed step; -1 when none failed. */
|
|
35
|
+
readonly failedStep: number;
|
|
36
|
+
readonly message: string | null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface PipelineStage {
|
|
40
|
+
/** The stage's or workflow's name; null for stages inferred from times. */
|
|
41
|
+
readonly name: string | null;
|
|
42
|
+
readonly status: PipelineStatus;
|
|
43
|
+
readonly url: string | null;
|
|
44
|
+
readonly ms: number | null;
|
|
45
|
+
readonly jobs: readonly PipelineJob[];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export type PipelineSource = "run" | "checks" | "list";
|
|
49
|
+
|
|
50
|
+
export interface PipelineRun {
|
|
51
|
+
readonly source: PipelineSource;
|
|
52
|
+
/** The workflow's name. */
|
|
53
|
+
readonly name: string | null;
|
|
54
|
+
/** What the run is about: the commit or pull request title. */
|
|
55
|
+
readonly title: string | null;
|
|
56
|
+
readonly status: PipelineStatus;
|
|
57
|
+
readonly detail: string | null;
|
|
58
|
+
readonly branch: string | null;
|
|
59
|
+
readonly sha: string | null;
|
|
60
|
+
readonly event: string | null;
|
|
61
|
+
readonly url: string | null;
|
|
62
|
+
/** Epoch ms the run was created or its first job started. */
|
|
63
|
+
readonly startedAt: number | null;
|
|
64
|
+
/** The newest time in the data: what a running run's "so far" is measured to; null when the data has no times. */
|
|
65
|
+
readonly asOf: number | null;
|
|
66
|
+
/** The whole run; null while it runs or when nothing is timed. */
|
|
67
|
+
readonly ms: number | null;
|
|
68
|
+
/** The length every job's `offset` and `ms` is drawn against; null when no job is timed. */
|
|
69
|
+
readonly span: number | null;
|
|
70
|
+
/**
|
|
71
|
+
* `stages`: stages that run one after another (a list's stages, or a gh
|
|
72
|
+
* run's jobs grouped by when they started: gh's JSON has no `needs`);
|
|
73
|
+
* `groups`: independent groups (a pull request's checks by workflow).
|
|
74
|
+
*/
|
|
75
|
+
readonly layout: "stages" | "groups";
|
|
76
|
+
readonly stages: readonly PipelineStage[];
|
|
77
|
+
readonly counts: Readonly<Record<PipelineStatus, number>>;
|
|
78
|
+
readonly jobCount: number;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export type PipelineResult = { readonly ok: true; readonly run: PipelineRun } | { readonly ok: false; readonly error: string };
|
|
82
|
+
|
|
83
|
+
const SHAPE_HINT =
|
|
84
|
+
"Pipeline needs gh run view --json …,jobs, gh pr checks --json name,state,bucket,…, or a list of stages [{name, status, jobs?}]";
|
|
85
|
+
|
|
86
|
+
/** Inferred stages past this many read as noise: the jobs show as one list. */
|
|
87
|
+
const MAX_INFERRED_STAGES = 8;
|
|
88
|
+
|
|
89
|
+
/** A plain data object's fields; absent keys read as undefined. */
|
|
90
|
+
type Fields = Readonly<Record<string, Value | undefined>>;
|
|
91
|
+
|
|
92
|
+
function fieldsOf(value: Value | undefined): Fields | null {
|
|
93
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
|
|
94
|
+
if ("kind" in value && (value.kind === "node" || value.kind === "action" || value.kind === "binding")) return null;
|
|
95
|
+
return value as Fields;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function str(value: Value | undefined): string | null {
|
|
99
|
+
if (typeof value === "string") return value.trim() === "" ? null : value.trim();
|
|
100
|
+
if (typeof value === "number" && Number.isFinite(value)) return String(value);
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function webUrl(value: Value | undefined): string | null {
|
|
105
|
+
const text = str(value);
|
|
106
|
+
return text !== null && /^https?:\/\/\S+$/i.test(text) ? text : null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** An ISO time as epoch ms; GitHub's `0001-01-01T00:00:00Z` (not yet) and anything unparsable are null. */
|
|
110
|
+
export function timestamp(value: Value | undefined): number | null {
|
|
111
|
+
const text = str(value);
|
|
112
|
+
if (text === null) return null;
|
|
113
|
+
const ms = Date.parse(text);
|
|
114
|
+
return Number.isFinite(ms) && ms > 0 ? ms : null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// ---------------------------------------------------------------------------
|
|
118
|
+
// Status words
|
|
119
|
+
|
|
120
|
+
const STATUS_WORDS: Readonly<Record<string, readonly [PipelineStatus, string | null]>> = {
|
|
121
|
+
success: ["success", null],
|
|
122
|
+
succeeded: ["success", null],
|
|
123
|
+
successful: ["success", null],
|
|
124
|
+
pass: ["success", null],
|
|
125
|
+
passed: ["success", null],
|
|
126
|
+
passing: ["success", null],
|
|
127
|
+
ok: ["success", null],
|
|
128
|
+
done: ["success", null],
|
|
129
|
+
completed: ["success", null],
|
|
130
|
+
complete: ["success", null],
|
|
131
|
+
green: ["success", null],
|
|
132
|
+
failure: ["failure", null],
|
|
133
|
+
failed: ["failure", null],
|
|
134
|
+
fail: ["failure", null],
|
|
135
|
+
failing: ["failure", null],
|
|
136
|
+
error: ["failure", "error"],
|
|
137
|
+
errored: ["failure", "error"],
|
|
138
|
+
broken: ["failure", null],
|
|
139
|
+
red: ["failure", null],
|
|
140
|
+
timedout: ["failure", "timed out"],
|
|
141
|
+
timeout: ["failure", "timed out"],
|
|
142
|
+
startupfailure: ["failure", "startup failure"],
|
|
143
|
+
actionrequired: ["failure", "action required"],
|
|
144
|
+
inprogress: ["in_progress", null],
|
|
145
|
+
running: ["in_progress", null],
|
|
146
|
+
active: ["in_progress", null],
|
|
147
|
+
started: ["in_progress", null],
|
|
148
|
+
building: ["in_progress", null],
|
|
149
|
+
deploying: ["in_progress", null],
|
|
150
|
+
queued: ["queued", null],
|
|
151
|
+
pending: ["queued", null],
|
|
152
|
+
waiting: ["queued", "waiting"],
|
|
153
|
+
requested: ["queued", null],
|
|
154
|
+
scheduled: ["queued", null],
|
|
155
|
+
expected: ["queued", "expected"],
|
|
156
|
+
blocked: ["queued", "blocked"],
|
|
157
|
+
cancelled: ["cancelled", null],
|
|
158
|
+
canceled: ["cancelled", null],
|
|
159
|
+
cancel: ["cancelled", null],
|
|
160
|
+
aborted: ["cancelled", null],
|
|
161
|
+
stopped: ["cancelled", null],
|
|
162
|
+
skipped: ["skipped", null],
|
|
163
|
+
skipping: ["skipped", null],
|
|
164
|
+
skip: ["skipped", null],
|
|
165
|
+
neutral: ["neutral", null],
|
|
166
|
+
stale: ["neutral", "stale"],
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
/** A status word (any case, `_`/`-`/space ignored) as a status and its detail; null when it is no status. */
|
|
170
|
+
export function pipelineStatus(value: Value | undefined): { readonly status: PipelineStatus; readonly detail: string | null } | null {
|
|
171
|
+
if (typeof value === "boolean") return { status: value ? "success" : "failure", detail: null };
|
|
172
|
+
if (typeof value !== "string") return null;
|
|
173
|
+
const word = value.trim().toLowerCase().replace(/[\s_-]+/g, "");
|
|
174
|
+
if (!Object.hasOwn(STATUS_WORDS, word)) return null;
|
|
175
|
+
const [status, detail] = STATUS_WORDS[word];
|
|
176
|
+
return { status, detail };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** A gh run, job or step: `status` until it completes, then its `conclusion`. */
|
|
180
|
+
function ghStatus(fields: Fields): { status: PipelineStatus; detail: string | null } {
|
|
181
|
+
const state = str(fields.status)?.toLowerCase() ?? null;
|
|
182
|
+
if (state === "completed" || state === null) {
|
|
183
|
+
const conclusion = pipelineStatus(fields.conclusion ?? undefined);
|
|
184
|
+
if (conclusion !== null) return conclusion;
|
|
185
|
+
return state === "completed" ? { status: "neutral", detail: null } : { status: "queued", detail: null };
|
|
186
|
+
}
|
|
187
|
+
return pipelineStatus(state) ?? { status: "queued", detail: state };
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** The state a set of jobs adds up to. */
|
|
191
|
+
export function overallStatus(statuses: readonly PipelineStatus[]): PipelineStatus {
|
|
192
|
+
if (statuses.length === 0) return "neutral";
|
|
193
|
+
const has = (status: PipelineStatus) => statuses.includes(status);
|
|
194
|
+
if (has("failure")) return "failure";
|
|
195
|
+
if (has("in_progress")) return "in_progress";
|
|
196
|
+
if (has("queued")) return statuses.every((status) => status === "queued") || !has("success") ? "queued" : "in_progress";
|
|
197
|
+
if (has("cancelled")) return "cancelled";
|
|
198
|
+
if (has("success")) return "success";
|
|
199
|
+
if (statuses.every((status) => status === "skipped")) return "skipped";
|
|
200
|
+
return "neutral";
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** Failures first, then running, queued…; the given order otherwise. */
|
|
204
|
+
function byAttention<T extends { readonly status: PipelineStatus }>(items: readonly T[]): T[] {
|
|
205
|
+
return items
|
|
206
|
+
.map((item, index) => ({ item, index }))
|
|
207
|
+
.sort((a, b) => STATUS_ORDER.indexOf(a.item.status) - STATUS_ORDER.indexOf(b.item.status) || a.index - b.index)
|
|
208
|
+
.map(({ item }) => item);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* The label two or more job names share before a separator, as a matrix
|
|
213
|
+
* names its jobs ("Build&Test: node-24, macos-latest", "test (ubuntu, 20)",
|
|
214
|
+
* "e2e / chromium"), so a stage can say it once: the label and how much of
|
|
215
|
+
* each name it covers. Null when they share none.
|
|
216
|
+
*/
|
|
217
|
+
export function matrixPrefix(names: readonly string[]): { readonly label: string; readonly length: number } | null {
|
|
218
|
+
if (names.length < 2) return null;
|
|
219
|
+
const head = (name: string) => /^(.+?)(?::\s+|\s+(?=\()|\s+[-/›]\s+)(?=\S)/.exec(name);
|
|
220
|
+
const first = head(names[0]);
|
|
221
|
+
if (first === null) return null;
|
|
222
|
+
return names.every((name) => head(name)?.[0] === first[0]) ? { label: first[1], length: first[0].length } : null;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// ---------------------------------------------------------------------------
|
|
226
|
+
// Durations
|
|
227
|
+
|
|
228
|
+
/** `850ms`, `45s`, `1.5 s`, `1m 20s`, `2h 5m`, `01:23`, `1:02:03`; numbers are seconds. Null when unreadable. */
|
|
229
|
+
export function parseDuration(value: Value | undefined): number | null {
|
|
230
|
+
if (typeof value === "number") return Number.isFinite(value) && value >= 0 ? value * 1000 : null;
|
|
231
|
+
if (typeof value !== "string") return null;
|
|
232
|
+
const text = value.trim().toLowerCase();
|
|
233
|
+
if (text === "") return null;
|
|
234
|
+
const clock = /^(?:(\d+):)?(\d{1,2}):(\d{2})(?:\.(\d+))?$/.exec(text);
|
|
235
|
+
if (clock !== null) {
|
|
236
|
+
const [, h, m, s] = clock;
|
|
237
|
+
return ((Number(h ?? 0) * 60 + Number(m)) * 60 + Number(s)) * 1000;
|
|
238
|
+
}
|
|
239
|
+
if (/^\d+(\.\d+)?$/.test(text)) return Number(text) * 1000;
|
|
240
|
+
const unit = /(\d+(?:\.\d+)?)\s*(ms|milliseconds?|s|secs?|seconds?|m|mins?|minutes?|h|hrs?|hours?)\b/g;
|
|
241
|
+
let total = 0;
|
|
242
|
+
let matched = "";
|
|
243
|
+
for (const match of text.matchAll(unit)) {
|
|
244
|
+
const amount = Number(match[1]);
|
|
245
|
+
const word = match[2];
|
|
246
|
+
total += word.startsWith("ms") || word.startsWith("milli") ? amount : word.startsWith("s") ? amount * 1000 : word.startsWith("m") ? amount * 60_000 : amount * 3_600_000;
|
|
247
|
+
matched += match[0];
|
|
248
|
+
}
|
|
249
|
+
// Everything but spaces and commas must have been read.
|
|
250
|
+
return matched !== "" && matched.replace(/\s/g, "").length === text.replace(/[\s,]/g, "").length ? total : null;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/** CI style: `0s`, `<1s`, `45s`, `1m 34s`, `1h 05m`. */
|
|
254
|
+
export function formatElapsed(ms: number): string {
|
|
255
|
+
if (!(ms > 0)) return "0s";
|
|
256
|
+
if (ms < 1000) return ms < 950 ? "<1s" : "1s";
|
|
257
|
+
const seconds = Math.round(ms / 1000);
|
|
258
|
+
if (seconds < 60) return `${seconds}s`;
|
|
259
|
+
const hours = Math.floor(seconds / 3600);
|
|
260
|
+
const minutes = Math.floor((seconds % 3600) / 60);
|
|
261
|
+
if (hours > 0) return `${hours}h ${String(minutes).padStart(2, "0")}m`;
|
|
262
|
+
return `${minutes}m ${String(seconds % 60).padStart(2, "0")}s`;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// ---------------------------------------------------------------------------
|
|
266
|
+
// Readers
|
|
267
|
+
|
|
268
|
+
interface TimedJob {
|
|
269
|
+
readonly job: Omit<PipelineJob, "offset">;
|
|
270
|
+
readonly startedAt: number | null;
|
|
271
|
+
readonly completedAt: number | null;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/** A gh step: `{name, status, conclusion, number, startedAt, completedAt}`. */
|
|
275
|
+
function ghStep(value: Value): PipelineStep | null {
|
|
276
|
+
const fields = fieldsOf(value);
|
|
277
|
+
const name = fields === null ? null : str(fields.name);
|
|
278
|
+
if (fields === null || name === null) return null;
|
|
279
|
+
const { status, detail } = ghStatus(fields);
|
|
280
|
+
const start = timestamp(fields.startedAt);
|
|
281
|
+
const end = timestamp(fields.completedAt);
|
|
282
|
+
const number = typeof fields.number === "number" && Number.isSafeInteger(fields.number) ? fields.number : null;
|
|
283
|
+
return { name, number, status, detail, ms: start !== null && end !== null ? Math.max(0, end - start) : null, message: null };
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/** A gh job; a running job is timed up to `asOf`, the newest time in the data. */
|
|
287
|
+
function ghJob(value: Value, asOf: number | null): TimedJob | null {
|
|
288
|
+
const fields = fieldsOf(value);
|
|
289
|
+
const name = fields === null ? null : str(fields.name);
|
|
290
|
+
if (fields === null || name === null) return null;
|
|
291
|
+
const { status, detail } = ghStatus(fields);
|
|
292
|
+
const steps = Array.isArray(fields.steps) ? fields.steps.flatMap((step) => ghStep(step) ?? []) : [];
|
|
293
|
+
const startedAt = timestamp(fields.startedAt);
|
|
294
|
+
// A skipped job can report its completion a second before its start.
|
|
295
|
+
const completedAt = startedAt === null ? null : (() => {
|
|
296
|
+
const end = timestamp(fields.completedAt);
|
|
297
|
+
return end === null ? null : Math.max(end, startedAt);
|
|
298
|
+
})();
|
|
299
|
+
const end = completedAt ?? (status === "in_progress" ? asOf : null);
|
|
300
|
+
const ms = startedAt !== null && end !== null ? Math.max(0, end - startedAt) : null;
|
|
301
|
+
return {
|
|
302
|
+
job: { name, status, detail, url: webUrl(fields.url), startedAt, ms, steps, failedStep: steps.findIndex((step) => step.status === "failure"), message: null },
|
|
303
|
+
startedAt,
|
|
304
|
+
completedAt,
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Jobs grouped into stages by when they ran: a job starts a later stage than
|
|
310
|
+
* every job that had finished by the time it started. gh's JSON has no
|
|
311
|
+
* `needs`, so this is the order things ran in, which for a workflow of
|
|
312
|
+
* dependent jobs is its graph's columns. Jobs that have not started go last.
|
|
313
|
+
*/
|
|
314
|
+
export function inferStages(jobs: readonly TimedJob[]): TimedJob[][] {
|
|
315
|
+
const started = jobs
|
|
316
|
+
.map((job, index) => ({ job, index }))
|
|
317
|
+
.filter(({ job }) => job.startedAt !== null)
|
|
318
|
+
.sort((a, b) => a.job.startedAt! - b.job.startedAt! || a.index - b.index);
|
|
319
|
+
const level = new Map<TimedJob, number>();
|
|
320
|
+
let deepest = 0;
|
|
321
|
+
for (const { job } of started) {
|
|
322
|
+
let stage = 0;
|
|
323
|
+
for (const [other, otherStage] of level) {
|
|
324
|
+
// A skipped job did nothing another could have waited for.
|
|
325
|
+
if (other.job.status === "skipped" || other.completedAt === null || other.completedAt > job.startedAt!) continue;
|
|
326
|
+
stage = Math.max(stage, otherStage + 1);
|
|
327
|
+
}
|
|
328
|
+
level.set(job, stage);
|
|
329
|
+
deepest = Math.max(deepest, stage);
|
|
330
|
+
}
|
|
331
|
+
const waiting = jobs.filter((job) => job.startedAt === null);
|
|
332
|
+
const count = deepest + 1 + (waiting.length > 0 && started.length > 0 ? 1 : 0);
|
|
333
|
+
if (count > MAX_INFERRED_STAGES) return [[...jobs]];
|
|
334
|
+
const stages: TimedJob[][] = Array.from({ length: deepest + 1 }, () => []);
|
|
335
|
+
// Keep the data's order within a stage.
|
|
336
|
+
for (const job of jobs) if (job.startedAt !== null) stages[level.get(job)!].push(job);
|
|
337
|
+
if (waiting.length > 0) stages.push(waiting);
|
|
338
|
+
return stages.filter((stage) => stage.length > 0);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function counted(jobs: readonly { readonly status: PipelineStatus }[]): Record<PipelineStatus, number> {
|
|
342
|
+
const counts: Record<PipelineStatus, number> = { failure: 0, in_progress: 0, queued: 0, cancelled: 0, success: 0, neutral: 0, skipped: 0 };
|
|
343
|
+
for (const job of jobs) counts[job.status]++;
|
|
344
|
+
return counts;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/** Timed jobs placed on a shared axis from the first start. */
|
|
348
|
+
function placed(jobs: readonly TimedJob[]): { jobs: Map<TimedJob, PipelineJob>; start: number | null; span: number | null } {
|
|
349
|
+
const starts = jobs.flatMap((job) => (job.startedAt === null ? [] : [job.startedAt]));
|
|
350
|
+
const start = starts.length === 0 ? null : Math.min(...starts);
|
|
351
|
+
let end = start;
|
|
352
|
+
const out = new Map<TimedJob, PipelineJob>();
|
|
353
|
+
for (const timed of jobs) {
|
|
354
|
+
const offset = start !== null && timed.startedAt !== null ? timed.startedAt - start : null;
|
|
355
|
+
if (offset !== null && timed.job.ms !== null) end = Math.max(end!, start! + offset + timed.job.ms);
|
|
356
|
+
out.set(timed, { ...timed.job, offset });
|
|
357
|
+
}
|
|
358
|
+
return { jobs: out, start, span: start === null || end === null || end <= start ? null : end - start };
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function stageOf(name: string | null, jobs: readonly PipelineJob[], url: string | null = null, ms: number | null = null): PipelineStage {
|
|
362
|
+
const timed = jobs.filter((job) => job.offset !== null && job.ms !== null);
|
|
363
|
+
const wall = timed.length === 0 ? null : Math.max(...timed.map((job) => job.offset! + job.ms!)) - Math.min(...timed.map((job) => job.offset!));
|
|
364
|
+
return { name, status: overallStatus(jobs.map((job) => job.status)), url, ms: ms ?? wall, jobs: byAttention(jobs) };
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function newestTime(values: readonly (number | null)[]): number | null {
|
|
368
|
+
const times = values.filter((value): value is number => value !== null);
|
|
369
|
+
return times.length === 0 ? null : Math.max(...times);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/** Every timestamp a gh run's JSON holds, run, jobs and steps. */
|
|
373
|
+
function ghTimes(run: Fields, jobs: readonly Value[]): (number | null)[] {
|
|
374
|
+
const times = [timestamp(run.createdAt), timestamp(run.updatedAt)];
|
|
375
|
+
for (const value of jobs) {
|
|
376
|
+
const job = fieldsOf(value);
|
|
377
|
+
if (job === null) continue;
|
|
378
|
+
times.push(timestamp(job.startedAt), timestamp(job.completedAt));
|
|
379
|
+
if (Array.isArray(job.steps)) {
|
|
380
|
+
for (const step of job.steps) {
|
|
381
|
+
const fields = fieldsOf(step);
|
|
382
|
+
if (fields !== null) times.push(timestamp(fields.startedAt), timestamp(fields.completedAt));
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
return times;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
function fromGhRun(run: Fields): PipelineRun {
|
|
390
|
+
const values = Array.isArray(run.jobs) ? run.jobs : [];
|
|
391
|
+
const asOf = newestTime(ghTimes(run, values));
|
|
392
|
+
const timed = values.flatMap((value) => ghJob(value, asOf) ?? []);
|
|
393
|
+
const { jobs, start, span } = placed(timed);
|
|
394
|
+
const stages = inferStages(timed).map((stage) => stageOf(null, stage.map((job) => jobs.get(job)!)));
|
|
395
|
+
const all = [...jobs.values()];
|
|
396
|
+
const own = str(run.status) === null && str(run.conclusion) === null ? null : ghStatus(run);
|
|
397
|
+
const { status, detail } = own ?? { status: overallStatus(all.map((job) => job.status)), detail: null };
|
|
398
|
+
const created = timestamp(run.createdAt);
|
|
399
|
+
const updated = timestamp(run.updatedAt);
|
|
400
|
+
const finished = status !== "in_progress" && status !== "queued";
|
|
401
|
+
const ms = finished && created !== null && updated !== null && updated >= created ? updated - created : finished && span !== null ? span : null;
|
|
402
|
+
return {
|
|
403
|
+
source: "run",
|
|
404
|
+
name: str(run.name) ?? str(run.workflowName),
|
|
405
|
+
title: str(run.displayTitle),
|
|
406
|
+
status,
|
|
407
|
+
detail,
|
|
408
|
+
branch: str(run.headBranch),
|
|
409
|
+
sha: str(run.headSha),
|
|
410
|
+
event: str(run.event),
|
|
411
|
+
url: webUrl(run.url),
|
|
412
|
+
startedAt: created ?? start,
|
|
413
|
+
asOf,
|
|
414
|
+
ms,
|
|
415
|
+
span,
|
|
416
|
+
layout: "stages",
|
|
417
|
+
stages,
|
|
418
|
+
counts: counted(all),
|
|
419
|
+
jobCount: all.length,
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/** The run id in a check's Actions link, so two runs of one workflow keep apart. */
|
|
424
|
+
function runIdOf(link: string | null): string | null {
|
|
425
|
+
return link === null ? null : (/\/actions\/runs\/(\d+)/.exec(link)?.[1] ?? null);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
function isCheck(value: Value): boolean {
|
|
429
|
+
const fields = fieldsOf(value);
|
|
430
|
+
return fields !== null && (fields.bucket !== undefined || (fields.state !== undefined && (fields.link !== undefined || fields.workflow !== undefined)));
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
function fromChecks(values: readonly Value[]): PipelineRun {
|
|
434
|
+
const timed: { group: string; workflow: string | null; timed: TimedJob }[] = [];
|
|
435
|
+
for (const value of values) {
|
|
436
|
+
const fields = fieldsOf(value);
|
|
437
|
+
const name = fields === null ? null : str(fields.name);
|
|
438
|
+
if (fields === null || name === null) continue;
|
|
439
|
+
const read = pipelineStatus(fields.state ?? undefined) ?? pipelineStatus(fields.bucket ?? undefined) ?? { status: "neutral" as const, detail: null };
|
|
440
|
+
const startedAt = timestamp(fields.startedAt);
|
|
441
|
+
const end = timestamp(fields.completedAt);
|
|
442
|
+
const completedAt = startedAt !== null && end !== null ? Math.max(end, startedAt) : null;
|
|
443
|
+
const ms = startedAt !== null && completedAt !== null && read.status !== "in_progress" && read.status !== "queued" ? completedAt - startedAt : null;
|
|
444
|
+
const link = webUrl(fields.link);
|
|
445
|
+
const workflow = str(fields.workflow);
|
|
446
|
+
timed.push({
|
|
447
|
+
group: `${workflow ?? ""}\u0000${workflow === null ? "" : (runIdOf(link) ?? "")}`,
|
|
448
|
+
workflow,
|
|
449
|
+
timed: {
|
|
450
|
+
job: { name, status: read.status, detail: read.detail, url: link, startedAt, ms, steps: [], failedStep: -1, message: null },
|
|
451
|
+
startedAt,
|
|
452
|
+
completedAt,
|
|
453
|
+
},
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
const { jobs, start, span } = placed(timed.map(({ timed }) => timed));
|
|
457
|
+
const groups = new Map<string, { workflow: string | null; jobs: PipelineJob[] }>();
|
|
458
|
+
for (const { group, workflow, timed: job } of timed) {
|
|
459
|
+
const entry = groups.get(group) ?? { workflow, jobs: [] };
|
|
460
|
+
entry.jobs.push(jobs.get(job)!);
|
|
461
|
+
groups.set(group, entry);
|
|
462
|
+
}
|
|
463
|
+
// One workflow that ran more than once on this commit numbers its runs by when they started.
|
|
464
|
+
const entries = [...groups.values()];
|
|
465
|
+
const firstStart = (jobs: readonly PipelineJob[]) => Math.min(...jobs.map((job) => job.startedAt ?? Number.POSITIVE_INFINITY));
|
|
466
|
+
const stages = entries.map(({ workflow, jobs: groupJobs }) => {
|
|
467
|
+
const runs = entries.filter((entry) => entry.workflow === workflow);
|
|
468
|
+
const nth = 1 + runs.filter((entry) => firstStart(entry.jobs) < firstStart(groupJobs)).length;
|
|
469
|
+
const name = workflow === null ? "Other checks" : runs.length > 1 ? `${workflow} · run ${nth} of ${runs.length}` : workflow;
|
|
470
|
+
const runUrl = groupJobs.map((job) => job.url).find((url) => url !== null && runIdOf(url) !== null);
|
|
471
|
+
return stageOf(name, groupJobs, workflow === null || runUrl === undefined ? null : runUrl!.replace(/\/job\/\d+.*$/, ""));
|
|
472
|
+
});
|
|
473
|
+
const all = [...jobs.values()];
|
|
474
|
+
const status = overallStatus(all.map((job) => job.status));
|
|
475
|
+
const finished = status !== "in_progress" && status !== "queued";
|
|
476
|
+
return {
|
|
477
|
+
source: "checks",
|
|
478
|
+
name: null,
|
|
479
|
+
title: null,
|
|
480
|
+
status,
|
|
481
|
+
detail: null,
|
|
482
|
+
branch: null,
|
|
483
|
+
sha: null,
|
|
484
|
+
event: null,
|
|
485
|
+
url: null,
|
|
486
|
+
startedAt: start,
|
|
487
|
+
asOf: newestTime(timed.flatMap(({ timed: job }) => [job.startedAt, job.completedAt])),
|
|
488
|
+
ms: finished ? span : null,
|
|
489
|
+
span,
|
|
490
|
+
layout: "groups",
|
|
491
|
+
stages: byAttention(stages),
|
|
492
|
+
counts: counted(all),
|
|
493
|
+
jobCount: all.length,
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/** A hand-written step: a name, or `{name, status?, duration?, message?}`. */
|
|
498
|
+
function listStep(value: Value, jobStatus: PipelineStatus, index: number): PipelineStep | null {
|
|
499
|
+
if (typeof value === "string") {
|
|
500
|
+
const name = value.trim();
|
|
501
|
+
return name === "" ? null : { name, number: index + 1, status: jobStatus === "success" ? "success" : "neutral", detail: null, ms: null, message: null };
|
|
502
|
+
}
|
|
503
|
+
const fields = fieldsOf(value);
|
|
504
|
+
const name = fields === null ? null : (str(fields.name) ?? str(fields.title));
|
|
505
|
+
if (fields === null || name === null) return null;
|
|
506
|
+
const read = pipelineStatus(fields.status ?? fields.conclusion ?? fields.state ?? undefined);
|
|
507
|
+
return {
|
|
508
|
+
name,
|
|
509
|
+
number: index + 1,
|
|
510
|
+
status: read?.status ?? (jobStatus === "success" ? "success" : "neutral"),
|
|
511
|
+
detail: read?.detail ?? null,
|
|
512
|
+
ms: listDuration(fields),
|
|
513
|
+
message: str(fields.message) ?? str(fields.error),
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
function listDuration(fields: Fields): number | null {
|
|
518
|
+
const given = parseDuration(fields.duration ?? fields.time ?? fields.elapsed ?? undefined);
|
|
519
|
+
if (given !== null) return given;
|
|
520
|
+
const start = timestamp(fields.startedAt ?? fields.start ?? undefined);
|
|
521
|
+
const end = timestamp(fields.completedAt ?? fields.end ?? undefined);
|
|
522
|
+
return start !== null && end !== null && end >= start ? end - start : null;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
/** A hand-written job: `{name, status, duration?, url?, steps?, message?}`. */
|
|
526
|
+
function listJob(value: Value): Omit<PipelineJob, "offset"> | null {
|
|
527
|
+
const fields = fieldsOf(value);
|
|
528
|
+
const name = typeof value === "string" ? value.trim() || null : fields === null ? null : (str(fields.name) ?? str(fields.title));
|
|
529
|
+
if (name === null) return null;
|
|
530
|
+
if (fields === null) return { name, status: "neutral", detail: null, url: null, startedAt: null, ms: null, steps: [], failedStep: -1, message: null };
|
|
531
|
+
const read = pipelineStatus(fields.status ?? fields.conclusion ?? fields.state ?? undefined);
|
|
532
|
+
const status = read?.status ?? "neutral";
|
|
533
|
+
const steps = Array.isArray(fields.steps) ? fields.steps.flatMap((step, index) => listStep(step, status, index) ?? []) : [];
|
|
534
|
+
return {
|
|
535
|
+
name,
|
|
536
|
+
status,
|
|
537
|
+
detail: read?.detail ?? null,
|
|
538
|
+
url: webUrl(fields.url ?? fields.link ?? undefined),
|
|
539
|
+
startedAt: timestamp(fields.startedAt ?? fields.start ?? undefined),
|
|
540
|
+
ms: listDuration(fields),
|
|
541
|
+
steps,
|
|
542
|
+
failedStep: steps.findIndex((step) => step.status === "failure"),
|
|
543
|
+
message: str(fields.message) ?? str(fields.error),
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
function fromList(values: readonly Value[], header: Fields | null): PipelineRun {
|
|
548
|
+
// Each item is a stage; one without jobs is a stage of one job, itself.
|
|
549
|
+
const raw = values.flatMap((value) => {
|
|
550
|
+
const fields = fieldsOf(value);
|
|
551
|
+
const self = listJob(value);
|
|
552
|
+
if (self === null) return [];
|
|
553
|
+
const nested = fields !== null && Array.isArray(fields.jobs) ? fields.jobs.flatMap((job) => listJob(job) ?? []) : [];
|
|
554
|
+
// A stage's own status, when the list gives one, wins over its jobs'.
|
|
555
|
+
const own = nested.length > 0 && fields !== null && pipelineStatus(fields.status ?? fields.conclusion ?? fields.state ?? undefined) !== null;
|
|
556
|
+
return [{ self, jobs: nested.length > 0 ? nested : [self], own }];
|
|
557
|
+
});
|
|
558
|
+
// Stages run one after another: with every stage timed, jobs sit on one axis.
|
|
559
|
+
const stageMs = raw.map(({ self, jobs }) => self.ms ?? (jobs.every((job) => job.ms !== null) ? Math.max(...jobs.map((job) => job.ms!)) : null));
|
|
560
|
+
const sequential = raw.length > 0 && stageMs.every((ms) => ms !== null);
|
|
561
|
+
const longest = Math.max(0, ...raw.flatMap(({ jobs }) => jobs.map((job) => job.ms ?? 0)));
|
|
562
|
+
let cursor = 0;
|
|
563
|
+
const stages = raw.map(({ self, jobs, own }, index) => {
|
|
564
|
+
const at = cursor;
|
|
565
|
+
if (sequential) cursor += stageMs[index]!;
|
|
566
|
+
const stage = stageOf(
|
|
567
|
+
self.name,
|
|
568
|
+
jobs.map((job) => ({ ...job, offset: job.ms === null ? null : sequential ? at : 0 })),
|
|
569
|
+
self.url,
|
|
570
|
+
stageMs[index],
|
|
571
|
+
);
|
|
572
|
+
return own ? { ...stage, status: self.status } : stage;
|
|
573
|
+
});
|
|
574
|
+
const all = stages.flatMap((stage) => stage.jobs);
|
|
575
|
+
const span = sequential ? cursor : longest;
|
|
576
|
+
const headerStatus = header === null ? null : pipelineStatus(header.status ?? header.conclusion ?? undefined);
|
|
577
|
+
return {
|
|
578
|
+
source: "list",
|
|
579
|
+
name: header === null ? null : (str(header.name) ?? str(header.workflow)),
|
|
580
|
+
title: header === null ? null : (str(header.title) ?? str(header.displayTitle)),
|
|
581
|
+
status: headerStatus?.status ?? overallStatus(stages.map((stage) => stage.status)),
|
|
582
|
+
detail: headerStatus?.detail ?? null,
|
|
583
|
+
branch: header === null ? null : (str(header.branch) ?? str(header.headBranch)),
|
|
584
|
+
sha: header === null ? null : (str(header.sha) ?? str(header.commit) ?? str(header.headSha)),
|
|
585
|
+
event: header === null ? null : str(header.event),
|
|
586
|
+
url: header === null ? null : webUrl(header.url),
|
|
587
|
+
startedAt: header === null ? null : timestamp(header.startedAt ?? header.createdAt ?? undefined),
|
|
588
|
+
asOf: null,
|
|
589
|
+
ms: (header === null ? null : parseDuration(header.duration ?? undefined)) ?? (sequential && cursor > 0 ? cursor : null),
|
|
590
|
+
span: span > 0 ? span : null,
|
|
591
|
+
layout: "stages",
|
|
592
|
+
stages,
|
|
593
|
+
counts: counted(all),
|
|
594
|
+
jobCount: all.length,
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/** The run `value` describes, or why it can't be read. */
|
|
599
|
+
export function readPipeline(value: Value | undefined): PipelineResult {
|
|
600
|
+
const fields = fieldsOf(value);
|
|
601
|
+
if (Array.isArray(value) && value.some(isCheck)) return { ok: true, run: fromChecks(value) };
|
|
602
|
+
if (fields !== null && Array.isArray(fields.jobs) && (fields.headSha !== undefined || fields.databaseId !== undefined || fields.conclusion !== undefined || isGhJobList(fields.jobs))) {
|
|
603
|
+
return { ok: true, run: fromGhRun(fields) };
|
|
604
|
+
}
|
|
605
|
+
const stages = Array.isArray(value) ? value : fields === null ? null : Array.isArray(fields.stages) ? fields.stages : Array.isArray(fields.jobs) ? fields.jobs : null;
|
|
606
|
+
if (stages !== null) {
|
|
607
|
+
const run = fromList(stages, Array.isArray(value) ? null : fields);
|
|
608
|
+
return stages.length > 0 && run.jobCount === 0 ? { ok: false, error: "Pipeline stages need a name and a status" } : { ok: true, run };
|
|
609
|
+
}
|
|
610
|
+
if (fields !== null && (fields.headSha !== undefined || fields.displayTitle !== undefined)) return { ok: true, run: fromGhRun(fields) };
|
|
611
|
+
return { ok: false, error: SHAPE_HINT };
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
/** gh's job objects carry `startedAt`/`conclusion`/`databaseId`; a hand list rarely does. */
|
|
615
|
+
function isGhJobList(jobs: readonly Value[]): boolean {
|
|
616
|
+
return jobs.some((job) => {
|
|
617
|
+
const fields = fieldsOf(job);
|
|
618
|
+
return fields !== null && (fields.databaseId !== undefined || (fields.conclusion !== undefined && fields.startedAt !== undefined));
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
// ---------------------------------------------------------------------------
|
|
623
|
+
// Words the renderer and the markdown share
|
|
624
|
+
|
|
625
|
+
export const STATUS_LABEL: Record<PipelineStatus, string> = {
|
|
626
|
+
failure: "Failed",
|
|
627
|
+
in_progress: "In progress",
|
|
628
|
+
queued: "Queued",
|
|
629
|
+
cancelled: "Cancelled",
|
|
630
|
+
success: "Succeeded",
|
|
631
|
+
neutral: "Neutral",
|
|
632
|
+
skipped: "Skipped",
|
|
633
|
+
};
|
|
634
|
+
|
|
635
|
+
/** States in attention order: failures, then what still runs, then the rest. */
|
|
636
|
+
export const STATUS_ORDER: readonly PipelineStatus[] = ["failure", "in_progress", "queued", "cancelled", "success", "neutral", "skipped"];
|
|
637
|
+
|
|
638
|
+
/** How a count of jobs in a state reads: "3 failed", "2 running". */
|
|
639
|
+
export const COUNT_WORD: Record<PipelineStatus, string> = {
|
|
640
|
+
failure: "failed",
|
|
641
|
+
in_progress: "running",
|
|
642
|
+
queued: "queued",
|
|
643
|
+
cancelled: "cancelled",
|
|
644
|
+
success: "passed",
|
|
645
|
+
neutral: "neutral",
|
|
646
|
+
skipped: "skipped",
|
|
647
|
+
};
|
|
648
|
+
|
|
649
|
+
/** "1 failed, 7 passed, 1 skipped": attention order, zero counts left out. */
|
|
650
|
+
export function jobCountsText(counts: Readonly<Record<PipelineStatus, number>>, separator = ", "): string {
|
|
651
|
+
const parts = STATUS_ORDER.filter((status) => counts[status] > 0).map((status) => `${counts[status]} ${COUNT_WORD[status]}`);
|
|
652
|
+
return parts.length === 0 ? "no jobs" : parts.join(separator);
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
/** The jobs that failed, each with its first failed step. */
|
|
656
|
+
export function failedJobs(run: PipelineRun): { readonly job: PipelineJob; readonly step: PipelineStep | null }[] {
|
|
657
|
+
return run.stages.flatMap((stage) =>
|
|
658
|
+
stage.jobs.filter((job) => job.status === "failure").map((job) => ({ job, step: job.failedStep < 0 ? null : job.steps[job.failedStep] })),
|
|
659
|
+
);
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
/** What "Investigate" sends: which jobs failed where, and the run's link. */
|
|
663
|
+
export function investigateMessage(run: PipelineRun): string | null {
|
|
664
|
+
const failed = failedJobs(run);
|
|
665
|
+
if (failed.length === 0) return null;
|
|
666
|
+
const subject = run.source === "checks" ? "these checks" : `the ${run.name ?? "CI"} run${run.branch === null ? "" : ` on ${run.branch}`}`;
|
|
667
|
+
const shown = failed.slice(0, 8).map(({ job, step }) => `${job.name}${step === null ? "" : ` (step "${step.name}")`}${job.url === null ? "" : ` ${job.url}`}`);
|
|
668
|
+
const more = failed.length > shown.length ? `; and ${failed.length - shown.length} more` : "";
|
|
669
|
+
return `Find out why ${subject} failed and fix it. Failed: ${shown.join("; ")}${more}${run.url === null ? "" : `. Run: ${run.url}`}`;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
/** What "Re-run failed jobs" sends; null when nothing failed or was cancelled. */
|
|
673
|
+
export function rerunMessage(run: PipelineRun): string | null {
|
|
674
|
+
const failed = run.counts.failure > 0;
|
|
675
|
+
if (!failed && run.status !== "cancelled") return null;
|
|
676
|
+
const what = failed ? (run.source === "checks" ? "the failed checks" : "the failed jobs") : "the cancelled run";
|
|
677
|
+
const of = run.source === "checks" ? "" : ` of ${run.name ?? "the run"}${run.branch === null ? "" : ` on ${run.branch}`}`;
|
|
678
|
+
return `Re-run ${what}${of}${run.url === null ? "" : ` (${run.url})`}.`;
|
|
679
|
+
}
|