@ref0/workspace 0.10.0 → 0.11.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/README.md +143 -1
- package/dist/bin.mjs +19 -7
- package/dist/lint/generic/folder-imports.mjs +84 -0
- package/dist/lint/generic/folder-layers.d.mts +40 -0
- package/dist/lint/generic/folder-layers.mjs +82 -0
- package/dist/lint/generic/imports.mjs +34 -0
- package/dist/lint/generic/package-graph.d.mts +36 -0
- package/dist/lint/generic/package-graph.mjs +111 -0
- package/dist/lint/generic/package-imports.mjs +85 -0
- package/dist/lint/generic/plugin.d.mts +4 -3
- package/dist/lint/generic/plugin.mjs +8 -3
- package/dist/lint/generic/rule-options.mjs +17 -0
- package/dist/lint/generic/workspace-packages.d.mts +29 -0
- package/dist/lint/generic/workspace-packages.mjs +78 -0
- package/dist/lint/graph.d.mts +4 -0
- package/dist/lint/graph.mjs +3 -0
- package/dist/review-record/command.mjs +107 -0
- package/dist/review-record/index.d.mts +3 -0
- package/dist/review-record/index.mjs +3 -0
- package/dist/review-record/review-record.d.mts +33 -0
- package/dist/review-record/review-record.mjs +1253 -0
- package/dist/review-record/settings.d.mts +39 -0
- package/dist/review-record/settings.mjs +100 -0
- package/dist/symbols/symbols.mjs +1 -1
- package/package.json +9 -1
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { importsVisitor } from "./imports.mjs";
|
|
2
|
+
import { decodePackageGraphOptions, edgeProblem, entryNamed, importedBy, listed, shown, testFile } from "./package-graph.mjs";
|
|
3
|
+
import { decodedOnce } from "./rule-options.mjs";
|
|
4
|
+
import { fromRoot, ownerOf, workspacePackages } from "./workspace-packages.mjs";
|
|
5
|
+
import { resolve } from "node:path";
|
|
6
|
+
import { defineRule } from "vite-plus/lint/plugins";
|
|
7
|
+
// src/lint/generic/package-imports.ts
|
|
8
|
+
const optionsOf = decodedOnce((options) => decodePackageGraphOptions(options)[0]);
|
|
9
|
+
const packageImportsRule = defineRule({
|
|
10
|
+
meta: {
|
|
11
|
+
messages: {
|
|
12
|
+
app: "Nothing imports an app, and {{to}} is one. Move what {{from}} needs into a package.",
|
|
13
|
+
edge: "{{from}} doesn't import {{to}}: the package graph has no such edge.",
|
|
14
|
+
entry: "{{from}} doesn't import {{entry}}: its edge to {{to}} in the package graph lists {{listed}}. To import another entry point, add it to that edge.",
|
|
15
|
+
tests: "{{from}} imports {{entry}} only in its tests, as the package graph says.",
|
|
16
|
+
types: "{{from}} takes only types from {{entry}}, as the package graph says. Write `import type`, which loads nothing: `import { type … }` still loads {{entry}}.",
|
|
17
|
+
relative: "This relative path leaves {{from}} for {{to}}. Import {{to}} by its name, through its exports.",
|
|
18
|
+
outside: "This relative path leaves {{from}} for a file no package or app holds.",
|
|
19
|
+
self: "{{from}} imports itself by name, which goes around its folder layers. Import the module by its relative path."
|
|
20
|
+
},
|
|
21
|
+
schema: [{
|
|
22
|
+
type: "object",
|
|
23
|
+
properties: {
|
|
24
|
+
root: { type: "string" },
|
|
25
|
+
packages: {
|
|
26
|
+
type: "array",
|
|
27
|
+
items: { type: "string" }
|
|
28
|
+
},
|
|
29
|
+
apps: {
|
|
30
|
+
type: "array",
|
|
31
|
+
items: { type: "string" }
|
|
32
|
+
},
|
|
33
|
+
graph: { type: "object" },
|
|
34
|
+
nodeFiles: { type: "object" }
|
|
35
|
+
},
|
|
36
|
+
required: [
|
|
37
|
+
"root",
|
|
38
|
+
"packages",
|
|
39
|
+
"graph"
|
|
40
|
+
],
|
|
41
|
+
additionalProperties: false
|
|
42
|
+
}]
|
|
43
|
+
},
|
|
44
|
+
create(context) {
|
|
45
|
+
const options = optionsOf(context.options);
|
|
46
|
+
const packages = workspacePackages(options);
|
|
47
|
+
const path = fromRoot(options.root, resolve(context.filename));
|
|
48
|
+
const from = ownerOf(path, packages);
|
|
49
|
+
if (from === void 0) return {};
|
|
50
|
+
const check = (node, source, typesOnly) => {
|
|
51
|
+
const { to, target } = importedBy(packages, path, source);
|
|
52
|
+
if (to === from) {
|
|
53
|
+
if (target === void 0 && !testFile.test(path)) context.report({
|
|
54
|
+
node,
|
|
55
|
+
messageId: "self",
|
|
56
|
+
data: { from: from.name }
|
|
57
|
+
});
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (to === void 0) {
|
|
61
|
+
if (target !== void 0) context.report({
|
|
62
|
+
node,
|
|
63
|
+
messageId: "outside",
|
|
64
|
+
data: { from: from.name }
|
|
65
|
+
});
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const entry = target === void 0 ? entryNamed(to, source) : void 0;
|
|
69
|
+
const messageId = edgeProblem(options, from, to, entry, path, typesOnly);
|
|
70
|
+
if (messageId === void 0) return;
|
|
71
|
+
context.report({
|
|
72
|
+
node,
|
|
73
|
+
messageId,
|
|
74
|
+
data: {
|
|
75
|
+
from: from.name,
|
|
76
|
+
to: to.name,
|
|
77
|
+
entry: entry === void 0 ? to.name : shown(to.name, entry),
|
|
78
|
+
listed: listed(options.graph[from.name]?.[to.name] ?? {})
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
return importsVisitor(check);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
export { packageImportsRule };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Rules any ref-0 repo can turn on, each over the files its config names.
|
|
3
|
-
* `entry-reexports` the repo's root, its packages and its source condition,
|
|
4
|
-
* repo's root and its comment budget's file
|
|
2
|
+
* Rules any ref-0 repo can turn on, each over the files its config names. Four take options:
|
|
3
|
+
* `entry-reexports` the repo's root, its packages and its source condition, `no-comments` the
|
|
4
|
+
* repo's root and its comment budget's file, `package-imports` where its packages are and their
|
|
5
|
+
* graph, and `folder-imports` its sources' layers.
|
|
5
6
|
*/
|
|
6
7
|
declare const _default: import("vite-plus/lint/plugins").Plugin;
|
|
7
8
|
export { _default as default };
|
|
@@ -2,16 +2,19 @@ import { effectEncodingRule } from "./effect-encoding.mjs";
|
|
|
2
2
|
import { entryReexportsRule } from "./entry-reexports.mjs";
|
|
3
3
|
import { envAtEntrypointsRule } from "./env-at-entrypoints.mjs";
|
|
4
4
|
import { exportTypeSideEffectsRule } from "./export-type-side-effects.mjs";
|
|
5
|
+
import { folderImportsRule } from "./folder-imports.mjs";
|
|
5
6
|
import { indexBarrelOnlyRule } from "./index-barrel.mjs";
|
|
6
7
|
import { logMessagesRule } from "./log-messages.mjs";
|
|
7
8
|
import { noCommentsRule } from "./no-comments.mjs";
|
|
9
|
+
import { packageImportsRule } from "./package-imports.mjs";
|
|
8
10
|
import { seededPropertiesRule } from "./seeded-properties.mjs";
|
|
9
11
|
import { definePlugin } from "vite-plus/lint/plugins";
|
|
10
12
|
// src/lint/generic/plugin.ts
|
|
11
13
|
/**
|
|
12
|
-
* Rules any ref-0 repo can turn on, each over the files its config names.
|
|
13
|
-
* `entry-reexports` the repo's root, its packages and its source condition,
|
|
14
|
-
* repo's root and its comment budget's file
|
|
14
|
+
* Rules any ref-0 repo can turn on, each over the files its config names. Four take options:
|
|
15
|
+
* `entry-reexports` the repo's root, its packages and its source condition, `no-comments` the
|
|
16
|
+
* repo's root and its comment budget's file, `package-imports` where its packages are and their
|
|
17
|
+
* graph, and `folder-imports` its sources' layers.
|
|
15
18
|
*/
|
|
16
19
|
var plugin_default = definePlugin({
|
|
17
20
|
meta: { name: "ref0-generic" },
|
|
@@ -20,9 +23,11 @@ var plugin_default = definePlugin({
|
|
|
20
23
|
"entry-reexports": entryReexportsRule,
|
|
21
24
|
"env-at-entrypoints": envAtEntrypointsRule,
|
|
22
25
|
"export-type-side-effects": exportTypeSideEffectsRule,
|
|
26
|
+
"folder-imports": folderImportsRule,
|
|
23
27
|
"index-barrel-only": indexBarrelOnlyRule,
|
|
24
28
|
"log-messages": logMessagesRule,
|
|
25
29
|
"no-comments": noCommentsRule,
|
|
30
|
+
"package-imports": packageImportsRule,
|
|
26
31
|
"seeded-properties": seededPropertiesRule
|
|
27
32
|
}
|
|
28
33
|
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// src/lint/generic/rule-options.ts
|
|
2
|
+
/**
|
|
3
|
+
* A rule's decoded options, kept for each options array. Oxlint hands every file a run lints under
|
|
4
|
+
* one config the same array, so a large option, such as a package graph, is decoded once a run
|
|
5
|
+
* rather than once a file.
|
|
6
|
+
*/
|
|
7
|
+
const decodedOnce = (decode) => {
|
|
8
|
+
const kept = /* @__PURE__ */ new WeakMap();
|
|
9
|
+
return (options) => {
|
|
10
|
+
const known = kept.get(options);
|
|
11
|
+
if (known !== void 0) return known;
|
|
12
|
+
const fresh = decode(options);
|
|
13
|
+
kept.set(options, fresh);
|
|
14
|
+
return fresh;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export { decodedOnce };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** Where a repo's packages are: its root, and the folders that hold each kind, as globs from it. */
|
|
2
|
+
export interface Workspace {
|
|
3
|
+
/** The repo's root, as an absolute path. */
|
|
4
|
+
readonly root: string;
|
|
5
|
+
/** Globs of the folders that hold libraries, which others import, such as `packages/*`. */
|
|
6
|
+
readonly packages: ReadonlyArray<string>;
|
|
7
|
+
/** Globs of the folders that hold apps, which nothing imports, such as `apps/*`. */
|
|
8
|
+
readonly apps?: ReadonlyArray<string>;
|
|
9
|
+
}
|
|
10
|
+
/** A workspace package: its name, its folder from the root, and what the checks read of it. */
|
|
11
|
+
export interface WorkspacePackage {
|
|
12
|
+
readonly name: string;
|
|
13
|
+
/** Its folder from the root, with `/` between its parts, such as `packages/ui`. */
|
|
14
|
+
readonly directory: string;
|
|
15
|
+
/** Whether it's an app, which nothing imports. */
|
|
16
|
+
readonly app: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Its entry points, as its `exports` keys them, such as `.`, `./cast` or `./vectors/*.json`. A
|
|
19
|
+
* package with no `exports`, or `exports` of a single target, has only `.`.
|
|
20
|
+
*/
|
|
21
|
+
readonly entries: ReadonlyArray<string>;
|
|
22
|
+
/** Every package it depends on, by any kind of dependency. */
|
|
23
|
+
readonly dependencies: ReadonlySet<string>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The workspace's packages and apps, by name: each folder a glob matches that holds a
|
|
27
|
+
* `package.json`. Two folders with one name throw, since an import can't tell them apart.
|
|
28
|
+
*/
|
|
29
|
+
export declare const workspacePackages: ({ root, packages, apps }: Workspace) => ReadonlyMap<string, WorkspacePackage>;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { globSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join, posix, relative, sep } from "node:path";
|
|
3
|
+
import { Schema } from "effect";
|
|
4
|
+
// src/lint/generic/workspace-packages.ts
|
|
5
|
+
const dependencyKinds = [
|
|
6
|
+
"dependencies",
|
|
7
|
+
"devDependencies",
|
|
8
|
+
"peerDependencies",
|
|
9
|
+
"optionalDependencies"
|
|
10
|
+
];
|
|
11
|
+
const Dependencies = Schema.optionalKey(Schema.Record(Schema.String, Schema.String));
|
|
12
|
+
/** A package's `exports`: one target, or targets by subpath or by condition. */
|
|
13
|
+
const Exports = Schema.Union([Schema.String, Schema.Record(Schema.String, Schema.Json)]);
|
|
14
|
+
/**
|
|
15
|
+
* What discovery reads of a workspace package's `package.json`: its name, its `exports`, whose keys
|
|
16
|
+
* are its entry points, and what it depends on.
|
|
17
|
+
*/
|
|
18
|
+
const decodeManifest = Schema.decodeUnknownSync(Schema.fromJsonString(Schema.Struct({
|
|
19
|
+
name: Schema.String,
|
|
20
|
+
exports: Schema.optionalKey(Exports),
|
|
21
|
+
dependencies: Dependencies,
|
|
22
|
+
devDependencies: Dependencies,
|
|
23
|
+
peerDependencies: Dependencies,
|
|
24
|
+
optionalDependencies: Dependencies
|
|
25
|
+
})));
|
|
26
|
+
const isString = Schema.is(Schema.String);
|
|
27
|
+
/** The entry points an `exports` field keys: its keys when each is a subpath, `.` otherwise. */
|
|
28
|
+
const entriesOf = (exports) => {
|
|
29
|
+
const keys = exports === void 0 || isString(exports) ? [] : Object.keys(exports);
|
|
30
|
+
return keys.length > 0 && keys.every((key) => key.startsWith(".")) ? keys : ["."];
|
|
31
|
+
};
|
|
32
|
+
/** A path from the root, with `/` between its parts. */
|
|
33
|
+
const fromRoot = (root, path) => relative(root, path).split(sep).join("/");
|
|
34
|
+
/** The folders from the root that hold a `package.json`, for each glob, in order. */
|
|
35
|
+
const foldersOf = (root, globs) => globs.flatMap((glob) => globSync(posix.join(glob, "package.json"), {
|
|
36
|
+
cwd: root,
|
|
37
|
+
exclude: (path) => path.split(/[\\/]/).includes("node_modules")
|
|
38
|
+
}).map((path) => posix.dirname(path.split(sep).join("/")))).toSorted();
|
|
39
|
+
/** Each workspace's packages as last read, by its options, so a lint run reads each manifest once. */
|
|
40
|
+
const read = /* @__PURE__ */ new Map();
|
|
41
|
+
/**
|
|
42
|
+
* The workspace's packages and apps, by name: each folder a glob matches that holds a
|
|
43
|
+
* `package.json`. Two folders with one name throw, since an import can't tell them apart.
|
|
44
|
+
*/
|
|
45
|
+
const workspacePackages = ({ root, packages, apps = [] }) => {
|
|
46
|
+
const key = JSON.stringify([
|
|
47
|
+
root,
|
|
48
|
+
packages,
|
|
49
|
+
apps
|
|
50
|
+
]);
|
|
51
|
+
const known = read.get(key);
|
|
52
|
+
if (known !== void 0) return known;
|
|
53
|
+
const found = /* @__PURE__ */ new Map();
|
|
54
|
+
const folders = [...foldersOf(root, packages).map((directory) => ({
|
|
55
|
+
directory,
|
|
56
|
+
app: false
|
|
57
|
+
})), ...foldersOf(root, apps).map((directory) => ({
|
|
58
|
+
directory,
|
|
59
|
+
app: true
|
|
60
|
+
}))];
|
|
61
|
+
for (const { directory, app } of folders) {
|
|
62
|
+
const manifest = decodeManifest(readFileSync(join(root, directory, "package.json"), "utf8"));
|
|
63
|
+
const twin = found.get(manifest.name);
|
|
64
|
+
if (twin !== void 0 && twin.directory !== directory) throw new Error(`${twin.directory} and ${directory} are both named ${manifest.name}.`);
|
|
65
|
+
found.set(manifest.name, {
|
|
66
|
+
name: manifest.name,
|
|
67
|
+
directory,
|
|
68
|
+
app: twin?.app === true || app,
|
|
69
|
+
entries: entriesOf(manifest.exports),
|
|
70
|
+
dependencies: new Set(dependencyKinds.flatMap((kind) => Object.keys(manifest[kind] ?? {})))
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
read.set(key, found);
|
|
74
|
+
return found;
|
|
75
|
+
};
|
|
76
|
+
/** The package that holds a path from the root: the deepest whose folder it's in. */
|
|
77
|
+
const ownerOf = (path, packages) => [...packages.values()].filter(({ directory }) => path.startsWith(`${directory}/`)).toSorted((a, b) => b.directory.length - a.directory.length)[0];
|
|
78
|
+
export { fromRoot, ownerOf, workspacePackages };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { FolderImportsOptions, FolderLayers, SourceLayers } from "./generic/folder-layers.mjs";
|
|
2
|
+
import { Edge, How, PackageGraph, PackageGraphOptions, graphProblems } from "./generic/package-graph.mjs";
|
|
3
|
+
import { Workspace, WorkspacePackage, workspacePackages } from "./generic/workspace-packages.mjs";
|
|
4
|
+
export { type Edge, type FolderImportsOptions, type FolderLayers, type How, type PackageGraph, type PackageGraphOptions, type SourceLayers, type Workspace, type WorkspacePackage, graphProblems, workspacePackages };
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { benchedCases, branchRecordOf, gh, gitIn, largeChange, pullChangesOf, recordFloor, recordOf, testChangesOf, verdict } from "./review-record.mjs";
|
|
2
|
+
import { defaults, settingsFrom, settingsPath } from "./settings.mjs";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
// src/review-record/command.ts
|
|
6
|
+
/**
|
|
7
|
+
* `ref0-workspace review-record`: whether a pull request's review is on record for its merge risk,
|
|
8
|
+
* as `review-record.ts` judges it, and what an agent asks of its branch before it posts one.
|
|
9
|
+
*
|
|
10
|
+
* ref0-workspace review-record CI: reads PR, BASE, HEAD, GITHUB_REPOSITORY and GH_TOKEN
|
|
11
|
+
* ref0-workspace review-record --count the branch's net lines of production source, and its floor
|
|
12
|
+
* ref0-workspace review-record --tier the branch's floor, and what sets it, as a Merge risk line
|
|
13
|
+
* ref0-workspace review-record --check <comment> [<body>] CI's checks on a session, before posting it
|
|
14
|
+
* ref0-workspace review-record --benched ci-bench: the cases PR's changes tie to, from this checkout's list
|
|
15
|
+
*
|
|
16
|
+
* CI runs it at the version the base's `pnpm-workspace.yaml` catalog names, in a blobless clone of
|
|
17
|
+
* the base and the head, and it reads the base's settings and lists from GitHub, so a pull request
|
|
18
|
+
* can't change the gate that judges it.
|
|
19
|
+
*/
|
|
20
|
+
const usage = [
|
|
21
|
+
"usage: ref0-workspace review-record CI: reads PR, BASE, HEAD, GITHUB_REPOSITORY",
|
|
22
|
+
" ref0-workspace review-record --count net lines of production source, and the floor",
|
|
23
|
+
" ref0-workspace review-record --tier the branch's tier floor, and what sets it",
|
|
24
|
+
" ref0-workspace review-record --check <comment> [<body>] CI's checks on a session comment and a body",
|
|
25
|
+
" ref0-workspace review-record --benched ci-bench: the cases PR's changes tie to, from this checkout's list"
|
|
26
|
+
].join("\n");
|
|
27
|
+
/** A tier floor as one line to paste into a body or a brief. */
|
|
28
|
+
const floorLine = (floor) => `Merge risk: ${floor.tier}, from ${floor.why.join("; ")}.`;
|
|
29
|
+
/** A file under `root`, or `undefined` when there's none. */
|
|
30
|
+
const fileAt = (root, path) => {
|
|
31
|
+
try {
|
|
32
|
+
return readFileSync(join(root, path), "utf8");
|
|
33
|
+
} catch {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
/** The branch's net lines of production source on stdout, and what they and its floor need on stderr. */
|
|
38
|
+
const count = (root) => {
|
|
39
|
+
const record = branchRecordOf(gitIn(root));
|
|
40
|
+
const { net, floor } = recordFloor(record);
|
|
41
|
+
const { files: tests } = testChangesOf(record.changes, record.settings ?? defaults);
|
|
42
|
+
console.log(net);
|
|
43
|
+
console.error(net >= 1e3 ? `Large: ${largeChange} or more net lines of production source, so a session needs a code quality reviewer.` : `Not large: under ${largeChange} net lines of production source.`);
|
|
44
|
+
console.error(`${floorLine(floor)} Name it or higher on the body's "Merge risk:" line.`);
|
|
45
|
+
if (tests.length > 0) console.error(`Tests: ${tests.length} files of test code changed, so the body names each on a "Break:" line at low or with a medium session that has no tests reviewer, and a high session needs a tests reviewer.`);
|
|
46
|
+
return 0;
|
|
47
|
+
};
|
|
48
|
+
/** A session comment and a body, from their files, judged as CI would judge them on this branch. */
|
|
49
|
+
const check = (root, files) => {
|
|
50
|
+
const [comment = "", body = comment] = files.map((file) => readFileSync(file, "utf8"));
|
|
51
|
+
const result = verdict(branchRecordOf(gitIn(root), [comment], body));
|
|
52
|
+
if (result.ok) {
|
|
53
|
+
console.log(result.why);
|
|
54
|
+
return 0;
|
|
55
|
+
}
|
|
56
|
+
for (const error of result.errors) console.log(error);
|
|
57
|
+
return 1;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* ci-bench's plan: the cases pull request `PR` of `GITHUB_REPOSITORY` changes the benched paths of,
|
|
61
|
+
* one a line, read from this checkout's settings and bench list, main's in ci-bench.
|
|
62
|
+
*/
|
|
63
|
+
const benched = (root, env) => {
|
|
64
|
+
const { PR: pull, GITHUB_REPOSITORY: repo } = env;
|
|
65
|
+
if (!pull || !repo) {
|
|
66
|
+
console.error(usage);
|
|
67
|
+
return 2;
|
|
68
|
+
}
|
|
69
|
+
const settings = settingsFrom(fileAt(root, settingsPath));
|
|
70
|
+
if (settings.benchedPaths === void 0) {
|
|
71
|
+
console.error(`${settingsPath} names no benchedPaths, so no case is benched`);
|
|
72
|
+
return 2;
|
|
73
|
+
}
|
|
74
|
+
const list = readFileSync(join(root, settings.benchedPaths), "utf8");
|
|
75
|
+
console.log(benchedCases(list, pullChangesOf(gh, repo, pull), settings).cases.join("\n"));
|
|
76
|
+
return 0;
|
|
77
|
+
};
|
|
78
|
+
/** CI's run: pull request `PR`'s review on record, each reason it isn't as an Actions error. */
|
|
79
|
+
const ci = (root, env) => {
|
|
80
|
+
const { PR: pull, BASE: base, HEAD: head, GITHUB_REPOSITORY: repo } = env;
|
|
81
|
+
if (!pull || !base || !head || !repo) {
|
|
82
|
+
console.error(usage);
|
|
83
|
+
return 2;
|
|
84
|
+
}
|
|
85
|
+
const result = verdict(recordOf(gh, gitIn(root, env), repo, pull, base, head));
|
|
86
|
+
if (result.ok) {
|
|
87
|
+
console.log(result.why);
|
|
88
|
+
return 0;
|
|
89
|
+
}
|
|
90
|
+
for (const error of result.errors) console.log(`::error::${error}`);
|
|
91
|
+
return 1;
|
|
92
|
+
};
|
|
93
|
+
/** Runs the subcommand `args` names in the checkout at `root`, and answers its exit code. */
|
|
94
|
+
const reviewRecord = (args, root, env) => {
|
|
95
|
+
const [flag, ...rest] = args;
|
|
96
|
+
if (flag === void 0) return ci(root, env);
|
|
97
|
+
if (flag === "--tier" && rest.length === 0) {
|
|
98
|
+
console.log(floorLine(recordFloor(branchRecordOf(gitIn(root))).floor));
|
|
99
|
+
return 0;
|
|
100
|
+
}
|
|
101
|
+
if (flag === "--count" && rest.length === 0) return count(root);
|
|
102
|
+
if (flag === "--check" && (rest.length === 1 || rest.length === 2)) return check(root, rest);
|
|
103
|
+
if (flag === "--benched" && rest.length === 0) return benched(root, env);
|
|
104
|
+
console.error(usage);
|
|
105
|
+
return 2;
|
|
106
|
+
};
|
|
107
|
+
export { reviewRecord, usage };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Settings } from "./settings.mjs";
|
|
2
|
+
/** A changed file, as GitHub's `pulls/<n>/files` lists it, in the fields read here. */
|
|
3
|
+
export interface Change {
|
|
4
|
+
readonly filename: string;
|
|
5
|
+
readonly additions: number;
|
|
6
|
+
readonly deletions: number;
|
|
7
|
+
readonly previous_filename?: string;
|
|
8
|
+
/** GitHub's: `added`, `removed`, `modified`, `renamed` and the like. */
|
|
9
|
+
readonly status?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Its hunks, kept for test code alone, from the first `@@` line: GitHub leaves it out of a file
|
|
12
|
+
* too big to show, and `testRisks` then reads the file as a risk.
|
|
13
|
+
*/
|
|
14
|
+
readonly patch?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Whether `path`, from the repo's root, is a test's alone: `.test.` in its name, under a `testing/`
|
|
18
|
+
* folder, or a package's `testing.ts` entry, which only the workspace's tests import, and none of
|
|
19
|
+
* the settings' `benchRuns`, the test helpers a bench case runs all the same. No bench case runs
|
|
20
|
+
* one, so no pull request owes a case's reading for it, `benchedCases`.
|
|
21
|
+
*/
|
|
22
|
+
export declare const testsOnly: (path: string, settings: Settings) => boolean;
|
|
23
|
+
/**
|
|
24
|
+
* The bench cases the settings' `benchedPaths` list ties a pull request's changes to, in the list's
|
|
25
|
+
* order, and the changed files that tie them: each case with a line whose glob matches a changed
|
|
26
|
+
* file, or the path a file was renamed from, and every case the list names when a `*` line
|
|
27
|
+
* matches. A test's path alone, `testsOnly`, ties none, since no case runs it. A line that isn't
|
|
28
|
+
* `<case> <glob>` throws.
|
|
29
|
+
*/
|
|
30
|
+
export declare const benchedCases: (list: string, changes: ReadonlyArray<Change>, settings: Settings) => {
|
|
31
|
+
cases: string[];
|
|
32
|
+
files: string[];
|
|
33
|
+
};
|