@popcorn245/cornfield 0.50.0 → 0.51.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/explorer/camera-frame.js +82 -0
- package/explorer/camera.js +7 -73
- package/explorer/check-model.js +3 -44
- package/explorer/cloud-model.js +2 -101
- package/explorer/cloud-panel.js +107 -0
- package/explorer/css/review.css +2 -0
- package/explorer/engine/connection.js +4 -1
- package/explorer/engine/map-rect.js +97 -0
- package/explorer/engine/player.js +2 -1
- package/explorer/engine/proposal.js +28 -7
- package/explorer/engine/server-load.js +64 -0
- package/explorer/engine/sheets.js +4 -86
- package/explorer/engine/source-address.js +58 -0
- package/explorer/engine/source.js +16 -45
- package/explorer/engine/theme-sheet.js +23 -1
- package/explorer/engine/topology.js +1 -1
- package/explorer/focus-room.js +1 -7
- package/explorer/focusables.js +1 -1
- package/explorer/forge-panel.js +36 -2630
- package/explorer/index.html +15 -147
- package/explorer/instance-state.js +0 -7
- package/explorer/instance.js +19 -2
- package/explorer/layer-model.js +1 -1
- package/explorer/outage-model.js +6 -76
- package/explorer/outage-scenario.js +83 -0
- package/explorer/page-pieces.js +21 -2
- package/explorer/page.js +3 -3
- package/explorer/panels.js +1 -5
- package/explorer/pieces/layers.js +1 -0
- package/explorer/pieces/node-panel.js +19 -8
- package/explorer/pieces/proposal.js +9 -0
- package/explorer/pieces/review-source.js +84 -0
- package/explorer/pieces/review.js +145 -12
- package/explorer/pieces/scope.js +23 -54
- package/explorer/pieces/status.js +5 -1
- package/explorer/pieces/work-agent.js +211 -0
- package/explorer/pieces/work-common.js +88 -0
- package/explorer/pieces/work-confirm.js +169 -0
- package/explorer/pieces/work-data.js +178 -0
- package/explorer/pieces/work-deploys.js +104 -0
- package/explorer/pieces/work-events.js +285 -0
- package/explorer/pieces/work-issues.js +43 -0
- package/explorer/pieces/work-markup.js +155 -0
- package/explorer/pieces/work-notes.js +177 -0
- package/explorer/pieces/work-paint.js +312 -0
- package/explorer/pieces/work-prs.js +253 -0
- package/explorer/pieces/work-runs.js +387 -0
- package/explorer/pieces/work-specs.js +71 -0
- package/explorer/pieces/work-threads.js +309 -0
- package/explorer/pieces/work.js +285 -0
- package/explorer/proposal-marks.js +220 -0
- package/explorer/proposal-model.js +23 -211
- package/explorer/proposal.js +1 -2
- package/explorer/runs-map.js +108 -103
- package/explorer/runs-view.js +8 -6
- package/explorer/scenario.js +2 -1
- package/explorer/scene.js +2 -2
- package/explorer/selection-model.js +2 -42
- package/explorer/selection-view.js +1 -1
- package/explorer/selection-words.js +52 -0
- package/explorer/strings.js +1 -1
- package/explorer/verdict-paint.js +51 -0
- package/explorer/waiting-model.js +12 -12
- package/explorer/waiting-view.js +6 -6
- package/package.json +1 -1
- package/explorer/feedback.js +0 -15
- package/explorer/waiting-line.js +0 -14
package/explorer/forge-panel.js
CHANGED
|
@@ -1,2649 +1,55 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module explorer/forge-panel
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* The text below describes each view as it was built.
|
|
9
|
-
*
|
|
10
|
-
* The repo's pull requests and issues, from whichever forge
|
|
11
|
-
* the config names, read through the server (`/api/forge/…`, server/forge-routes.js; the signed-in maintainer's own
|
|
12
|
-
* token never leaves it). A header button opens it: a slide-over from the left from 768px, a bottom sheet on a phone
|
|
13
|
-
* (sheets.js). With no forge in the config, or no sign-in (Stage 1: there is nobody to ask the forge as, and the
|
|
14
|
-
* server answers 403), the button and the panel stay hidden and nothing else changes.
|
|
15
|
-
*
|
|
16
|
-
* - Two lists, Pull requests and Issues, with filters on what is loaded: state, label, author and a search
|
|
17
|
-
* box. A row links out to the forge; a pull request's row selects it.
|
|
18
|
-
* - A selected pull request asks for its files and the checks on its head. Each file lights the node whose
|
|
19
|
-
* `file` holds it (the deepest one), a failing check lights the test files its name names, and the rest of the
|
|
20
|
-
* map fades back (`state.forgeLit`, painted by scene.js). A file on no node is listed, with the others, as not on
|
|
21
|
-
* the map. Each node has a button that selects it on the map.
|
|
22
|
-
* - The third tab, Agents, groups the work by what it belongs to (explorer/agents-model.js): one group per proposal
|
|
23
|
-
* (the spec PR and the work on it), per issue (its pull requests and branches) and one for the rest, with the work
|
|
24
|
-
* made by an agent marked and why. Nothing is launched (ADR 0007); a pull request there selects like any other.
|
|
25
|
-
* - A fourth tab, Deploys (PIPE-03, docs/deploys.md): the latest workflow runs that are deploys, each with the nodes
|
|
26
|
-
* the config says it restarted. Selecting one lights those nodes (a stack brings its containers; a failed deploy lights
|
|
27
|
-
* them red) through the same paint path, turning on the layers they are on; a deploy no `deploys.restarts` names is listed and says it lights nothing.
|
|
28
|
-
* Only one thing is selected at a time, a pull request or a deploy.
|
|
29
|
-
* - A Threads tab (docs/threads.md): the ideas (issues labelled `idea`) and the spec PRs' conversations, newest activity first.
|
|
30
|
-
* Opening one shows its messages, read-only, with a link out to the forge to reply (writing happens there, spec 0005 D6), and
|
|
31
|
-
* lights the nodes its text mentions (`[[node-id]]`, `[[repo/path]]`, a `cornfield-thread` block; core/mentions.js) the way a
|
|
32
|
-
* pull request lights its files. "New idea" opens an issue with the label as the signed-in maintainer: a POST to cornfield's
|
|
33
|
-
* own server, which guards, counts and audits it. A node's panel lists the threads that mention it (`state.threadIndex`).
|
|
34
|
-
* - Keys: Tab reaches the header button, Enter opens the panel with the focus on its title; Escape closes it and
|
|
35
|
-
* gives the focus back to the button. What happens (a list loaded, a pull request selected, what it lights, a
|
|
36
|
-
* failure) is said through the map's live region (`announce`, keyboard.js). Closed, the panel is `inert`.
|
|
37
|
-
* - Actions (CF-08), on a selected pull request, for a signed-in maintainer: Land it, when it is open, ready and every
|
|
38
|
-
* check is green, and Re-run on a failed or cancelled check the forge can run again. Where a button is not shown the panel says
|
|
39
|
-
* why. Land it opens a confirm dialog that shows exactly what will land (the pull request, its head commit, where
|
|
40
|
-
* it goes, how, each check); a scrim covers the page, the dialog is `aria-modal`, Tab stays inside, Escape and Cancel close it and give the
|
|
41
|
-
* focus back, and it is announced. What is sent is the head that was shown: a push since is refused by the server,
|
|
42
|
-
* which checks everything again (server/forge-actions.js). While one is in flight the buttons are off.
|
|
43
|
-
* - With `proposals.approveLands` on, a spec pull request that was approved and is waiting for its checks says **Will land when
|
|
44
|
-
* checks pass** (read from `GET /api/forge/pulls/<n>/landing`, the server's own state) with a **Cancel** that POSTs to
|
|
45
|
-
* `…/landing/cancel` (server/lander.js). With the key off the panel asks nothing and shows nothing more.
|
|
46
|
-
* - The pipeline's own steps (PIPE-05, server/pipeline.js), each one button with a confirm step that shows exactly what
|
|
47
|
-
* will be made, read from the server first (the plan, with a digest the server must find again):
|
|
48
|
-
* 1. an open issue in the Issues list has **Start a spec …**: a branch, a stub proposal and a draft spec pull request;
|
|
49
|
-
* 2. a selected spec pull request whose latest maintainer review approves a proposal has **Open the build issue …**:
|
|
50
|
-
* an issue linking the pull request and the proposal, with the node changes as a checklist;
|
|
51
|
-
* 3. **Land it** (above) is the third step.
|
|
52
|
-
* Asking a step again finds what the first ask made and says so; it makes nothing twice. No step starts an agent.
|
|
53
|
-
* - Errors and rate limits are a line in the panel, in the words the server gives; a stale answer says it is old.
|
|
54
|
-
* - A third tab, Release notes (PIPE-04): the pull requests merged since a tag, grouped by what they changed on the
|
|
55
|
-
* map, as Markdown to preview and Copy (the clipboard, else the selected text to copy by hand). "Post as draft"
|
|
56
|
-
* asks first (the tag, and in words what will and will not happen), then POSTs once to the server, which makes the
|
|
57
|
-
* notes again itself and has the forge keep them as a DRAFT release; nothing is published and no tag is made. The
|
|
58
|
-
* page never sends the text of the notes, only the tag. The result, or the forge's refusal, is a line in words.
|
|
59
|
-
*
|
|
60
|
-
* - Agent runs (issue #80, spec 0005, explorer/runs-model.js): **Start an agent** on an open issue and on an issue or proposal group of the Agents
|
|
61
|
-
* tab opens a dialog (kind, a profile when the config lists any, a brief, and in words what it will do) and POSTs once to
|
|
62
|
-
* `/api/agent-runs`; the Agents tab lists the runs with their state, links and a **Stop**, which asks the runner to stop. cornfield only
|
|
63
|
-
* asks: the request is a comment on the forge, as the maintainer. A refusal (the limit, a run already open) is said in the dialog, with
|
|
64
|
-
* a way to ask on purpose where the rule allows it.
|
|
65
|
-
*
|
|
66
|
-
* What is asked, which words and which nodes are forge-panel-model.js, tested without a page.
|
|
67
|
-
*/
|
|
68
|
-
|
|
69
|
-
import { state, nodeById, escHtml, touchScene, onSceneTouch } from './state.js';
|
|
70
|
-
import { render, isNodeVisible } from './render.js';
|
|
71
|
-
import { selectNode, repaintThreads } from './panels.js';
|
|
72
|
-
import { announce } from './keyboard.js';
|
|
73
|
-
import { trapTab } from './focusables.js';
|
|
74
|
-
import { isPhone, registerSheet, expandSheet, collapseSheet, showSheet, refreshStubs } from './sheets.js';
|
|
75
|
-
import { relativeTime } from './review-model.js';
|
|
76
|
-
import { LAYER_DEFS, toggleLayer } from './layers.js';
|
|
77
|
-
import { layerOn } from './layer-model.js';
|
|
78
|
-
import { WORK_URL, groupWork, filterGroups, groupWords, workStatus, markWords } from './agents-model.js';
|
|
79
|
-
import {
|
|
80
|
-
RUNS_URL, runsUrl, stopUrl, runOnThread, threadRunWords, runOnPull, pullRunWords, canRetry, retryRefs, retryWords, limitsFromFields, defaultLimits, LIMIT_KEYS, briefUrl, answerUrl, answerBody, answerWordsFor, KINDS, aboutWords, statusWords, statusWhy, runMeta, canStop, runsStatus, runnerState, runnerWords, triggerNotice, totalsLines, handLines, startBody, startWords, stopWords, confirmStartWords, litOfRun, changeWords,
|
|
81
|
-
} from './runs-model.js';
|
|
82
|
-
import { runsHtml, totalsHtml, loadingRowsHtml, loadingLinesHtml, runPillHtml } from './runs-view.js';
|
|
83
|
-
import { setRunsOnMap, clearRunsOnMap } from './runs-map.js';
|
|
84
|
-
import {
|
|
85
|
-
STATES, defaultFilters, listUrl, pullUrl, serverState, filterItems, facetsOf, stateWords, metaWords, checkWords, checksWords, litFor, errorWords,
|
|
86
|
-
landingUrl, cancelLandingUrl, landingWords, mergeBlock, rerunWhy, confirmMerge, mergeBody, actionUrl, actionWords,
|
|
87
|
-
specBlock, buildOffers, planUrl, confirmSpec, confirmBuild, specBody, buildBody, existingWords,
|
|
88
|
-
listKeyOf, litForDeploy, nodesForRestarts, deployWords, deployMeta, emptyWords, approvalWarning,
|
|
89
|
-
DRAFTS_URL, notesUrl, sinceChoices, notesSummary, validTag, confirmWords, postedWords, draftRequest,
|
|
90
|
-
threadsUrl, threadUrl, issueUrl, IDEAS_URL, threadKindWords, threadMeta, litForThread, mentionsIndex, ideaRequest, ideaWords,
|
|
91
|
-
} from './forge-panel-model.js';
|
|
92
|
-
import { cornStateAttr, markStateAttr, stateIconHtml } from './corn-state.js';
|
|
93
|
-
import { sayResult, clearResult, resultOf, showResultIn, resetFeedbackForTests } from './feedback.js';
|
|
94
|
-
import { isOffline, initConnection, notSentWords, resetConnectionForTests } from './connection.js';
|
|
95
|
-
import { proposalListing, onProposalListing, loadProposalList, hooks as proposalHooks } from './proposal.js';
|
|
96
|
-
import { mergeSpecs } from './proposal-model.js';
|
|
97
|
-
import { t } from './strings.js';
|
|
98
|
-
import { waiting, specGroups, workButtonName, waitingWords, runWaitingOn } from './waiting-model.js';
|
|
99
|
-
import { paintWaitingLine, resetWaitingLineForTests } from './waiting-line.js';
|
|
100
|
-
import { specGroupsHtml } from './waiting-view.js';
|
|
101
|
-
|
|
102
|
-
const $ = (id) => document.getElementById(id);
|
|
103
|
-
const FORGE_NAMES = { github: 'GitHub', forgejo: 'Forgejo' };
|
|
104
|
-
const SEARCH_ANNOUNCE_MS = 500;
|
|
105
|
-
|
|
106
|
-
/** What is shown: the lists loaded, the filters, the selected pull request with its files and checks */
|
|
107
|
-
const ui = {
|
|
108
|
-
config: null,
|
|
109
|
-
open: false,
|
|
110
|
-
kind: 'specs', // the tab: specs | pulls | issues | threads | work (Runs) | deploys; 'notes' is the Release notes view, reached from the PRs list
|
|
111
|
-
filtersOpen: false, // the Filter chip's box
|
|
112
|
-
filters: defaultFilters(),
|
|
113
|
-
lists: {}, // `${kind}|${server state}` -> { items, at, rate, stale }
|
|
114
|
-
work: null, // { grouped, problem, at, rate, stale } of the Agents tab
|
|
115
|
-
specQuery: '', // the Specs tab's search (spec 0010 D5)
|
|
116
|
-
draftsOpen: null, // the Drafts group opened (true) or folded (false) by hand; null: as the model has it (folded past 10 rows)
|
|
117
|
-
workFilters: { agentsOnly: false, finished: false },
|
|
118
|
-
loading: false,
|
|
119
|
-
error: '',
|
|
120
|
-
selected: null, // the pull request's number
|
|
121
|
-
selectedOn: '', // the tab it was selected on ('pulls' or 'work')
|
|
122
|
-
detail: null, // { pull, files, checks, at, rate, stale } of the selected one
|
|
123
|
-
landing: null, // what waits to land on its approval for the selected pull request ({ slug, by, since }), or null
|
|
124
|
-
detailError: '',
|
|
125
|
-
lit: null, // litFor(detail, nodes)
|
|
126
|
-
thread: null, // the selected thread's number (Threads tab)
|
|
127
|
-
threadDetail: null, // { thread, at, rate, stale } of the selected one: its messages, as written
|
|
128
|
-
threadError: '',
|
|
129
|
-
litThread: null, // litForThread(thread, nodes)
|
|
130
|
-
idea: freshIdea(), // the New idea form
|
|
131
|
-
deploy: null, // the selected deploy's id; the deploy itself is `deployItem`
|
|
132
|
-
deployItem: null,
|
|
133
|
-
litDeploy: null, // litForDeploy(deployItem, nodes)
|
|
134
|
-
nodesSeen: null, // the `state.nodes` the lights were worked out for
|
|
135
|
-
busy: '', // the action in flight ('merge', or 'rerun:<check id>'), so a second click does nothing
|
|
136
|
-
note: null, // { text, ok }: what the last action came to, for the selected pull request
|
|
137
|
-
confirm: null, // { opener: selector, kind: 'merge' | 'spec' | 'build', plan?, n?, slug? } while the confirm dialog is open
|
|
138
|
-
actNote: null, // { text, ok, url }: what the last pipeline step came to
|
|
139
|
-
notes: freshNotes(), // the Release notes view
|
|
140
|
-
runs: null, // { data, error } of the Agents tab's runs: what /api/agent-runs answered
|
|
141
|
-
runNote: null, // { text, ok }: what the last Stop came to
|
|
142
|
-
runSel: null, // the run lit on the map (Light on the map), by id
|
|
143
|
-
runnerSaid: null, // the runner state last shown ('online', 'offline', 'none'; null off the pull transport), so a change is said once
|
|
144
|
-
runTimelines: new Set(), // the runs whose timeline is open
|
|
145
|
-
runReplies: new Map(), // the reply typed so far for each waiting run, so a repaint (the runs are looked at again) keeps it
|
|
146
|
-
agent: null, // { opener, refs, posting, retryOf, filled } while the Start an agent dialog is open
|
|
147
|
-
retrying: false, // a Start again reading its run's whole brief, so a second click does nothing
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
/** The Release notes view: the draft loaded for a tag, and where the confirm step is */
|
|
151
|
-
function freshNotes() {
|
|
152
|
-
return { since: '', data: null, loading: false, error: '', confirm: false, posting: false, message: '', bad: false, link: null };
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/** The New idea form: whether it is open, one send in flight, and what the last send came to */
|
|
156
|
-
function freshIdea() {
|
|
157
|
-
// `opener` is the id of the node whose panel button that opened the form ('' when the bar's own button did), `node` the node it was about
|
|
158
|
-
return { open: false, busy: false, message: '', bad: false, link: null, opener: '', node: null };
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
let wired = false;
|
|
162
|
-
let runsTimer = 0;
|
|
163
|
-
/** How often the runs are read again while one is open */
|
|
164
|
-
export const RUNS_POLL_MS = 60_000;
|
|
165
|
-
let threadToken = 0;
|
|
166
|
-
let indexToken = 0;
|
|
167
|
-
let indexLoading = false;
|
|
168
|
-
let indexCache = null; // { items, nodes, map } the mentions index for the list and map it was made from
|
|
169
|
-
let listToken = 0;
|
|
170
|
-
let pullToken = 0;
|
|
171
|
-
let notesToken = 0;
|
|
172
|
-
let searchTimer = null;
|
|
173
|
-
let offScene = null;
|
|
174
|
-
let offListing = null;
|
|
175
|
-
let now = () => Date.now();
|
|
176
|
-
|
|
177
|
-
const forgeName = () => FORGE_NAMES[ui.config && ui.config.forge && ui.config.forge.type] || 'the forge';
|
|
178
|
-
const listKey = () => listKeyOf(ui.kind, ui.filters.state);
|
|
179
|
-
const current = () => (ui.kind === 'work' ? ui.work : ui.kind === 'specs' ? specsList() : ui.lists[listKey()]) || null;
|
|
180
|
-
/** The proposals the Proposals menu lists (proposal.js reads them), as a list of the panel's own shape; null before the first answer */
|
|
181
|
-
let merged = { entries: null, items: [] }; // mergeSpecs of the listing last seen: it is asked for many times a paint
|
|
182
|
-
function specsList() {
|
|
183
|
-
const { entries, problem, forgeProblem, at } = proposalListing();
|
|
184
|
-
// One row for a proposal, however many places it is in: its spec PR and the copy in a checkout or a worktree are one (mergeSpecs)
|
|
185
|
-
if (entries && merged.entries !== entries) merged = { entries, items: mergeSpecs(entries) };
|
|
186
|
-
return entries ? { items: merged.items, at: at ? new Date(at).toISOString() : '', rate: '', stale: '', problem: problem || forgeProblem || '' } : null;
|
|
187
|
-
}
|
|
188
|
-
/** What waits on the maintainer now (spec 0010 D1): the specs to decide and the runs that wait on an answer, from what has been read */
|
|
189
|
-
const waitingNow = () => waiting({ specs: specsList() && specsList().items, runs: ui.runs && ui.runs.data ? ui.runs.data.runs : null });
|
|
190
|
-
const groupsShown = () => (ui.work ? filterGroups(ui.work.grouped.groups, ui.workFilters) : []);
|
|
191
|
-
const plural = (n, word, more = `${word}s`) => `${n} ${n === 1 ? word : more}`;
|
|
192
|
-
const kindWords = () => ({ specs: 'spec', pulls: 'pull request', issues: 'issue', threads: 'thread', deploys: 'deploy' })[ui.kind] || 'piece of work';
|
|
193
|
-
/** A link only if it is the forge's web address: a forge's JSON is data, not trusted markup */
|
|
194
|
-
const safeUrl = (u) => (typeof u === 'string' && /^https?:\/\//i.test(u) ? u : null);
|
|
195
|
-
|
|
196
|
-
// ---------------------------------------------------------------------------
|
|
197
|
-
// Asking the server
|
|
198
|
-
// ---------------------------------------------------------------------------
|
|
199
|
-
|
|
200
|
-
/** A failed answer in words (the model's), said as offline when the browser is, and naming what could not be loaded */
|
|
201
|
-
const failWords = (res, what = '') => errorWords(res.status, res.body, { offline: isOffline(), what });
|
|
202
|
-
|
|
203
|
-
/** One GET (or the one POST, with its JSON); `{ ok, status, body }`, with a status of null when the server did not answer */
|
|
204
|
-
async function request(url, refresh, post) {
|
|
205
|
-
try {
|
|
206
|
-
// Refresh sends `Cache-Control: no-cache`, which the server takes as "ask the forge again"
|
|
207
|
-
const init = post ? { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(post) } : refresh ? { cache: 'reload' } : {};
|
|
208
|
-
const res = await fetch(url, init);
|
|
209
|
-
let body = null;
|
|
210
|
-
try { body = await res.json(); } catch { /* no body */ }
|
|
211
|
-
return { ok: !!res.ok && !!body && body.ok !== false, status: res.status, body };
|
|
212
|
-
} catch {
|
|
213
|
-
return { ok: false, status: null, body: null };
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/** Loads the Agents tab: everything it groups, in one answer */
|
|
218
|
-
async function loadWork(refresh, token) {
|
|
219
|
-
ui.loading = true;
|
|
220
|
-
ui.error = '';
|
|
221
|
-
paint();
|
|
222
|
-
const [res] = await Promise.all([request(WORK_URL, refresh), loadRuns(refresh)]);
|
|
223
|
-
if (token !== listToken) return;
|
|
224
|
-
ui.loading = false;
|
|
225
|
-
if (res.ok) {
|
|
226
|
-
const b = res.body;
|
|
227
|
-
ui.work = { grouped: groupWork(b), problem: b.specsProblem || '', at: b.at, rate: b.rate || '', stale: b.stale || '' };
|
|
228
|
-
announce(`${workStatus(groupsShown(), '', now())}${ui.work.stale ? '. This is an older answer' : ''}`);
|
|
229
|
-
} else {
|
|
230
|
-
ui.error = failWords(res, 'the work');
|
|
231
|
-
announce(ui.error);
|
|
232
|
-
}
|
|
233
|
-
paint();
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/** Loads the runs for the Agents tab (a refresh also has cornfield look at the forge for their reports first); a failure is a line, never a blank panel */
|
|
237
|
-
async function loadRuns(refresh, { say = true } = {}) {
|
|
238
|
-
const before = ui.runs && ui.runs.data ? ui.runs.data.runs : null;
|
|
239
|
-
const res = await request(runsUrl(refresh), refresh);
|
|
240
|
-
ui.runs = res.ok && Array.isArray(res.body.runs) ? { data: res.body, error: '' } : { data: ui.runs && ui.runs.data, error: failWords(res, 'the runs') };
|
|
241
|
-
paintWaiting(); // the number follows the runs, whether or not the panel is open
|
|
242
|
-
if (!(ui.runs && ui.runs.data)) return;
|
|
243
|
-
// The map shows the open runs' nodes; a run lit on the map follows its nodes; what changed is said, once the first answer is in
|
|
244
|
-
setRunsOnMap(ui.runs.data.runs);
|
|
245
|
-
syncRunsPoll();
|
|
246
|
-
if (ui.runSel) relightRun();
|
|
247
|
-
const said = say ? changeWords(before, ui.runs.data.runs) : [];
|
|
248
|
-
// A runner appearing or going quiet is said once, when the state changes (the line itself is plain text, not a live region). The state last
|
|
249
|
-
// shown is kept, not worked out again from the last listing: a runner that goes quiet is the same listing judged later
|
|
250
|
-
const was = ui.runnerSaid;
|
|
251
|
-
const is = runnerState(ui.runs.data.runnerPresence, now());
|
|
252
|
-
ui.runnerSaid = is;
|
|
253
|
-
if (say && was && is && was !== is) said.push(runnerWords(ui.runs.data.runnerPresence, now()));
|
|
254
|
-
if (said.length) announce(said.join('. '));
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* Looks at the runs again in `RUNS_POLL_MS`, but only while one is open: a run's answer that has none open disarms it, and the next answer
|
|
259
|
-
* with one open (a run requested here, or a look from elsewhere) arms it again. One timer at most; never while the page is hidden or put
|
|
260
|
-
* away (`pagehide`). So the marks on the map and the words follow the runs.
|
|
261
|
-
*/
|
|
262
|
-
function syncRunsPoll() {
|
|
263
|
-
const open = !!(ui.runs && ui.runs.data && ui.runs.data.open > 0);
|
|
264
|
-
if (!open || pageAway) {
|
|
265
|
-
clearTimeout(runsTimer);
|
|
266
|
-
runsTimer = 0;
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
if (runsTimer) return;
|
|
270
|
-
runsTimer = setTimeout(async () => {
|
|
271
|
-
runsTimer = 0;
|
|
272
|
-
if (!(typeof document !== 'undefined' && document.hidden)) {
|
|
273
|
-
await loadRuns(false);
|
|
274
|
-
paint();
|
|
275
|
-
}
|
|
276
|
-
syncRunsPoll();
|
|
277
|
-
}, RUNS_POLL_MS);
|
|
278
|
-
}
|
|
279
|
-
/** The page is being put away (closed, or into the back-forward cache): no look until it is shown again */
|
|
280
|
-
let pageAway = false;
|
|
281
|
-
function onPageHide() { pageAway = true; syncRunsPoll(); }
|
|
282
|
-
function onPageShow() { pageAway = false; syncRunsPoll(); }
|
|
283
|
-
|
|
284
|
-
/** Loads the list the kind and state name (again, past the server's cache, on a refresh) */
|
|
285
|
-
async function loadList(refresh = false, quiet = false) {
|
|
286
|
-
const token = ++listToken;
|
|
287
|
-
if (ui.kind === 'work') return loadWork(refresh, token);
|
|
288
|
-
if (ui.kind === 'specs') return loadSpecs(token, quiet);
|
|
289
|
-
const key = listKey();
|
|
290
|
-
ui.loading = true;
|
|
291
|
-
ui.error = '';
|
|
292
|
-
paint();
|
|
293
|
-
const res = await request(listUrl(ui.kind, ui.filters.state), refresh);
|
|
294
|
-
if (token !== listToken) return;
|
|
295
|
-
ui.loading = false;
|
|
296
|
-
if (res.ok) {
|
|
297
|
-
ui.lists[key] = { items: res.body.items || [], at: res.body.at, rate: res.body.rate || '', stale: res.body.stale || '', problem: res.body.problem || '' };
|
|
298
|
-
if (ui.kind === 'threads') {
|
|
299
|
-
repaintThreads();
|
|
300
|
-
// A thread's row names the state of the run that is about it (issue #104): the runs are read, once, when the tab is the first thing opened
|
|
301
|
-
if (!ui.runs) loadRuns(false, { say: false }).then(() => { if (ui.open && ui.kind === 'threads') paint(); }, () => {});
|
|
302
|
-
}
|
|
303
|
-
if (!quiet) announce(`${plural(filterItems(ui.lists[key].items, ui.kind, ui.filters).length, kindWords())} shown${ui.lists[key].stale ? '. This is an older answer' : ''}`);
|
|
304
|
-
} else {
|
|
305
|
-
ui.error = failWords(res, `the ${kindWords()}s`);
|
|
306
|
-
if (!quiet) announce(ui.error);
|
|
307
|
-
}
|
|
308
|
-
paintFilters();
|
|
309
|
-
paint();
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
/** Loads the Specs tab: the proposals the server finds (the list the header's Proposals menu shows, proposal.js); always asked again, worktrees come and go */
|
|
313
|
-
async function loadSpecs(token, quiet) {
|
|
314
|
-
ui.loading = true;
|
|
315
|
-
ui.error = '';
|
|
316
|
-
paint();
|
|
317
|
-
await loadProposalList();
|
|
318
|
-
if (token !== listToken) return;
|
|
319
|
-
ui.loading = false;
|
|
320
|
-
const { entries, problem } = proposalListing();
|
|
321
|
-
if (!entries) ui.error = `Could not load the proposals. ${problem || 'cornfield did not answer.'}`;
|
|
322
|
-
if (!quiet) announce(ui.error || specsShownWords());
|
|
323
|
-
paint();
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
/** What the Specs tab says when it is read or searched: how many rows show, and how many of them wait on a decision */
|
|
327
|
-
function specsShownWords() {
|
|
328
|
-
const list = current();
|
|
329
|
-
if (!list) return 'Looking for proposals';
|
|
330
|
-
const shown = specGroups(list.items, { query: ui.specQuery }).reduce((n, g) => n + g.shown, 0);
|
|
331
|
-
if (ui.specQuery.trim() && !shown) return `No spec matches ${ui.specQuery.trim()}`;
|
|
332
|
-
const decide = waitingNow().specs;
|
|
333
|
-
return `${plural(shown, 'spec')} shown${decide ? `, ${decide} ${t('toDecide').toLowerCase()}` : ''}`;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
/** How often the specs are read again for the number while the page is open (spec 0010 D2: at most every 5 minutes; the server keeps what it read by PR head) */
|
|
337
|
-
export const SPECS_POLL_MS = 5 * 60_000;
|
|
338
|
-
let specsTimer = 0;
|
|
339
|
-
let specsReading = false;
|
|
340
|
-
|
|
341
|
-
/** Reads the proposals now, quietly (the number and the list follow); one read at a time */
|
|
342
|
-
async function readSpecsQuiet() {
|
|
343
|
-
if (specsReading) return;
|
|
344
|
-
specsReading = true;
|
|
345
|
-
try { await loadProposalList(); } finally { specsReading = false; }
|
|
346
|
-
paintWaiting();
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
/** The specs part of the number is read again every `SPECS_POLL_MS`, never while the page is hidden or put away; one timer at most */
|
|
350
|
-
function syncSpecsPoll() {
|
|
351
|
-
if (specsTimer || !ui.config) return;
|
|
352
|
-
specsTimer = setTimeout(async () => {
|
|
353
|
-
specsTimer = 0;
|
|
354
|
-
if (!pageAway && !(typeof document !== 'undefined' && document.hidden)) await readSpecsQuiet();
|
|
355
|
-
syncSpecsPoll();
|
|
356
|
-
}, SPECS_POLL_MS);
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
/** The counts on the tabs, read quietly the first time the panel opens: the open pull requests and issues (the Threads and Runs counts come from what those tabs read anyway) */
|
|
360
|
-
function primeCounts() {
|
|
361
|
-
for (const kind of ['pulls', 'issues']) {
|
|
362
|
-
const key = listKeyOf(kind, 'open');
|
|
363
|
-
if (ui.lists[key] || primed.has(kind) || kind === ui.kind) continue;
|
|
364
|
-
primed.add(kind);
|
|
365
|
-
request(listUrl(kind, 'open'), false).then((res) => {
|
|
366
|
-
if (res.ok && !ui.lists[key]) ui.lists[key] = { items: res.body.items || [], at: res.body.at, rate: res.body.rate || '', stale: res.body.stale || '', problem: res.body.problem || '' };
|
|
367
|
-
if (ui.open) paint();
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
if (!primed.has('threads')) { primed.add('threads'); ensureThreadsList(); }
|
|
371
|
-
if (ui.kind !== 'specs') readSpecsQuiet(); // the specs part of the number is read when Work opens (spec 0010 D2)
|
|
372
|
-
}
|
|
373
|
-
const primed = new Set();
|
|
374
|
-
|
|
375
|
-
/** Selects a pull request: asks for its files and checks, then lights what they are on the map */
|
|
376
|
-
async function selectPull(n) {
|
|
377
|
-
const token = ++pullToken;
|
|
378
|
-
dropThread();
|
|
379
|
-
ui.deploy = null;
|
|
380
|
-
ui.deployItem = null;
|
|
381
|
-
ui.litDeploy = null;
|
|
382
|
-
ui.selected = n;
|
|
383
|
-
ui.selectedOn = ui.kind; // the PRs list or the Runs tab's groups: its detail replaces that list only
|
|
384
|
-
ui.detail = null;
|
|
385
|
-
ui.landing = null;
|
|
386
|
-
ui.detailError = '';
|
|
387
|
-
ui.lit = null;
|
|
388
|
-
ui.note = null;
|
|
389
|
-
state.forgeLit = null;
|
|
390
|
-
touchScene();
|
|
391
|
-
render();
|
|
392
|
-
paint();
|
|
393
|
-
const res = await request(pullUrl(n), false);
|
|
394
|
-
if (token !== pullToken) return;
|
|
395
|
-
if (!res.ok) {
|
|
396
|
-
ui.detailError = failWords(res, `pull request ${n}`);
|
|
397
|
-
announce(ui.detailError);
|
|
398
|
-
paint();
|
|
399
|
-
return;
|
|
400
|
-
}
|
|
401
|
-
ui.detail = { pull: res.body.pull, files: res.body.files || [], checks: res.body.checks || [], specs: res.body.specs || [], at: res.body.at, rate: res.body.rate || '', stale: res.body.stale || '' };
|
|
402
|
-
relight();
|
|
403
|
-
// The run that made it is on the detail: the runs are read once, if the config has any
|
|
404
|
-
if (!ui.runs && ui.config.agents && ui.config.agents.runs) loadRuns(false, { say: false }).then(() => { if (ui.selected === n) paint(); }, () => {});
|
|
405
|
-
await loadLanding(n, token);
|
|
406
|
-
$('forge-panel').querySelector('.hx-forge-body').scrollTop = 0; // the pull request's files are what was asked for, not the row that was tapped
|
|
407
|
-
announce(selectionWords());
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
/** Asks the server whether the selected pull request waits to land on its approval (a read of the server's own state, not of the forge); nothing is shown when it does not */
|
|
411
|
-
async function loadLanding(n, token) {
|
|
412
|
-
if (!(ui.config && ui.config.forge && ui.config.forge.approveLands)) return; // the key is off: nothing to ask
|
|
413
|
-
const res = await request(landingUrl(n), true);
|
|
414
|
-
if (token !== pullToken || ui.selected !== n) return;
|
|
415
|
-
ui.landing = res.ok && res.body && res.body.landing ? res.body.landing : null;
|
|
416
|
-
paint();
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
/** Stops the landing that waits on the selected pull request: a POST from this page, then the pull request is read again */
|
|
420
|
-
async function cancelLanding(n) {
|
|
421
|
-
if (ui.busy) return;
|
|
422
|
-
ui.busy = 'landing';
|
|
423
|
-
ui.note = null;
|
|
424
|
-
paint();
|
|
425
|
-
const res = await post(cancelLandingUrl(n), {});
|
|
426
|
-
ui.busy = '';
|
|
427
|
-
ui.note = { text: res.ok ? `Pull request #${n} will not land on its own. It stays open.` : `Not cancelled: ${(res.body && res.body.error) || 'cornfield did not answer.'}`, ok: res.ok };
|
|
428
|
-
announce(ui.note.text);
|
|
429
|
-
ui.landing = null;
|
|
430
|
-
paint();
|
|
431
|
-
if (ui.selected === n) await refreshForge({ quiet: true });
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
/** Lets go of the selected pull request: nothing is lit any more */
|
|
435
|
-
export function clearPull() {
|
|
436
|
-
pullToken++;
|
|
437
|
-
const had = ui.selected;
|
|
438
|
-
if (ui.confirm) closeConfirm({ restoreFocus: false });
|
|
439
|
-
ui.selected = null;
|
|
440
|
-
ui.note = null;
|
|
441
|
-
ui.detail = null;
|
|
442
|
-
ui.landing = null;
|
|
443
|
-
ui.detailError = '';
|
|
444
|
-
ui.lit = null;
|
|
445
|
-
state.forgeLit = null;
|
|
446
|
-
touchScene();
|
|
447
|
-
render();
|
|
448
|
-
paint();
|
|
449
|
-
if (had !== null) announce(`Pull request ${had} cleared`);
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
/** What the selected pull request lights, worked out again: for the nodes now on the map */
|
|
453
|
-
function relight() {
|
|
454
|
-
ui.nodesSeen = state.nodes;
|
|
455
|
-
if (ui.runSel) {
|
|
456
|
-
const run = runById(ui.runSel);
|
|
457
|
-
state.forgeLit = run ? litOfRun(run) : null;
|
|
458
|
-
} else if (ui.threadDetail && ui.threadDetail.thread) {
|
|
459
|
-
ui.litThread = litForThread(ui.threadDetail.thread, state.nodes);
|
|
460
|
-
state.forgeLit = { changed: ui.litThread.changed, failing: ui.litThread.failing };
|
|
461
|
-
} else if (ui.deployItem) {
|
|
462
|
-
ui.litDeploy = litForDeploy(ui.deployItem, state.nodes);
|
|
463
|
-
state.forgeLit = { changed: ui.litDeploy.changed, failing: ui.litDeploy.failing };
|
|
464
|
-
} else if (ui.detail) {
|
|
465
|
-
ui.lit = litFor(ui.detail, state.nodes);
|
|
466
|
-
state.forgeLit = { changed: ui.lit.changed, failing: ui.lit.failing };
|
|
467
|
-
} else {
|
|
468
|
-
ui.lit = null;
|
|
469
|
-
state.forgeLit = null;
|
|
470
|
-
}
|
|
471
|
-
touchScene();
|
|
472
|
-
render();
|
|
473
|
-
paint();
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
/** A proposal opening, or the live layer, changes the nodes: the lights follow them */
|
|
477
|
-
function onNodesChange() {
|
|
478
|
-
if ((ui.detail || ui.deployItem || ui.threadDetail) && state.nodes !== ui.nodesSeen) relight();
|
|
479
|
-
repaintThreads();
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
/** Selects a deploy: nothing to ask (the list holds what it restarted), so its nodes light at once */
|
|
483
|
-
export function selectDeploy(id) {
|
|
484
|
-
const found = ui.lists.deploys && ui.lists.deploys.items.find((d) => d.id === id);
|
|
485
|
-
if (!found) return;
|
|
486
|
-
pullToken++;
|
|
487
|
-
dropThread();
|
|
488
|
-
ui.selected = null;
|
|
489
|
-
ui.detail = null;
|
|
490
|
-
ui.detailError = '';
|
|
491
|
-
ui.lit = null;
|
|
492
|
-
ui.deploy = id;
|
|
493
|
-
ui.deployItem = found;
|
|
494
|
-
// A container, a stack or a machine is on a layer that starts off: the layers the deploy's nodes are on come on, or nothing would light
|
|
495
|
-
const turnedOn = [];
|
|
496
|
-
for (const n of litForDeploy(found, state.nodes).nodes) {
|
|
497
|
-
const layer = LAYER_DEFS.find((l) => l.key === n.type);
|
|
498
|
-
if (layer && !layerOn(state, layer.key)) { toggleLayer(layer.key); turnedOn.push(layer.label); }
|
|
499
|
-
}
|
|
500
|
-
relight();
|
|
501
|
-
$('forge-panel').querySelector('.hx-forge-body').scrollTop = 0; // the deploy's nodes are what was asked for, not the row that was tapped
|
|
502
|
-
announce(deploySelectionWords(turnedOn));
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
/** Lets go of the selected deploy: nothing is lit any more */
|
|
506
|
-
export function clearDeploy() {
|
|
507
|
-
const had = ui.deployItem;
|
|
508
|
-
ui.deploy = null;
|
|
509
|
-
ui.deployItem = null;
|
|
510
|
-
ui.litDeploy = null;
|
|
511
|
-
state.forgeLit = null;
|
|
512
|
-
touchScene();
|
|
513
|
-
render();
|
|
514
|
-
paint();
|
|
515
|
-
if (had) announce(`Deploy ${had.name} cleared`);
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
// ---------------------------------------------------------------------------
|
|
519
|
-
// Threads
|
|
520
|
-
// ---------------------------------------------------------------------------
|
|
521
|
-
|
|
522
|
-
/** Forgets the selected thread without painting: another thing is being selected */
|
|
523
|
-
function dropThread() {
|
|
524
|
-
ui.runSel = null;
|
|
525
|
-
threadToken++;
|
|
526
|
-
ui.thread = null;
|
|
527
|
-
ui.threadDetail = null;
|
|
528
|
-
ui.threadError = '';
|
|
529
|
-
ui.litThread = null;
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
/** Selects a thread: asks for its messages (read-only), then lights the nodes they mention */
|
|
533
|
-
/** The thread a successful answer holds, or null (a failure, or an answer without one) */
|
|
534
|
-
const threadOf = (res) => (res && res.ok && res.body && res.body.thread && typeof res.body.thread === 'object' && Array.isArray(res.body.thread.messages) ? res.body.thread : null);
|
|
535
|
-
|
|
536
|
-
async function selectThread(n) {
|
|
537
|
-
const token = ++threadToken;
|
|
538
|
-
pullToken++;
|
|
539
|
-
ui.runSel = null;
|
|
540
|
-
ui.selected = null;
|
|
541
|
-
ui.detail = null;
|
|
542
|
-
ui.detailError = '';
|
|
543
|
-
ui.lit = null;
|
|
544
|
-
ui.landing = null;
|
|
545
|
-
ui.deploy = null;
|
|
546
|
-
ui.deployItem = null;
|
|
547
|
-
ui.litDeploy = null;
|
|
548
|
-
ui.thread = n;
|
|
549
|
-
ui.threadDetail = null;
|
|
550
|
-
ui.threadError = '';
|
|
551
|
-
ui.litThread = null;
|
|
552
|
-
state.forgeLit = null;
|
|
553
|
-
touchScene();
|
|
554
|
-
render();
|
|
555
|
-
paint();
|
|
556
|
-
const res = await request(threadUrl(n), false);
|
|
557
|
-
if (token !== threadToken) return;
|
|
558
|
-
// An answer without a thread in it is a failure too: nothing to show or light
|
|
559
|
-
const thread = threadOf(res);
|
|
560
|
-
if (!thread) {
|
|
561
|
-
ui.threadError = res.ok ? `Thread ${n} could not be read: the answer had no thread in it. Refresh to ask again.` : failWords(res, `thread ${n}`);
|
|
562
|
-
announce(ui.threadError);
|
|
563
|
-
paint();
|
|
564
|
-
return;
|
|
565
|
-
}
|
|
566
|
-
ui.threadDetail = { thread, at: res.body.at, rate: res.body.rate || '', stale: res.body.stale || '' };
|
|
567
|
-
relight();
|
|
568
|
-
$('forge-panel').querySelector('.hx-forge-body').scrollTop = 0; // the thread's messages are what was asked for, not the row that was tapped
|
|
569
|
-
announce(threadSelectionWords());
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
/** Lets go of the selected thread: nothing is lit any more */
|
|
573
|
-
export function clearThread() {
|
|
574
|
-
const had = ui.thread;
|
|
575
|
-
dropThread();
|
|
576
|
-
state.forgeLit = null;
|
|
577
|
-
touchScene();
|
|
578
|
-
render();
|
|
579
|
-
paint();
|
|
580
|
-
if (had !== null) announce(`Thread ${had} cleared`);
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
/** What a screen reader hears when a thread is selected */
|
|
584
|
-
function threadSelectionWords() {
|
|
585
|
-
const { thread } = ui.threadDetail;
|
|
586
|
-
const lit = ui.litThread ? ui.litThread.nodes.length : 0;
|
|
587
|
-
const off = ui.litThread ? ui.litThread.unresolved.length : 0;
|
|
588
|
-
return `Thread ${thread.number}, ${thread.title}: ${plural(thread.messages.length, 'message')}, ${lit ? `${plural(lit, 'node')} lit` : 'no node mentioned'}${off ? `, ${off} named that ${off === 1 ? 'is' : 'are'} not on the map` : ''}. Read-only: reply on ${forgeName()}.`;
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
/** Shows a thread from the map (a node's "Mentioned in"): the panel opens on the Threads tab with that thread selected */
|
|
592
|
-
function openThread(n) {
|
|
593
|
-
if (ui.kind !== 'threads') {
|
|
594
|
-
ui.kind = 'threads';
|
|
595
|
-
ui.actNote = null;
|
|
596
|
-
ui.filters = defaultFilters('threads');
|
|
597
|
-
}
|
|
598
|
-
openForge();
|
|
599
|
-
paintFilters();
|
|
600
|
-
selectThread(n);
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
/** The threads list for the node panel's "Mentioned in", read once (quietly) when a node is first selected, and when the Threads tab loads it */
|
|
604
|
-
function ensureThreadsList() {
|
|
605
|
-
if (!ui.config || ui.config.threads === false || ui.lists['threads|open'] || indexLoading) return;
|
|
606
|
-
indexLoading = true;
|
|
607
|
-
const token = ++indexToken;
|
|
608
|
-
request(threadsUrl('open'), false).then((res) => {
|
|
609
|
-
indexLoading = false;
|
|
610
|
-
if (token !== indexToken || !res.ok || ui.lists['threads|open']) return;
|
|
611
|
-
ui.lists['threads|open'] = { items: res.body.items || [], at: res.body.at, rate: res.body.rate || '', stale: res.body.stale || '', problem: res.body.problem || '' };
|
|
612
|
-
repaintThreads();
|
|
613
|
-
if (ui.open && ui.kind === 'threads') paint();
|
|
614
|
-
});
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
/** The threads that mention a node on the map now, or null while the list has not been read */
|
|
618
|
-
function threadsFor(nodeId) {
|
|
619
|
-
const list = ui.lists['threads|open'];
|
|
620
|
-
if (!list) return null;
|
|
621
|
-
if (!indexCache || indexCache.items !== list.items || indexCache.nodes !== state.nodes) indexCache = { items: list.items, nodes: state.nodes, map: mentionsIndex(list.items, state.nodes) };
|
|
622
|
-
return indexCache.map.get(nodeId) || [];
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
// ---------------------------------------------------------------------------
|
|
626
|
-
// New idea
|
|
627
|
-
// ---------------------------------------------------------------------------
|
|
628
|
-
|
|
629
|
-
/** Opens or closes the form; the focus goes to the title, or back to the button */
|
|
630
|
-
function toggleIdea(open) {
|
|
631
|
-
ui.idea.open = open;
|
|
632
|
-
if (open) { ui.idea.message = ''; ui.idea.opener = ''; ui.idea.node = null; }
|
|
633
|
-
paintIdea();
|
|
634
|
-
if (open) $('idea-title').focus(); else focusIdeaOpener();
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
/** Puts the focus back on what opened the form: the node panel's button while it is still there, else the New idea button */
|
|
638
|
-
function focusIdeaOpener() {
|
|
639
|
-
const from = ui.idea.opener ? [...document.querySelectorAll('[data-thread-start]')].find((b) => b.dataset.threadStart === ui.idea.opener) : null;
|
|
640
|
-
(from && !from.closest('[inert]') ? from : $('idea-open')).focus();
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
/** A node id that reads back as one mention: no brackets or line breaks, as core/mentions.js parses them */
|
|
644
|
-
const MENTIONABLE = /^[^[\]\r\n]{1,200}$/;
|
|
645
|
-
|
|
646
|
-
/** "Start a thread about this" (a node's panel): the New idea form, with the node's label as the title and its mention in the text */
|
|
647
|
-
function startThread(node) {
|
|
648
|
-
if (!node || ui.idea.busy || !ui.config || ui.config.threads === false) return;
|
|
649
|
-
if (ui.kind !== 'threads') {
|
|
650
|
-
ui.kind = 'threads';
|
|
651
|
-
ui.actNote = null;
|
|
652
|
-
ui.filters = defaultFilters('threads');
|
|
653
|
-
}
|
|
654
|
-
openForge();
|
|
655
|
-
paintFilters();
|
|
656
|
-
ui.idea.open = true;
|
|
657
|
-
ui.idea.message = '';
|
|
658
|
-
ui.idea.bad = false;
|
|
659
|
-
ui.idea.link = null;
|
|
660
|
-
ui.idea.node = { id: node.id, label: node.label };
|
|
661
|
-
ui.idea.opener = node.id;
|
|
662
|
-
// Never lose a draft: a title already typed stays, and text already typed stays under the mention, which is added once (`.value` is
|
|
663
|
-
// text, never markup, so the label and the id need no escaping here)
|
|
664
|
-
const title = $('idea-title');
|
|
665
|
-
if (title.value.trim() === '') title.value = String(node.label || node.id).slice(0, 256);
|
|
666
|
-
const text = $('idea-body');
|
|
667
|
-
const mention = MENTIONABLE.test(node.id) ? `[[${node.id}]]` : '';
|
|
668
|
-
if (mention && !text.value.includes(mention)) text.value = text.value.trim() === '' ? `${mention}\n\n` : `${mention}\n\n${text.value}`;
|
|
669
|
-
paintIdea();
|
|
670
|
-
$('idea-title').focus();
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
/** The one write: a POST to cornfield's own server, which opens an issue with the label as the maintainer */
|
|
674
|
-
async function sendIdea() {
|
|
675
|
-
if (ui.idea.busy) return;
|
|
676
|
-
const asked = ideaRequest($('idea-title').value, $('idea-body').value);
|
|
677
|
-
if (!asked) {
|
|
678
|
-
ui.idea.message = 'Give the idea a title.';
|
|
679
|
-
ui.idea.bad = true;
|
|
680
|
-
ui.idea.link = null;
|
|
681
|
-
paintIdea();
|
|
682
|
-
announce(ui.idea.message);
|
|
683
|
-
$('idea-title').focus();
|
|
684
|
-
return;
|
|
685
|
-
}
|
|
686
|
-
ui.idea.busy = true;
|
|
687
|
-
ui.idea.message = '';
|
|
688
|
-
paintIdea();
|
|
689
|
-
announce(`Opening the idea on ${forgeName()}`);
|
|
690
|
-
const res = await post(IDEAS_URL, asked);
|
|
691
|
-
ui.idea.busy = false;
|
|
692
|
-
ui.idea.message = ideaWords(forgeName(), res);
|
|
693
|
-
ui.idea.bad = !res.ok;
|
|
694
|
-
ui.idea.link = res.ok && res.body.issue ? res.body.issue.url : null;
|
|
695
|
-
if (res.ok) {
|
|
696
|
-
ui.idea.open = false;
|
|
697
|
-
$('idea-title').value = '';
|
|
698
|
-
$('idea-body').value = '';
|
|
699
|
-
}
|
|
700
|
-
paintIdea();
|
|
701
|
-
announce(ui.idea.message);
|
|
702
|
-
if (res.ok) await afterIdea(res);
|
|
703
|
-
else $('idea-title').focus();
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
/**
|
|
707
|
-
* After an idea is opened: the list read again, the new thread selected (so what it mentions lights), the focus back on what opened
|
|
708
|
-
* the form, and all of it said once. The idea is on the forge whatever happens here, so a failure is said, never thrown.
|
|
709
|
-
*/
|
|
710
|
-
async function afterIdea(res) {
|
|
711
|
-
const about = ui.idea.node;
|
|
712
|
-
const n = res.body && res.body.number;
|
|
713
|
-
let trouble = '';
|
|
714
|
-
try {
|
|
715
|
-
// The new thread is shown where threads are: an idea opened from Specs goes on to the Threads tab
|
|
716
|
-
if (ui.kind !== 'threads') { ui.kind = 'threads'; ui.actNote = null; ui.filters = defaultFilters('threads'); paintFilters(); }
|
|
717
|
-
ui.lists = {};
|
|
718
|
-
primed.clear(); // the tabs' counts are read again
|
|
719
|
-
indexCache = null;
|
|
720
|
-
await loadList(true, true);
|
|
721
|
-
if (ui.open) primeCounts();
|
|
722
|
-
ensureThreadsList();
|
|
723
|
-
// The new thread is selected in the list, so what it mentions lights on the map once its messages are in
|
|
724
|
-
if (Number.isInteger(n)) await selectThread(n);
|
|
725
|
-
} catch (err) {
|
|
726
|
-
trouble = ` The list could not be read again (${err instanceof Error ? err.message : err}); Refresh asks for it.`;
|
|
727
|
-
}
|
|
728
|
-
// Then the focus goes back to what opened the form: after the selection, which draws the node's panel (and its button) again
|
|
729
|
-
try { focusIdeaOpener(); } catch { /* the page moved on */ }
|
|
730
|
-
ui.idea.opener = '';
|
|
731
|
-
ui.idea.node = null;
|
|
732
|
-
const shown = ui.thread === n && ui.threadDetail && ui.threadDetail.thread ? ` ${threadSelectionWords()}` : ui.thread === n && ui.threadError ? ` ${ui.threadError}` : '';
|
|
733
|
-
// Opened from a node: say that its "Mentioned in" lists the new thread
|
|
734
|
-
const listed = about && (threadsFor(about.id) || []).some((t) => t.number === n);
|
|
735
|
-
announce(`${ui.idea.message}${shown}${listed ? ` It is listed under Threads for ${about.label}.` : ''}${trouble}`);
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
/** The New idea bar and form, from `ui.idea`; typed text and the focus are left alone */
|
|
739
|
-
function paintIdea() {
|
|
740
|
-
const bar = $('forge-idea');
|
|
741
|
-
if (!bar) return;
|
|
742
|
-
// An idea is a thread: with threads off (`threads: false`) there is no New idea, on Specs either
|
|
743
|
-
bar.hidden = (ui.kind !== 'threads' && ui.kind !== 'specs') || !!detailKey() || !ui.config || ui.config.threads === false;
|
|
744
|
-
$('idea-open').setAttribute('aria-expanded', String(ui.idea.open));
|
|
745
|
-
$('idea-form').hidden = !ui.idea.open;
|
|
746
|
-
$('idea-send').textContent = ui.idea.busy ? 'Opening …' : 'Open the idea';
|
|
747
|
-
$('idea-send').disabled = ui.idea.busy;
|
|
748
|
-
if (ui.idea.open) {
|
|
749
|
-
const label = (ui.config && ui.config.threads && ui.config.threads.label) || 'idea';
|
|
750
|
-
$('idea-words').textContent = `This opens an issue labelled "${label}" on ${forgeName()}, as you. The conversation lives there; cornfield keeps no copy of it.`;
|
|
751
|
-
}
|
|
752
|
-
const message = $('idea-message');
|
|
753
|
-
message.hidden = !ui.idea.message;
|
|
754
|
-
message.classList.toggle('hx-forge-msg--bad', ui.idea.bad);
|
|
755
|
-
if (ui.idea.bad) message.dataset.cornState = 'failure'; else delete message.dataset.cornState;
|
|
756
|
-
message.textContent = ui.idea.message;
|
|
757
|
-
if (ui.idea.message && ui.idea.link && safeUrl(ui.idea.link)) {
|
|
758
|
-
const link = document.createElement('a');
|
|
759
|
-
link.className = 'hx-link';
|
|
760
|
-
link.dataset.corn = 'text-link';
|
|
761
|
-
link.href = ui.idea.link;
|
|
762
|
-
link.target = '_blank';
|
|
763
|
-
link.rel = 'noreferrer';
|
|
764
|
-
link.textContent = `Open it on ${forgeName()} (new tab)`;
|
|
765
|
-
message.append(' ', link);
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
/** What a screen reader hears when a deploy is selected */
|
|
770
|
-
function deploySelectionWords(turnedOn = []) {
|
|
771
|
-
const { name, branch } = ui.deployItem;
|
|
772
|
-
const lit = ui.litDeploy;
|
|
773
|
-
const head = `Deploy ${name}${branch ? ` of ${branch}` : ''}, ${deployWords(ui.deployItem).toLowerCase()}`;
|
|
774
|
-
if (!ui.deployItem.restarts.length) return `${head}. No node is mapped to it, so nothing is lit.`;
|
|
775
|
-
const layers = turnedOn.length ? ` Turned on the ${turnedOn.join(' and ')} ${turnedOn.length === 1 ? 'layer' : 'layers'}.` : '';
|
|
776
|
-
return `${head}: ${plural(lit.nodes.length, 'node')} restarted and lit${lit.missing.length ? `, ${lit.missing.length} named that ${lit.missing.length === 1 ? 'is' : 'are'} not on the map` : ''}.${layers}`;
|
|
777
|
-
}
|
|
778
|
-
|
|
779
|
-
/** What a screen reader hears when a pull request is selected */
|
|
780
|
-
function selectionWords() {
|
|
781
|
-
const { pull, files, checks } = ui.detail;
|
|
782
|
-
const mapped = ui.lit ? ui.lit.files.filter((f) => f.nodes.length).length : 0;
|
|
783
|
-
const lit = ui.lit ? new Set([...ui.lit.changed, ...ui.lit.failing]).size : 0;
|
|
784
|
-
return `Pull request ${pull.number}, ${pull.title}: ${plural(files.length, 'file')}, ${mapped} on the map${lit ? `, ${plural(lit, 'node')} lit` : ''}. ${checksWords(checks)}.`;
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
// ---------------------------------------------------------------------------
|
|
788
|
-
// Release notes
|
|
789
|
-
// ---------------------------------------------------------------------------
|
|
790
|
-
|
|
791
|
-
/** Loads the draft for the tag chosen (again, past the server's cache, on a refresh) */
|
|
792
|
-
async function loadNotes(refresh = false) {
|
|
793
|
-
const token = ++notesToken;
|
|
794
|
-
const n = ui.notes;
|
|
795
|
-
n.loading = true;
|
|
796
|
-
n.error = '';
|
|
797
|
-
n.message = '';
|
|
798
|
-
closeNotesConfirm(false);
|
|
799
|
-
paint();
|
|
800
|
-
const res = await request(notesUrl(n.since), refresh);
|
|
801
|
-
if (token !== notesToken) return;
|
|
802
|
-
n.loading = false;
|
|
803
|
-
if (res.ok) {
|
|
804
|
-
n.data = res.body;
|
|
805
|
-
announce(`Release notes drafted. ${notesSummary(n.data)}${n.data.stale ? ' This is an older answer' : ''}`);
|
|
806
|
-
} else {
|
|
807
|
-
n.error = failWords(res, 'the release notes');
|
|
808
|
-
announce(n.error);
|
|
809
|
-
}
|
|
810
|
-
paint();
|
|
811
|
-
}
|
|
812
|
-
|
|
813
|
-
/** Says something about the last Copy or Post, on the page and to a screen reader */
|
|
814
|
-
function say(words, bad = false, link = null) {
|
|
815
|
-
ui.notes.message = words;
|
|
816
|
-
ui.notes.bad = bad;
|
|
817
|
-
ui.notes.link = link;
|
|
818
|
-
paintNotes();
|
|
819
|
-
announce(words);
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
/** Copies the draft: the clipboard, else the text selected for the person to copy */
|
|
823
|
-
async function copyNotes() {
|
|
824
|
-
const data = ui.notes.data;
|
|
825
|
-
if (!data) return;
|
|
826
|
-
try {
|
|
827
|
-
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
828
|
-
await navigator.clipboard.writeText(data.markdown);
|
|
829
|
-
say('Copied the release notes.');
|
|
830
|
-
return;
|
|
831
|
-
}
|
|
832
|
-
} catch { /* blocked: try the old way */ }
|
|
833
|
-
const area = $('notes-preview');
|
|
834
|
-
area.focus();
|
|
835
|
-
area.select();
|
|
836
|
-
let copied = false;
|
|
837
|
-
try { copied = typeof document.execCommand === 'function' && document.execCommand('copy'); } catch { copied = false; }
|
|
838
|
-
say(copied ? 'Copied the release notes.' : 'Copying was blocked. The draft is selected: press Ctrl+C, or Command+C on a Mac.', !copied);
|
|
839
|
-
}
|
|
840
|
-
|
|
841
|
-
/** The confirm step: what will happen in words, and the tag to ask for (the one the server suggests, to change) */
|
|
842
|
-
function openNotesConfirm() {
|
|
843
|
-
const n = ui.notes;
|
|
844
|
-
if (!n.data || n.posting) return;
|
|
845
|
-
if (!n.data.count) { say('There are no merged pull requests to put in a draft.', true); return; }
|
|
846
|
-
n.confirm = true;
|
|
847
|
-
n.message = '';
|
|
848
|
-
$('notes-tag').value = n.data.suggestedTag || '';
|
|
849
|
-
paintNotes();
|
|
850
|
-
$('notes-tag').focus();
|
|
851
|
-
announce('Post as a draft release. Check the tag, then create the draft.');
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
/** Closes the confirm step; the focus goes back to the button that opened it unless told not to */
|
|
855
|
-
function closeNotesConfirm(restoreFocus = true) {
|
|
856
|
-
const n = ui.notes;
|
|
857
|
-
if (!n.confirm) return;
|
|
858
|
-
n.confirm = false;
|
|
859
|
-
paintNotes();
|
|
860
|
-
if (restoreFocus) $('notes-post').focus();
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
/** The one write: asks the server to have the forge keep the notes as a draft release for the tag typed */
|
|
864
|
-
async function postDraft() {
|
|
865
|
-
const n = ui.notes;
|
|
866
|
-
if (!n.confirm || n.posting || !n.data) return;
|
|
867
|
-
const tag = $('notes-tag').value.trim();
|
|
868
|
-
if (!validTag(tag)) { say('Give the tag the draft is for, like v0.2.0: letters, digits, dots, dashes and slashes, no spaces.', true); $('notes-tag').focus(); return; }
|
|
869
|
-
n.posting = true;
|
|
870
|
-
n.message = '';
|
|
871
|
-
paintNotes();
|
|
872
|
-
announce('Creating the draft release');
|
|
873
|
-
const res = await request(DRAFTS_URL, false, draftRequest(tag, n.since));
|
|
874
|
-
n.posting = false;
|
|
875
|
-
if (res.ok) {
|
|
876
|
-
n.confirm = false;
|
|
877
|
-
say(postedWords({ forge: forgeName(), tag, count: res.body.count }), false, res.body.release && res.body.release.url);
|
|
878
|
-
$('notes-post').focus();
|
|
879
|
-
return;
|
|
880
|
-
}
|
|
881
|
-
say(res.status === 401 ? 'Your sign-in has ended. Sign in again to post a draft.' : failWords(res), true);
|
|
882
|
-
$('notes-tag').focus();
|
|
883
|
-
}
|
|
884
|
-
|
|
885
|
-
/** The Release notes view, from `ui.notes`; the typed tag and the focus are left alone */
|
|
886
|
-
function paintNotes() {
|
|
887
|
-
const n = ui.notes;
|
|
888
|
-
const data = n.data;
|
|
889
|
-
const since = $('notes-since');
|
|
890
|
-
// The choices are drawn again only when they change, so the select keeps the focus while a draft is loaded for it
|
|
891
|
-
const choices = (data ? sinceChoices(data) : [['', 'Latest tag']]).map(([v, l]) => option(v, l, false)).join('');
|
|
892
|
-
if (since.dataset.choices !== choices) { since.innerHTML = choices; since.dataset.choices = choices; }
|
|
893
|
-
since.value = n.since;
|
|
894
|
-
const area = $('notes-preview');
|
|
895
|
-
if (area.value !== (data ? data.markdown : '')) area.value = data ? data.markdown : '';
|
|
896
|
-
$('notes-copy').disabled = !data;
|
|
897
|
-
$('notes-post').disabled = !data;
|
|
898
|
-
$('notes-post').setAttribute('aria-expanded', String(n.confirm));
|
|
899
|
-
const confirm = $('notes-confirm');
|
|
900
|
-
confirm.hidden = !n.confirm;
|
|
901
|
-
if (n.confirm && data) {
|
|
902
|
-
$('notes-confirm-words').textContent = confirmWords({ forge: forgeName(), repo: ui.config.forge.repo, tag: '', count: data.count });
|
|
903
|
-
$('notes-confirm-yes').textContent = n.posting ? 'Creating …' : 'Create the draft';
|
|
904
|
-
}
|
|
905
|
-
const message = $('notes-message');
|
|
906
|
-
message.hidden = !n.message;
|
|
907
|
-
message.classList.toggle('hx-forge-msg--bad', n.bad);
|
|
908
|
-
if (n.bad) message.dataset.cornState = 'failure'; else delete message.dataset.cornState;
|
|
909
|
-
message.textContent = n.message;
|
|
910
|
-
if (n.message && n.link && safeUrl(n.link)) {
|
|
911
|
-
const link = document.createElement('a');
|
|
912
|
-
link.className = 'hx-link';
|
|
913
|
-
link.dataset.corn = 'text-link';
|
|
914
|
-
link.href = n.link;
|
|
915
|
-
link.target = '_blank';
|
|
916
|
-
link.rel = 'noreferrer';
|
|
917
|
-
link.textContent = `Open the draft on ${forgeName()} (new tab)`;
|
|
918
|
-
message.append(' ', link);
|
|
919
|
-
}
|
|
920
|
-
}
|
|
921
|
-
|
|
922
|
-
// ---------------------------------------------------------------------------
|
|
923
|
-
// Drawing
|
|
924
|
-
// ---------------------------------------------------------------------------
|
|
925
|
-
|
|
926
|
-
const option = (value, label, on) => `<option value="${escHtml(value)}"${on ? ' selected' : ''}>${escHtml(label)}</option>`;
|
|
927
|
-
|
|
928
|
-
/** Whether the Filter chip applies to the view: the proposals and the release notes have nothing to filter */
|
|
929
|
-
const filterable = () => ui.kind !== 'specs' && ui.kind !== 'notes';
|
|
930
|
-
|
|
931
|
-
/** How many filters are on: a state other than the default, a label, an author, a search; on Runs, its two checkboxes */
|
|
932
|
-
function activeFilters() {
|
|
933
|
-
if (ui.kind === 'work') return Number(ui.workFilters.agentsOnly) + Number(ui.workFilters.finished);
|
|
934
|
-
if (!filterable()) return 0;
|
|
935
|
-
const f = ui.filters;
|
|
936
|
-
return Number(f.state !== defaultFilters(ui.kind).state) + Number(!!f.label) + Number(!!f.author) + Number(!!f.text);
|
|
937
|
-
}
|
|
938
|
-
|
|
939
|
-
/** The Filter chip, its count, and the box behind it */
|
|
940
|
-
function paintChip() {
|
|
941
|
-
const chip = $('forge-filter-chip');
|
|
942
|
-
const box = $('forge-filter-box');
|
|
943
|
-
const on = filterable() && !detailKey();
|
|
944
|
-
const n = activeFilters();
|
|
945
|
-
chip.hidden = !on;
|
|
946
|
-
chip.setAttribute('aria-expanded', String(on && ui.filtersOpen));
|
|
947
|
-
chip.setAttribute('aria-label', n ? `Filter, ${plural(n, 'filter')} on` : 'Filter');
|
|
948
|
-
const count = chip.querySelector('.hx-forge-count');
|
|
949
|
-
count.hidden = !n;
|
|
950
|
-
count.textContent = String(n);
|
|
951
|
-
chip.classList.toggle('is-on', n > 0);
|
|
952
|
-
box.hidden = !(on && ui.filtersOpen);
|
|
953
|
-
}
|
|
954
|
-
|
|
955
|
-
/** The filters' choices: the states of the kind, the labels and authors of what is loaded */
|
|
956
|
-
function paintFilters() {
|
|
957
|
-
$('forge-filters').hidden = ui.kind === 'work' || !filterable();
|
|
958
|
-
$('forge-work-filters').hidden = ui.kind !== 'work';
|
|
959
|
-
$('forge-work-agents').checked = ui.workFilters.agentsOnly;
|
|
960
|
-
$('forge-work-finished').checked = ui.workFilters.finished;
|
|
961
|
-
if (ui.kind === 'work' || !filterable()) return;
|
|
962
|
-
const items = current() && ui.kind !== 'deploys' ? current().items : [];
|
|
963
|
-
const { labels, authors } = facetsOf(items);
|
|
964
|
-
if (ui.filters.label && !labels.includes(ui.filters.label)) ui.filters.label = '';
|
|
965
|
-
if (ui.filters.author && !authors.includes(ui.filters.author)) ui.filters.author = '';
|
|
966
|
-
$('forge-state').innerHTML = STATES[ui.kind].map(([v, l]) => option(v, l, v === ui.filters.state)).join('');
|
|
967
|
-
$('forge-label').innerHTML = option('', 'Any label', !ui.filters.label) + labels.map((l) => option(l, l, l === ui.filters.label)).join('');
|
|
968
|
-
$('forge-author').innerHTML = option('', 'Anyone', !ui.filters.author) + authors.map((a) => option(a, a, a === ui.filters.author)).join('');
|
|
969
|
-
// A deploy has no labels and no author to pick: its list is filtered by state and the search
|
|
970
|
-
$('forge-label').parentElement.hidden = ui.kind === 'deploys' || ui.kind === 'threads';
|
|
971
|
-
$('forge-author').parentElement.hidden = ui.kind === 'deploys';
|
|
972
|
-
// …and its search reads the workflow, what it ran for, the branch and who started it, not a number or a label
|
|
973
|
-
$('forge-text').placeholder = ui.kind === 'deploys' ? 'Workflow, branch, commit, who' : ui.kind === 'threads' ? 'Title, number, author' : 'Title, number, label';
|
|
974
|
-
}
|
|
975
|
-
|
|
976
|
-
/** What a deploy lights, said short, for its row: how many nodes, or that it is not mapped */
|
|
977
|
-
function lightsWords(deploy) {
|
|
978
|
-
if (!deploy.restarts.length) return 'Not mapped to a node';
|
|
979
|
-
const { nodes } = nodesForRestarts(deploy.restarts, state.nodes);
|
|
980
|
-
return nodes.length ? `Lights ${plural(nodes.length, 'node')}` : 'Names nodes not on the map';
|
|
981
|
-
}
|
|
982
|
-
|
|
983
|
-
function deployHtml(d) {
|
|
984
|
-
const link = safeUrl(d.url);
|
|
985
|
-
const out = link ? `<a data-corn="out-link" class="hx-forge-out" href="${escHtml(link)}" target="_blank" rel="noreferrer" aria-label="Open deploy ${escHtml(d.name)} on ${escHtml(forgeName())} (new tab)">↗</a>` : '';
|
|
986
|
-
return `<li class="hx-forge-item"><button type="button" class="hx-forge-row" data-forge-deploy="${escHtml(d.id)}" aria-pressed="${ui.deploy === d.id}" data-corn="row">
|
|
987
|
-
<span class="hx-forge-title">${escHtml(d.name)}${d.title && d.title !== d.name ? `<span class="hx-faint"> · ${escHtml(d.title)}</span>` : ''}</span>
|
|
988
|
-
<span class="hx-forge-meta"><span class="hx-forge-state hx-forge-state--${escHtml(d.state)}" data-corn="state-pill"${cornStateAttr(d.state)}>${stateIconHtml(d.state)}${escHtml(deployWords(d))}</span> ${escHtml(deployMeta(d, now()))}</span>
|
|
989
|
-
<span class="hx-forge-labels"><span class="hx-forge-label" data-corn="tag">${escHtml(lightsWords(d))}</span></span></button>${out}</li>`;
|
|
990
|
-
}
|
|
991
|
-
|
|
992
|
-
/** One thread in the list: a row that opens it, and a link out to the forge */
|
|
993
|
-
function threadHtml(t) {
|
|
994
|
-
const link = safeUrl(t.url);
|
|
995
|
-
const out = link ? `<a data-corn="out-link" class="hx-forge-out" href="${escHtml(link)}" target="_blank" rel="noreferrer" aria-label="Open thread ${t.number} on ${escHtml(forgeName())} (new tab)">↗</a>` : '';
|
|
996
|
-
const note = [t.proposals && t.proposals.length ? `Proposal ${t.proposals.map((p) => p.slug).join(', ')}` : '', t.idea ? `Idea #${t.idea}` : ''].filter(Boolean).join(' · ');
|
|
997
|
-
// The run that is about this thread, as a word (issue #104): the Agents tab's list, read for every tab, says it; the row only names its state
|
|
998
|
-
const runs = ui.runs && ui.runs.data ? ui.runs.data.runs : null;
|
|
999
|
-
const run = runOnThread(runs, t.number);
|
|
1000
|
-
const runWord = run ? `${runPillHtml({ esc: escHtml }, run, threadRunWords(runs, t.number), ` data-thread-run="${escHtml(run.runId)}"`)} ` : '';
|
|
1001
|
-
return `<li class="hx-forge-item"><button type="button" class="hx-forge-row" data-forge-thread="${t.number}" aria-pressed="${ui.thread === t.number}" data-corn="row">
|
|
1002
|
-
<span class="hx-forge-title">${escHtml(t.title)}</span>
|
|
1003
|
-
<span class="hx-forge-meta"><span class="hx-forge-state hx-forge-state--${escHtml(t.state)}" data-corn="state-pill"${cornStateAttr(t.state)}>${escHtml(t.state === 'open' ? 'Open' : 'Closed')}</span> ${runWord}<span class="hx-forge-label" data-corn="tag">${escHtml(threadKindWords(t))}</span> ${escHtml(threadMeta(t, now()))}</span>${note ? `<span class="hx-forge-meta">${escHtml(note)}</span>` : ''}</button>${out}</li>`;
|
|
1004
|
-
}
|
|
1005
|
-
|
|
1006
|
-
function itemHtml(item, before = '', after = '') {
|
|
1007
|
-
if (ui.kind === 'deploys') return deployHtml(item);
|
|
1008
|
-
if (ui.kind === 'threads') return threadHtml(item);
|
|
1009
|
-
const link = safeUrl(item.url);
|
|
1010
|
-
const labels = item.labels.length ? `<span class="hx-forge-labels">${item.labels.map((l) => `<span class="hx-forge-label" data-corn="tag">${escHtml(l)}</span>`).join('')}</span>` : '';
|
|
1011
|
-
const inner = `<span class="hx-forge-title">${escHtml(item.title)}</span>
|
|
1012
|
-
<span class="hx-forge-meta"><span class="hx-forge-state hx-forge-state--${escHtml(item.draft ? 'draft' : item.state)}" data-corn="state-pill"${cornStateAttr(item.draft ? 'draft' : item.state)}>${escHtml(stateWords(item))}</span> ${escHtml(metaWords(item, now()))}</span>${before}${after}${labels}`;
|
|
1013
|
-
const out = link ? `<a data-corn="out-link" class="hx-forge-out" href="${escHtml(link)}" target="_blank" rel="noreferrer" aria-label="Open ${escHtml(item.head ? 'pull request' : 'issue')} ${item.number} on ${escHtml(forgeName())} (new tab)">↗</a>` : '';
|
|
1014
|
-
if (ui.kind !== 'issues') {
|
|
1015
|
-
return `<li class="hx-forge-item"><button type="button" class="hx-forge-row" data-forge-pr="${item.number}" aria-pressed="${ui.selected === item.number}" data-corn="row">${inner}</button>${out}</li>`;
|
|
1016
|
-
}
|
|
1017
|
-
// An issue has no more to show here: its row is the link out; an open one also starts its spec (step 1 of the pipeline)
|
|
1018
|
-
const spec = specBlock(item) === null
|
|
1019
|
-
? `<button data-corn-kind="secondary" type="button" class="hx-btn hx-forge-act hx-forge-startspec" data-forge-spec="${item.number}" aria-label="Start a spec for issue ${item.number}"${ui.busy ? ' disabled' : ''}>Start a spec …</button>`
|
|
1020
|
-
: '';
|
|
1021
|
-
const agent = item.state === 'open'
|
|
1022
|
-
? `<button data-corn-kind="secondary" type="button" class="hx-btn hx-forge-act hx-forge-startspec" data-forge-agent="issue:${item.number}" aria-label="${escHtml(t('startAgent'))} on issue ${item.number}">${escHtml(t('startAgent'))} …</button>`
|
|
1023
|
-
: '';
|
|
1024
|
-
return link
|
|
1025
|
-
? `<li class="hx-forge-item"><a class="hx-forge-row" href="${escHtml(link)}" target="_blank" rel="noreferrer" data-corn="row">${inner}<span class="hx-sr-only"> (opens ${escHtml(forgeName())} in a new tab)</span></a>${spec}${agent}</li>`
|
|
1026
|
-
: `<li class="hx-forge-item"><div class="hx-forge-row" data-corn="row">${inner}</div>${spec}${agent}</li>`;
|
|
1027
|
-
}
|
|
1028
|
-
|
|
1029
|
-
/** One piece of work in a group: a pull request (a row that selects it, as in the Pull requests tab) or a branch with none */
|
|
1030
|
-
function workHtml(e) {
|
|
1031
|
-
const mark = e.mark ? `<span class="hx-forge-agentline"><span class="hx-forge-agent" title="Agent-made: ${escHtml(markWords(e.mark))}" data-corn="badge">Agent</span><span class="hx-forge-why hx-faint">${escHtml(markWords(e.mark))}</span></span>` : '';
|
|
1032
|
-
if (e.type === 'pull') {
|
|
1033
|
-
const also = e.issues.slice(1);
|
|
1034
|
-
const note = [e.proposal ? `Spec PR for ${e.proposal}` : '', also.length ? `Also closes ${also.map((n) => `#${n}`).join(', ')}` : ''].filter(Boolean);
|
|
1035
|
-
return itemHtml(e.pull, mark, note.length ? `<span class="hx-forge-meta">${escHtml(note.join(' · '))}</span>` : '');
|
|
1036
|
-
}
|
|
1037
|
-
return `<li class="hx-forge-item"><div class="hx-forge-row hx-forge-branch" data-corn="row"><span class="hx-forge-title"><span class="hx-sr-only">Branch </span><code class="hx-code">${escHtml(e.branch.name)}</code></span><span class="hx-forge-meta"><span class="hx-forge-state hx-forge-state--draft" data-corn="state-pill" data-corn-state="draft">Branch</span> no pull request yet</span>${mark}</div></li>`;
|
|
1038
|
-
}
|
|
1039
|
-
|
|
1040
|
-
/** The Agents tab's groups, each a heading and its work */
|
|
1041
|
-
function groupsHtml(groups) {
|
|
1042
|
-
return groups.map((g, i) => {
|
|
1043
|
-
const link = g.issue && safeUrl(g.issue.url) ? ` <a data-corn="text-link" class="hx-link hx-forge-gout" href="${escHtml(g.issue.url)}" target="_blank" rel="noreferrer" aria-label="Open issue ${g.number} on ${escHtml(forgeName())} (new tab)">↗</a>` : '';
|
|
1044
|
-
const startRef = g.kind === 'issue' && g.issue && g.issue.state === 'open' ? `issue:${g.number}` : g.kind === 'proposal' ? `proposal:${g.slug}` : null;
|
|
1045
|
-
const start = startRef ? ` <button data-corn-kind="secondary" type="button" class="hx-btn hx-forge-act" data-forge-agent="${escHtml(startRef)}" aria-label="${escHtml(t('startAgent'))} on ${escHtml(g.kind === 'issue' ? `issue ${g.number}` : `proposal ${g.slug}`)}">${escHtml(t('startAgent'))} …</button>` : '';
|
|
1046
|
-
return `<li class="hx-forge-group"><h3 class="hx-forge-gtitle" id="forge-group-${i}">${escHtml(g.title)}${link}</h3>${start}<p class="hx-forge-meta">${escHtml(groupWords(g))}</p><ul class="hx-forge-list" aria-labelledby="forge-group-${i}">${g.entries.map(workHtml).join('')}</ul></li>`;
|
|
1047
|
-
}).join('');
|
|
1048
|
-
}
|
|
1049
|
-
|
|
1050
|
-
/** Which selection replaces the list now, as a key ('pr:12', 'thread:3', 'deploy:9004'), or '' while the list shows. A selection stays lit on the map but shows only on the tab it belongs to. */
|
|
1051
|
-
function detailKey() {
|
|
1052
|
-
if (ui.kind === 'threads' && ui.thread !== null) return `thread:${ui.thread}`;
|
|
1053
|
-
if (ui.kind === 'deploys' && ui.deployItem) return `deploy:${ui.deploy}`;
|
|
1054
|
-
if (ui.selected !== null && ui.kind === ui.selectedOn) return `pr:${ui.selected}`;
|
|
1055
|
-
return '';
|
|
1056
|
-
}
|
|
1057
|
-
|
|
1058
|
-
/** The back control of a detail: an arrow and the name of the list it returns to ("All pull requests") */
|
|
1059
|
-
const backHtml = (action, words) => `<button data-corn="back" type="button" class="hx-forge-back" data-action="${action}"><svg width="14" height="14" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" aria-hidden="true"><path d="M10 3L5 8l5 5"/></svg><span class="hx-forge-back-text">${escHtml(words)}</span></button>`;
|
|
1060
|
-
|
|
1061
|
-
/** The selected deploy: what it was, and the nodes it restarted (each a button that selects it on the map) */
|
|
1062
|
-
function deployDetailHtml() {
|
|
1063
|
-
const d = ui.deployItem;
|
|
1064
|
-
const lit = ui.litDeploy;
|
|
1065
|
-
const url = safeUrl(d.url);
|
|
1066
|
-
const head = `${backHtml('clear-forge-deploy', 'All deploys')}<h3 class="hx-forge-detail-title" data-corn="detail-title">${escHtml(d.name)}</h3>
|
|
1067
|
-
<p class="hx-forge-meta"><span class="hx-forge-state hx-forge-state--${escHtml(d.state)}" data-corn="state-pill"${cornStateAttr(d.state)}>${stateIconHtml(d.state)}${escHtml(deployWords(d))}</span> ${escHtml(deployMeta(d, now()))}${url ? ` · <a data-corn="text-link" class="hx-link" href="${escHtml(url)}" target="_blank" rel="noreferrer">Open on ${escHtml(forgeName())} ↗</a>` : ''}</p>`;
|
|
1068
|
-
const stale = ui.lists.deploys && ui.lists.deploys.stale;
|
|
1069
|
-
let body;
|
|
1070
|
-
if (!d.restarts.length) {
|
|
1071
|
-
body = '<p class="hx-forge-notice" data-corn="notice">No node is mapped to this deploy, so nothing is lit. Say what it restarts under <code class="hx-code">deploys.restarts</code> in cornfield.config.js (docs/deploys.md).</p>';
|
|
1072
|
-
} else {
|
|
1073
|
-
const rows = lit.nodes.map((n) => `<li class="hx-forge-file" data-corn="file"><button data-corn="node-chip" type="button" class="hx-forge-node" data-forge-node="${escHtml(n.id)}" aria-label="Show ${escHtml(n.label)} on the map${isNodeVisible(n) ? '' : ' (its layer is off)'}">${escHtml(n.label)}${isNodeVisible(n) ? '' : ' · layer off'}</button> <span class="hx-faint">${escHtml(n.type)}</span></li>`).join('');
|
|
1074
|
-
const missing = lit.missing.length ? `<p class="hx-forge-notice" data-corn="notice">${escHtml(lit.missing.join(', '))} ${lit.missing.length === 1 ? 'is' : 'are'} named in the config but not on the map.</p>` : '';
|
|
1075
|
-
const key = lit.nodes.length ? `<p class="hx-forge-key hx-faint"><span class="hx-mark-dot hx-mark-dot--${d.state === 'failure' ? 'removed' : 'changed'}" data-corn="mark-dot"${markStateAttr(d.state === 'failure' ? 'removed' : 'changed')} aria-hidden="true"></span>${d.state === 'failure' ? 'restarted by a deploy that failed' : 'restarted by this deploy'}</p>` : '';
|
|
1076
|
-
body = `<h4 class="hx-forge-sub">${escHtml(`Restarted: ${plural(lit.nodes.length, 'node')} on the map`)}</h4>${key}${rows ? `<ul class="hx-forge-files">${rows}</ul>` : ''}${missing}`;
|
|
1077
|
-
}
|
|
1078
|
-
return `${head}${stale ? `<p class="hx-forge-notice" data-corn="notice">${escHtml(`This is an older answer. ${stale}`)}</p>` : ''}${body}`;
|
|
1079
|
-
}
|
|
1080
|
-
|
|
1081
|
-
/** A node button, as in a pull request's files: it selects the node on the map */
|
|
1082
|
-
const nodeButton = (n) => `<button data-corn="node-chip" type="button" class="hx-forge-node" data-forge-node="${escHtml(n.id)}" aria-label="Show ${escHtml(n.label)} on the map${isNodeVisible(n) ? '' : ' (its layer is off)'}">${escHtml(n.label)}${isNodeVisible(n) ? '' : ' · layer off'}</button>`;
|
|
1083
|
-
|
|
1084
|
-
/** The selected thread: read-only, its messages as written, a way to reply on the forge, and the nodes its text lights */
|
|
1085
|
-
function threadDetailHtml() {
|
|
1086
|
-
const head = (title) => `${backHtml('clear-forge-thread', 'All threads')}<h3 class="hx-forge-detail-title" data-corn="detail-title">${title}</h3>`;
|
|
1087
|
-
if (ui.threadError) return `${head(`Thread ${ui.thread}`)}<p class="hx-forge-notice" data-corn="notice">${escHtml(ui.threadError)}</p>`;
|
|
1088
|
-
if (!ui.threadDetail) return `${head(`Thread ${ui.thread}`)}<p class="hx-faint">Loading its messages …</p>`;
|
|
1089
|
-
const { thread: t, stale } = ui.threadDetail;
|
|
1090
|
-
const lit = ui.litThread;
|
|
1091
|
-
const url = safeUrl(t.url);
|
|
1092
|
-
const reply = url ? `<a data-corn="text-link" class="hx-link" href="${escHtml(url)}" target="_blank" rel="noreferrer">Reply on ${escHtml(forgeName())} (new tab)</a>` : '';
|
|
1093
|
-
const named = [
|
|
1094
|
-
...(t.proposals || []).map((p) => `Proposal <code class="hx-code">${escHtml(p.slug)}</code> in pull request #${p.pull}`),
|
|
1095
|
-
...(t.kind === 'proposal' ? [`Spec pull request for <code class="hx-code">${escHtml((t.slugs || []).join(', '))}</code>`] : []),
|
|
1096
|
-
...(t.idea ? [`Names idea #${t.idea}`] : []),
|
|
1097
|
-
];
|
|
1098
|
-
const msgs = t.messages.map((m) => {
|
|
1099
|
-
const own = lit.perMessage.get(m.id) || { nodes: [], unresolved: [] };
|
|
1100
|
-
const link = safeUrl(m.url) ? ` <a data-corn="out-link" class="hx-link" href="${escHtml(m.url)}" target="_blank" rel="noreferrer" aria-label="Open this message on ${escHtml(forgeName())} (new tab)">↗</a>` : '';
|
|
1101
|
-
const chips = own.nodes.length || own.unresolved.length
|
|
1102
|
-
? `<span class="hx-forge-nodes hx-thread-nodes">${own.nodes.map(nodeButton).join('')}${own.unresolved.length ? `<span class="hx-faint">not on the map: ${own.unresolved.map((r) => `<code class="hx-code">${escHtml(r)}</code>`).join(' ')}</span>` : ''}</span>`
|
|
1103
|
-
: '';
|
|
1104
|
-
return `<li class="hx-thread-msg" data-corn="thread-message"><p class="hx-forge-meta"><strong class="hx-strong">${escHtml(m.author ? m.author.login : 'someone')}</strong>${m.opening ? ' opened this' : ''} · ${escHtml(relativeTime(m.createdAt, now()))}${link}</p><p class="hx-thread-body">${escHtml(m.body.trim() === '' ? '(no text)' : m.body)}${m.cut ? '\n… (cut here; the rest is on the forge)' : ''}</p>${chips}</li>`;
|
|
1105
|
-
}).join('');
|
|
1106
|
-
const key = lit.nodes.length ? `<p class="hx-forge-key hx-faint"><span class="hx-mark-dot hx-mark-dot--changed" data-corn="mark-dot" data-corn-state="changed" aria-hidden="true"></span>a node this thread mentions</p>` : '';
|
|
1107
|
-
return `${head(`#${t.number} ${escHtml(t.title)}`)}
|
|
1108
|
-
<p class="hx-forge-meta"><span class="hx-forge-state hx-forge-state--${escHtml(t.state)}" data-corn="state-pill"${cornStateAttr(t.state)}>${t.state === 'open' ? 'Open' : 'Closed'}</span> ${escHtml(threadKindWords(t))} · ${escHtml(threadMeta({ ...t, comments: t.messages.length - (t.kind === 'idea' ? 1 : 0) + (t.hidden || 0) }, now()))}</p>
|
|
1109
|
-
<p class="hx-forge-why hx-faint">Read-only here: a thread is a conversation on ${escHtml(forgeName())}, so you reply there. ${reply}</p>
|
|
1110
|
-
${named.length ? `<p class="hx-forge-meta">${named.join(' · ')}</p>` : ''}
|
|
1111
|
-
${stale ? `<p class="hx-forge-notice" data-corn="notice">${escHtml(`This is an older answer. ${stale}`)}</p>` : ''}
|
|
1112
|
-
<h4 class="hx-forge-sub">${escHtml(`Mentions: ${plural(lit.nodes.length, 'node')} on the map`)}</h4>
|
|
1113
|
-
${key}
|
|
1114
|
-
${lit.nodes.length ? `<span class="hx-forge-nodes hx-thread-nodes">${lit.nodes.map(nodeButton).join('')}</span>` : '<p class="hx-faint">No message mentions a node. Write [[node-id]] or [[repo/path]] in a message to point at the map.</p>'}
|
|
1115
|
-
${lit.unresolved.length ? `<p class="hx-forge-notice" data-corn="notice">${escHtml(lit.unresolved.join(', '))} ${lit.unresolved.length === 1 ? 'is' : 'are'} mentioned but not on the map, so ${lit.unresolved.length === 1 ? 'it stays' : 'they stay'} text.</p>` : ''}
|
|
1116
|
-
<h4 class="hx-forge-sub">${escHtml(plural(t.messages.length, 'message'))}</h4>
|
|
1117
|
-
${t.hidden ? `<p class="hx-forge-why hx-faint">${escHtml(plural(t.hidden, 'earlier message'))} not shown; they are on ${escHtml(forgeName())}.</p>` : ''}
|
|
1118
|
-
<ol class="hx-thread-msgs" aria-label="Messages">${msgs}</ol>`;
|
|
1119
|
-
}
|
|
1120
|
-
|
|
1121
|
-
function detailHtml() {
|
|
1122
|
-
const shown = detailKey();
|
|
1123
|
-
if (shown.startsWith('thread:')) return threadDetailHtml();
|
|
1124
|
-
if (shown.startsWith('deploy:')) return deployDetailHtml();
|
|
1125
|
-
if (!shown) return '';
|
|
1126
|
-
const head = (title, meta) => `${backHtml('clear-forge-pr', ui.kind === 'work' ? 'All work' : 'All pull requests')}${meta || ''}<h3 class="hx-forge-detail-title" data-corn="detail-title">${title}</h3>`;
|
|
1127
|
-
if (ui.detailError) return `${head(`Pull request ${ui.selected}`)}<p class="hx-forge-notice" data-corn="notice">${escHtml(ui.detailError)}</p>`;
|
|
1128
|
-
if (!ui.detail) return `${head(`Pull request ${ui.selected}`)}<p class="hx-faint">Loading its files and checks …</p><ul class="hx-forge-list" aria-hidden="true">${loadingRowsHtml(4)}</ul>`;
|
|
1129
|
-
const { pull, checks, stale } = ui.detail;
|
|
1130
|
-
const lit = ui.lit;
|
|
1131
|
-
const mapped = lit.files.filter((f) => f.nodes.length).length;
|
|
1132
|
-
const url = safeUrl(pull.url);
|
|
1133
|
-
const failing = new Map(lit.checks.map((c) => [c.check.id, c]));
|
|
1134
|
-
|
|
1135
|
-
const checkRows = checks.map((c) => {
|
|
1136
|
-
const failed = failing.get(c.id);
|
|
1137
|
-
const lights = failed
|
|
1138
|
-
? `<span class="hx-faint hx-forge-lights">${failed.tests.length
|
|
1139
|
-
? `Lights ${failed.tests.map((t) => `<code class="hx-code">${escHtml(t.path)}</code>${t.nodes.length ? '' : ' (not on the map)'}`).join(', ')}`
|
|
1140
|
-
: 'Names no test file, so lights nothing'}</span>`
|
|
1141
|
-
: '';
|
|
1142
|
-
const name = safeUrl(c.url) ? `<a data-corn="text-link" class="hx-link" href="${escHtml(c.url)}" target="_blank" rel="noreferrer">${escHtml(c.name)}</a>` : `<span class="hx-name">${escHtml(c.name)}</span>`;
|
|
1143
|
-
const why = rerunWhy(c, forgeName());
|
|
1144
|
-
const again = c.state === 'failure' && c.canRerun
|
|
1145
|
-
? `<button data-corn-kind="secondary" type="button" class="hx-btn hx-forge-act" data-forge-rerun="${escHtml(c.id)}" aria-label="Re-run ${escHtml(c.name)}"${ui.busy ? ' disabled' : ''}>Re-run</button>`
|
|
1146
|
-
: '';
|
|
1147
|
-
const whyNot = why ? `<span class="hx-faint hx-forge-lights">${escHtml(why)}</span>` : '';
|
|
1148
|
-
return `<li class="hx-forge-check"><span class="hx-forge-state hx-forge-state--${escHtml(c.state)}" data-corn="state-pill"${cornStateAttr(c.state)}>${stateIconHtml(c.state)}${escHtml(checkWords(c))}</span> ${name}${again}${lights}${whyNot}</li>`;
|
|
1149
|
-
}).join('');
|
|
1150
|
-
|
|
1151
|
-
const fileRows = lit.files.map((f) => {
|
|
1152
|
-
const nodes = f.nodes.length
|
|
1153
|
-
? f.nodes.map((n) => `<button data-corn="node-chip" type="button" class="hx-forge-node" data-forge-node="${escHtml(n.id)}" aria-label="Show ${escHtml(n.label)} on the map${isNodeVisible(n) ? '' : ' (its layer is off)'}">${escHtml(n.label)}${isNodeVisible(n) ? '' : ' · layer off'}</button>`).join('')
|
|
1154
|
-
: '<span class="hx-faint">not on the map</span>';
|
|
1155
|
-
const renamed = f.status === 'renamed' && f.previousPath ? `<span class="hx-faint"> from ${escHtml(f.previousPath)}</span>` : '';
|
|
1156
|
-
return `<li class="hx-forge-file" data-corn="file"><span class="hx-forge-fstatus">${escHtml(f.status)}</span> <code class="hx-code">${escHtml(f.path)}</code>${renamed} <span class="hx-good">+${f.additions}</span> <span class="hx-forge-del">−${f.deletions}</span><span class="hx-forge-nodes">${nodes}</span></li>`;
|
|
1157
|
-
}).join('');
|
|
1158
|
-
|
|
1159
|
-
// Land it is the one primary action, with Open on the forge beside it; a pull request that cannot land says why in one line
|
|
1160
|
-
const block = mergeBlock(ui.detail);
|
|
1161
|
-
const land = block
|
|
1162
|
-
? `<button type="button" class="hx-btn hx-btn--approve" disabled data-corn-kind="approve">${escHtml(t('landIt'))}</button>`
|
|
1163
|
-
: `<button type="button" class="hx-btn hx-btn--approve hx-forge-act" data-forge-merge="${escHtml(String(pull.number))}"${ui.busy ? ' disabled' : ''} data-corn-kind="approve">${escHtml(t('landIt'))} …</button>`;
|
|
1164
|
-
const act = `<div class="hx-forge-cta">${land}${url ? `<a data-corn="open-link" data-corn-kind="secondary" class="hx-btn hx-forge-open" href="${escHtml(url)}" target="_blank" rel="noreferrer">Open on ${escHtml(forgeName())} ↗</a>` : ''}</div>${block ? `<p class="hx-forge-why hx-faint">${escHtml(block)}</p>` : ''}${approvalWarning(ui.detail) ? `<p class="hx-forge-why hx-faint" data-corn="notice" data-corn-state="waiting">${escHtml(approvalWarning(ui.detail))}</p>` : ''}`;
|
|
1165
|
-
// A spec approved with `proposals.approveLands` waits for its checks: said here, with a way to stop it
|
|
1166
|
-
const waiting = ui.landing && pull.state === 'open'
|
|
1167
|
-
? `<div class="hx-forge-step"><p class="hx-forge-notice hx-forge-notice--ok" role="status" data-corn="notice" data-corn-state="success">${escHtml(landingWords(ui.landing, now()))}</p><button data-corn-kind="secondary" type="button" class="hx-btn hx-forge-act" data-forge-landing-cancel="${pull.number}"${ui.busy ? ' disabled' : ''}>Cancel</button></div>`
|
|
1168
|
-
: '';
|
|
1169
|
-
const note = ui.note ? `<p class="hx-forge-notice${ui.note.ok ? ' hx-forge-notice--ok' : ''}" data-corn="notice"${ui.note.ok ? ' data-corn-state="success"' : ''}>${escHtml(ui.note.text)}</p>` : '';
|
|
1170
|
-
// Step 2 of the pipeline: a spec pull request with an approved proposal opens its build issue
|
|
1171
|
-
const offers = buildOffers(ui.detail);
|
|
1172
|
-
const build = offers.length
|
|
1173
|
-
? `<h4 class="hx-forge-subact">Build issue</h4>${offers.map((o) => (o.offer
|
|
1174
|
-
? `<div class="hx-forge-step"><button type="button" class="hx-btn hx-btn--approve hx-forge-act" data-forge-build="${escHtml(o.slug)}" aria-label="Open the build issue for ${escHtml(o.slug)}"${ui.busy ? ' disabled' : ''} data-corn-kind="approve">Open the build issue …</button><p class="hx-forge-why hx-faint"><code class="hx-code">${escHtml(o.slug)}</code> is approved. Opens a confirm step that shows the issue. Nothing is built.</p></div>`
|
|
1175
|
-
: `<p class="hx-forge-why hx-faint"><code class="hx-code">${escHtml(o.slug)}</code>: ${escHtml(o.why)}</p>`)).join('')}`
|
|
1176
|
-
: '';
|
|
1177
|
-
|
|
1178
|
-
const key = lit.changed.size || lit.failing.size
|
|
1179
|
-
? `<p class="hx-forge-key hx-faint">${lit.changed.size ? '<span class="hx-mark-dot hx-mark-dot--changed" data-corn="mark-dot" data-corn-state="changed" aria-hidden="true"></span>a file this pull request changes ' : ''}${lit.failing.size ? '<span class="hx-mark-dot hx-mark-dot--removed" data-corn="mark-dot" data-corn-state="removed" aria-hidden="true"></span>a test a failing check names' : ''}</p>`
|
|
1180
|
-
: '';
|
|
1181
|
-
// Its run: who is running it, their state, the time and the cost (the runs are read for the Runs tab, and once for the first PR selected)
|
|
1182
|
-
const runs = ui.runs && ui.runs.data ? ui.runs.data.runs : null;
|
|
1183
|
-
const made = runOnPull(runs, pull.number);
|
|
1184
|
-
const runSection = made
|
|
1185
|
-
? `<h4 class="hx-forge-sub">Run</h4><p class="hx-forge-runline"${cornStateAttr(made.status)} data-corn="run">${runPillHtml({ esc: escHtml }, made, statusWords(made))} ${escHtml(pullRunWords(made, now(), { state: false }))}</p>`
|
|
1186
|
-
: '';
|
|
1187
|
-
const meta = `<p class="hx-forge-meta hx-forge-dmeta"><span class="hx-forge-state hx-forge-state--${escHtml(pull.draft ? 'draft' : pull.state)}" data-corn="state-pill"${cornStateAttr(pull.draft ? 'draft' : pull.state)}>${escHtml(stateWords(pull))}</span> <span data-corn="count">#${escHtml(String(pull.number))}</span> <span>${escHtml(pull.head.ref)} → ${escHtml(pull.base.ref)}</span> <span>${escHtml(pull.author ? pull.author.login : 'someone')}</span> <span>${escHtml(relativeTime(pull.createdAt || pull.updatedAt, now()))}</span></p>`;
|
|
1188
|
-
return `${head(escHtml(pull.title), meta)}
|
|
1189
|
-
${act}
|
|
1190
|
-
${stale ? `<p class="hx-forge-notice" data-corn="notice">${escHtml(`This is an older answer. ${stale}`)}</p>` : ''}
|
|
1191
|
-
${note}
|
|
1192
|
-
${waiting}
|
|
1193
|
-
${build}
|
|
1194
|
-
<h4 class="hx-forge-sub">Checks: ${escHtml(checksWords(checks))}</h4>
|
|
1195
|
-
${checks.length ? `<ul class="hx-forge-checks">${checkRows}</ul>` : ''}
|
|
1196
|
-
<h4 class="hx-forge-sub">${escHtml(plural(lit.files.length, 'file'))} changed, ${mapped} on the map</h4>
|
|
1197
|
-
${key}
|
|
1198
|
-
<ul class="hx-forge-files">${fileRows}</ul>
|
|
1199
|
-
${runSection}`;
|
|
1200
|
-
}
|
|
1201
|
-
|
|
1202
|
-
/** How to find an element of the panel again after it is drawn anew, or null */
|
|
1203
|
-
function findAgain(el) {
|
|
1204
|
-
if (!el || !el.dataset) return null;
|
|
1205
|
-
if (el.classList.contains('hx-forge-back') && el.closest('#forge-detail')) return '#forge-detail .hx-forge-back'; // the detail is drawn anew as its answer comes in
|
|
1206
|
-
if (el.dataset.forgePr) return `[data-forge-pr="${el.dataset.forgePr}"]`;
|
|
1207
|
-
if (el.dataset.forgeDeploy) return `[data-forge-deploy="${el.dataset.forgeDeploy}"]`;
|
|
1208
|
-
if (el.dataset.forgeThread) return `[data-forge-thread="${el.dataset.forgeThread}"]`;
|
|
1209
|
-
if (el.dataset.forgeNode) return `[data-forge-node="${el.dataset.forgeNode}"]`;
|
|
1210
|
-
if (el.dataset.specGroupToggle) return `[data-spec-group-toggle="${el.dataset.specGroupToggle}"]`;
|
|
1211
|
-
if (el.dataset.forgeMerge) return '[data-forge-merge]';
|
|
1212
|
-
if (el.dataset.forgeSpec) return `[data-forge-spec="${el.dataset.forgeSpec}"]`;
|
|
1213
|
-
if (el.dataset.forgeBuild) return `[data-forge-build="${el.dataset.forgeBuild}"]`;
|
|
1214
|
-
if (el.dataset.forgeRerun) return `[data-forge-rerun="${el.dataset.forgeRerun}"]`;
|
|
1215
|
-
if (el.dataset.forgeAgent) return `[data-forge-agent="${el.dataset.forgeAgent}"]`;
|
|
1216
|
-
if (el.dataset.forgeStop) return `[data-forge-stop="${el.dataset.forgeStop}"]`;
|
|
1217
|
-
if (el.dataset.forgeRetry) return `[data-forge-retry="${el.dataset.forgeRetry}"]`;
|
|
1218
|
-
if (el.dataset.runReply) return `[data-run-reply="${el.dataset.runReply}"]`;
|
|
1219
|
-
if (el.dataset.runAnswer) return `[data-run-answer="${el.dataset.runAnswer}"][data-run-id="${el.dataset.runId}"]`;
|
|
1220
|
-
if (el.dataset.runSelect) return `[data-run-select="${el.dataset.runSelect}"]`;
|
|
1221
|
-
if (el.dataset.runTimeline) return `[data-run-timeline="${el.dataset.runTimeline}"]`;
|
|
1222
|
-
return null;
|
|
1223
|
-
}
|
|
1224
|
-
|
|
1225
|
-
/** What the focus does when a selection replaces the list, and when it goes back: the key of the selection shown at the last paint, and the tab it was on */
|
|
1226
|
-
let shownKey = '';
|
|
1227
|
-
let shownKind = '';
|
|
1228
|
-
let returnTo = null; // the selector of the row that opened the selection
|
|
1229
|
-
|
|
1230
|
-
const key0 = () => detailKey();
|
|
1231
|
-
|
|
1232
|
-
/** Everything the panel shows, from `ui` (a row or node button that had the focus has it again) */
|
|
1233
|
-
function paint() {
|
|
1234
|
-
const panel = $('forge-panel');
|
|
1235
|
-
if (!panel) return;
|
|
1236
|
-
const had = panel.contains(document.activeElement) ? document.activeElement : null;
|
|
1237
|
-
const again = had ? findAgain(had) : null;
|
|
1238
|
-
// A list drawn again must not move what the person is looking at: the scroll of the panel stays where it was
|
|
1239
|
-
const scroller = panel.querySelector('.hx-forge-body');
|
|
1240
|
-
const scrolled = scroller ? scroller.scrollTop : 0;
|
|
1241
|
-
const keyBefore = shownKey;
|
|
1242
|
-
draw(panel);
|
|
1243
|
-
if (scroller && scrolled && key0() === keyBefore && scroller.scrollTop !== scrolled) scroller.scrollTop = scrolled;
|
|
1244
|
-
const back = again && panel.querySelector(again);
|
|
1245
|
-
if (back && back !== document.activeElement && !back.closest('[hidden]')) back.focus();
|
|
1246
|
-
// Retry was pressed and its notice is gone (the list is being read again): the focus goes to the panel's title, never to the page
|
|
1247
|
-
if (had && had.dataset && had.dataset.action === 'retry-forge' && !panel.contains(document.activeElement)) $('forge-title').focus();
|
|
1248
|
-
// A control of a run card that is no longer drawn (the run went on): the focus goes to that run's card, never to the page
|
|
1249
|
-
const hadRun = had && !had.isConnected && had.closest('[data-run]');
|
|
1250
|
-
if (hadRun && !panel.contains(document.activeElement)) {
|
|
1251
|
-
const card = [...panel.querySelectorAll('[data-run]')].find((c) => c.dataset.run === hadRun.dataset.run);
|
|
1252
|
-
if (card) card.focus();
|
|
1253
|
-
}
|
|
1254
|
-
// A selection replaces the list: the focus goes to its back control, and returns to the row when it is let go of
|
|
1255
|
-
// (a tab changed leaves the focus on the tab)
|
|
1256
|
-
const key = detailKey();
|
|
1257
|
-
if (key !== shownKey && shownKind === ui.kind) {
|
|
1258
|
-
if (key) {
|
|
1259
|
-
const target = panel.querySelector('#forge-detail .hx-forge-back');
|
|
1260
|
-
if (target && (had || !shownKey)) target.focus();
|
|
1261
|
-
} else {
|
|
1262
|
-
const row = returnTo && panel.querySelector(returnTo);
|
|
1263
|
-
if (row && !row.closest('[hidden]')) row.focus(); else $('forge-title').focus();
|
|
1264
|
-
returnTo = null;
|
|
1265
|
-
}
|
|
1266
|
-
}
|
|
1267
|
-
shownKey = key;
|
|
1268
|
-
shownKind = ui.kind;
|
|
1269
|
-
}
|
|
1270
|
-
|
|
1271
|
-
/** The tabs' counts, where there is one: the proposals, the open pull requests and issues and threads, the runs still open */
|
|
1272
|
-
function paintCounts() {
|
|
1273
|
-
const open = (key) => (ui.lists[key] ? ui.lists[key].items.length : null);
|
|
1274
|
-
const specs = specsList() && specsList().items;
|
|
1275
|
-
const runs = ui.runs && ui.runs.data ? ui.runs.data.open : null;
|
|
1276
|
-
const counts = { specs: specs ? specs.length : null, pulls: open('pulls|open'), issues: open('issues|open'), threads: ui.config && ui.config.threads === false ? null : open('threads|open'), work: runs };
|
|
1277
|
-
// What waits on you shows as a filled badge on its tab: Specs the specs to decide, Runs the runs that need an answer (spec 0010 D2); with nothing
|
|
1278
|
-
// waiting, the tab shows its plain total like the others. One number a tab, and its name says so.
|
|
1279
|
-
const w = waitingNow();
|
|
1280
|
-
const share = { specs: w.specs, work: w.runs };
|
|
1281
|
-
for (const btn of document.querySelectorAll('#forge-panel [data-forge-kind]')) {
|
|
1282
|
-
const kind = btn.dataset.forgeKind;
|
|
1283
|
-
const el = btn.querySelector('.hx-forge-count');
|
|
1284
|
-
if (!el) continue;
|
|
1285
|
-
const waits = share[kind] || 0;
|
|
1286
|
-
const n = waits || counts[kind];
|
|
1287
|
-
el.hidden = !(kind in counts); // a tab with no count at all (Deploys) shows none; the others hold their width while empty
|
|
1288
|
-
el.textContent = n ? String(n) : '';
|
|
1289
|
-
// The hook says which it is: a filled badge for what waits on you, a plain count for the total
|
|
1290
|
-
el.dataset.corn = waits ? 'waiting-badge' : 'count';
|
|
1291
|
-
el.classList.toggle('hx-forge-count--waiting', !!waits);
|
|
1292
|
-
const label = btn.querySelector('[data-corn-string]');
|
|
1293
|
-
if (waits && label) btn.setAttribute('aria-label', `${label.textContent}, ${waitingWords(waits)}`); else btn.removeAttribute('aria-label');
|
|
1294
|
-
}
|
|
1295
|
-
}
|
|
1296
|
-
|
|
1297
|
-
/** The one number, wherever it shows: the tabs' badges, the Work button's, and the browser tab's title; called whenever the specs or the runs were read */
|
|
1298
|
-
function paintWaiting() {
|
|
1299
|
-
paintCounts();
|
|
1300
|
-
paintButton();
|
|
1301
|
-
paintTitle();
|
|
1302
|
-
paintBarLine();
|
|
1303
|
-
refreshStubs();
|
|
1304
|
-
}
|
|
1305
|
-
|
|
1306
|
-
/** The proposal bar's line: a run waits on the open proposal (spec 0010 D2) */
|
|
1307
|
-
function paintBarLine(open = !!state.proposal) {
|
|
1308
|
-
const run = open && state.proposalSlug && ui.runs && ui.runs.data ? runWaitingOn(ui.runs.data.runs, state.proposalSlug) : null;
|
|
1309
|
-
paintWaitingLine(run, `${state.proposalSource || ''}/${state.proposalSlug || ''}`);
|
|
1310
|
-
}
|
|
1311
|
-
|
|
1312
|
-
/** Answer, on the proposal bar's line: Work opens on Runs at that run with its reply field focused */
|
|
1313
|
-
async function answerFromBar(id) {
|
|
1314
|
-
if (!(await openRunLink(id))) return;
|
|
1315
|
-
const field = $('forge-runs-list').querySelector(`[data-run-reply="${id}"]`);
|
|
1316
|
-
if (field) field.focus();
|
|
1317
|
-
}
|
|
1318
|
-
|
|
1319
|
-
/** The browser tab's title starts "(3) " while something waits, then the page's own title (the app's configured name, whatever the server wrote) */
|
|
1320
|
-
let baseTitle = null;
|
|
1321
|
-
function paintTitle() {
|
|
1322
|
-
if (typeof document === 'undefined') return;
|
|
1323
|
-
if (baseTitle === null) baseTitle = document.title.replace(/^\(\d+\) /, '');
|
|
1324
|
-
const n = waitingNow().total;
|
|
1325
|
-
document.title = n > 0 ? `(${n}) ${baseTitle}` : baseTitle;
|
|
1326
|
-
}
|
|
1327
|
-
|
|
1328
|
-
/** Says (on the panel's top, for the CSS) that the tabs run on past an edge: a fade shows on that side, so Deploys is not simply missing on a phone */
|
|
1329
|
-
function paintTabsMore() {
|
|
1330
|
-
const top = document.querySelector('#forge-panel .hx-forge-top');
|
|
1331
|
-
const tabs = top && top.querySelector('.hx-forge-tabs');
|
|
1332
|
-
if (!tabs) return;
|
|
1333
|
-
const more = [];
|
|
1334
|
-
if (tabs.scrollLeft > 1) more.push('start');
|
|
1335
|
-
if (tabs.scrollWidth - tabs.clientWidth - tabs.scrollLeft > 1) more.push('end');
|
|
1336
|
-
if (more.length) top.dataset.more = more.join(' '); else delete top.dataset.more;
|
|
1337
|
-
// A row given the focus is scrolled clear of the fixed top, never left under it (its height changes with the theme and the width)
|
|
1338
|
-
const body = top.parentElement;
|
|
1339
|
-
if (body) body.style.scrollPaddingTop = `${top.offsetHeight}px`;
|
|
1340
|
-
}
|
|
1341
|
-
|
|
1342
|
-
/** A notice line: its words, and a Retry that reads the tab again (for a failure or an older answer) */
|
|
1343
|
-
function setNotice(el, words, retry) {
|
|
1344
|
-
el.hidden = !words;
|
|
1345
|
-
el.textContent = words;
|
|
1346
|
-
if (words && retry) {
|
|
1347
|
-
const again = document.createElement('button');
|
|
1348
|
-
again.type = 'button';
|
|
1349
|
-
again.className = 'hx-btn hx-forge-act';
|
|
1350
|
-
again.dataset.action = 'retry-forge';
|
|
1351
|
-
again.dataset.cornKind = 'quiet';
|
|
1352
|
-
again.textContent = 'Retry';
|
|
1353
|
-
el.append(' ', again);
|
|
1354
|
-
}
|
|
1355
|
-
}
|
|
1356
|
-
|
|
1357
|
-
function draw(panel) {
|
|
1358
|
-
for (const btn of panel.querySelectorAll('[data-forge-kind]')) btn.setAttribute('aria-pressed', String(btn.dataset.forgeKind === (ui.kind === 'notes' ? 'pulls' : ui.kind)));
|
|
1359
|
-
paintCounts();
|
|
1360
|
-
const notes = ui.kind === 'notes';
|
|
1361
|
-
const specs = ui.kind === 'specs';
|
|
1362
|
-
const showing = detailKey();
|
|
1363
|
-
$('forge-filters').hidden = notes || ui.kind === 'work' || specs;
|
|
1364
|
-
const searchBox = $('forge-specs-search');
|
|
1365
|
-
if (searchBox) searchBox.hidden = !specs || !!showing;
|
|
1366
|
-
$('forge-work-filters').hidden = ui.kind !== 'work';
|
|
1367
|
-
$('forge-bar').hidden = !!showing;
|
|
1368
|
-
paintChip();
|
|
1369
|
-
$('forge-list').hidden = notes || !!showing;
|
|
1370
|
-
$('forge-notes').hidden = !notes;
|
|
1371
|
-
$('notes-open').hidden = ui.kind !== 'pulls' || !!showing;
|
|
1372
|
-
$('forge-foot').hidden = notes || !!showing;
|
|
1373
|
-
if (notes) {
|
|
1374
|
-
drawNotes();
|
|
1375
|
-
return;
|
|
1376
|
-
}
|
|
1377
|
-
|
|
1378
|
-
const list = current();
|
|
1379
|
-
const work = ui.kind === 'work';
|
|
1380
|
-
const groups = work ? groupsShown() : [];
|
|
1381
|
-
const shown = list && !work && !specs ? filterItems(list.items, ui.kind, ui.filters) : [];
|
|
1382
|
-
const status = $('forge-status');
|
|
1383
|
-
if (ui.loading && !list) status.textContent = work ? `Loading the work from ${forgeName()} …` : specs ? 'Looking for proposals …' : `Loading ${kindWords()}s from ${forgeName()} …`;
|
|
1384
|
-
else if (!list) status.textContent = '';
|
|
1385
|
-
else if (work) status.textContent = workStatus(groups, list.at, now());
|
|
1386
|
-
else if (specs) status.textContent = `${waitingNow().specs ? `${waitingNow().specs} ${t('toDecide').toLowerCase()} \u00b7 ` : ''}${plural(list.items.length, 'proposal')}${list.at ? `, as of ${relativeTime(list.at, now())}` : ''}`;
|
|
1387
|
-
else status.textContent = `${shown.length} of ${plural(list.items.length, kindWords())}${list.at ? `, as of ${relativeTime(list.at, now())}` : ''}`;
|
|
1388
|
-
|
|
1389
|
-
const notice = $('forge-notice');
|
|
1390
|
-
const words = ui.error || (list && list.stale ? `Showing an older answer. ${list.stale}` : '') || (specs && list && list.problem ? `The spec PRs could not be listed: ${list.problem}` : '') || (work && list && list.problem ? `Spec pull requests could not all be read: ${list.problem}` : '') || (ui.kind === 'threads' && list && list.problem ? `Some threads could not all be read: ${list.problem}` : '');
|
|
1391
|
-
setNotice(notice, words, !!words);
|
|
1392
|
-
|
|
1393
|
-
const act = $('forge-act-note');
|
|
1394
|
-
if (act) {
|
|
1395
|
-
act.hidden = !ui.actNote;
|
|
1396
|
-
const link = ui.actNote && safeUrl(ui.actNote.url);
|
|
1397
|
-
act.className = `hx-forge-notice${ui.actNote && ui.actNote.ok ? ' hx-forge-notice--ok' : ''}`;
|
|
1398
|
-
if (ui.actNote && ui.actNote.ok) act.dataset.cornState = 'success'; else delete act.dataset.cornState;
|
|
1399
|
-
act.innerHTML = ui.actNote ? `${escHtml(ui.actNote.text)}${link ? ` <a data-corn="text-link" class="hx-link" href="${escHtml(link)}" target="_blank" rel="noreferrer">Open on ${escHtml(forgeName())} ↗</a>` : ''}` : '';
|
|
1400
|
-
}
|
|
1401
|
-
|
|
1402
|
-
const rows = $('forge-list');
|
|
1403
|
-
const empty = (words) => `<li class="hx-forge-empty hx-faint" data-corn="empty">${escHtml(words)}</li>`;
|
|
1404
|
-
rows.setAttribute('aria-busy', String(!!ui.loading && !list));
|
|
1405
|
-
// A list that is being read holds its height with rows of the right size, so nothing jumps when the data comes
|
|
1406
|
-
// (On Runs the list sits under the runs, whose height is not known yet: rows held there would jump when the runs arrive, so they wait. They
|
|
1407
|
-
// are drawn with the work's answer all the same, which loadWork paints only once the runs are read too, failed or not.)
|
|
1408
|
-
if (!list) rows.innerHTML = ui.loading && !(work && !(ui.runs && ui.runs.data)) ? loadingRowsHtml(4) : '';
|
|
1409
|
-
else if (specs) {
|
|
1410
|
-
const open = state.proposal ? { slug: state.proposalSlug, source: state.proposalSource } : null;
|
|
1411
|
-
const groups = specGroups(list.items, { query: ui.specQuery });
|
|
1412
|
-
rows.innerHTML = groups.length ? specGroupsHtml(groups, { current: open, nowMs: now(), draftsOpen: ui.draftsOpen })
|
|
1413
|
-
: list.items.length ? `<li class="hx-forge-empty hx-faint" data-corn="empty">No spec matches \u201c${escHtml(ui.specQuery.trim())}\u201d. <button type="button" class="hx-btn hx-forge-act" data-corn-kind="quiet" data-action="clear-specs-search">Clear the search</button></li>`
|
|
1414
|
-
: empty(emptyWords('specs', forgeName()));
|
|
1415
|
-
}
|
|
1416
|
-
else if (work) rows.innerHTML = groups.length ? groupsHtml(groups) : empty(ui.work.grouped.groups.length ? 'No work matches these filters.' : emptyWords('work', forgeName()));
|
|
1417
|
-
else rows.innerHTML = shown.length ? shown.map((i) => itemHtml(i)).join('') : empty(list.items.length ? `No ${kindWords()} matches these filters.` : emptyWords(ui.kind, forgeName()));
|
|
1418
|
-
|
|
1419
|
-
const detail = $('forge-detail');
|
|
1420
|
-
detail.hidden = !showing;
|
|
1421
|
-
detail.setAttribute('aria-label', showing.startsWith('thread:') ? 'Selected thread' : showing.startsWith('deploy:') ? 'Selected deploy' : 'Selected pull request');
|
|
1422
|
-
detail.innerHTML = detailHtml();
|
|
1423
|
-
|
|
1424
|
-
paintIdea();
|
|
1425
|
-
$('forge-foot').hidden = $('notes-open').hidden && $('forge-idea').hidden;
|
|
1426
|
-
const rate = (showing && ((ui.threadDetail && ui.threadDetail.rate) || (ui.detail && ui.detail.rate))) || (list && list.rate) || '';
|
|
1427
|
-
$('forge-rate').textContent = rate;
|
|
1428
|
-
paintRuns();
|
|
1429
|
-
paintButton();
|
|
1430
|
-
paintTabsMore();
|
|
1431
|
-
}
|
|
1432
|
-
|
|
1433
|
-
/** The runs of the Agents tab: state, what each is about, links, and Stop. A runner's words are escaped like any text from the forge. */
|
|
1434
|
-
function paintRuns() {
|
|
1435
|
-
const box = $('forge-runs');
|
|
1436
|
-
if (!box) return;
|
|
1437
|
-
box.hidden = ui.kind !== 'work' || !!detailKey();
|
|
1438
|
-
if (box.hidden) return;
|
|
1439
|
-
const data = ui.runs && ui.runs.data;
|
|
1440
|
-
$('forge-runs-status').textContent = data ? runsStatus(data) : ui.loading ? 'Loading the runs …' : '';
|
|
1441
|
-
const note = $('forge-runs-note');
|
|
1442
|
-
const failed = ui.runs && ui.runs.error;
|
|
1443
|
-
const words = failed || (ui.runNote ? ui.runNote.text : '');
|
|
1444
|
-
note.className = `hx-forge-notice${!failed && ui.runNote && ui.runNote.ok ? ' hx-forge-notice--ok' : ''}`;
|
|
1445
|
-
if (!failed && ui.runNote && ui.runNote.ok) note.dataset.cornState = 'success'; else delete note.dataset.cornState;
|
|
1446
|
-
setNotice(note, words, !!failed);
|
|
1447
|
-
paintRunner('forge-runs-runner', data);
|
|
1448
|
-
const waiting = !data && !failed && !!ui.loading; // the runner line and the totals hold their place while the runs load (not beside a failure)
|
|
1449
|
-
if (waiting) { const r = $('forge-runs-runner'); r.hidden = false; r.innerHTML = loadingLinesHtml(1); }
|
|
1450
|
-
const trig = $('forge-runs-trigger');
|
|
1451
|
-
if (trig) {
|
|
1452
|
-
const skipped = data ? triggerNotice(data) : '';
|
|
1453
|
-
trig.hidden = !skipped;
|
|
1454
|
-
trig.textContent = skipped;
|
|
1455
|
-
}
|
|
1456
|
-
const totals = $('forge-runs-totals');
|
|
1457
|
-
if (totals) {
|
|
1458
|
-
const lines = data ? totalsLines(data.totals) : [];
|
|
1459
|
-
totals.hidden = !lines.length && !waiting;
|
|
1460
|
-
totals.innerHTML = waiting ? loadingLinesHtml(3) : totalsHtml(viewContext(), lines);
|
|
1461
|
-
}
|
|
1462
|
-
const hand = $('forge-runs-hand');
|
|
1463
|
-
if (hand) {
|
|
1464
|
-
const lines = data ? handLines(data) : [];
|
|
1465
|
-
hand.hidden = !lines.length;
|
|
1466
|
-
hand.innerHTML = lines.map((l) => `<li>${escHtml(l)}</li>`).join('');
|
|
1467
|
-
}
|
|
1468
|
-
const list = $('forge-runs-list');
|
|
1469
|
-
list.setAttribute('aria-busy', String(!data && !!ui.loading));
|
|
1470
|
-
if (!data) { list.innerHTML = ui.loading ? loadingRowsHtml(3) : ''; return; }
|
|
1471
|
-
patchList(list, data.runs.length ? runsHtml(viewContext(), data.runs) : '<li class="hx-forge-empty hx-faint" data-corn="empty">No agent has been asked for yet. Start one from an issue or a proposal: Issues, then Start an agent.</li>');
|
|
1472
|
-
}
|
|
1473
|
-
|
|
1474
|
-
/**
|
|
1475
|
-
* Draws a list again without disturbing what the person is doing in it. The new rows are made first and set against the old by their key
|
|
1476
|
-
* (a run's id, a compare group's): a row that has not changed is left alone, a row that has is replaced, and **a row that holds the focus in
|
|
1477
|
-
* a field, or a reply typed and not sent, is kept as it is** (its result line is the one part brought up to date), so the caret, the
|
|
1478
|
-
* selection, the focus and the text stay where they were. A row whose field is no longer asked for is replaced like any other.
|
|
1479
|
-
*/
|
|
1480
|
-
function patchList(list, html) {
|
|
1481
|
-
const tpl = document.createElement('template');
|
|
1482
|
-
tpl.innerHTML = html;
|
|
1483
|
-
const fresh = [...tpl.content.children];
|
|
1484
|
-
const keyOf = (el) => el.dataset.key || el.dataset.run || null;
|
|
1485
|
-
const old = new Map([...list.children].filter((el) => keyOf(el)).map((el) => [keyOf(el), el]));
|
|
1486
|
-
const typing = (el) => el.contains(document.activeElement) && document.activeElement.matches('input, textarea');
|
|
1487
|
-
const redraw = new Set(redrawRuns); // runs the page has just acted on: their cards say what the action did, so they are drawn anew (the focus is put back by hand)
|
|
1488
|
-
redrawRuns.clear();
|
|
1489
|
-
const unsent = (el) => [...el.querySelectorAll('[data-run-reply]')].some((f) => f.value !== '');
|
|
1490
|
-
const target = fresh.map((f) => {
|
|
1491
|
-
const was = keyOf(f) && old.get(keyOf(f));
|
|
1492
|
-
if (!was) return f;
|
|
1493
|
-
if (was.outerHTML === f.outerHTML) return was;
|
|
1494
|
-
const field = was.querySelector('[data-run-reply]');
|
|
1495
|
-
const twin = field && f.querySelector(`[data-run-reply="${field.dataset.runReply}"]`);
|
|
1496
|
-
if (!redraw.has(keyOf(f)) && (typing(was) || unsent(was)) && twin) {
|
|
1497
|
-
// The field stays (the very element, never taken out of the page, so the focus, caret, selection and a phone's keyboard stay);
|
|
1498
|
-
// everything around it is the new card's, so a state that changed is shown (graftAround)
|
|
1499
|
-
const theirs = twin.getAttribute('value') || '';
|
|
1500
|
-
graftAround(was, field, twin);
|
|
1501
|
-
// The typed text is in `ui.runReplies` as well, always (every keystroke); a field that differs from it was changed by the page itself
|
|
1502
|
-
if (field.value !== theirs) field.value = theirs;
|
|
1503
|
-
return was;
|
|
1504
|
-
}
|
|
1505
|
-
return f;
|
|
1506
|
-
});
|
|
1507
|
-
target.forEach((node, i) => {
|
|
1508
|
-
const at = list.children[i];
|
|
1509
|
-
if (at === node) return;
|
|
1510
|
-
if (at && keyOf(at) && keyOf(at) === keyOf(node)) at.replaceWith(node); else list.insertBefore(node, at || null);
|
|
1511
|
-
});
|
|
1512
|
-
while (list.children.length > target.length) list.lastElementChild.remove();
|
|
1513
|
-
}
|
|
1514
|
-
|
|
1515
|
-
/**
|
|
1516
|
-
* Makes `root` (an old row) what `fresh` (its new drawing) is, except that `keep` (inside `root`) stays the same element in the same place,
|
|
1517
|
-
* standing for `twin` (its match inside `fresh`): at each level from `keep` up to `root`, the parent takes the new parent's attributes and
|
|
1518
|
-
* children, with the kept branch in its place. `keep` itself is never taken out of the page.
|
|
1519
|
-
*/
|
|
1520
|
-
function graftAround(root, keep, twin) {
|
|
1521
|
-
const sync = (to, from) => {
|
|
1522
|
-
for (const a of [...to.attributes]) if (!from.hasAttribute(a.name) && a.name !== 'value') to.removeAttribute(a.name);
|
|
1523
|
-
for (const a of [...from.attributes]) if (a.name !== 'value' && to.getAttribute(a.name) !== a.value) to.setAttribute(a.name, a.value);
|
|
1524
|
-
};
|
|
1525
|
-
sync(keep, twin);
|
|
1526
|
-
let w = keep;
|
|
1527
|
-
let f = twin;
|
|
1528
|
-
while (w !== root && w.parentElement && f.parentElement) {
|
|
1529
|
-
const wp = w.parentElement;
|
|
1530
|
-
const fp = f.parentElement;
|
|
1531
|
-
sync(wp, fp);
|
|
1532
|
-
const kids = [...fp.childNodes];
|
|
1533
|
-
const at = kids.indexOf(f);
|
|
1534
|
-
for (const n of [...wp.childNodes]) if (n !== w) n.remove();
|
|
1535
|
-
for (const n of kids.slice(0, at)) wp.insertBefore(n, w);
|
|
1536
|
-
for (const n of kids.slice(at + 1)) wp.append(n);
|
|
1537
|
-
w = wp;
|
|
1538
|
-
f = fp;
|
|
1539
|
-
}
|
|
1540
|
-
}
|
|
1541
|
-
|
|
1542
|
-
/** Whether a run would wait for a runner that is not there (pull transport only; issue #183, spec 0007 D1) */
|
|
1543
|
-
function runnerAway() {
|
|
1544
|
-
const data = ui.runs && ui.runs.data;
|
|
1545
|
-
const state = data ? runnerState(data.runnerPresence, now()) : null;
|
|
1546
|
-
return state === 'offline' || state === 'none';
|
|
1547
|
-
}
|
|
1548
|
-
|
|
1549
|
-
/** The Start dialog's button: "Ask the runner", or "Queue it (no runner online)" while no runner polls, so the click says what it does */
|
|
1550
|
-
function askRunnerWords() {
|
|
1551
|
-
return runnerAway() ? `${t('queueIt')} (no runner online)` : t('askRunner');
|
|
1552
|
-
}
|
|
1553
|
-
|
|
1554
|
-
/**
|
|
1555
|
-
* The one line on whether a runner is polling (pull transport only), in the Runs view and the Start dialog; hidden where it does not apply.
|
|
1556
|
-
* While no runner is online it is a notice at the top of the view, not the faint line: a run asked for would wait (issue #183).
|
|
1557
|
-
*/
|
|
1558
|
-
function paintRunner(id, data) {
|
|
1559
|
-
const el = $(id);
|
|
1560
|
-
if (!el) return;
|
|
1561
|
-
const words = data ? runnerWords(data.runnerPresence, now()) : '';
|
|
1562
|
-
el.hidden = !words;
|
|
1563
|
-
el.textContent = words;
|
|
1564
|
-
const state = data ? runnerState(data.runnerPresence, now()) : null;
|
|
1565
|
-
const away = state === 'offline' || state === 'none';
|
|
1566
|
-
el.className = away ? 'hx-forge-notice' : 'hx-forge-meta';
|
|
1567
|
-
if (away) { el.dataset.corn = 'notice'; el.dataset.cornState = 'waiting'; } else { delete el.dataset.corn; delete el.dataset.cornState; }
|
|
1568
|
-
}
|
|
1569
|
-
|
|
1570
|
-
/** What the Runs view needs to know of the page */
|
|
1571
|
-
function viewContext() {
|
|
1572
|
-
const f = ui.config && ui.config.forge;
|
|
1573
|
-
const base = f && safeUrl(f.url) ? f.url.replace(/\/+$/, '') : null;
|
|
1574
|
-
return {
|
|
1575
|
-
esc: escHtml, safeUrl, forgeName: forgeName(), forgeType: f ? f.type : 'github', repoUrl: base && f.repo ? `${base}/${f.repo}` : null,
|
|
1576
|
-
now: now(), nodes: state.nodes, selected: ui.runSel, timelines: ui.runTimelines, replies: ui.runReplies, busy: !!ui.busy,
|
|
1577
|
-
results: { get: (id) => resultOf(id) },
|
|
1578
|
-
};
|
|
1579
|
-
}
|
|
1580
|
-
|
|
1581
|
-
const runById = (id) => ((ui.runs && ui.runs.data && ui.runs.data.runs) || []).find((r) => r.runId === id) || null;
|
|
1582
|
-
|
|
1583
|
-
/** The nodes of a selected run, worked out again (the runs were read again, or the map changed) */
|
|
1584
|
-
function relightRun() {
|
|
1585
|
-
if (!runById(ui.runSel)) ui.runSel = null;
|
|
1586
|
-
relight();
|
|
1587
|
-
}
|
|
1588
|
-
|
|
1589
|
-
/** Lights the nodes of a run on the map, like a pull request; the same button lets go of it */
|
|
1590
|
-
function selectRun(id) {
|
|
1591
|
-
const run = runById(id);
|
|
1592
|
-
if (!run) return;
|
|
1593
|
-
if (ui.runSel === id) {
|
|
1594
|
-
ui.runSel = null;
|
|
1595
|
-
relight();
|
|
1596
|
-
announce(`Run ${id} no longer lit on the map`);
|
|
1597
|
-
return;
|
|
1598
|
-
}
|
|
1599
|
-
const had = ui.runSel;
|
|
1600
|
-
pullToken++;
|
|
1601
|
-
dropThread();
|
|
1602
|
-
Object.assign(ui, { selected: null, detail: null, detailError: '', lit: null, landing: null, note: null, deploy: null, deployItem: null, litDeploy: null });
|
|
1603
|
-
ui.runSel = id;
|
|
1604
|
-
relight();
|
|
1605
|
-
const n = (run.nodes || []).length;
|
|
1606
|
-
announce(n ? `Run ${id}: ${n} ${n === 1 ? 'node' : 'nodes'} lit on the map${had ? '' : ''}` : `Run ${id} has no node on the map yet`);
|
|
1607
|
-
}
|
|
1608
|
-
|
|
1609
|
-
/** Opens or closes the timeline of a run (it stays open when the list is drawn again) */
|
|
1610
|
-
function toggleTimeline(id) {
|
|
1611
|
-
if (ui.runTimelines.has(id)) ui.runTimelines.delete(id); else ui.runTimelines.add(id);
|
|
1612
|
-
paint();
|
|
1613
|
-
}
|
|
1614
|
-
|
|
1615
|
-
/** The panel's lines for the Release notes view: the status, a failure, the rate limit; the rest is paintNotes */
|
|
1616
|
-
function drawNotes() {
|
|
1617
|
-
const n = ui.notes;
|
|
1618
|
-
$('forge-status').textContent = n.loading && !n.data ? `Drafting the release notes from ${forgeName()} …` : n.data ? notesSummary(n.data) : '';
|
|
1619
|
-
const notice = $('forge-notice');
|
|
1620
|
-
const words = n.error || (n.data && n.data.stale ? `Showing an older answer. ${n.data.stale}` : '');
|
|
1621
|
-
setNotice(notice, words, !!words);
|
|
1622
|
-
$('forge-detail').hidden = true;
|
|
1623
|
-
paintIdea();
|
|
1624
|
-
$('forge-rate').textContent = (n.data && n.data.rate) || '';
|
|
1625
|
-
paintNotes();
|
|
1626
|
-
paintButton();
|
|
1627
|
-
}
|
|
1628
|
-
|
|
1629
|
-
/** The toggles that open the panel (`data-action="toggle-forge"`: the header's, whatever it calls it) say whether it is open, and the old button which selection is lit */
|
|
1630
|
-
function paintButton() {
|
|
1631
|
-
for (const toggle of document.querySelectorAll('[data-action="toggle-forge"]')) toggle.setAttribute('aria-expanded', String(ui.open));
|
|
1632
|
-
const btn = $('forge-btn');
|
|
1633
|
-
if (!btn) return;
|
|
1634
|
-
const lit = ui.selected !== null || !!ui.deployItem || ui.thread !== null || !!ui.runSel;
|
|
1635
|
-
const tag = $('forge-btn-lit');
|
|
1636
|
-
if (tag) {
|
|
1637
|
-
tag.hidden = !lit;
|
|
1638
|
-
tag.textContent = ui.runSel ? 'run' : ui.thread !== null ? `thread #${ui.thread}` : ui.deployItem ? 'deploy' : lit ? `#${ui.selected}` : '';
|
|
1639
|
-
}
|
|
1640
|
-
const n = waitingNow().total;
|
|
1641
|
-
// A run would wait for a runner that is not there: a dot, and the name says so (issue #183); it sits beside the waiting badge, not on it
|
|
1642
|
-
const away = runnerAway();
|
|
1643
|
-
const dot = $('forge-btn-dot');
|
|
1644
|
-
if (dot) dot.hidden = !away;
|
|
1645
|
-
const badge = $('forge-btn-waiting');
|
|
1646
|
-
if (badge) {
|
|
1647
|
-
badge.hidden = n === 0;
|
|
1648
|
-
badge.textContent = n ? String(n) : '';
|
|
1649
|
-
}
|
|
1650
|
-
btn.setAttribute('aria-label', `${workButtonName(t('issuesAndPrs'), n)}${away ? ', no runner online' : ''}${ui.runSel ? ', a run lit on the map' : ui.thread !== null ? `, thread ${ui.thread} selected` : ui.deployItem ? ', a deploy selected' : lit ? `, pull request ${ui.selected} selected` : ''}`);
|
|
1651
|
-
}
|
|
1652
|
-
|
|
1653
|
-
// ---------------------------------------------------------------------------
|
|
1654
|
-
// Actions: land a green pull request, re-run a failed check
|
|
1655
|
-
// ---------------------------------------------------------------------------
|
|
1656
|
-
|
|
1657
|
-
/** One POST of JSON; `{ ok, status, body }`, with a status of null when the server did not answer */
|
|
1658
|
-
async function post(url, payload) {
|
|
1659
|
-
try {
|
|
1660
|
-
const res = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) });
|
|
1661
|
-
let body = null;
|
|
1662
|
-
try { body = await res.json(); } catch { /* no body */ }
|
|
1663
|
-
return { ok: !!res.ok && !!body && body.ok === true, status: res.status, body };
|
|
1664
|
-
} catch {
|
|
1665
|
-
return { ok: false, status: null, body: null };
|
|
1666
|
-
}
|
|
1667
|
-
}
|
|
1668
|
-
|
|
1669
|
-
/** What an action came to: said on the panel and through the live region, and everything is read again from the forge */
|
|
1670
|
-
async function finishAction(action, res, n) {
|
|
1671
|
-
const text = actionWords(action, res.status, res.body, n);
|
|
1672
|
-
ui.busy = '';
|
|
1673
|
-
ui.note = { text, ok: res.ok };
|
|
1674
|
-
announce(text);
|
|
1675
|
-
paint();
|
|
1676
|
-
if (res.status === null) return;
|
|
1677
|
-
// The other tabs' answers are from before it: they are read again when next shown (the server let go of its own copies)
|
|
1678
|
-
if (ui.kind === 'work') ui.lists = {};
|
|
1679
|
-
else { ui.lists = { [listKey()]: ui.lists[listKey()] }; ui.work = null; }
|
|
1680
|
-
// Whatever it came to (a refusal says the pull request is not what was shown), the panel looks again
|
|
1681
|
-
if (ui.selected === n) await refreshForge({ quiet: true });
|
|
1682
|
-
}
|
|
1683
|
-
|
|
1684
|
-
/** Re-runs one failed check on the head that is shown */
|
|
1685
|
-
async function rerunCheck(id) {
|
|
1686
|
-
if (ui.busy || !ui.detail) return;
|
|
1687
|
-
const { pull, checks } = ui.detail;
|
|
1688
|
-
const check = checks.find((c) => c.id === id);
|
|
1689
|
-
if (!check || check.state !== 'failure' || !check.canRerun) return;
|
|
1690
|
-
ui.busy = `rerun:${id}`;
|
|
1691
|
-
ui.note = null;
|
|
1692
|
-
announce(`Re-running ${check.name}`);
|
|
1693
|
-
paint();
|
|
1694
|
-
const res = await post(actionUrl(pull.number, 'rerun'), { sha: pull.head.sha, check: id });
|
|
1695
|
-
await finishAction('rerun', res, pull.number);
|
|
1696
|
-
}
|
|
1697
|
-
|
|
1698
|
-
const confirmEl = () => $('forge-confirm');
|
|
1699
|
-
|
|
1700
|
-
/** While the confirm step is open the focus cannot leave it: a focus that lands elsewhere is brought back */
|
|
1701
|
-
function keepFocusIn(e) {
|
|
1702
|
-
const el = confirmEl();
|
|
1703
|
-
if (ui.confirm && el && !el.contains(e.target)) el.querySelector('[data-action="forge-confirm-cancel"]').focus();
|
|
1704
|
-
}
|
|
1705
|
-
|
|
1706
|
-
/** Fills and opens the confirm step; the focus goes to Cancel. `what` is the model's: title, lines, checks, previews, note */
|
|
1707
|
-
function showConfirm(what, goLabel, state) {
|
|
1708
|
-
const el = confirmEl();
|
|
1709
|
-
const asCode = ['Commit', 'At commit', 'Branch', 'File', 'Proposal'];
|
|
1710
|
-
$('forge-confirm-title').textContent = what.title;
|
|
1711
|
-
$('forge-confirm-body').innerHTML = `<dl class="hx-confirm-facts">${what.lines.map(([k, v]) => `<dt>${escHtml(k)}</dt><dd>${asCode.includes(k) ? `<code class="hx-code">${escHtml(v)}</code>` : escHtml(v)}</dd>`).join('')}</dl>
|
|
1712
|
-
${(what.checks || []).length ? `<ul class="hx-confirm-checks">${what.checks.map((c) => `<li><span class="hx-forge-state hx-forge-state--success" data-corn="state-pill" data-corn-state="success">${escHtml(c.words)}</span> ${escHtml(c.name)}</li>`).join('')}</ul>` : ''}
|
|
1713
|
-
${(what.previews || []).map((pv) => `<p class="hx-confirm-label">${escHtml(pv.label)}</p><pre class="hx-confirm-pre" data-corn="confirm-preview" tabindex="0" role="region" aria-label="${escHtml(pv.label)}">${escHtml(pv.text)}</pre>`).join('')}
|
|
1714
|
-
<p class="hx-confirm-note">${escHtml(what.note)}</p>`;
|
|
1715
|
-
const go = el.querySelector('[data-action="forge-confirm-go"]');
|
|
1716
|
-
go.disabled = false;
|
|
1717
|
-
go.textContent = goLabel;
|
|
1718
|
-
go.removeAttribute('aria-busy');
|
|
1719
|
-
// The scrim covers the page for the pointer, aria-modal tells a reader the rest is out of play, and the focus stays in
|
|
1720
|
-
ui.confirm = state;
|
|
1721
|
-
document.addEventListener('focusin', keepFocusIn);
|
|
1722
|
-
el.hidden = false;
|
|
1723
|
-
el.querySelector('[data-action="forge-confirm-cancel"]').focus();
|
|
1724
|
-
announce(`${what.title} ${what.lines.map(([k, v]) => `${k}: ${v}`).join('. ')}. ${what.note} Cancel or ${goLabel}.`);
|
|
1725
|
-
}
|
|
1726
|
-
|
|
1727
|
-
/** Opens the confirm step for landing the selected pull request: what will land, exactly */
|
|
1728
|
-
function openConfirm(opener) {
|
|
1729
|
-
if (!confirmEl() || ui.confirm || ui.busy || !ui.detail || mergeBlock(ui.detail)) return;
|
|
1730
|
-
showConfirm(confirmMerge(ui.detail, forgeName(), ui.config && ui.config.forge && ui.config.forge.mergeMethod), t('landIt'), { opener, kind: 'merge' });
|
|
1731
|
-
}
|
|
1732
|
-
|
|
1733
|
-
/** What a pipeline step came to, on the panel (with a link to what it made) and through the live region */
|
|
1734
|
-
function stepNote(text, ok, url = null) {
|
|
1735
|
-
ui.actNote = { text, ok, url };
|
|
1736
|
-
announce(text);
|
|
1737
|
-
paint();
|
|
1738
|
-
}
|
|
1739
|
-
|
|
1740
|
-
/** Forgets the lists of the other kind (a step made something there), so they are asked again when shown */
|
|
1741
|
-
function forgetOtherLists() {
|
|
1742
|
-
for (const key of Object.keys(ui.lists)) if (!key.startsWith(`${ui.kind}|`)) delete ui.lists[key];
|
|
1743
|
-
}
|
|
1744
|
-
|
|
1745
|
-
/**
|
|
1746
|
-
* A pipeline step, first half: reads the plan from the server (what would be made, from the forge now). A step that
|
|
1747
|
-
* was done before says so and stops; otherwise the confirm step shows the plan and nothing is made until it is confirmed.
|
|
1748
|
-
*/
|
|
1749
|
-
async function askPlan(action, n, slug, opener) {
|
|
1750
|
-
if (ui.busy || ui.confirm || !confirmEl()) return;
|
|
1751
|
-
ui.busy = `plan:${action}`;
|
|
1752
|
-
ui.actNote = null;
|
|
1753
|
-
announce(action === 'spec' ? `Looking at what a spec for issue ${n} would make` : `Looking at the build issue for ${slug}`);
|
|
1754
|
-
paint();
|
|
1755
|
-
const res = await request(planUrl(action, n, slug), true);
|
|
1756
|
-
ui.busy = '';
|
|
1757
|
-
// The button was off while it asked; it has the focus again whatever the answer is
|
|
1758
|
-
const refocus = () => { const back = $('forge-panel').querySelector(opener); if (back && !back.disabled && !ui.confirm) back.focus(); };
|
|
1759
|
-
if (!res.ok || !res.body || !res.body.plan) {
|
|
1760
|
-
stepNote(actionWords(action, res.status, res.body, n), false);
|
|
1761
|
-
refocus();
|
|
1762
|
-
return;
|
|
1763
|
-
}
|
|
1764
|
-
const { plan } = res.body;
|
|
1765
|
-
if (plan.existing) {
|
|
1766
|
-
stepNote(existingWords(action, plan), true, plan.existing.url);
|
|
1767
|
-
refocus();
|
|
1768
|
-
return;
|
|
1769
|
-
}
|
|
1770
|
-
paint();
|
|
1771
|
-
const what = action === 'spec' ? confirmSpec(plan, forgeName()) : confirmBuild(plan, forgeName());
|
|
1772
|
-
showConfirm(what, what.go, { opener, kind: action, plan, n, slug });
|
|
1773
|
-
}
|
|
1774
|
-
|
|
1775
|
-
/** A pipeline step, second half: the plan that was shown is confirmed; the server plans again and must find the same */
|
|
1776
|
-
async function confirmedStep() {
|
|
1777
|
-
if (ui.busy || !ui.confirm || !ui.confirm.plan) return;
|
|
1778
|
-
const { kind, plan, n } = ui.confirm;
|
|
1779
|
-
ui.busy = kind;
|
|
1780
|
-
ui.actNote = null;
|
|
1781
|
-
const go = confirmEl().querySelector('[data-action="forge-confirm-go"]');
|
|
1782
|
-
go.disabled = true;
|
|
1783
|
-
go.setAttribute('aria-busy', 'true');
|
|
1784
|
-
go.textContent = 'Working …';
|
|
1785
|
-
announce(kind === 'spec' ? `Starting the spec for issue ${n}` : `Opening the build issue for ${plan.slug}`);
|
|
1786
|
-
const res = await post(actionUrl(n, kind), kind === 'spec' ? specBody(plan) : buildBody(plan));
|
|
1787
|
-
closeConfirm();
|
|
1788
|
-
ui.busy = '';
|
|
1789
|
-
const made = res.body && (kind === 'spec' ? res.body.pull : res.body.issue);
|
|
1790
|
-
stepNote(actionWords(kind, res.status, res.body, n), res.ok, res.ok && made ? made.url : null);
|
|
1791
|
-
// Whatever it came to, it is read again: a refusal says the issue or the pull request is not what was shown
|
|
1792
|
-
if (res.status !== null) {
|
|
1793
|
-
forgetOtherLists();
|
|
1794
|
-
if (kind === 'build' && ui.selected === n) await refreshForge({ quiet: true });
|
|
1795
|
-
else await loadList(true, true);
|
|
1796
|
-
}
|
|
1797
|
-
}
|
|
1798
|
-
|
|
1799
|
-
/** Closes the confirm step; the focus goes back to the button that opened it (or the panel's title if that is gone) */
|
|
1800
|
-
function closeConfirm({ restoreFocus = true } = {}) {
|
|
1801
|
-
const el = confirmEl();
|
|
1802
|
-
if (!el || !ui.confirm) return;
|
|
1803
|
-
const { opener } = ui.confirm;
|
|
1804
|
-
ui.confirm = null;
|
|
1805
|
-
el.hidden = true;
|
|
1806
|
-
document.removeEventListener('focusin', keepFocusIn);
|
|
1807
|
-
if (!restoreFocus) return;
|
|
1808
|
-
const back = $('forge-panel').querySelector(opener) || $('forge-title');
|
|
1809
|
-
if (back && !back.disabled) back.focus();
|
|
1810
|
-
}
|
|
1811
|
-
|
|
1812
|
-
/** Land it, confirmed: posts the head that was shown */
|
|
1813
|
-
async function confirmedMerge() {
|
|
1814
|
-
if (ui.busy || !ui.detail || !ui.confirm || ui.confirm.kind !== 'merge') return;
|
|
1815
|
-
const { pull } = ui.detail;
|
|
1816
|
-
const body = mergeBody(ui.detail);
|
|
1817
|
-
ui.busy = 'merge';
|
|
1818
|
-
ui.note = null;
|
|
1819
|
-
const go = confirmEl().querySelector('[data-action="forge-confirm-go"]');
|
|
1820
|
-
go.disabled = true;
|
|
1821
|
-
go.setAttribute('aria-busy', 'true');
|
|
1822
|
-
go.textContent = 'Landing …';
|
|
1823
|
-
announce(`Landing pull request ${pull.number}`);
|
|
1824
|
-
const res = await post(actionUrl(pull.number, 'merge'), body);
|
|
1825
|
-
closeConfirm();
|
|
1826
|
-
await finishAction('merge', res, pull.number);
|
|
1827
|
-
}
|
|
1828
|
-
|
|
1829
|
-
/** Keys inside the confirm step: Escape cancels, Tab stays between its two buttons, nothing reaches the map behind it */
|
|
1830
|
-
function onConfirmKey(e) {
|
|
1831
|
-
e.stopPropagation();
|
|
1832
|
-
if (e.key === 'Escape') {
|
|
1833
|
-
e.preventDefault();
|
|
1834
|
-
if (!ui.busy) closeConfirm();
|
|
1835
|
-
return;
|
|
1836
|
-
}
|
|
1837
|
-
trapTab(e, confirmEl());
|
|
1838
|
-
}
|
|
1839
|
-
|
|
1840
|
-
function onConfirmClick(e) {
|
|
1841
|
-
const t = e.target;
|
|
1842
|
-
if (t === confirmEl()) { if (!ui.busy) closeConfirm(); return; } // the scrim
|
|
1843
|
-
const action = t.closest && t.closest('[data-action]');
|
|
1844
|
-
if (!action) return;
|
|
1845
|
-
if (action.dataset.action === 'forge-confirm-cancel') { if (!ui.busy) closeConfirm(); } else if (action.dataset.action === 'forge-confirm-go') { if (ui.confirm && ui.confirm.kind === 'merge') confirmedMerge(); else confirmedStep(); }
|
|
1846
|
-
}
|
|
1847
|
-
|
|
1848
|
-
// ---------------------------------------------------------------------------
|
|
1849
|
-
// Agent runs: Start an agent, and Stop
|
|
1850
|
-
// ---------------------------------------------------------------------------
|
|
1851
|
-
|
|
1852
|
-
const agentEl = () => $('agent-start');
|
|
1853
|
-
|
|
1854
|
-
/** While the dialog is open the focus cannot leave it */
|
|
1855
|
-
function keepFocusInAgent(e) {
|
|
1856
|
-
const el = agentEl();
|
|
1857
|
-
if (ui.agent && el && !el.contains(e.target)) $('agent-kind').focus();
|
|
1858
|
-
}
|
|
1859
|
-
|
|
1860
|
-
/**
|
|
1861
|
-
* Opens the Start an agent dialog for `issue:<n>` or `proposal:<slug>`; the focus goes to the first field. The limit fields hold what the request
|
|
1862
|
-
* starts from (the config's, for the profile). With `again` (a run that failed or was stopped) it is **Start again**: the same kind, refs,
|
|
1863
|
-
* profile, brief and limits filled in, all editable, and the request will carry `retryOf`. `brief` is that run's whole brief when the list's was cut
|
|
1864
|
-
*/
|
|
1865
|
-
async function openAgent(ref, opener, again = null, brief = null) {
|
|
1866
|
-
if (!agentEl() || ui.agent) return;
|
|
1867
|
-
const at = ref.indexOf(':');
|
|
1868
|
-
const type = ref.slice(0, at);
|
|
1869
|
-
const value = ref.slice(at + 1);
|
|
1870
|
-
const refs = again ? retryRefs(again) : type === 'proposal' ? { proposal: value } : { issue: Number(value) };
|
|
1871
|
-
ui.agent = { opener, refs, posting: false, retryOf: again ? again.runId : null };
|
|
1872
|
-
// The profiles the config lists come with the runs: asked for if the Agents tab has not been opened yet
|
|
1873
|
-
if (!ui.runs) { await loadRuns(false); if (ui.kind === 'work') paint(); }
|
|
1874
|
-
if (!ui.agent) return;
|
|
1875
|
-
const profiles = (ui.runs && ui.runs.data && ui.runs.data.profiles) || [];
|
|
1876
|
-
$('agent-start-about').textContent = `About ${aboutWords(refs)}`;
|
|
1877
|
-
paintRunner('agent-start-runner', ui.runs && ui.runs.data);
|
|
1878
|
-
const kind = again ? again.kind : 'code';
|
|
1879
|
-
// The old run's profile stays on offer even if the config no longer lists it: the server then says so, in its words
|
|
1880
|
-
const shown = again && again.profile && !profiles.includes(again.profile) ? [...profiles, again.profile] : profiles;
|
|
1881
|
-
$('agent-kind').innerHTML = KINDS.map(([v, l]) => option(v, l, v === kind)).join('');
|
|
1882
|
-
$('agent-profile').innerHTML = option('', 'No profile', !(again && again.profile)) + shown.map((p) => option(p, p, !!again && p === again.profile)).join('');
|
|
1883
|
-
$('agent-profile-field').hidden = !shown.length;
|
|
1884
|
-
$('agent-profile').value = again && again.profile ? again.profile : ''; // as well as `selected`, which not every DOM honours
|
|
1885
|
-
$('agent-start-title').textContent = again ? t('startAgain') : t('startAgent');
|
|
1886
|
-
const note = $('agent-retry-note');
|
|
1887
|
-
note.hidden = !again;
|
|
1888
|
-
note.textContent = again ? retryWords(again) : '';
|
|
1889
|
-
fillLimits(again ? again.limits || {} : limitDefaultsNow());
|
|
1890
|
-
$('agent-brief').value = brief ?? (again && typeof again.brief === 'string' ? again.brief : '');
|
|
1891
|
-
$('agent-force').checked = false;
|
|
1892
|
-
$('agent-force-field').hidden = true;
|
|
1893
|
-
$('agent-start-msg').hidden = true;
|
|
1894
|
-
$('agent-start-msg').textContent = '';
|
|
1895
|
-
$('agent-start-words').textContent = confirmStartWords(refs, forgeName());
|
|
1896
|
-
const go = $('agent-start-go');
|
|
1897
|
-
go.disabled = false;
|
|
1898
|
-
go.removeAttribute('aria-busy');
|
|
1899
|
-
go.textContent = askRunnerWords();
|
|
1900
|
-
document.addEventListener('focusin', keepFocusInAgent);
|
|
1901
|
-
agentEl().hidden = false;
|
|
1902
|
-
$('agent-kind').focus();
|
|
1903
|
-
announce(`${again ? t('startAgain') : t('startAgent')} on ${aboutWords(refs)}. ${confirmStartWords(refs, forgeName())}`);
|
|
1904
|
-
}
|
|
1905
|
-
|
|
1906
|
-
/** "Start again" on a run that failed or was stopped. A brief the list shows cut is read whole first: the dialog never starts from part of one */
|
|
1907
|
-
async function startAgain(runId) {
|
|
1908
|
-
const run = ui.runs && ui.runs.data ? ui.runs.data.runs.find((r) => r.runId === runId) : null;
|
|
1909
|
-
if (!run || !canRetry(run) || ui.agent || ui.retrying) return;
|
|
1910
|
-
let brief = null;
|
|
1911
|
-
if (run.briefCut) {
|
|
1912
|
-
ui.retrying = true;
|
|
1913
|
-
const res = await request(briefUrl(runId), false);
|
|
1914
|
-
ui.retrying = false;
|
|
1915
|
-
if (!res.ok || typeof res.body.brief !== 'string') {
|
|
1916
|
-
ui.runNote = { text: `The brief of ${runId} could not be read, so Start again did not open: ${failWords(res)}`, ok: false };
|
|
1917
|
-
paint();
|
|
1918
|
-
announce(ui.runNote.text);
|
|
1919
|
-
return;
|
|
1920
|
-
}
|
|
1921
|
-
brief = res.body.brief;
|
|
1922
|
-
}
|
|
1923
|
-
const about = run.refs.proposal != null ? `proposal:${run.refs.proposal}` : `issue:${run.refs.issue ?? run.refs.thread}`;
|
|
1924
|
-
openAgent(about, `[data-forge-retry="${runId}"]`, run, brief);
|
|
1925
|
-
}
|
|
1926
|
-
|
|
1927
|
-
/** Takes the person to another run of the list: the row scrolls into view and has the focus */
|
|
1928
|
-
function goToRun(runId) {
|
|
1929
|
-
bringIntoView([...document.querySelectorAll('#forge-runs-list [data-run]')].find((r) => r.dataset.run === runId));
|
|
1930
|
-
}
|
|
1931
|
-
|
|
1932
|
-
/** The limits the config gives a request under the chosen profile */
|
|
1933
|
-
const limitDefaultsNow = () => defaultLimits(ui.runs && ui.runs.data && ui.runs.data.limits, $('agent-profile-field').hidden ? '' : $('agent-profile').value);
|
|
1934
|
-
/** What the four limit fields hold, as text */
|
|
1935
|
-
const limitFields = () => Object.fromEntries(LIMIT_KEYS.map((k) => [k, $(`agent-limit-${k}`).value]));
|
|
1936
|
-
|
|
1937
|
-
/** Fills the four limit fields (blank where `limits` has none) and remembers what was filled */
|
|
1938
|
-
function fillLimits(limits) {
|
|
1939
|
-
for (const k of LIMIT_KEYS) {
|
|
1940
|
-
const field = $(`agent-limit-${k}`);
|
|
1941
|
-
field.value = limits && limits[k] != null ? String(limits[k]) : '';
|
|
1942
|
-
field.removeAttribute('aria-invalid');
|
|
1943
|
-
field.removeAttribute('aria-describedby');
|
|
1944
|
-
}
|
|
1945
|
-
if (ui.agent) ui.agent.filled = JSON.stringify(limitFields());
|
|
1946
|
-
}
|
|
1947
|
-
|
|
1948
|
-
/** Another profile: its limits fill the fields, unless the person has typed in them */
|
|
1949
|
-
function onAgentProfile() {
|
|
1950
|
-
if (ui.agent && ui.agent.filled === JSON.stringify(limitFields())) fillLimits(limitDefaultsNow());
|
|
1951
|
-
}
|
|
1952
|
-
|
|
1953
|
-
/** Closes the dialog; the focus goes back to the button that opened it unless told not to */
|
|
1954
|
-
function closeAgent({ restoreFocus = true } = {}) {
|
|
1955
|
-
const el = agentEl();
|
|
1956
|
-
if (!el || !ui.agent) return;
|
|
1957
|
-
const { opener } = ui.agent;
|
|
1958
|
-
ui.agent = null;
|
|
1959
|
-
el.hidden = true;
|
|
1960
|
-
document.removeEventListener('focusin', keepFocusInAgent);
|
|
1961
|
-
if (!restoreFocus) return;
|
|
1962
|
-
const back = document.querySelector(opener) || $('forge-title'); // the node panel's Start a run is an opener too
|
|
1963
|
-
if (back && !back.disabled) back.focus();
|
|
1964
|
-
}
|
|
1965
|
-
|
|
1966
|
-
/** The one write: posts the choices once; a refusal stays in the dialog, in the server's words */
|
|
1967
|
-
async function submitAgent(e) {
|
|
1968
|
-
e.preventDefault();
|
|
1969
|
-
if (!ui.agent || ui.agent.posting) return;
|
|
1970
|
-
ui.agent.posting = true;
|
|
1971
|
-
const go = $('agent-start-go');
|
|
1972
|
-
go.disabled = true;
|
|
1973
|
-
go.setAttribute('aria-busy', 'true');
|
|
1974
|
-
go.textContent = 'Asking …';
|
|
1975
|
-
$('agent-start-msg').hidden = true;
|
|
1976
|
-
const again = ui.agent.retryOf;
|
|
1977
|
-
const fields = limitFields();
|
|
1978
|
-
const limits = limitsFromFields(fields);
|
|
1979
|
-
// Each field that is not a number above zero is marked, and the first has the focus; the message says why
|
|
1980
|
-
const wrong = LIMIT_KEYS.filter((k) => limitsFromFields({ [k]: fields[k] }) === null);
|
|
1981
|
-
for (const k of LIMIT_KEYS) {
|
|
1982
|
-
const field = $(`agent-limit-${k}`);
|
|
1983
|
-
if (wrong.includes(k)) { field.setAttribute('aria-invalid', 'true'); field.setAttribute('aria-describedby', 'agent-start-msg'); } else { field.removeAttribute('aria-invalid'); field.removeAttribute('aria-describedby'); }
|
|
1984
|
-
}
|
|
1985
|
-
if (limits === null) {
|
|
1986
|
-
ui.agent.posting = false;
|
|
1987
|
-
go.disabled = false;
|
|
1988
|
-
go.removeAttribute('aria-busy');
|
|
1989
|
-
go.textContent = askRunnerWords();
|
|
1990
|
-
const bad = $('agent-start-msg');
|
|
1991
|
-
bad.textContent = `A limit is a number above zero, or blank for the config's (${wrong.join(', ')}).`;
|
|
1992
|
-
bad.hidden = false;
|
|
1993
|
-
$(`agent-limit-${wrong[0]}`).focus();
|
|
1994
|
-
announce(bad.textContent);
|
|
1995
|
-
return;
|
|
1996
|
-
}
|
|
1997
|
-
const res = await post(RUNS_URL, startBody({
|
|
1998
|
-
kind: $('agent-kind').value, profile: $('agent-profile-field').hidden ? '' : $('agent-profile').value, brief: $('agent-brief').value, refs: ui.agent.refs, force: $('agent-force').checked,
|
|
1999
|
-
limits, ...(again ? { retryOf: again } : {}),
|
|
2000
|
-
}));
|
|
2001
|
-
if (!ui.agent) return;
|
|
2002
|
-
ui.agent.posting = false;
|
|
2003
|
-
const text = startWords(res.status, res.body);
|
|
2004
|
-
if (res.ok) {
|
|
2005
|
-
closeAgent();
|
|
2006
|
-
ui.runNote = { text, ok: true };
|
|
2007
|
-
announce(text);
|
|
2008
|
-
await loadRuns(false);
|
|
2009
|
-
paint();
|
|
2010
|
-
return;
|
|
2011
|
-
}
|
|
2012
|
-
go.disabled = false;
|
|
2013
|
-
go.removeAttribute('aria-busy');
|
|
2014
|
-
go.textContent = askRunnerWords();
|
|
2015
|
-
const msg = $('agent-start-msg');
|
|
2016
|
-
msg.textContent = text;
|
|
2017
|
-
msg.hidden = false;
|
|
2018
|
-
// The one-per-issue rule can be set aside on purpose; the cap cannot
|
|
2019
|
-
if (res.body && res.body.code === 'run-open') $('agent-force-field').hidden = false;
|
|
2020
|
-
announce(text);
|
|
2021
|
-
}
|
|
2022
|
-
|
|
2023
|
-
/** Keys inside the dialog: Escape cancels, Tab stays inside, nothing reaches the map behind it */
|
|
2024
|
-
function onAgentKey(e) {
|
|
2025
|
-
e.stopPropagation();
|
|
2026
|
-
if (e.key === 'Escape') {
|
|
2027
|
-
e.preventDefault();
|
|
2028
|
-
if (!ui.agent || !ui.agent.posting) closeAgent();
|
|
2029
|
-
return;
|
|
2030
|
-
}
|
|
2031
|
-
trapTab(e, agentEl());
|
|
2032
|
-
}
|
|
2033
|
-
|
|
2034
|
-
function onAgentClick(e) {
|
|
2035
|
-
const t = e.target;
|
|
2036
|
-
if (t === agentEl()) { if (ui.agent && !ui.agent.posting) closeAgent(); return; } // the scrim
|
|
2037
|
-
if (t.closest && t.closest('[data-action="agent-start-cancel"]') && ui.agent && !ui.agent.posting) closeAgent();
|
|
2038
|
-
}
|
|
2039
|
-
|
|
2040
|
-
/** The runs whose card is drawn anew at the next paint, whatever holds the focus in it (the page itself changed what it says) */
|
|
2041
|
-
const redrawRuns = new Set();
|
|
2042
|
-
|
|
2043
|
-
/** Gives the focus to the first of `selectors` that is there and not disabled, inside the card of a run (else the card itself) */
|
|
2044
|
-
function focusInRun(runId, selectors) {
|
|
2045
|
-
const panel = $('forge-panel');
|
|
2046
|
-
const card = panel && [...panel.querySelectorAll('[data-run]')].find((c) => c.dataset.run === runId);
|
|
2047
|
-
if (!card) return;
|
|
2048
|
-
const to = selectors.map((sel) => card.querySelector(sel)).find((el) => el && !el.disabled) || card;
|
|
2049
|
-
if (to !== document.activeElement) to.focus();
|
|
2050
|
-
if (to.matches('input') && typeof to.setSelectionRange === 'function') to.setSelectionRange(to.value.length, to.value.length); // typing goes on at the end of what is there
|
|
2051
|
-
}
|
|
2052
|
-
|
|
2053
|
-
/** Back online: a tab that could not be read is read again, so its error does not outlive the cause (the same function each time, added once) */
|
|
2054
|
-
function readOnline() {
|
|
2055
|
-
if (ui.open && (ui.error || (ui.runs && ui.runs.error) || ui.detailError || (ui.kind === 'notes' && ui.notes.error))) refreshForge({ quiet: true });
|
|
2056
|
-
}
|
|
2057
|
-
|
|
2058
|
-
/** Lets go of a reply that was not sent because its run stopped waiting: the field goes, and the focus goes to the run's card */
|
|
2059
|
-
function discardReply(runId) {
|
|
2060
|
-
ui.runReplies.delete(runId);
|
|
2061
|
-
redrawRuns.add(runId);
|
|
2062
|
-
paint();
|
|
2063
|
-
focusInRun(runId, []);
|
|
2064
|
-
}
|
|
2065
|
-
|
|
2066
|
-
/** Asks a run to stop: one POST, then the runs are read again. What it came to is said in the run's own card, and to a screen reader */
|
|
2067
|
-
async function stopRun(runId) {
|
|
2068
|
-
if (ui.busy) return;
|
|
2069
|
-
ui.busy = 'stop';
|
|
2070
|
-
ui.runNote = null;
|
|
2071
|
-
clearResult(runId);
|
|
2072
|
-
announce('Asking this run to stop'); // the focus is in the run's card, whose controls name it
|
|
2073
|
-
paint();
|
|
2074
|
-
const res = await post(stopUrl(runId), {});
|
|
2075
|
-
ui.busy = '';
|
|
2076
|
-
sayResult(runId, res.status === null ? notSentWords('The stop request') : stopWords(res.status, res.body, 'this run'), res.ok);
|
|
2077
|
-
await loadRuns(false, { say: false });
|
|
2078
|
-
redrawRuns.add(runId);
|
|
2079
|
-
paint();
|
|
2080
|
-
// The Stop button is gone once the stop is asked for: the focus goes to the run's row, never to the page
|
|
2081
|
-
focusInRun(runId, [`[data-forge-stop="${runId}"]`]);
|
|
2082
|
-
}
|
|
2083
|
-
|
|
2084
|
-
/** Answers a waiting run: Continue, Stop, or a reply with the text typed. One POST, then the runs are read again */
|
|
2085
|
-
async function answerRun(runId, action) {
|
|
2086
|
-
if (ui.busy) return;
|
|
2087
|
-
const text = ui.runReplies.get(runId) || '';
|
|
2088
|
-
clearResult(runId);
|
|
2089
|
-
if (action === 'reply' && text.trim() === '') {
|
|
2090
|
-
sayResult(runId, 'Write a reply first.', false);
|
|
2091
|
-
paint();
|
|
2092
|
-
focusInRun(runId, [`[data-run-reply="${runId}"]`]);
|
|
2093
|
-
return;
|
|
2094
|
-
}
|
|
2095
|
-
// Where the focus goes back to once it is sent: the reply field after a reply (empty, for the next one), the button after Continue; while the
|
|
2096
|
-
// buttons are disabled the focus has nowhere to stay, so it is put back by hand. A run that no longer asks (a Stop) gets its Timeline button
|
|
2097
|
-
const back = action === 'reply' ? `[data-run-reply="${runId}"]` : `[data-run-answer="${action}"][data-run-id="${runId}"]`;
|
|
2098
|
-
ui.busy = 'answer';
|
|
2099
|
-
ui.runNote = null;
|
|
2100
|
-
announce(action === 'reply' ? 'Sending your reply' : 'Sending your answer');
|
|
2101
|
-
paint();
|
|
2102
|
-
const res = await post(answerUrl(runId), answerBody(action, text));
|
|
2103
|
-
ui.busy = '';
|
|
2104
|
-
if (res.ok && action === 'reply') ui.runReplies.delete(runId); // sent: the field is empty for the next; a reply that was not sent stays as it was typed
|
|
2105
|
-
const words = res.status === null ? notSentWords(action === 'reply' ? 'Your reply' : 'The answer') : answerWordsFor(res.status, res.body, 'this run', action);
|
|
2106
|
-
sayResult(runId, words, res.ok);
|
|
2107
|
-
await loadRuns(false, { say: false });
|
|
2108
|
-
redrawRuns.add(runId);
|
|
2109
|
-
paint();
|
|
2110
|
-
focusInRun(runId, [back, `[data-run-timeline="${runId}"]`]);
|
|
2111
|
-
}
|
|
2112
|
-
|
|
2113
|
-
// ---------------------------------------------------------------------------
|
|
2114
|
-
// Opening and closing
|
|
2115
|
-
// ---------------------------------------------------------------------------
|
|
2116
|
-
|
|
2117
|
-
export const isForgeOpen = () => ui.open;
|
|
2118
|
-
|
|
2119
|
-
/** What opened the panel (a toggle in the header), so Escape and Close give the focus back to it */
|
|
2120
|
-
let openerEl = null;
|
|
2121
|
-
|
|
2122
|
-
/**
|
|
2123
|
-
* Opens the panel with the focus on its title; the first time, loads what its tab shows (the proposals, to start with).
|
|
2124
|
-
* `tab` opens it on that tab ('specs', 'pulls', 'issues', 'threads', 'work' for Runs, 'deploys'), whichever was shown last otherwise.
|
|
4
|
+
* A bridge (spec 0011 D2 and D3, step 6): the Work panel is a piece on the instance (pieces/work.js, with a part per tab in pieces/work-*.js) and its
|
|
5
|
+
* pure half is forge-panel-model.js. This file keeps the old names for the page (page.js, deep-link.js, panels.js) and for the tests that drive the
|
|
6
|
+
* panel through cornfield's own page, bound to the page's instance and to the piece the page mounts at the places in index.html. It goes when
|
|
7
|
+
* those callers are on the instance (the `corn-work` shell for a host, and a page shell that mounts the piece itself).
|
|
2125
8
|
*/
|
|
2126
|
-
export function openForge({ load = true, tab } = {}) {
|
|
2127
|
-
const panel = $('forge-panel');
|
|
2128
|
-
if (!panel || panel.hidden) return;
|
|
2129
|
-
if (tab && tab !== (ui.kind === 'notes' ? 'pulls' : ui.kind) && TABS.includes(tab)) { // the Release notes are one level down on PRs
|
|
2130
|
-
ui.kind = tab;
|
|
2131
|
-
ui.filters = defaultFilters(tab);
|
|
2132
|
-
ui.actNote = null;
|
|
2133
|
-
} else if (!tab && load && !ui.open) {
|
|
2134
|
-
// Opened by a toggle: on the tab with the oldest thing waiting on you, else the tab used last (spec 0010 D2)
|
|
2135
|
-
const oldest = waitingNow().oldest;
|
|
2136
|
-
if (oldest && oldest !== ui.kind) {
|
|
2137
|
-
ui.kind = oldest;
|
|
2138
|
-
ui.filters = defaultFilters(oldest);
|
|
2139
|
-
ui.actNote = null;
|
|
2140
|
-
paintFilters();
|
|
2141
|
-
}
|
|
2142
|
-
}
|
|
2143
|
-
ui.open = true;
|
|
2144
|
-
panel.inert = false;
|
|
2145
|
-
panel.classList.add('forge-open');
|
|
2146
|
-
if (isPhone()) { showSheet('forge'); if (tab) expandSheet('forge'); } // a peek; only a link that names a tab (a deep link, "Open the Specs list") opens it expanded
|
|
2147
|
-
paintButton();
|
|
2148
|
-
const title = $('forge-title');
|
|
2149
|
-
title.focus();
|
|
2150
|
-
announce('Work');
|
|
2151
|
-
if (!load) return; // a deep link loads the list it wants itself (openTab)
|
|
2152
|
-
if (!tab) primeCounts(); // opened by a toggle, not for a tab: the other tabs' counts are read quietly
|
|
2153
|
-
if (ui.kind === 'notes') { if (!ui.notes.data && !ui.notes.loading) loadNotes(); else paint(); return; }
|
|
2154
|
-
if (ui.kind === 'specs' || !current()) { paintFilters(); loadList(); } else paint();
|
|
2155
|
-
}
|
|
2156
|
-
|
|
2157
|
-
/** The tabs, in the order of the loop */
|
|
2158
|
-
const TABS = ['specs', 'pulls', 'issues', 'threads', 'work', 'deploys'];
|
|
2159
|
-
|
|
2160
|
-
// ---------------------------------------------------------------------------
|
|
2161
|
-
// Deep links (explorer/deep-link.js): a run, an issue, a proposal's Start dialog
|
|
2162
|
-
// ---------------------------------------------------------------------------
|
|
2163
|
-
|
|
2164
|
-
/** Shows `tab` in the panel, opened (and, on a phone, expanded), with its list read; resolves when the list is in */
|
|
2165
|
-
async function openTab(tab) {
|
|
2166
|
-
ui.kind = tab;
|
|
2167
|
-
ui.filters = defaultFilters(tab); // a filter left from before must not hide what the link names
|
|
2168
|
-
ui.actNote = null;
|
|
2169
|
-
paintFilters();
|
|
2170
|
-
if (!ui.open) openForge({ load: false });
|
|
2171
|
-
if (isPhone()) expandSheet('forge');
|
|
2172
|
-
if (current()) paint(); else await loadList();
|
|
2173
|
-
}
|
|
2174
|
-
|
|
2175
|
-
/** What a link names is not there: a line in the panel, said through the live region */
|
|
2176
|
-
function linkMissing(words) {
|
|
2177
|
-
ui.actNote = { ok: false, text: words };
|
|
2178
|
-
paint();
|
|
2179
|
-
announce(words);
|
|
2180
|
-
return false;
|
|
2181
|
-
}
|
|
2182
|
-
|
|
2183
|
-
/** Moves the focus to `el` (made focusable if it is a row) and brings it into view */
|
|
2184
|
-
function bringIntoView(el) {
|
|
2185
|
-
if (!el) return;
|
|
2186
|
-
if (!el.matches('button, a, input, select, textarea')) el.setAttribute('tabindex', '-1');
|
|
2187
|
-
el.focus();
|
|
2188
|
-
if (typeof el.scrollIntoView === 'function') el.scrollIntoView({ block: 'nearest' });
|
|
2189
|
-
}
|
|
2190
9
|
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
let run = runById(id);
|
|
2197
|
-
// A run asked for a moment ago may not be in what was read before: ask once more, past the cache
|
|
2198
|
-
if (!run && ui.runs && ui.runs.data) { await loadRuns(true, { say: false }); run = runById(id); }
|
|
2199
|
-
if (!run) return linkMissing(ui.runs && ui.runs.data ? `There is no run ${id}.` : (ui.runs && ui.runs.error) || 'The runs could not be read.');
|
|
2200
|
-
if (ui.runSel !== id) selectRun(id);
|
|
2201
|
-
paint();
|
|
2202
|
-
bringIntoView($('forge-runs-list').querySelector(`[data-run="${id}"]`));
|
|
2203
|
-
announce(`Run ${id}, in the Runs view`);
|
|
2204
|
-
return true;
|
|
2205
|
-
}
|
|
2206
|
-
|
|
2207
|
-
/** `?issue=<n>`: the Issues tab with that issue's Start an agent button in view and focused, ready to press */
|
|
2208
|
-
export async function openIssueLink(n) {
|
|
2209
|
-
if (!ui.config) return false;
|
|
2210
|
-
await openTab('issues');
|
|
2211
|
-
const list = current();
|
|
2212
|
-
if (!list) return linkMissing(ui.error || 'The issues could not be read.');
|
|
2213
|
-
const item = list.items.find((i) => i.number === n);
|
|
2214
|
-
if (!item) return issueNotListed(n);
|
|
2215
|
-
paint();
|
|
2216
|
-
const start = $('forge-list').querySelector(`[data-forge-agent="issue:${n}"]`);
|
|
2217
|
-
bringIntoView(start);
|
|
2218
|
-
announce(`Issue ${n}: ${item.title}. Start an agent is ready`);
|
|
2219
|
-
return true;
|
|
2220
|
-
}
|
|
2221
|
-
|
|
2222
|
-
/** An issue the open list does not hold: asked for once, directly, so a closed one is called closed and a missing one missing */
|
|
2223
|
-
async function issueNotListed(n) {
|
|
2224
|
-
const res = await request(issueUrl(n));
|
|
2225
|
-
if (res.ok && res.body.issue) {
|
|
2226
|
-
const { issue } = res.body;
|
|
2227
|
-
ui.actNote = { ok: false, text: issue.state === 'closed' ? `Issue ${n} is closed: ${issue.title}` : `Issue ${n} is open, but not in the list shown here: ${issue.title}`, url: issue.url };
|
|
2228
|
-
paint();
|
|
2229
|
-
announce(ui.actNote.text);
|
|
2230
|
-
return false;
|
|
2231
|
-
}
|
|
2232
|
-
return linkMissing(res.status === 404 ? `There is no issue ${n}.` : failWords(res, `issue ${n}`));
|
|
2233
|
-
}
|
|
10
|
+
import { pagePiece, setPagePieceOptions } from './page-pieces.js';
|
|
11
|
+
import { initConnection, resetConnectionForTests } from './connection.js';
|
|
12
|
+
import { pageInstance } from './state.js';
|
|
13
|
+
import { resetFeedback } from './engine/feedback.js';
|
|
14
|
+
import { RUNS_POLL_MS, SPECS_POLL_MS } from './pieces/work.js';
|
|
2234
15
|
|
|
2235
|
-
|
|
2236
|
-
export const canStartAgent = () => !!(ui.config && ui.config.agents && agentEl());
|
|
16
|
+
export { RUNS_POLL_MS, SPECS_POLL_MS };
|
|
2237
17
|
|
|
2238
|
-
|
|
2239
|
-
export async function openProposalStart(slug, opener = '#forge-title') {
|
|
2240
|
-
if (!ui.config || !agentEl()) return false;
|
|
2241
|
-
await openAgent(`proposal:${slug}`, opener);
|
|
2242
|
-
return !!ui.agent;
|
|
2243
|
-
}
|
|
2244
|
-
|
|
2245
|
-
/** Closes the panel. What a selected pull request lit stays lit (the button says which); Clear lets go of it. */
|
|
2246
|
-
export function closeForge({ restoreFocus = true } = {}) {
|
|
2247
|
-
const panel = $('forge-panel');
|
|
2248
|
-
if (!panel || !ui.open) return;
|
|
2249
|
-
const hadFocus = panel.contains(document.activeElement);
|
|
2250
|
-
ui.open = false;
|
|
2251
|
-
panel.classList.remove('forge-open');
|
|
2252
|
-
panel.inert = true;
|
|
2253
|
-
collapseSheet('forge');
|
|
2254
|
-
paintButton();
|
|
2255
|
-
const back = openerEl && openerEl.isConnected ? openerEl : $('forge-btn');
|
|
2256
|
-
if (restoreFocus && hadFocus && back) back.focus();
|
|
2257
|
-
announce('Work closed');
|
|
2258
|
-
}
|
|
2259
|
-
|
|
2260
|
-
export const toggleForge = () => (ui.open ? closeForge() : openForge());
|
|
2261
|
-
|
|
2262
|
-
/** Asks the forge again, past the server's cache: the list, and the selected pull request */
|
|
2263
|
-
export async function refreshForge({ quiet = false } = {}) {
|
|
2264
|
-
if (!quiet) announce('Asking the forge again');
|
|
2265
|
-
if (ui.kind === 'notes') { await loadNotes(true); return; }
|
|
2266
|
-
const n = ui.selected;
|
|
2267
|
-
await loadList(true, quiet);
|
|
2268
|
-
if (ui.deployItem) {
|
|
2269
|
-
// The list is read again: the deploy as the forge now has it (still running, now finished), else the last copy
|
|
2270
|
-
const again = ui.lists.deploys && ui.lists.deploys.items.find((d) => d.id === ui.deploy);
|
|
2271
|
-
if (again) { ui.deployItem = again; relight(); }
|
|
2272
|
-
return;
|
|
2273
|
-
}
|
|
2274
|
-
if (ui.thread !== null) {
|
|
2275
|
-
const at = ui.thread;
|
|
2276
|
-
const token = ++threadToken;
|
|
2277
|
-
const res = await request(threadUrl(at), true);
|
|
2278
|
-
const thread = threadOf(res);
|
|
2279
|
-
if (token !== threadToken || !thread) return;
|
|
2280
|
-
ui.threadDetail = { thread, at: res.body.at, rate: res.body.rate || '', stale: res.body.stale || '' };
|
|
2281
|
-
relight();
|
|
2282
|
-
return;
|
|
2283
|
-
}
|
|
2284
|
-
if (n !== null && ui.selected === n) {
|
|
2285
|
-
const token = ++pullToken;
|
|
2286
|
-
const res = await request(pullUrl(n), true);
|
|
2287
|
-
if (token !== pullToken || !res.ok) return;
|
|
2288
|
-
ui.detail = { pull: res.body.pull, files: res.body.files || [], checks: res.body.checks || [], specs: res.body.specs || [], at: res.body.at, rate: res.body.rate || '', stale: res.body.stale || '' };
|
|
2289
|
-
relight();
|
|
2290
|
-
await loadLanding(n, token);
|
|
2291
|
-
}
|
|
2292
|
-
}
|
|
2293
|
-
|
|
2294
|
-
// ---------------------------------------------------------------------------
|
|
2295
|
-
// Events
|
|
2296
|
-
// ---------------------------------------------------------------------------
|
|
2297
|
-
|
|
2298
|
-
/** After a filter changes: the list again, and how many it holds */
|
|
2299
|
-
function filtersChanged(announceNow = true) {
|
|
2300
|
-
paint();
|
|
2301
|
-
const list = current();
|
|
2302
|
-
if (announceNow && list && ui.kind === 'work') announce(workStatus(groupsShown(), '', now()));
|
|
2303
|
-
else if (announceNow && list) announce(`${filterItems(list.items, ui.kind, ui.filters).length} of ${plural(list.items.length, kindWords())} shown`);
|
|
2304
|
-
}
|
|
2305
|
-
|
|
2306
|
-
function onClick(e) {
|
|
2307
|
-
const t = e.target;
|
|
2308
|
-
if (!t.closest) return;
|
|
2309
|
-
const kind = t.closest('[data-forge-kind]');
|
|
2310
|
-
if (kind) {
|
|
2311
|
-
if (kind.dataset.forgeKind === ui.kind) return;
|
|
2312
|
-
ui.kind = kind.dataset.forgeKind;
|
|
2313
|
-
ui.actNote = null;
|
|
2314
|
-
ui.filters = defaultFilters(ui.kind);
|
|
2315
|
-
paintFilters();
|
|
2316
|
-
// The proposals are asked for again each time (worktrees come and go); the other lists keep what they have
|
|
2317
|
-
if (ui.kind === 'specs') { paint(); loadList(false, true); announce(current() ? `${plural(current().items.length, 'spec')} shown` : 'Looking for proposals'); } else if (current()) filtersChanged(); else { paint(); loadList(); }
|
|
2318
|
-
return;
|
|
2319
|
-
}
|
|
2320
|
-
const fold = t.closest('[data-spec-group-toggle]');
|
|
2321
|
-
if (fold) {
|
|
2322
|
-
// Drafts folded behind their header, opened by hand and folded again; the focus stays on the header (findAgain)
|
|
2323
|
-
const drafts = specGroups(specsList() ? specsList().items : [], { query: ui.specQuery }).find((g) => g.key === 'drafts');
|
|
2324
|
-
const folded = ui.draftsOpen === null ? !!(drafts && drafts.collapsed) : !ui.draftsOpen;
|
|
2325
|
-
ui.draftsOpen = folded;
|
|
2326
|
-
paint();
|
|
2327
|
-
return;
|
|
2328
|
-
}
|
|
2329
|
-
const pr = t.closest('[data-forge-pr]');
|
|
2330
|
-
if (pr) {
|
|
2331
|
-
const n = Number(pr.dataset.forgePr);
|
|
2332
|
-
returnTo = findAgain(pr); // the row to give the focus back to when the selection is let go of
|
|
2333
|
-
if (ui.selected === n) clearPull(); else selectPull(n);
|
|
2334
|
-
return;
|
|
2335
|
-
}
|
|
2336
|
-
const thr = t.closest('[data-forge-thread]');
|
|
2337
|
-
if (thr) {
|
|
2338
|
-
const n = Number(thr.dataset.forgeThread);
|
|
2339
|
-
returnTo = findAgain(thr);
|
|
2340
|
-
if (ui.thread === n) clearThread(); else selectThread(n);
|
|
2341
|
-
return;
|
|
2342
|
-
}
|
|
2343
|
-
const dep = t.closest('[data-forge-deploy]');
|
|
2344
|
-
if (dep) {
|
|
2345
|
-
returnTo = findAgain(dep);
|
|
2346
|
-
if (ui.deploy === dep.dataset.forgeDeploy) clearDeploy(); else selectDeploy(dep.dataset.forgeDeploy);
|
|
2347
|
-
return;
|
|
2348
|
-
}
|
|
2349
|
-
const nodeBtn = t.closest('[data-forge-node]');
|
|
2350
|
-
if (nodeBtn) {
|
|
2351
|
-
const node = nodeById(nodeBtn.dataset.forgeNode);
|
|
2352
|
-
if (!node) return;
|
|
2353
|
-
selectNode(node, { frame: true });
|
|
2354
|
-
if (isPhone()) collapseSheet('forge'); // the map and the node's sheet are what is wanted now
|
|
2355
|
-
announce(`${node.label}, ${node.type}`);
|
|
2356
|
-
return;
|
|
2357
|
-
}
|
|
2358
|
-
const agent = t.closest('[data-forge-agent]');
|
|
2359
|
-
if (agent) { openAgent(agent.dataset.forgeAgent, `[data-forge-agent="${agent.dataset.forgeAgent}"]`); return; }
|
|
2360
|
-
const stop = t.closest('[data-forge-stop]');
|
|
2361
|
-
if (stop) { stopRun(stop.dataset.forgeStop); return; }
|
|
2362
|
-
const retry = t.closest('[data-forge-retry]');
|
|
2363
|
-
if (retry) { startAgain(retry.dataset.forgeRetry); return; }
|
|
2364
|
-
const goto = t.closest('[data-run-goto]');
|
|
2365
|
-
if (goto) { goToRun(goto.dataset.runGoto); return; }
|
|
2366
|
-
const answer = t.closest('[data-run-answer]');
|
|
2367
|
-
if (answer) { answerRun(answer.dataset.runId, answer.dataset.runAnswer); return; }
|
|
2368
|
-
const discard = t.closest('[data-run-discard]');
|
|
2369
|
-
if (discard) { discardReply(discard.dataset.runDiscard); return; }
|
|
2370
|
-
const pick = t.closest('[data-run-select]');
|
|
2371
|
-
if (pick) { selectRun(pick.dataset.runSelect); return; }
|
|
2372
|
-
const timeline = t.closest('[data-run-timeline]');
|
|
2373
|
-
if (timeline) { toggleTimeline(timeline.dataset.runTimeline); return; }
|
|
2374
|
-
const unland = t.closest('[data-forge-landing-cancel]');
|
|
2375
|
-
if (unland) { cancelLanding(Number(unland.dataset.forgeLandingCancel)); return; }
|
|
2376
|
-
const merge = t.closest('[data-forge-merge]');
|
|
2377
|
-
if (merge) { openConfirm('[data-forge-merge]'); return; }
|
|
2378
|
-
const spec = t.closest('[data-forge-spec]');
|
|
2379
|
-
if (spec) { askPlan('spec', Number(spec.dataset.forgeSpec), null, `[data-forge-spec="${spec.dataset.forgeSpec}"]`); return; }
|
|
2380
|
-
const build = t.closest('[data-forge-build]');
|
|
2381
|
-
if (build && ui.selected !== null) { askPlan('build', ui.selected, build.dataset.forgeBuild, `[data-forge-build="${build.dataset.forgeBuild}"]`); return; }
|
|
2382
|
-
const rerun = t.closest('[data-forge-rerun]');
|
|
2383
|
-
if (rerun) { rerunCheck(rerun.dataset.forgeRerun); return; }
|
|
2384
|
-
const action = t.closest('[data-action]');
|
|
2385
|
-
if (!action) return;
|
|
2386
|
-
if (action.dataset.action === 'close-forge') closeForge();
|
|
2387
|
-
else if (action.dataset.action === 'refresh-forge' || action.dataset.action === 'retry-forge') refreshForge();
|
|
2388
|
-
else if (action.dataset.action === 'clear-specs-search') {
|
|
2389
|
-
ui.specQuery = '';
|
|
2390
|
-
const box = $('specs-search');
|
|
2391
|
-
if (box) { box.value = ''; }
|
|
2392
|
-
paint();
|
|
2393
|
-
announce(specsShownWords());
|
|
2394
|
-
if (box) box.focus();
|
|
2395
|
-
}
|
|
2396
|
-
else if (action.dataset.action === 'copy-notes') copyNotes();
|
|
2397
|
-
else if (action.dataset.action === 'post-notes') { if (ui.notes.confirm) closeNotesConfirm(); else openNotesConfirm(); }
|
|
2398
|
-
else if (action.dataset.action === 'confirm-notes') postDraft();
|
|
2399
|
-
else if (action.dataset.action === 'cancel-notes') { closeNotesConfirm(); announce('Cancelled. Nothing was posted.'); }
|
|
2400
|
-
else if (action.dataset.action === 'clear-forge-pr') clearPull();
|
|
2401
|
-
else if (action.dataset.action === 'clear-forge-deploy') clearDeploy();
|
|
2402
|
-
else if (action.dataset.action === 'clear-forge-thread') clearThread();
|
|
2403
|
-
else if (action.dataset.action === 'toggle-filters') { ui.filtersOpen = !ui.filtersOpen; paintChip(); }
|
|
2404
|
-
else if (action.dataset.action === 'open-notes') openNotes();
|
|
2405
|
-
else if (action.dataset.action === 'close-notes') closeNotes();
|
|
2406
|
-
else if (action.dataset.action === 'open-proposal' && isPhone()) collapseSheet('forge'); // the proposal's own bar and the map are what is wanted now
|
|
2407
|
-
else if (action.dataset.action === 'idea-open') toggleIdea(!ui.idea.open);
|
|
2408
|
-
else if (action.dataset.action === 'idea-send') {
|
|
2409
|
-
// Nothing of it may escape as an unhandled rejection: what went wrong is said, and the form is usable again
|
|
2410
|
-
sendIdea().catch((err) => {
|
|
2411
|
-
ui.idea.busy = false;
|
|
2412
|
-
ui.idea.message = `Something went wrong in the page: ${err instanceof Error ? err.message : err}`;
|
|
2413
|
-
ui.idea.bad = true;
|
|
2414
|
-
paintIdea();
|
|
2415
|
-
announce(ui.idea.message);
|
|
2416
|
-
});
|
|
2417
|
-
}
|
|
2418
|
-
else if (action.dataset.action === 'idea-cancel') { toggleIdea(false); announce('Cancelled. Nothing was opened.'); }
|
|
2419
|
-
}
|
|
2420
|
-
|
|
2421
|
-
/** The Release notes view, from the PRs list: its own page with a way back */
|
|
2422
|
-
function openNotes() {
|
|
2423
|
-
ui.kind = 'notes';
|
|
2424
|
-
ui.actNote = null;
|
|
2425
|
-
if (ui.notes.data || ui.notes.loading) { paint(); announce(`Release notes. ${ui.notes.data ? notesSummary(ui.notes.data) : ''}`); } else loadNotes();
|
|
2426
|
-
$('notes-title').focus();
|
|
2427
|
-
}
|
|
2428
|
-
|
|
2429
|
-
/** Back from the Release notes to the PRs list, the focus on the button that opened them */
|
|
2430
|
-
function closeNotes() {
|
|
2431
|
-
ui.kind = 'pulls';
|
|
2432
|
-
paint();
|
|
2433
|
-
$('notes-open').focus();
|
|
2434
|
-
announce('All pull requests');
|
|
2435
|
-
}
|
|
2436
|
-
|
|
2437
|
-
function onChange(e) {
|
|
2438
|
-
const id = e.target.id;
|
|
2439
|
-
if (id === 'notes-since') {
|
|
2440
|
-
ui.notes.since = e.target.value;
|
|
2441
|
-
ui.notes.message = '';
|
|
2442
|
-
loadNotes();
|
|
2443
|
-
} else if (id === 'forge-state') {
|
|
2444
|
-
ui.filters.state = e.target.value;
|
|
2445
|
-
paintFilters();
|
|
2446
|
-
if (current()) filtersChanged(); else { paint(); loadList(); }
|
|
2447
|
-
} else if (id === 'forge-work-agents' || id === 'forge-work-finished') {
|
|
2448
|
-
if (id === 'forge-work-agents') ui.workFilters.agentsOnly = e.target.checked;
|
|
2449
|
-
else ui.workFilters.finished = e.target.checked;
|
|
2450
|
-
paint();
|
|
2451
|
-
announce(workStatus(groupsShown(), '', now()));
|
|
2452
|
-
} else if (id === 'forge-label') {
|
|
2453
|
-
ui.filters.label = e.target.value;
|
|
2454
|
-
filtersChanged();
|
|
2455
|
-
} else if (id === 'forge-author') {
|
|
2456
|
-
ui.filters.author = e.target.value;
|
|
2457
|
-
filtersChanged();
|
|
2458
|
-
}
|
|
2459
|
-
}
|
|
2460
|
-
|
|
2461
|
-
function onInput(e) {
|
|
2462
|
-
if (e.target.dataset && e.target.dataset.runReply) {
|
|
2463
|
-
const id = e.target.dataset.runReply;
|
|
2464
|
-
ui.runReplies.set(id, e.target.value);
|
|
2465
|
-
// "Write a reply first" goes once something is written: a refusal does not outlive what it was about
|
|
2466
|
-
const said = resultOf(id);
|
|
2467
|
-
if (said && !said.ok && e.target.value.trim()) { clearResult(id); showResultIn(e.target.closest('[data-run]') && e.target.closest('[data-run]').querySelector(`[data-run-result="${id}"]`), id); }
|
|
2468
|
-
return;
|
|
2469
|
-
}
|
|
2470
|
-
if (e.target.id === 'specs-search') {
|
|
2471
|
-
ui.specQuery = e.target.value;
|
|
2472
|
-
paint();
|
|
2473
|
-
clearTimeout(searchTimer);
|
|
2474
|
-
searchTimer = setTimeout(() => announce(specsShownWords()), SEARCH_ANNOUNCE_MS);
|
|
2475
|
-
return;
|
|
2476
|
-
}
|
|
2477
|
-
if (e.target.id !== 'forge-text') return;
|
|
2478
|
-
ui.filters.text = e.target.value;
|
|
2479
|
-
filtersChanged(false);
|
|
2480
|
-
clearTimeout(searchTimer);
|
|
2481
|
-
searchTimer = setTimeout(() => filtersChanged(), SEARCH_ANNOUNCE_MS);
|
|
2482
|
-
}
|
|
2483
|
-
|
|
2484
|
-
/** Escape anywhere in the panel closes it, and the button has the focus again (a field's own Escape comes first) */
|
|
2485
|
-
function onKey(e) {
|
|
2486
|
-
if (e.key === 'Enter' && e.target.dataset && e.target.dataset.runReply && !e.defaultPrevented) { e.preventDefault(); answerRun(e.target.dataset.runReply, 'reply'); return; }
|
|
2487
|
-
if (e.key === 'Enter' && e.target.id === 'notes-tag' && !e.defaultPrevented) { e.preventDefault(); postDraft(); return; }
|
|
2488
|
-
if (e.key === 'Escape' && !e.defaultPrevented && ui.notes.confirm && e.target.closest && e.target.closest('#notes-confirm')) {
|
|
2489
|
-
e.preventDefault();
|
|
2490
|
-
closeNotesConfirm();
|
|
2491
|
-
announce('Cancelled. Nothing was posted.');
|
|
2492
|
-
return;
|
|
2493
|
-
}
|
|
2494
|
-
if (e.key !== 'Escape' || e.defaultPrevented) return;
|
|
2495
|
-
if (e.target.closest && e.target.closest('select, input, textarea')) return;
|
|
2496
|
-
e.preventDefault();
|
|
2497
|
-
closeForge();
|
|
2498
|
-
}
|
|
2499
|
-
|
|
2500
|
-
/** Any `data-action="toggle-forge"` opens and closes the panel; one listener on the page, however many times the panel is wired */
|
|
2501
|
-
let onToggle = null;
|
|
2502
|
-
function wireToggles() {
|
|
2503
|
-
if (onToggle) document.removeEventListener('click', onToggle);
|
|
2504
|
-
onToggle = (e) => {
|
|
2505
|
-
const el = e.target.closest && e.target.closest('[data-action="toggle-forge"]');
|
|
2506
|
-
if (!el) return;
|
|
2507
|
-
openerEl = el;
|
|
2508
|
-
toggleForge();
|
|
2509
|
-
};
|
|
2510
|
-
document.addEventListener('click', onToggle);
|
|
2511
|
-
}
|
|
18
|
+
const piece = () => pagePiece('work');
|
|
2512
19
|
|
|
2513
20
|
/**
|
|
2514
|
-
*
|
|
2515
|
-
*
|
|
21
|
+
* Starts the panel (page.js calls this once the config is read). With no forge in the config, or nobody signed in, the button and the panel stay
|
|
22
|
+
* hidden, and this returns false.
|
|
2516
23
|
* @param {{ forge?: { type: string, repo: string } | null, signIn?: false | { login: string } }} config what `/cornfield/config.json` said
|
|
2517
24
|
* @param {{ clock?: () => number }} [opts] `clock` for the times shown (tests)
|
|
2518
25
|
* @returns {boolean} whether the panel is on
|
|
2519
26
|
*/
|
|
2520
27
|
export function initForgePanel(config, opts = {}) {
|
|
2521
|
-
const
|
|
2522
|
-
if (!
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
if (
|
|
2526
|
-
|
|
2527
|
-
panel.hidden = false;
|
|
2528
|
-
// The Specs tab lists the proposals: the account menu's Proposals entry is only for a cornfield without the panel (no forge, or no sign-in)
|
|
2529
|
-
const proposalsEntry = $('proposal-wrap');
|
|
2530
|
-
if (proposalsEntry) proposalsEntry.hidden = true;
|
|
2531
|
-
// `threads: false` in the config turns the tab off; a server that does not say has threads
|
|
2532
|
-
const threadsOn = config.threads !== false;
|
|
2533
|
-
const tab = panel.querySelector('[data-forge-kind="threads"]');
|
|
2534
|
-
if (tab) tab.hidden = !threadsOn;
|
|
2535
|
-
state.threadIndex = threadsOn ? { for: threadsFor, ensure: ensureThreadsList, open: openThread, start: startThread, forge: forgeName } : null;
|
|
2536
|
-
// On a phone Work is a sheet: it opens as a peek and displaces the node panel; folded to a stub it says its title and what waits on you (spec 0010 D7)
|
|
2537
|
-
registerSheet('forge', panel, {
|
|
2538
|
-
stub: () => { const n = waitingNow().total; return { title: t('issuesAndPrs'), badge: n ? String(n) : '', label: workButtonName(t('issuesAndPrs'), n) }; },
|
|
2539
|
-
away: () => closeForge({ restoreFocus: false }),
|
|
2540
|
-
});
|
|
2541
|
-
paintFilters();
|
|
2542
|
-
paint();
|
|
2543
|
-
// The map shows the open runs whether or not the panel is open: read them once now, and again now and then while any is open
|
|
2544
|
-
if (config.agents && config.agents.runs) {
|
|
2545
|
-
loadRuns(false).then(() => { if (ui.kind === 'work') paint(); }, () => {});
|
|
2546
|
-
}
|
|
2547
|
-
// The specs part of what waits on you is read once now and every 5 minutes after (the server keeps it by PR head), and after a review is sent
|
|
2548
|
-
proposalHooks.reviewed = () => { readSpecsQuiet(); };
|
|
2549
|
-
// The proposal bar says so when a run waits on the proposal it shows: drawn with the bar, and again as the runs are read
|
|
2550
|
-
if (!(proposalHooks.bar && proposalHooks.bar.waitingLine)) {
|
|
2551
|
-
const barBefore = proposalHooks.bar;
|
|
2552
|
-
proposalHooks.bar = (open) => { if (barBefore) barBefore(open); paintBarLine(open); };
|
|
2553
|
-
proposalHooks.bar.waitingLine = true;
|
|
2554
|
-
}
|
|
2555
|
-
const bar = $('proposal-bar');
|
|
2556
|
-
if (bar && !bar.dataset.waitingWired) {
|
|
2557
|
-
bar.dataset.waitingWired = '1';
|
|
2558
|
-
bar.addEventListener('click', (e) => {
|
|
2559
|
-
const go = e.target.closest && e.target.closest('[data-waiting-answer]');
|
|
2560
|
-
if (go) { e.preventDefault(); e.stopPropagation(); answerFromBar(go.dataset.waitingAnswer); }
|
|
2561
|
-
}, true);
|
|
2562
|
-
}
|
|
2563
|
-
readSpecsQuiet();
|
|
2564
|
-
syncSpecsPoll();
|
|
2565
|
-
if (!wired) {
|
|
2566
|
-
wired = true;
|
|
2567
|
-
initConnection();
|
|
2568
|
-
if (typeof window !== 'undefined') window.addEventListener('online', readOnline);
|
|
2569
|
-
const tabs = panel.querySelector('.hx-forge-tabs');
|
|
2570
|
-
if (tabs) tabs.addEventListener('scroll', paintTabsMore, { passive: true });
|
|
2571
|
-
if (typeof window !== 'undefined') window.addEventListener('resize', paintTabsMore);
|
|
2572
|
-
wireToggles();
|
|
2573
|
-
panel.addEventListener('click', onClick);
|
|
2574
|
-
panel.addEventListener('change', onChange);
|
|
2575
|
-
panel.addEventListener('input', onInput);
|
|
2576
|
-
panel.addEventListener('keydown', onKey);
|
|
2577
|
-
if (typeof window !== 'undefined') {
|
|
2578
|
-
window.addEventListener('pagehide', onPageHide);
|
|
2579
|
-
window.addEventListener('pageshow', onPageShow);
|
|
2580
|
-
}
|
|
2581
|
-
const agent = agentEl();
|
|
2582
|
-
if (agent) {
|
|
2583
|
-
agent.addEventListener('click', onAgentClick);
|
|
2584
|
-
agent.addEventListener('keydown', onAgentKey);
|
|
2585
|
-
agent.querySelector('form').addEventListener('submit', submitAgent);
|
|
2586
|
-
$('agent-profile').addEventListener('change', onAgentProfile);
|
|
2587
|
-
}
|
|
2588
|
-
const confirm = confirmEl();
|
|
2589
|
-
if (confirm) {
|
|
2590
|
-
confirm.addEventListener('click', onConfirmClick);
|
|
2591
|
-
confirm.addEventListener('keydown', onConfirmKey);
|
|
2592
|
-
}
|
|
2593
|
-
offScene = onSceneTouch(onNodesChange);
|
|
2594
|
-
// The header's Proposals menu reads the same list: when it is read again the Specs tab and its count follow
|
|
2595
|
-
offListing = onProposalListing(() => { paintWaiting(); if (ui.open) paint(); });
|
|
2596
|
-
// A node's panel lists the threads that mention it; a click there shows one in this panel
|
|
2597
|
-
const drawer = $('spec-drawer');
|
|
2598
|
-
if (drawer) drawer.addEventListener('click', (e) => {
|
|
2599
|
-
const open = e.target.closest && e.target.closest('[data-thread-open]');
|
|
2600
|
-
if (open && state.threadIndex) { openThread(Number(open.dataset.threadOpen)); return; }
|
|
2601
|
-
const start = e.target.closest && e.target.closest('[data-thread-start]');
|
|
2602
|
-
if (start && state.threadIndex && state.selectedNode) startThread(state.selectedNode);
|
|
2603
|
-
});
|
|
2604
|
-
}
|
|
2605
|
-
return true;
|
|
28
|
+
const p = piece();
|
|
29
|
+
if (!p) return false;
|
|
30
|
+
p.update(opts.clock ? { clock: opts.clock, config } : { config });
|
|
31
|
+
const on = p.isOn();
|
|
32
|
+
if (on) initConnection(); // the offline banner (explorer/connection.js) is the page's; it follows the Work panel, as it always has
|
|
33
|
+
return on;
|
|
2606
34
|
}
|
|
2607
35
|
|
|
2608
36
|
/** For tests: forget the page this was wired to, and everything shown */
|
|
2609
|
-
export function resetForgePanelForTests(clock
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
if (onToggle) document.removeEventListener('click', onToggle);
|
|
2613
|
-
onToggle = null;
|
|
2614
|
-
openerEl = null;
|
|
2615
|
-
primed.clear();
|
|
2616
|
-
shownKey = '';
|
|
2617
|
-
shownKind = '';
|
|
2618
|
-
returnTo = null;
|
|
2619
|
-
if (offScene) offScene();
|
|
2620
|
-
offScene = null;
|
|
2621
|
-
if (offListing) offListing();
|
|
2622
|
-
offListing = null;
|
|
2623
|
-
clearTimeout(searchTimer);
|
|
2624
|
-
wired = false;
|
|
2625
|
-
now = clock;
|
|
2626
|
-
listToken++;
|
|
2627
|
-
pullToken++;
|
|
2628
|
-
notesToken++;
|
|
2629
|
-
threadToken++;
|
|
2630
|
-
indexToken++;
|
|
2631
|
-
indexLoading = false;
|
|
2632
|
-
indexCache = null;
|
|
2633
|
-
state.forgeLit = null;
|
|
2634
|
-
state.threadIndex = null;
|
|
2635
|
-
clearTimeout(runsTimer);
|
|
2636
|
-
runsTimer = 0;
|
|
2637
|
-
clearTimeout(specsTimer);
|
|
2638
|
-
specsTimer = 0;
|
|
2639
|
-
specsReading = false;
|
|
2640
|
-
merged = { entries: null, items: [] };
|
|
2641
|
-
resetWaitingLineForTests();
|
|
2642
|
-
if (typeof document !== 'undefined' && baseTitle !== null) document.title = baseTitle;
|
|
2643
|
-
baseTitle = null;
|
|
2644
|
-
pageAway = false;
|
|
2645
|
-
clearRunsOnMap();
|
|
2646
|
-
Object.assign(ui, { specQuery: '', draftsOpen: null, runSel: null, runTimelines: new Set(), runReplies: new Map(), thread: null, threadDetail: null, threadError: '', litThread: null, idea: freshIdea(), config: null, open: false, kind: 'specs', filtersOpen: false, filters: defaultFilters(), lists: {}, work: null, workFilters: { agentsOnly: false, finished: false }, loading: false, error: '', selected: null, selectedOn: '', detail: null, landing: null, detailError: '', lit: null, deploy: null, deployItem: null, litDeploy: null, nodesSeen: null, busy: '', note: null, confirm: null, actNote: null, notes: freshNotes(), runs: null, runnerSaid: null, runNote: null, agent: null, retrying: false });
|
|
2647
|
-
resetFeedbackForTests();
|
|
37
|
+
export function resetForgePanelForTests(clock) {
|
|
38
|
+
setPagePieceOptions('work', clock ? { clock } : undefined);
|
|
39
|
+
resetFeedback(pageInstance());
|
|
2648
40
|
resetConnectionForTests();
|
|
2649
41
|
}
|
|
42
|
+
|
|
43
|
+
export const isForgeOpen = () => { const p = piece(); return !!p && p.isForgeOpen(); };
|
|
44
|
+
export const openForge = (opts) => { const p = piece(); if (p) p.openForge(opts); };
|
|
45
|
+
export const closeForge = (opts) => { const p = piece(); if (p) p.closeForge(opts); };
|
|
46
|
+
export const toggleForge = () => { const p = piece(); if (p) p.toggleForge(); };
|
|
47
|
+
export const refreshForge = (opts) => { const p = piece(); return p ? p.refreshForge(opts) : Promise.resolve(); };
|
|
48
|
+
export const clearPull = () => { const p = piece(); if (p) p.clearPull(); };
|
|
49
|
+
export const clearDeploy = () => { const p = piece(); if (p) p.clearDeploy(); };
|
|
50
|
+
export const clearThread = () => { const p = piece(); if (p) p.clearThread(); };
|
|
51
|
+
export const selectDeploy = (id) => { const p = piece(); if (p) p.selectDeploy(id); };
|
|
52
|
+
export const openRunLink = (id) => { const p = piece(); return p && p.isOn() ? p.openRunLink(id) : Promise.resolve(false); };
|
|
53
|
+
export const openIssueLink = (n) => { const p = piece(); return p && p.isOn() ? p.openIssueLink(n) : Promise.resolve(false); };
|
|
54
|
+
export const openProposalStart = (slug, opener) => { const p = piece(); return p && p.isOn() ? p.openProposalStart(slug, opener) : Promise.resolve(false); };
|
|
55
|
+
export const canStartAgent = () => { const p = piece(); return !!p && p.canStartAgent(); };
|