Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
test-results/
playwright-report/
dist/
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@ npm start -- --repo ~/code/ionic-framework --pr 31321

Press <kbd>?</kbd> in the app for what each marker means and the keyboard shortcuts.

### Exporting a static site

`export` writes the same review as plain files, for hosting where there is no clone to read from.

```sh
npm run export -- --base origin/main --head my-branch
npm run export -- --base <sha> --head <sha> --out dist --label '#31321 fix(item): ...' --url <pull request>
```

| Option | |
| ------------------------------- | ----------------------------------------------------------------------------------------- |
| `--base <ref>`, `--head <ref>` | Required. A pull request number is not accepted. |
| `--out <dir>` | Defaults to `dist`. An earlier export there is replaced, but any other files are refused. |
| `--label <text>`, `--url <url>` | The header title and its link. Default to the refs. |
| `--repo`, `--path` | Same as above. |

The exported page is read-only. Viewed marks stay in the browser, and a newer push is noticed when the deployment's `head.json` names a different commit.

When `--url` is a pull request, the page loads its comments from GitHub's public API each time it opens, with no comment box. That API allows 60 requests an hour per network, one request per 100 comments, and can't say whether a thread is resolved. A range with no changed screenshots writes nothing and exits successfully.

### Why it needs a local clone

The clone is where everything is read from:
Expand Down
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import playwright from 'eslint-plugin-playwright';
import globals from 'globals';

