pr-scene
v1.7.0
Published
Demo your action: render believable pull request scenes
Maintainers
Readme
pr-scene
Render a believable pull request — comments, checks, reviews and merge state — from plain JSON, so your GitHub Action's demo page can show what it does before anyone installs it. Framework-agnostic HTML in one scoped stylesheet.
The playground lives at https://radomir.dev/pr-scene/.
Install
npm i pr-sceneQuick start
import { renderScene } from "pr-scene";
import "pr-scene/styles.css";
const scene = {
pr: {
title: "feat(api): add a sliding-window rate limiter",
number: 482,
author: "alex-dev",
base: "main",
head: "feat/rate-limiter",
state: "open",
},
timeline: [
{
kind: "comment",
comment: {
author: "github-actions",
bot: true,
createdAt: "2026-11-26T11:58:00Z",
body: "### CI\n\n- [x] Lint\n- [ ] Tests",
},
},
{ kind: "checks" },
],
checks: [
{ name: "Lint", status: "passed", workflow: "CI", duration: "14s" },
{ name: "Tests", status: "running", workflow: "CI", duration: "32s" },
],
mergeable: true,
};
document.querySelector("#pr").innerHTML = renderScene(scene, { theme: "light" });renderScene returns the whole page: .ps-root carrying the theme, and .ps-page inside it. Pass now to freeze relative timestamps for screenshots.
The scene
pr, timeline, checks, mergeable and view are documented with their types in docs/scene.md. A minimal scene is just { pr }; the checks box then reports that status is pending.
Timeline items render in order:
{ kind: "comment", comment }— a card with avatar, author, optionalbotpill, relative time,editedmarker and sanitised markdown.{ kind: "checks" }— the checks box and merge footer, with a status badge on the timeline rail.{ kind: "review", review }— approved, changes-requested or commented.{ kind: "merged", actor?, sha?, at? }— the purple merge event.
Theming
The stylesheet ships light and dark tokens switched by data-theme on .ps-root. renderScene(scene, { theme }) sets it, and scene.view.theme is the fallback when no option is given.
Markdown
Comment bodies run through marked with GFM, are sanitised with DOMPurify, and get GitHub's task-list classes with their checkboxes enabled. renderMarkdown(source, { mode: "source" }) returns an escaped pre instead, which keeps <!-- slot:name --> markers visible.
Known gaps
Fenced code with a language renders as plain code; GitHub wraps it in syntax-highlighted spans, and pr-scene does not. GitHub alerts (> [!NOTE], TIP, IMPORTANT, WARNING, CAUTION) are supported and covered by the golden fixtures.
Editing a comment
The helpers mirror the radomir-dev/actions contract, so a demo can react the way a workflow does:
import { countTasks, flipTask, replaceSlot, replaceSlots, hasSlot } from "pr-scene";
const body = "- [ ] preview\n- [ ] visual\n\n<!-- slot:footer -->\n\n<!-- /slot:footer -->";
flipTask(body, 1); // ticks the second task
replaceSlots(body, { footer: "[Workflow run](https://github.com/acme/app/actions/runs/1)" });
hasSlot(body, "footer"); // true
countTasks(body); // 2Validation
validateScene(value) returns messages that name the offending path, and renderScene throws with the same text. The JSON Schema ships as pr-scene/scene.schema.json and is committed at schema/scene.schema.json.
API reference
Generated from the TypeScript types into docs/api/. npm run docs regenerates it; npm run docs:check fails when it is stale, and CI regenerates it on main.
Development
npm installinstalls dependencies and the lefthook hooks.npm run devserves the playground.npm run doctorruns every check: typecheck, lint, format, docs, coverage, build, dist verification and end-to-end tests.npm run doctor -- --fastskips the slow end-to-end step, which is what CI runs.npm run shotswrites one screenshot per scenario intoscreenshots/.
Files stop at 150 lines, functions at 30, cognitive complexity at 5.
Releasing
npm run doctornpm run buildnpm publish --access publicfrom the release commit.
Published by hand for now; switching the release workflow to npm trusted publishing is follow-up work (#15).
The package is ESM-only. files ships dist/, which holds the compiled modules, declarations, styles.css and scene.schema.json; sideEffects names the stylesheet so the JavaScript stays tree-shakeable.
License
MIT
