@popcorn245/cornfield 0.58.0 → 0.59.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/core/config.js +3 -0
- package/core/history.js +222 -0
- package/package.json +1 -1
- package/server/server.js +22 -1
package/core/config.js
CHANGED
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
* embed: { origins: [] }, // exact origins of sibling apps that may read, and decide a review, as the signed-in maintainer (docs/embedding.md)
|
|
34
34
|
* proxy: {}, // { '/api/': 'http://127.0.0.1:3245' }: same-origin paths for a live source
|
|
35
35
|
* importMap: {}, // bare imports a repo-local browser module needs: { name: '/repo/path.js' }
|
|
36
|
+
* history: false, // true: read the repo's git history for the History layer, a node's commits and Replay (docs/config.md#history; spec 0014)
|
|
36
37
|
* dataDir: null, // where cornfield keeps its own state (reviews; the SQLite file in v1)
|
|
37
38
|
* }
|
|
38
39
|
*
|
|
@@ -182,6 +183,7 @@ export const DEFAULTS = Object.freeze({
|
|
|
182
183
|
embed: { origins: [] },
|
|
183
184
|
proxy: {},
|
|
184
185
|
importMap: {},
|
|
186
|
+
history: false,
|
|
185
187
|
dataDir: null,
|
|
186
188
|
});
|
|
187
189
|
|
|
@@ -393,6 +395,7 @@ export function configProblems(c) {
|
|
|
393
395
|
if (l !== undefined && (!isText(l) || l.includes(',') || l.trim() !== l || l.length > MAX_LABEL)) out.push(`threads.label is the name of the label that makes an issue an idea, like "idea": text of at most ${MAX_LABEL} characters, no comma, no space at either end.`);
|
|
394
396
|
}
|
|
395
397
|
}
|
|
398
|
+
if (c.history !== undefined && typeof c.history !== 'boolean') out.push('"history" is true or false: true reads the repo\'s git history (docs/config.md#history).');
|
|
396
399
|
if (c.releaseNotes !== undefined) {
|
|
397
400
|
if (!isObject(c.releaseNotes)) out.push('"releaseNotes" is { breakingLabel }.');
|
|
398
401
|
else if (c.releaseNotes.breakingLabel !== undefined && (!isText(c.releaseNotes.breakingLabel) || c.releaseNotes.breakingLabel.includes(','))) out.push('releaseNotes.breakingLabel is a label\'s name, like "breaking".');
|
package/core/history.js
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/history
|
|
3
|
+
*
|
|
4
|
+
* The map's own history (spec 0014 D4): which commits changed each node, when each node was born, and, for each commit,
|
|
5
|
+
* the trail it names from spec to issue to pull request. Read from `git log` when the config says `history: true`.
|
|
6
|
+
*
|
|
7
|
+
* Two halves:
|
|
8
|
+
* - pure: `parseLog` reads the fixed format `readLog` asks git for, `traceOf` reads a commit's trail from its message
|
|
9
|
+
* and files, and `historyOf` ties the commits to a map's nodes. No I/O; tested in Node.
|
|
10
|
+
* - `readLog` and `createHistory`: run git, read-only, and keep the answer per HEAD.
|
|
11
|
+
*
|
|
12
|
+
* Running git is the one program cornfield runs, so it is held tight (spec 0014, question 1):
|
|
13
|
+
* - a fixed list of arguments, `execFile` with no shell, the repo's path as `-C`, nothing from a request in it;
|
|
14
|
+
* - nothing from the repo's own config may run a program: no pager, external diff, text conversion, signature check
|
|
15
|
+
* or fsmonitor, and no terminal prompt;
|
|
16
|
+
* - a time and size ceiling, and at most MAX_COMMITS commits.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { execFile } from 'node:child_process';
|
|
20
|
+
|
|
21
|
+
/** The most commits read, newest first: a long history is cut at its newest MAX_COMMITS */
|
|
22
|
+
export const MAX_COMMITS = 5000;
|
|
23
|
+
/** How long `git log` may take, and how much it may say, before it is given up on */
|
|
24
|
+
export const GIT_TIMEOUT_MS = 15_000;
|
|
25
|
+
export const GIT_MAX_BYTES = 64 * 1024 * 1024;
|
|
26
|
+
|
|
27
|
+
const RS = '\x1e';
|
|
28
|
+
const US = '\x1f';
|
|
29
|
+
/** The format each commit is written in: record separator, hash, author date (ISO), subject, body, then its files */
|
|
30
|
+
export const LOG_FORMAT = `${RS}%H${US}%aI${US}%s${US}%b${US}`;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The arguments `readLog` runs git with: settings that keep the repo's own config from running anything, then the log
|
|
34
|
+
* of the checked-out branch, first parent only (a merged branch's own commits are its pull request's), with renames.
|
|
35
|
+
* @param {string} root the repo's folder
|
|
36
|
+
*/
|
|
37
|
+
export function gitArgs(root) {
|
|
38
|
+
return [
|
|
39
|
+
'-C', root,
|
|
40
|
+
'-c', 'core.pager=cat', '-c', 'core.fsmonitor=false', '-c', 'log.showSignature=false', '-c', 'diff.external=',
|
|
41
|
+
'--no-pager', 'log', '--first-parent', `--max-count=${MAX_COMMITS}`, `--format=${LOG_FORMAT}`,
|
|
42
|
+
'--name-status', '-M', '--no-ext-diff', '--no-textconv', '--no-color', 'HEAD', '--',
|
|
43
|
+
];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The environment git runs in: no prompt, no system config, the user's own config kept (it is theirs, not the repo's) */
|
|
47
|
+
export const gitEnv = (env = process.env) => ({ ...env, GIT_TERMINAL_PROMPT: '0', GIT_CONFIG_NOSYSTEM: '1', GIT_PAGER: 'cat', GIT_EXTERNAL_DIFF: '', LC_ALL: 'C' });
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @typedef {object} RawCommit
|
|
51
|
+
* @property {string} sha
|
|
52
|
+
* @property {string} date the author date, ISO 8601
|
|
53
|
+
* @property {string} subject
|
|
54
|
+
* @property {string} body
|
|
55
|
+
* @property {{ status: string, path: string, from?: string }[]} files A, M, D, R (with `from`), C, T
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The commits in `readLog`'s output, oldest first. A malformed record is left out.
|
|
60
|
+
* @param {string} text
|
|
61
|
+
* @returns {RawCommit[]}
|
|
62
|
+
*/
|
|
63
|
+
export function parseLog(text) {
|
|
64
|
+
const out = [];
|
|
65
|
+
for (const rec of String(text).split(RS).slice(1)) {
|
|
66
|
+
const parts = rec.split(US);
|
|
67
|
+
if (parts.length < 5) continue;
|
|
68
|
+
const [sha, date, subject, body] = parts;
|
|
69
|
+
if (!/^[0-9a-f]{40}$/.test(sha) || Number.isNaN(Date.parse(date))) continue;
|
|
70
|
+
const files = [];
|
|
71
|
+
for (const line of parts.slice(4).join(US).split('\n')) {
|
|
72
|
+
const cols = line.split('\t');
|
|
73
|
+
if (cols.length < 2 || !/^[AMDRCT]\d*$/.test(cols[0])) continue;
|
|
74
|
+
const status = cols[0][0];
|
|
75
|
+
if ((status === 'R' || status === 'C') && cols.length >= 3) files.push({ status, from: cols[1], path: cols[2] });
|
|
76
|
+
else files.push({ status, path: cols[1] });
|
|
77
|
+
}
|
|
78
|
+
out.push({ sha, date, subject: subject.trim(), body: body.trim(), files });
|
|
79
|
+
}
|
|
80
|
+
return out.reverse();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** The words that say a commit closes an issue (GitHub's and Forgejo's) */
|
|
84
|
+
const CLOSES = /\b(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)\s+#(\d+)\b/gi;
|
|
85
|
+
const KEY = /\[([A-Z][A-Z0-9]*-\d+)\]/g;
|
|
86
|
+
const SPEC_WORD = /\bspecs?\s+(\d{4})\b/gi;
|
|
87
|
+
const SPEC_FILE = /^docs\/specs\/(\d{4})-[^/]+\.md$/;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The trail a commit names (spec 0014 D2, question 3): its pull request (the last `(#N)` in its subject, as a squash
|
|
91
|
+
* merge writes it), its issues (an earlier `(#N)`, a `Closes #N`), the issue keys it carries (`[CF-45]`), and its specs
|
|
92
|
+
* (`spec 0012` in its message, or a spec file it changed). What it does not name is not guessed.
|
|
93
|
+
* @param {{ subject: string, body?: string, files?: { path: string }[] }} commit
|
|
94
|
+
* @returns {{ pr: number | null, issues: number[], keys: string[], specs: string[] }}
|
|
95
|
+
*/
|
|
96
|
+
export function traceOf({ subject, body = '', files = [] }) {
|
|
97
|
+
const refs = [...String(subject).matchAll(/\(#(\d+)\)/g)].map((m) => Number(m[1]));
|
|
98
|
+
const pr = refs.length ? refs[refs.length - 1] : null;
|
|
99
|
+
const issues = [];
|
|
100
|
+
const add = (n) => { if (n !== pr && !issues.includes(n)) issues.push(n); };
|
|
101
|
+
refs.slice(0, -1).forEach(add);
|
|
102
|
+
for (const m of `${subject}\n${body}`.matchAll(CLOSES)) add(Number(m[1]));
|
|
103
|
+
const keys = [...new Set([...`${subject}\n${body}`.matchAll(KEY)].map((m) => m[1]))];
|
|
104
|
+
const specs = [];
|
|
105
|
+
for (const m of `${subject}\n${body}`.matchAll(SPEC_WORD)) if (!specs.includes(m[1])) specs.push(m[1]);
|
|
106
|
+
for (const f of files) { const m = SPEC_FILE.exec(f.path); if (m && !specs.includes(m[1])) specs.push(m[1]); }
|
|
107
|
+
return { pr, issues, keys, specs };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** A commit's subject without the `(#N)` its pull request left on it */
|
|
111
|
+
export const cleanSubject = (subject) => String(subject).replace(/\s*\(#\d+\)/g, '').trim();
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* @typedef {object} History
|
|
115
|
+
* @property {{ sha: string, date: string, subject: string, pr: number | null, issues: number[], keys: string[], specs: string[], files: number, nodes: string[] }[]} commits oldest first
|
|
116
|
+
* @property {Record<string, { born: number, commits: number[] }>} nodes by node id: the index of the commit it was born in, and of every commit that changed it
|
|
117
|
+
* @property {boolean} cut whether the history was cut at MAX_COMMITS
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Ties commits to a map's nodes. A node owns its `file`, and everything under it when that is a folder. Renames are
|
|
122
|
+
* followed back (question 4): a file renamed into a node's path brings its older history with it. A node is born at the
|
|
123
|
+
* first commit that changed what it owns; one that nothing in the history touches is born with the first commit.
|
|
124
|
+
* A child is never born before its parent: its parent is born with it.
|
|
125
|
+
* @param {RawCommit[]} raw oldest first (parseLog)
|
|
126
|
+
* @param {{ nodes: { id: string, file?: string }[], edges?: { from: string, to: string, dashed?: boolean, kind?: string }[] }} topology
|
|
127
|
+
* @param {{ cut?: boolean }} [opts]
|
|
128
|
+
* @returns {History}
|
|
129
|
+
*/
|
|
130
|
+
export function historyOf(raw, topology, { cut = false } = {}) {
|
|
131
|
+
const nodes = (topology && Array.isArray(topology.nodes) ? topology.nodes : []).filter((n) => n && typeof n.id === 'string');
|
|
132
|
+
// Each node's paths, newest name first; walked newest to oldest so a rename adds the older name before it is met
|
|
133
|
+
const owns = new Map(nodes.filter((n) => typeof n.file === 'string' && n.file.trim()).map((n) => [n.id, new Set([n.file.replace(/\/+$/, '')])]));
|
|
134
|
+
const covers = (p, f) => f === p || f.startsWith(`${p}/`);
|
|
135
|
+
const touched = raw.map(() => new Set());
|
|
136
|
+
for (let i = raw.length - 1; i >= 0; i--) {
|
|
137
|
+
for (const f of raw[i].files) {
|
|
138
|
+
for (const [id, paths] of owns) {
|
|
139
|
+
for (const p of [...paths]) {
|
|
140
|
+
if (!covers(p, f.path)) continue;
|
|
141
|
+
if (f.status !== 'D') touched[i].add(id);
|
|
142
|
+
// The node's own file came from another name: follow it back. A rename inside a folder node needs nothing, the folder covers both
|
|
143
|
+
if (f.status === 'R' && f.from && f.path === p) paths.add(f.from);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const out = {};
|
|
149
|
+
nodes.forEach((n) => { out[n.id] = { born: 0, commits: [] }; });
|
|
150
|
+
touched.forEach((ids, i) => ids.forEach((id) => out[id].commits.push(i)));
|
|
151
|
+
for (const n of nodes) out[n.id].born = out[n.id].commits.length ? out[n.id].commits[0] : 0;
|
|
152
|
+
// Parents first: ownership edges (no kind, not dashed), a parent born no later than its child
|
|
153
|
+
const parent = new Map();
|
|
154
|
+
for (const e of topology?.edges || []) if (e && !e.dashed && !e.kind && out[e.from] && out[e.to] && !parent.has(e.to) && e.from !== e.to) parent.set(e.to, e.from);
|
|
155
|
+
for (const n of nodes) {
|
|
156
|
+
const seen = new Set([n.id]);
|
|
157
|
+
for (let c = n.id, p = parent.get(c); p && !seen.has(p); c = p, p = parent.get(p)) {
|
|
158
|
+
seen.add(p);
|
|
159
|
+
if (out[p].born > out[c].born) out[p].born = out[c].born;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
const commits = raw.map((c, i) => ({ sha: c.sha, date: c.date, subject: cleanSubject(c.subject), ...traceOf(c), files: c.files.length, nodes: [...touched[i]].sort() }));
|
|
163
|
+
return { commits, nodes: out, cut };
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Runs git and reads the log of the checked-out branch. Rejects with a plain message when git is not there, the folder
|
|
168
|
+
* is not a repo, or git gives up.
|
|
169
|
+
* @param {string} root
|
|
170
|
+
* @param {{ env?: NodeJS.ProcessEnv, run?: typeof execFile }} [opts] `run` is the tests' fake
|
|
171
|
+
* @returns {Promise<{ raw: RawCommit[], cut: boolean }>}
|
|
172
|
+
*/
|
|
173
|
+
export function readLog(root, { env = process.env, run = execFile } = {}) {
|
|
174
|
+
return new Promise((resolve, reject) => {
|
|
175
|
+
run('git', gitArgs(root), { env: gitEnv(env), timeout: GIT_TIMEOUT_MS, maxBuffer: GIT_MAX_BYTES, windowsHide: true, encoding: 'utf8' }, (err, stdout) => {
|
|
176
|
+
if (err) {
|
|
177
|
+
const why = err.code === 'ENOENT' ? 'git is not installed where cornfield runs' : err.killed ? `git log took longer than ${GIT_TIMEOUT_MS / 1000}s` : 'the repo has no history git can read (is it a git checkout with a commit?)';
|
|
178
|
+
return reject(Object.assign(new Error(`The history could not be read: ${why}.`), { code: 'ENOHISTORY' }));
|
|
179
|
+
}
|
|
180
|
+
const raw = parseLog(stdout);
|
|
181
|
+
resolve({ raw, cut: raw.length >= MAX_COMMITS });
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** The commit HEAD points at, by asking git with the same guards; null when there is none */
|
|
187
|
+
export function readHead(root, { env = process.env, run = execFile } = {}) {
|
|
188
|
+
return new Promise((resolve) => {
|
|
189
|
+
run('git', ['-C', root, '-c', 'core.fsmonitor=false', 'rev-parse', '--verify', '--quiet', 'HEAD'], { env: gitEnv(env), timeout: GIT_TIMEOUT_MS, windowsHide: true, encoding: 'utf8' }, (err, stdout) => {
|
|
190
|
+
const sha = String(stdout || '').trim();
|
|
191
|
+
resolve(!err && /^[0-9a-f]{40}$/.test(sha) ? sha : null);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* The history of one repo, kept per HEAD and map: read again only when either changes. One read at a time; callers
|
|
198
|
+
* that ask while it runs share it.
|
|
199
|
+
* @param {string} root
|
|
200
|
+
* @param {{ env?: NodeJS.ProcessEnv, run?: typeof execFile }} [opts]
|
|
201
|
+
* @returns {{ get(topology: object, topologyKey: string): Promise<History & { head: string }> }}
|
|
202
|
+
*/
|
|
203
|
+
export function createHistory(root, opts = {}) {
|
|
204
|
+
let kept = null; // { key, value }
|
|
205
|
+
let pending = null; // { key, promise }
|
|
206
|
+
return {
|
|
207
|
+
async get(topology, topologyKey) {
|
|
208
|
+
const head = await readHead(root, opts);
|
|
209
|
+
if (!head) throw Object.assign(new Error('The history could not be read: the repo has no commit yet, or is not a git checkout.'), { code: 'ENOHISTORY' });
|
|
210
|
+
const key = `${head}|${topologyKey}`;
|
|
211
|
+
if (kept && kept.key === key) return kept.value;
|
|
212
|
+
if (pending && pending.key === key) return pending.promise;
|
|
213
|
+
const promise = readLog(root, opts).then(({ raw, cut }) => {
|
|
214
|
+
const value = { head, ...historyOf(raw, topology, { cut }) };
|
|
215
|
+
kept = { key, value };
|
|
216
|
+
return value;
|
|
217
|
+
}).finally(() => { if (pending && pending.key === key) pending = null; });
|
|
218
|
+
pending = { key, promise };
|
|
219
|
+
return promise;
|
|
220
|
+
},
|
|
221
|
+
};
|
|
222
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@popcorn245/cornfield",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.59.0",
|
|
4
4
|
"description": "A self-hostable dev dashboard with the topology map at its centre: proposals on the map, scenarios, outages and what-if edits, for any repo.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "popcorn245 (https://github.com/popcorn245)",
|
package/server/server.js
CHANGED
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
* that says how to build them when this checkout has none (server/components.js)
|
|
24
24
|
* GET /cornfield/brand/<key>.<ext> a brand image the config's `brand` names (logo, wordmark, favicon; svg or png, 512 KB each): those files only
|
|
25
25
|
* GET /manifest.webmanifest the web app manifest: the repo's title, or built from `brand` when the config sets one
|
|
26
|
-
* GET /api/
|
|
26
|
+
* GET /api/history the map's git history (core/history.js; spec 0014), when the config says `history: true`: a 404 otherwise
|
|
27
|
+
* GET /api/forge/… issues pull requests, their files and checks, release notes: read from the forge (server/forge-routes.js)
|
|
27
28
|
* POST /api/forge/pulls/<n>/merge|rerun land a green pull request, re-run a failed check (server/forge-actions.js)
|
|
28
29
|
* POST /api/forge/issues/<n>/spec, /pulls/<n>/build the pipeline's steps (server/pipeline.js, server/forge-actions.js)
|
|
29
30
|
* POST /api/forge/release-drafts the release notes kept as a DRAFT release on the forge (never published, no tag made)
|
|
@@ -83,6 +84,7 @@ import { createRunnerWatch, runnerPresence } from './runner-presence.js';
|
|
|
83
84
|
import { createTriggers } from './triggers.js';
|
|
84
85
|
import { brandHead, escapeHtml, themeHead, themeHtmlTag } from './page-head.js';
|
|
85
86
|
import { compressResponse } from './compress.js';
|
|
87
|
+
import { createHistory } from '../core/history.js';
|
|
86
88
|
|
|
87
89
|
export const CORNFIELD_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
88
90
|
const EXPLORER_DIR = path.join(CORNFIELD_DIR, 'explorer');
|
|
@@ -263,6 +265,8 @@ export function clientConfig(config, signIn = false) {
|
|
|
263
265
|
forge: config.forge ? { type: config.forge.type, url: config.forge.url || (config.forge.type === 'github' ? 'https://github.com' : null), repo: config.forge.repo, mergeMethod: config.forge.mergeMethod || 'merge', ...(config.forge.baseBranch ? { baseBranch: config.forge.baseBranch } : {}), ...(config.approveLands ? { approveLands: true } : {}) } : null,
|
|
264
266
|
// Threads (docs/threads.md): the idea label, or false when `threads: false` turns the Threads tab off
|
|
265
267
|
threads: config.threads === false ? false : { label: ideaLabel(config) },
|
|
268
|
+
// The map's git history is read (spec 0014): the page then offers the History layer, a node's commits and Replay
|
|
269
|
+
history: config.history === true,
|
|
266
270
|
sources: browserSources(config),
|
|
267
271
|
// Agent runs are followed (and marked on the map) where there is a forge and a sign-in (docs/agents.md)
|
|
268
272
|
...(config.forge && signIn ? { agents: { runs: true } } : {}),
|
|
@@ -320,6 +324,8 @@ export function createCornfieldServer(config, opts = {}) {
|
|
|
320
324
|
const components = createComponents({ dir: opts.componentsDir ?? path.join(CORNFIELD_DIR, 'components', 'dist') });
|
|
321
325
|
const where = { root, proposals: config.proposals, worktrees: config.worktrees, worktreeMaxAgeDays: config.worktreeMaxAgeDays, topology: config.topology, dataDir: config.dataDir, publicHost, publicOrigin, embedOrigins: embed.origins };
|
|
322
326
|
const fixtureCache = new Map();
|
|
327
|
+
// The repo's git history, read when first asked for and kept per HEAD and map (core/history.js); only with `history: true`
|
|
328
|
+
const history = config.history === true ? createHistory(root) : null;
|
|
323
329
|
// What the line above Approve says an approval does besides posting (spec 0007 D1, server/decision.js): landing, and the run a trigger asks for
|
|
324
330
|
const approvalRun = triggersOf(config).find(([event]) => event === 'spec.approved');
|
|
325
331
|
const decisionFacts = {
|
|
@@ -517,6 +523,21 @@ export function createCornfieldServer(config, opts = {}) {
|
|
|
517
523
|
if (!file) return sendJson(res, 404, { error: `${config.topology} is not there yet: run cornfield sync` });
|
|
518
524
|
return sendFile(req, res, file, reqPath);
|
|
519
525
|
}
|
|
526
|
+
if (reqPath === '/api/history') {
|
|
527
|
+
if (!history) return sendJson(res, 404, { ok: false, error: 'History is off. Set history: true in cornfield.config.js to read the repo\'s git history (docs/config.md#history).' });
|
|
528
|
+
const file = inside(root, config.topology);
|
|
529
|
+
const got = file && readPlain(file);
|
|
530
|
+
if (!got) return sendJson(res, 404, { ok: false, error: `${config.topology} is not there yet: run cornfield sync` });
|
|
531
|
+
let topology;
|
|
532
|
+
try { topology = JSON.parse(got.body.toString('utf8')); } catch { return sendJson(res, 422, { ok: false, error: `${config.topology} is not valid JSON` }); }
|
|
533
|
+
try {
|
|
534
|
+
const data = await history.get(topology, `${got.stats.mtimeMs}|${got.stats.size}`);
|
|
535
|
+
return sendJson(res, 200, { ok: true, ...data });
|
|
536
|
+
} catch (err) {
|
|
537
|
+
if (err.code !== 'ENOHISTORY') throw err;
|
|
538
|
+
return sendJson(res, 503, { ok: false, error: err.message });
|
|
539
|
+
}
|
|
540
|
+
}
|
|
520
541
|
if (reqPath === '/topology.cloud.json') {
|
|
521
542
|
const file = inside(root, CLOUD_FILE);
|
|
522
543
|
const got = file && readPlain(file);
|