export default [
{ ignores: ['node_modules/**', 'playwright-report/**', 'test-results/**'] },
{ ignores: ['node_modules/**', 'playwright-report/**', 'test-results/**', 'dist/**'] },

js.configs.recommended,
importPlugin.flatConfigs.recommended,
Expand Down
110 changes: 110 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"scripts": {
"start": "node src/cli.mjs",
"export": "node src/cli.mjs export",
"lint": "eslint . && stylelint \"src/**/*.css\" && prettier \"./**/*.{html,js,mjs,css}\" --write --cache",
"lint.fix": "eslint . --fix && stylelint \"src/**/*.css\" --fix && prettier \"./**/*.{html,js,mjs,css}\" --write --cache",
"test": "npm run test.spec && npm run test.e2e",
Expand All @@ -35,6 +36,7 @@
"eslint-plugin-playwright": "^2.12.0",
"globals": "^17.13.0",
"prettier": "^3.9.9",
"sirv-cli": "^3.0.1",
"stylelint": "^16.26.1",
"stylelint-order": "^7.0.1",
"typescript": "^7.0.2"
Expand Down
10 changes: 7 additions & 3 deletions src/cli.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
#!/usr/bin/env node
/*
* Entry point for npm start. Kept apart from index.mjs so tests can import the
* server's pieces without starting it.
* Entry point for npm start and npm run export. Kept apart from index.mjs so tests can
* import the server's pieces without starting it.
*
* - `export` as the first argument writes a static site instead of serving.
* - Any startup failure, such as no clone found or no screenshots in the range,
* prints as one line and exits with code 1.
*/
import { exportSite } from './export.mjs';
import { main } from './index.mjs';

main().catch((error) => {
const run = process.argv[2] === 'export' ? () => exportSite(process.argv.slice(3)) : main;

run().catch((error) => {
process.stderr.write(`\n ${error.message}\n\n`);
process.exit(1);
});
59 changes: 46 additions & 13 deletions src/client/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
*
* - The comment box, teammates' comments and the c shortcut appear only for a pull
* request with gh signed in. Viewed marks work in every case.
* - A static export shows teammates' comments, read only, when its --url named a pull
* request. It never has a comment box.
* - If a push changed screenshots since they were marked viewed, the sidebar says how
* many lost their mark.
* - The orphans only and encoding only checkboxes appear only when there is one.
* - A newer push is checked for on load and whenever the tab regains focus.
* - A newer push is checked for on load and whenever the tab regains focus. A static
* export also checks when an image fails to load.
* - Every image is prefetched after the first render, so stepping through stays
* instant.
*/
import { renderPublish, wireComments } from './scripts/comments.js';
import { loadThreads, renderPublish, wireComments } from './scripts/comments.js';
import { wireControls } from './scripts/controls.js';
import { dom } from './scripts/dom.js';
import { indexGroups, reencodedOnly } from './scripts/entries.js';
Expand All @@ -20,7 +23,7 @@ import { blobUrl } from './scripts/links.js';
import { renderList, renderProgress } from './scripts/list.js';
import { restoreMode, select } from './scripts/stage.js';
import { state } from './scripts/state.js';
import { checkFreshness } from './scripts/sync.js';
import { checkFreshness, restoreViewed } from './scripts/sync.js';
import { restoreTheme } from './scripts/theme.js';

/**
Expand All @@ -35,16 +38,22 @@ const init = async () => {

window.addEventListener('focus', checkFreshness);

const manifest = await fetch('/api/manifest').then((response) => response.json());
const manifest = await fetch('manifest.json', { cache: 'no-cache' }).then((response) => response.json());

state.static = manifest.static === true;
/* A static export has no server to keep marks, so this browser keeps them, and
reports the ones a push undid the same way the server does. */
const local = state.static ? restoreViewed(manifest.entries) : null;
const saved = local ?? manifest.state;

state.head = manifest.head ?? null;
state.blobBase = manifest.blobBase ?? null;
state.entries = manifest.entries;
state.viewed = new Set(Object.keys(manifest.state.viewed ?? {}));
state.comments = new Map(Object.entries(manifest.state.comments ?? {}));
state.stale = new Set(manifest.state.stale ?? []);
state.unsent = new Set(manifest.state.unsent ?? []);
state.posted = new Set(manifest.state.posted ?? []);
state.viewed = new Set(Object.keys(saved.viewed ?? {}));
state.comments = new Map(Object.entries(saved.comments ?? {}));
state.stale = new Set(saved.stale ?? []);
state.unsent = new Set(saved.unsent ?? []);
state.posted = new Set(saved.posted ?? []);
state.threads = manifest.threads ?? {};
state.pr = manifest.pr ?? null;
state.prState = manifest.prState ?? null;
Expand All @@ -55,12 +64,15 @@ const init = async () => {
never leave this machine. Viewed stays either way: it is how a range is worked
through, pull request or not. */
dom.commentSection.hidden = !state.pr || !state.viewer;
/* Read only, so the section shows threads and nothing to type into. renderThreads
opens it on a screenshot that has some. */
dom.comment.hidden = state.static;
renderPublish();

/* Only the screenshots that lost their tick are worth saying out loud. Carrying
progress over is the expected outcome and needs no announcement; ticks vanishing
without explanation does. */
const { reset = 0 } = manifest.carriedOver ?? {};
const { reset = 0 } = local ?? manifest.carriedOver ?? {};
if (reset) {
dom.carried.hidden = false;
dom.carried.textContent = `${reset} ${
Expand Down Expand Up @@ -97,12 +109,33 @@ const init = async () => {
reported without waiting for the reviewer to mark something. */
checkFreshness();

/* Not awaited: comments arrive whenever GitHub answers, and the prefetch below
shouldn't wait on them. */
if (state.static && manifest.pullRequest) {
loadThreads(manifest.pullRequest);
}

/* A deployment replaced by a newer push serves only that push's images, so one that
fails to load is often the first sign of it. An empty src fires error too, and is
only a side with nothing to show. */
if (state.static) {
dom.stage.addEventListener(
'error',
(event) => {
if (/** @type {HTMLImageElement} */ (event.target).getAttribute('src')) {
checkFreshness();
}
},
true
);
}

/* Warm the cache so stepping through hundreds of screenshots stays instant. */
const queue = state.entries
.flatMap((entry) => [
entry.status === 'A' ? null : blobUrl('expected', entry.path),
entry.status === 'D' ? null : blobUrl('actual', entry.path),
entry.comparable ? blobUrl('diff', entry.path) : null,
entry.status === 'A' ? null : blobUrl('expected', entry),
entry.status === 'D' ? null : blobUrl('actual', entry),
entry.comparable ? blobUrl('diff', entry) : null,
])
.filter(Boolean);

Expand Down
8 changes: 7 additions & 1 deletion src/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
</div>
<p id="carried" class="carried" hidden></p>
<p id="pushed" class="pushed" hidden></p>
<p id="threadsFailed" class="threads-failed" hidden></p>
<div id="facets" class="facets mono"></div>
<nav id="list" class="list"></nav>
</aside>
Expand Down Expand Up @@ -211,7 +212,8 @@ <h2>Filters</h2>
<h2>What needs GitHub</h2>
<ul>
<li>
Marking viewed always works. It is kept in a local file, so the directory ticks, the progress bar,
Marking viewed always works. It is kept in a local file, or in this browser on a hosted review, so the
directory ticks, the progress bar,
<b>Hide viewed</b>, <kbd>v</kbd> and <kbd>V</kbd> behave the same however the review was started.
</li>
<li>
Expand All @@ -231,6 +233,10 @@ <h2>What needs GitHub</h2>
Signed out, a new push is noticed more slowly, because GitHub allows far fewer anonymous requests and the
check is spaced out to stay within them.
</li>
<li>
A hosted review shows the pull request's comments, read anonymously from GitHub when the page opens, but has
no comment box. It can't tell which threads are resolved, so none is marked resolved.
</li>
</ul>
<h2>Keyboard</h2>
<dl>
Expand Down
Loading
Loading