repopo 0.13.0 → 0.14.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/CHANGELOG.md +17 -0
- package/README.md +13 -6
- package/esm/api.d.ts +2 -0
- package/esm/api.d.ts.map +1 -1
- package/esm/api.js +1 -0
- package/esm/api.js.map +1 -1
- package/esm/commands/check-native.d.ts +2 -0
- package/esm/commands/check-native.d.ts.map +1 -1
- package/esm/commands/check-native.js +9 -0
- package/esm/commands/check-native.js.map +1 -1
- package/esm/commands/check.d.ts +2 -0
- package/esm/commands/check.d.ts.map +1 -1
- package/esm/commands/check.js +26 -2
- package/esm/commands/check.js.map +1 -1
- package/esm/commands/list.d.ts.map +1 -1
- package/esm/commands/list.js +1 -1
- package/esm/commands/list.js.map +1 -1
- package/esm/config.d.ts +5 -0
- package/esm/config.d.ts.map +1 -1
- package/esm/config.js.map +1 -1
- package/esm/context.d.ts +2 -0
- package/esm/context.d.ts.map +1 -1
- package/esm/context.js +11 -0
- package/esm/context.js.map +1 -1
- package/esm/makePolicy.d.ts.map +1 -1
- package/esm/makePolicy.js +3 -1
- package/esm/makePolicy.js.map +1 -1
- package/esm/policies/MaxChangedFiles.d.ts +17 -0
- package/esm/policies/MaxChangedFiles.d.ts.map +1 -0
- package/esm/policies/MaxChangedFiles.js +22 -0
- package/esm/policies/MaxChangedFiles.js.map +1 -0
- package/esm/policies/RequireCompanionChanges.d.ts +16 -0
- package/esm/policies/RequireCompanionChanges.d.ts.map +1 -0
- package/esm/policies/RequireCompanionChanges.js +42 -0
- package/esm/policies/RequireCompanionChanges.js.map +1 -0
- package/esm/policies.d.ts +2 -0
- package/esm/policies.d.ts.map +1 -1
- package/esm/policies.js +2 -0
- package/esm/policies.js.map +1 -1
- package/esm/policy.d.ts +9 -3
- package/esm/policy.d.ts.map +1 -1
- package/esm/policy.js.map +1 -1
- package/esm/policyExecution.d.ts +4 -3
- package/esm/policyExecution.d.ts.map +1 -1
- package/esm/policyExecution.js +13 -3
- package/esm/policyExecution.js.map +1 -1
- package/esm/repositoryChanges.d.ts +26 -0
- package/esm/repositoryChanges.d.ts.map +1 -0
- package/esm/repositoryChanges.js +172 -0
- package/esm/repositoryChanges.js.map +1 -0
- package/esm/repositoryFiles.d.ts +2 -0
- package/esm/repositoryFiles.d.ts.map +1 -1
- package/esm/repositoryFiles.js +6 -3
- package/esm/repositoryFiles.js.map +1 -1
- package/esm/runner.d.ts +5 -4
- package/esm/runner.d.ts.map +1 -1
- package/esm/runner.js +26 -27
- package/esm/runner.js.map +1 -1
- package/oclif.manifest.json +39 -1
- package/package.json +1 -1
- package/sidecar/sidecar.mjs +48 -8
package/sidecar/sidecar.mjs
CHANGED
|
@@ -6,17 +6,27 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { Console } from "node:console";
|
|
8
8
|
import { stat } from "node:fs/promises";
|
|
9
|
+
import { env } from "node:process";
|
|
9
10
|
import { createInterface } from "node:readline";
|
|
10
11
|
import { types } from "node:util";
|
|
11
12
|
import { TypeScriptLoader } from "@tylerbu/lilconfig-loader-ts";
|
|
12
13
|
import { all, run } from "effection";
|
|
13
14
|
import { lilconfig } from "lilconfig";
|
|
14
15
|
import { DefaultPolicyConfig } from "../esm/config.js";
|
|
15
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
createExcludedPolicyFileMap,
|
|
18
|
+
exclusionRegex,
|
|
19
|
+
matchesPath,
|
|
20
|
+
} from "../esm/context.js";
|
|
16
21
|
import { ParsedFileCache } from "../esm/fileCache.js";
|
|
17
22
|
import { identifyPolicyInstances, makePolicy } from "../esm/makePolicy.js";
|
|
18
23
|
import { newPerfStats } from "../esm/perf.js";
|
|
19
24
|
import { executionMessage, PolicyExecutor } from "../esm/policyExecution.js";
|
|
25
|
+
import {
|
|
26
|
+
annotateInventory,
|
|
27
|
+
collectRepositoryInventory,
|
|
28
|
+
validateChangeOptions,
|
|
29
|
+
} from "../esm/repositoryChanges.js";
|
|
20
30
|
|
|
21
31
|
// Policy logging must not corrupt the JSON response stream.
|
|
22
32
|
globalThis.console = new Console(process.stderr);
|
|
@@ -219,6 +229,7 @@ async function loadConfig(params) {
|
|
|
219
229
|
policies,
|
|
220
230
|
root: params.gitRoot ?? process.cwd(),
|
|
221
231
|
exclude: config.excludeFiles ?? [],
|
|
232
|
+
changes: config.changes,
|
|
222
233
|
};
|
|
223
234
|
options.exclude.forEach(exclusionRegex);
|
|
224
235
|
createExcludedPolicyFileMap(policies);
|
|
@@ -228,9 +239,7 @@ async function loadConfig(params) {
|
|
|
228
239
|
instanceId: policy.instanceId,
|
|
229
240
|
description: policy.description,
|
|
230
241
|
scope: policy.scope ?? "file",
|
|
231
|
-
...(policy.
|
|
232
|
-
? {}
|
|
233
|
-
: { match: serializeRegex(policy.match) }),
|
|
242
|
+
...(policy.match ? { match: serializeRegex(policy.match) } : {}),
|
|
234
243
|
hasResolver: typeof policy.resolver === "function",
|
|
235
244
|
exclude: (policy.exclude ?? []).map(serializeExclusion),
|
|
236
245
|
})),
|
|
@@ -240,11 +249,31 @@ async function loadConfig(params) {
|
|
|
240
249
|
return metadata;
|
|
241
250
|
}
|
|
242
251
|
|
|
243
|
-
function beginRun(params) {
|
|
252
|
+
async function beginRun(params) {
|
|
244
253
|
if (!registration)
|
|
245
254
|
throw new Error("Load configuration before running policies.");
|
|
246
255
|
session?.cache?.clear();
|
|
256
|
+
session = undefined;
|
|
257
|
+
const mode = params.changeMode ?? registration.changes?.mode;
|
|
258
|
+
const options = {
|
|
259
|
+
mode,
|
|
260
|
+
base:
|
|
261
|
+
params.changeBase ??
|
|
262
|
+
((mode ?? "pr") === "pr"
|
|
263
|
+
? env.GITHUB_BASE_REF ||
|
|
264
|
+
env.CI_MERGE_REQUEST_TARGET_BRANCH_NAME ||
|
|
265
|
+
registration.changes?.base
|
|
266
|
+
: undefined),
|
|
267
|
+
};
|
|
268
|
+
validateChangeOptions(options);
|
|
269
|
+
const inventory =
|
|
270
|
+
registration.policies.some((policy) => policy.scope === "changes") ||
|
|
271
|
+
params.changeMode != null ||
|
|
272
|
+
params.changeBase != null
|
|
273
|
+
? await collectRepositoryInventory(registration.root, options)
|
|
274
|
+
: [];
|
|
247
275
|
session = {
|
|
276
|
+
inventory,
|
|
248
277
|
executor: new PolicyExecutor(registration.root, params.fix ?? false),
|
|
249
278
|
cache: params.fix ? undefined : new ParsedFileCache(),
|
|
250
279
|
};
|
|
@@ -272,10 +301,21 @@ async function executeUnits(params) {
|
|
|
272
301
|
skipped: [],
|
|
273
302
|
perfStats: newPerfStats(),
|
|
274
303
|
};
|
|
275
|
-
if (policy.scope === "repository") {
|
|
304
|
+
if (policy.scope === "repository" || policy.scope === "changes") {
|
|
276
305
|
if (!Array.isArray(unit.files))
|
|
277
306
|
throw new Error("Repository units require explicit inventory.");
|
|
278
|
-
|
|
307
|
+
const exclusions = [
|
|
308
|
+
...registration.exclude,
|
|
309
|
+
...(policy.exclude ?? []),
|
|
310
|
+
].map(exclusionRegex);
|
|
311
|
+
const entries = annotateInventory(
|
|
312
|
+
unit.files,
|
|
313
|
+
session.inventory,
|
|
314
|
+
).filter(
|
|
315
|
+
(entry) =>
|
|
316
|
+
!exclusions.some((regex) => matchesPath(regex, entry.path)),
|
|
317
|
+
);
|
|
318
|
+
yield* session.executor.repository(policy, entries, result);
|
|
279
319
|
} else {
|
|
280
320
|
if (typeof unit.file !== "string")
|
|
281
321
|
throw new Error("File units require a file.");
|
|
@@ -358,7 +398,7 @@ async function main() {
|
|
|
358
398
|
data = await loadConfig(params);
|
|
359
399
|
break;
|
|
360
400
|
case "begin_run":
|
|
361
|
-
data = beginRun(params);
|
|
401
|
+
data = await beginRun(params);
|
|
362
402
|
break;
|
|
363
403
|
case "execute_units":
|
|
364
404
|
try {
|