@rmartz/pr-policy 1.1.0 → 1.3.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 +10 -10
- package/dist/bin/pr-policy.js +1 -1
- package/dist/{chunk-YCBII74A.js → chunk-FYYCFBD7.js} +220 -49
- package/dist/index.d.ts +12 -2
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,16 +12,16 @@ new required-status name.
|
|
|
12
12
|
|
|
13
13
|
## Checks
|
|
14
14
|
|
|
15
|
-
| Check | Blocks when
|
|
16
|
-
| --------------------------------------------------------------------- |
|
|
17
|
-
| **Blocking labels** ([docs](docs/checks/merge-block.md)) | The PR carries `do not merge`, `dnm`, `blocked`, or `escalation needed` (shows as pending).
|
|
18
|
-
| **CI-change classification** ([docs](docs/checks/ci-change.md)) | A `.github/workflows/**` change loosens CI (a removed job, `continue-on-error`, a narrowed trigger, …) and no human has applied `CI change approved` (shows as pending). Owns `CI approval needed`.
|
|
19
|
-
| **Base branch** ([docs](docs/checks/base-branch.md)) | The PR targets a branch other than the default and it isn't a non-epic PR on an open epic's branch. A stacked PR waits for its base PR (shows as pending); a base no open PR heads blocks.
|
|
20
|
-
| **Title-type rules** ([docs](docs/checks/title.md)) | The squash title isn't a valid Conventional Commit, puts `!` on a non-functional type, disagrees with the `breaking change` label,
|
|
21
|
-
| **UAT sign-off** ([docs](docs/checks/uat.md)) | The PR isn't docs, tests, CI, dependency-only, or repo metadata, and no trusted user has applied `UAT passed` (or `tested`)
|
|
22
|
-
| **Dependabot claim verification** ([docs](docs/checks/dependabot.md)) | A Dependabot PR touches a non-dependency path, changes a dependency its description doesn't claim, pins a version other than the claimed one, or edits anything Dependabot never edits (a `package.json` script, a workflow step).
|
|
23
|
-
| Domain labels (backlog) | Never blocks. Additive path-glob → domain-label map.
|
|
24
|
-
| Milestone inheritance (backlog) | Never blocks. Issue → PR milestone.
|
|
15
|
+
| Check | Blocks when |
|
|
16
|
+
| --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
17
|
+
| **Blocking labels** ([docs](docs/checks/merge-block.md)) | The PR carries `do not merge`, `dnm`, `blocked`, or `escalation needed` (shows as pending). |
|
|
18
|
+
| **CI-change classification** ([docs](docs/checks/ci-change.md)) | A `.github/workflows/**` change loosens CI (a removed job, `continue-on-error`, a narrowed trigger, …) and no human has applied `CI change approved` (shows as pending). Owns `CI approval needed`. |
|
|
19
|
+
| **Base branch** ([docs](docs/checks/base-branch.md)) | The PR targets a branch other than the default and it isn't a non-epic PR on an open epic's branch. A stacked PR waits for its base PR (shows as pending); a base no open PR heads blocks. |
|
|
20
|
+
| **Title-type rules** ([docs](docs/checks/title.md)) | The squash title isn't a valid Conventional Commit, puts `!` on a non-functional type, disagrees with the `breaking change` label, types a linter/formatter bump as a non-release, non-`ci` type, or changes paths its type rules out (`docs`, `test`, `refactor`, `ci`). |
|
|
21
|
+
| **UAT sign-off** ([docs](docs/checks/uat.md)) | The PR isn't docs, tests, CI, dependency-only, or repo metadata, and no trusted user has applied `no UAT needed`, or `UAT passed` (or `tested`) since the last push (shows as pending). |
|
|
22
|
+
| **Dependabot claim verification** ([docs](docs/checks/dependabot.md)) | A Dependabot PR touches a non-dependency path, changes a dependency its description doesn't claim, pins a version other than the claimed one, or edits anything Dependabot never edits (a `package.json` script, a workflow step). |
|
|
23
|
+
| Domain labels (backlog) | Never blocks. Additive path-glob → domain-label map. |
|
|
24
|
+
| Milestone inheritance (backlog) | Never blocks. Issue → PR milestone. |
|
|
25
25
|
|
|
26
26
|
The design, and why this is separate from `merge-safety` and `pr-lifecycle`, is
|
|
27
27
|
in [docs/decisions.md](docs/decisions.md).
|
package/dist/bin/pr-policy.js
CHANGED
|
@@ -904,8 +904,7 @@ function isTestPath(path) {
|
|
|
904
904
|
return parts.slice(0, -1).some((dir) => TEST_DIRS.has(dir)) || TEST_FILE.test(name);
|
|
905
905
|
}
|
|
906
906
|
|
|
907
|
-
// src/checks/
|
|
908
|
-
var TRIVIAL_CATEGORIES = ["docs", "tests", "ci", "dependencies", "metadata"];
|
|
907
|
+
// src/checks/path-kinds.ts
|
|
909
908
|
var LOCKFILES = /* @__PURE__ */ new Set([
|
|
910
909
|
"pnpm-lock.yaml",
|
|
911
910
|
"package-lock.json",
|
|
@@ -918,53 +917,115 @@ var LOCKFILES = /* @__PURE__ */ new Set([
|
|
|
918
917
|
"go.sum"
|
|
919
918
|
]);
|
|
920
919
|
var ROOT_METADATA = /^(LICEN[CS]E|COPYING)(\..+)?$|^CODEOWNERS$|^\.(gitignore|gitattributes|editorconfig)$/;
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
920
|
+
var TOOLING_CONFIG = new RegExp(
|
|
921
|
+
[
|
|
922
|
+
String.raw`^eslint\.config\.[cm]?[jt]s$`,
|
|
923
|
+
String.raw`^\.eslintrc(\..+)?$`,
|
|
924
|
+
String.raw`^\.eslintignore$`,
|
|
925
|
+
String.raw`^prettier\.config\.[cm]?[jt]s$`,
|
|
926
|
+
String.raw`^\.prettierrc(\..+)?$`,
|
|
927
|
+
String.raw`^\.prettierignore$`,
|
|
928
|
+
String.raw`^(vitest|jest|playwright|cypress)\.config\.[cm]?[jt]s$`,
|
|
929
|
+
String.raw`^vitest\.workspace\.[cm]?[jt]s$`,
|
|
930
|
+
String.raw`^\.?ruff\.toml$`,
|
|
931
|
+
String.raw`^\.flake8$`,
|
|
932
|
+
String.raw`^\.?pylintrc$`,
|
|
933
|
+
String.raw`^\.?mypy\.ini$`,
|
|
934
|
+
String.raw`^pytest\.ini$`,
|
|
935
|
+
String.raw`^\.coveragerc$`,
|
|
936
|
+
String.raw`^\.markdownlint(-cli2)?(\..+)?$`,
|
|
937
|
+
String.raw`^\.yamllint(\..+)?$`,
|
|
938
|
+
String.raw`^\.pre-commit-config\.ya?ml$`,
|
|
939
|
+
String.raw`^\.repo-hygiene\.ya?ml$`,
|
|
940
|
+
String.raw`^\.releaserc(\..+)?$`,
|
|
941
|
+
String.raw`^release\.config\.[cm]?[jt]s$`,
|
|
942
|
+
String.raw`^commitlint\.config\.[cm]?[jt]s$`,
|
|
943
|
+
String.raw`^\.commitlintrc(\..+)?$`,
|
|
944
|
+
String.raw`^\.lintstagedrc(\..+)?$`,
|
|
945
|
+
String.raw`^lint-staged\.config\.[cm]?[jt]s$`,
|
|
946
|
+
String.raw`^\.?codecov\.ya?ml$`
|
|
947
|
+
].join("|")
|
|
948
|
+
);
|
|
949
|
+
var DEV_REQUIREMENTS_FILE = /^requirements[-_.](dev|test|tests|lint|ci)([-_.][\w.-]*)?\.txt$/;
|
|
950
|
+
function basename2(path) {
|
|
951
|
+
return path.slice(path.lastIndexOf("/") + 1);
|
|
952
|
+
}
|
|
953
|
+
function isLockfile(path) {
|
|
954
|
+
return LOCKFILES.has(basename2(path));
|
|
955
|
+
}
|
|
956
|
+
function changedDependencies(change) {
|
|
957
|
+
if (change.baseText === void 0 || change.headText === void 0) return void 0;
|
|
958
|
+
const before = manifestVersions(change.path, change.baseText);
|
|
959
|
+
const after = manifestVersions(change.path, change.headText);
|
|
960
|
+
if (before === null || after === null) return void 0;
|
|
961
|
+
const names = /* @__PURE__ */ new Set([...before.keys(), ...after.keys()]);
|
|
962
|
+
return [...names].filter((name) => before.get(name) !== after.get(name));
|
|
963
|
+
}
|
|
964
|
+
function parseRecord(text) {
|
|
965
|
+
try {
|
|
966
|
+
return asRecord(JSON.parse(text));
|
|
967
|
+
} catch {
|
|
968
|
+
return void 0;
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
function packageJsonScope(change) {
|
|
972
|
+
if (change.baseText === void 0 || change.headText === void 0) return void 0;
|
|
973
|
+
const before = parseRecord(change.baseText);
|
|
974
|
+
const after = parseRecord(change.headText);
|
|
975
|
+
if (before === void 0 || after === void 0) return void 0;
|
|
976
|
+
const without = (record, fields) => {
|
|
932
977
|
const rest = { ...record };
|
|
933
|
-
for (const field of
|
|
978
|
+
for (const field of fields) delete rest[field];
|
|
934
979
|
return rest;
|
|
935
980
|
};
|
|
936
|
-
const
|
|
937
|
-
|
|
938
|
-
|
|
981
|
+
const versionFields = [...DEPENDENCY_FIELDS, "packageManager"];
|
|
982
|
+
if (!deepEqual(without(before, versionFields), without(after, versionFields))) return void 0;
|
|
983
|
+
const runtimeFields = DEPENDENCY_FIELDS.filter((field) => field !== "devDependencies");
|
|
984
|
+
const sensitive = new Set(CI_SENSITIVE_PACKAGES);
|
|
985
|
+
for (const field of runtimeFields) {
|
|
986
|
+
const was = asRecord(before[field]) ?? {};
|
|
987
|
+
const now = asRecord(after[field]) ?? {};
|
|
988
|
+
const names = /* @__PURE__ */ new Set([...Object.keys(was), ...Object.keys(now)]);
|
|
989
|
+
for (const name of names) {
|
|
990
|
+
if (!deepEqual(was[name], now[name]) && !sensitive.has(name)) return "runtime";
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
return "tooling";
|
|
939
994
|
}
|
|
940
|
-
function
|
|
995
|
+
function requirementsScope(change) {
|
|
996
|
+
if (change === void 0) return "runtime";
|
|
997
|
+
if (DEV_REQUIREMENTS_FILE.test(basename2(change.path))) return "tooling";
|
|
998
|
+
const changed = changedDependencies(change);
|
|
999
|
+
const sensitive = new Set(CI_SENSITIVE_PACKAGES);
|
|
1000
|
+
return changed !== void 0 && changed.every((name) => sensitive.has(name)) ? "tooling" : "runtime";
|
|
1001
|
+
}
|
|
1002
|
+
function manifestKind(path, context) {
|
|
1003
|
+
const change = context.manifestChanges.find((file) => file.path === path);
|
|
1004
|
+
if (basename2(path) !== "package.json") {
|
|
1005
|
+
return requirementsScope(change) === "tooling" ? "tooling-manifest" : "runtime-manifest";
|
|
1006
|
+
}
|
|
1007
|
+
if (change === void 0) return void 0;
|
|
1008
|
+
const scope = packageJsonScope(change);
|
|
1009
|
+
if (scope === void 0) return void 0;
|
|
1010
|
+
return scope === "tooling" ? "tooling-manifest" : "runtime-manifest";
|
|
1011
|
+
}
|
|
1012
|
+
function pathKind(path, context) {
|
|
941
1013
|
const parts = path.split("/");
|
|
942
|
-
const name = parts
|
|
1014
|
+
const name = parts.at(-1) ?? "";
|
|
943
1015
|
if (name.endsWith(".md") || parts[0] === "docs") return "docs";
|
|
944
1016
|
if (isTestPath(path)) return "tests";
|
|
945
1017
|
if (path.startsWith(".github/workflows/") || path.startsWith(".github/actions/")) {
|
|
946
|
-
const change =
|
|
1018
|
+
const change = context.workflowChanges.find((file) => file.path === path);
|
|
947
1019
|
return change !== void 0 && isShippedReusableWorkflow(change) ? void 0 : "ci";
|
|
948
1020
|
}
|
|
949
|
-
if (LOCKFILES.has(name)) return "
|
|
950
|
-
if (isManifestPath(path))
|
|
951
|
-
if (name !== "package.json") return "dependencies";
|
|
952
|
-
const change = pr.manifestChanges.find((file) => file.path === path);
|
|
953
|
-
return isDependencyOnlyManifest(change) ? "dependencies" : void 0;
|
|
954
|
-
}
|
|
1021
|
+
if (LOCKFILES.has(name)) return "lockfile";
|
|
1022
|
+
if (isManifestPath(path)) return manifestKind(path, context);
|
|
955
1023
|
if (parts[0] === ".github" || parts[0] === ".vscode") return "metadata";
|
|
956
1024
|
if (parts.length === 1 && ROOT_METADATA.test(name)) return "metadata";
|
|
1025
|
+
if (TOOLING_CONFIG.test(name)) return "tooling-config";
|
|
1026
|
+
if (parts[0] === "scripts" && parts.length > 1) return "repo-script";
|
|
957
1027
|
return void 0;
|
|
958
1028
|
}
|
|
959
|
-
function trivialCategories(pr) {
|
|
960
|
-
const found = /* @__PURE__ */ new Set();
|
|
961
|
-
for (const path of pr.changedFiles) {
|
|
962
|
-
const category = categoryOf(path, pr);
|
|
963
|
-
if (category === void 0) return void 0;
|
|
964
|
-
found.add(category);
|
|
965
|
-
}
|
|
966
|
-
return TRIVIAL_CATEGORIES.filter((category) => found.has(category));
|
|
967
|
-
}
|
|
968
1029
|
|
|
969
1030
|
// src/checks/dependabot/paths.ts
|
|
970
1031
|
var OTHER_ECOSYSTEM_FILES = /* @__PURE__ */ new Set([
|
|
@@ -986,8 +1047,8 @@ var DOCKERFILE = /^(Dockerfile|Containerfile)([.-].+)?$|\.Dockerfile$|^docker-co
|
|
|
986
1047
|
function dependencyPathKind(path) {
|
|
987
1048
|
if (isWorkflowPath(path)) return "workflow";
|
|
988
1049
|
if (isManifestPath(path)) return "manifest";
|
|
1050
|
+
if (isLockfile(path)) return "lockfile";
|
|
989
1051
|
const name = path.slice(path.lastIndexOf("/") + 1);
|
|
990
|
-
if (LOCKFILES.has(name)) return "lockfile";
|
|
991
1052
|
if (OTHER_ECOSYSTEM_FILES.has(name) || DOCKERFILE.test(name)) return "other-ecosystem";
|
|
992
1053
|
return void 0;
|
|
993
1054
|
}
|
|
@@ -1190,13 +1251,23 @@ function majorBumps(changes) {
|
|
|
1190
1251
|
function isMarkdownPath(path) {
|
|
1191
1252
|
return path.toLowerCase().endsWith(".md");
|
|
1192
1253
|
}
|
|
1254
|
+
var CI_KINDS = /* @__PURE__ */ new Set([
|
|
1255
|
+
"docs",
|
|
1256
|
+
"tests",
|
|
1257
|
+
"ci",
|
|
1258
|
+
"tooling-config",
|
|
1259
|
+
"repo-script",
|
|
1260
|
+
"lockfile",
|
|
1261
|
+
"tooling-manifest",
|
|
1262
|
+
"metadata"
|
|
1263
|
+
]);
|
|
1193
1264
|
var quote = (paths) => {
|
|
1194
1265
|
const shown = paths.slice(0, 5).map((path) => `\`${path}\``);
|
|
1195
1266
|
if (paths.length > 5) shown.push(`and ${paths.length - 5} more`);
|
|
1196
1267
|
return shown.join(", ");
|
|
1197
1268
|
};
|
|
1198
|
-
function typePathViolation(type,
|
|
1199
|
-
const paths = [...new Set(changedFiles)];
|
|
1269
|
+
function typePathViolation(type, facts) {
|
|
1270
|
+
const paths = [...new Set(facts.changedFiles)];
|
|
1200
1271
|
if (type === "docs") {
|
|
1201
1272
|
const offending = paths.filter((path) => !isMarkdownPath(path));
|
|
1202
1273
|
if (offending.length === 0) return void 0;
|
|
@@ -1212,6 +1283,14 @@ function typePathViolation(type, changedFiles) {
|
|
|
1212
1283
|
if (offending.length === 0) return void 0;
|
|
1213
1284
|
return `A \`test\` PR may change only test files and docs, so it locks in current behaviour without changing it, but this one changes ${quote(offending)}. \`test\` doesn't release, so that change would never ship. Retitle to the type of the non-test change, or split it into its own PR.`;
|
|
1214
1285
|
}
|
|
1286
|
+
if (type === "ci") {
|
|
1287
|
+
const offending = paths.filter((path) => {
|
|
1288
|
+
const kind = pathKind(path, facts);
|
|
1289
|
+
return kind === void 0 || !CI_KINDS.has(kind);
|
|
1290
|
+
});
|
|
1291
|
+
if (offending.length === 0) return void 0;
|
|
1292
|
+
return `A \`ci\` PR may change only CI and tooling (\`.github/\`, linter, formatter, and test-runner config, \`scripts/\`, lockfiles, dev-tool versions, tests, and docs), but this one changes ${quote(offending)}. A \`package.json\` counts only when nothing but dev-dependency or lint/format tool versions changed. \`ci\` doesn't release and needs no UAT, so that change would ship untested in someone else's release. Retitle to the type of that change, or split it into its own PR.`;
|
|
1293
|
+
}
|
|
1215
1294
|
return void 0;
|
|
1216
1295
|
}
|
|
1217
1296
|
|
|
@@ -1318,7 +1397,7 @@ function titleRules(pr, text) {
|
|
|
1318
1397
|
);
|
|
1319
1398
|
}
|
|
1320
1399
|
}
|
|
1321
|
-
const pathViolation = typePathViolation(title.type, pr
|
|
1400
|
+
const pathViolation = typePathViolation(title.type, pr);
|
|
1322
1401
|
if (pathViolation !== void 0) findings.push(block2(pathViolation));
|
|
1323
1402
|
const mayRetitle = !functional && title.type !== "ci";
|
|
1324
1403
|
const workflows = substantiveWorkflowChanges(pr.workflowChanges);
|
|
@@ -1383,12 +1462,52 @@ var baseBranchCheck = {
|
|
|
1383
1462
|
evaluate: async (pr) => decideBaseBranch(pr)
|
|
1384
1463
|
};
|
|
1385
1464
|
|
|
1465
|
+
// src/checks/uat/trivial.ts
|
|
1466
|
+
var TRIVIAL_CATEGORIES = ["docs", "tests", "ci", "dependencies", "metadata"];
|
|
1467
|
+
function categoryOf(kind) {
|
|
1468
|
+
switch (kind) {
|
|
1469
|
+
case "docs":
|
|
1470
|
+
case "tests":
|
|
1471
|
+
case "ci":
|
|
1472
|
+
case "metadata":
|
|
1473
|
+
return kind;
|
|
1474
|
+
case "lockfile":
|
|
1475
|
+
case "tooling-manifest":
|
|
1476
|
+
case "runtime-manifest":
|
|
1477
|
+
return "dependencies";
|
|
1478
|
+
case "tooling-config":
|
|
1479
|
+
case "repo-script":
|
|
1480
|
+
case void 0:
|
|
1481
|
+
return void 0;
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
function trivialCategories(pr) {
|
|
1485
|
+
const found = /* @__PURE__ */ new Set();
|
|
1486
|
+
for (const path of pr.changedFiles) {
|
|
1487
|
+
const category = categoryOf(pathKind(path, pr));
|
|
1488
|
+
if (category === void 0) return void 0;
|
|
1489
|
+
found.add(category);
|
|
1490
|
+
}
|
|
1491
|
+
return TRIVIAL_CATEGORIES.filter((category) => found.has(category));
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1386
1494
|
// src/checks/uat/index.ts
|
|
1387
1495
|
var UAT_CHECK = "uat";
|
|
1388
1496
|
var PASSING_LABELS = [UAT_PASSED_LABEL, LEGACY_UAT_PASSED_LABEL, NO_UAT_NEEDED_LABEL];
|
|
1497
|
+
var HEAD_BOUND_SIGN_OFFS = [UAT_PASSED_LABEL, LEGACY_UAT_PASSED_LABEL];
|
|
1389
1498
|
function info2(message) {
|
|
1390
1499
|
return { check: UAT_CHECK, message, effect: "info" };
|
|
1391
1500
|
}
|
|
1501
|
+
function staleReason(pr, label) {
|
|
1502
|
+
if (!HEAD_BOUND_SIGN_OFFS.includes(label)) return void 0;
|
|
1503
|
+
if (pr.headPushedAt === void 0) {
|
|
1504
|
+
return "the time the current head was pushed is unknown, so it may predate the head";
|
|
1505
|
+
}
|
|
1506
|
+
const appliedAt = pr.signOffs.find((signOff) => signOff.label === label)?.appliedAt;
|
|
1507
|
+
if (appliedAt === void 0) return "the time it was applied is unknown";
|
|
1508
|
+
if (Date.parse(appliedAt) > Date.parse(pr.headPushedAt)) return void 0;
|
|
1509
|
+
return "it was applied before the current head was pushed, and a new head needs a person to test it again";
|
|
1510
|
+
}
|
|
1392
1511
|
function decideUat(pr) {
|
|
1393
1512
|
const categories = trivialCategories(pr);
|
|
1394
1513
|
if (categories !== void 0) {
|
|
@@ -1398,7 +1517,12 @@ function decideUat(pr) {
|
|
|
1398
1517
|
if (parseTitle(pr.title)?.type === "refactor") {
|
|
1399
1518
|
return { findings: [info2("No UAT needed: a refactor changes no behaviour.")] };
|
|
1400
1519
|
}
|
|
1401
|
-
const
|
|
1520
|
+
const stale = PASSING_LABELS.flatMap((label) => {
|
|
1521
|
+
const reason = pr.labels.includes(label) ? staleReason(pr, label) : void 0;
|
|
1522
|
+
return reason === void 0 ? [] : [{ label, reason }];
|
|
1523
|
+
});
|
|
1524
|
+
const current = PASSING_LABELS.filter((label) => !stale.some((entry) => entry.label === label));
|
|
1525
|
+
const state = signOffState(pr, current);
|
|
1402
1526
|
if (state.status === "trusted") {
|
|
1403
1527
|
return {
|
|
1404
1528
|
findings: [
|
|
@@ -1414,7 +1538,10 @@ function decideUat(pr) {
|
|
|
1414
1538
|
message: `Waiting for UAT. A person applies \`${UAT_PASSED_LABEL}\` after testing, or the review agent or a person applies \`${NO_UAT_NEEDED_LABEL}\`.`,
|
|
1415
1539
|
effect: "hold"
|
|
1416
1540
|
};
|
|
1417
|
-
const why =
|
|
1541
|
+
const why = stale.map(({ label, reason }) => info2(`\`${label}\` doesn't count: ${reason}.`));
|
|
1542
|
+
if (state.status === "untrusted") {
|
|
1543
|
+
why.push(info2(`\`${state.label}\` doesn't count: ${state.reason}.`));
|
|
1544
|
+
}
|
|
1418
1545
|
return { findings: [hold, ...why] };
|
|
1419
1546
|
}
|
|
1420
1547
|
var uatCheck = {
|
|
@@ -1454,10 +1581,10 @@ function buildReport(findings) {
|
|
|
1454
1581
|
outcome = "pending";
|
|
1455
1582
|
title = `Waiting on ${plural(holds.length, "human sign-off")}`;
|
|
1456
1583
|
}
|
|
1457
|
-
const
|
|
1584
|
+
const lines2 = findings.map(
|
|
1458
1585
|
(finding) => `- ${ICONS[finding.effect]} **${finding.check}**: ${finding.message}`
|
|
1459
1586
|
);
|
|
1460
|
-
const summary =
|
|
1587
|
+
const summary = lines2.length > 0 ? lines2.join("\n") : "No policy findings.";
|
|
1461
1588
|
return { outcome, title, summary, findings };
|
|
1462
1589
|
}
|
|
1463
1590
|
|
|
@@ -1511,10 +1638,14 @@ function parseSignOffs(value) {
|
|
|
1511
1638
|
return value.map((item, index) => {
|
|
1512
1639
|
const where = `facts.signOffs[${index}]`;
|
|
1513
1640
|
if (typeof item !== "object" || item === null) throw new Error(`${where} must be an object`);
|
|
1514
|
-
const { label, appliedBy } = item;
|
|
1641
|
+
const { label, appliedBy, appliedAt } = item;
|
|
1515
1642
|
if (typeof label !== "string") throw new Error(`${where}.label must be a string`);
|
|
1643
|
+
if (!isOptionalString(appliedAt)) throw new Error(`${where}.appliedAt must be a string`);
|
|
1644
|
+
const signOff = { label };
|
|
1516
1645
|
const actor = parseActor(`${where}.appliedBy`, appliedBy);
|
|
1517
|
-
|
|
1646
|
+
if (actor !== void 0) signOff.appliedBy = actor;
|
|
1647
|
+
if (appliedAt !== void 0) signOff.appliedAt = appliedAt;
|
|
1648
|
+
return signOff;
|
|
1518
1649
|
});
|
|
1519
1650
|
}
|
|
1520
1651
|
function parseAuthor(value) {
|
|
@@ -1562,10 +1693,12 @@ function parseFacts(raw) {
|
|
|
1562
1693
|
changedFiles,
|
|
1563
1694
|
workflowChanges,
|
|
1564
1695
|
manifestChanges,
|
|
1565
|
-
signOffs
|
|
1696
|
+
signOffs,
|
|
1697
|
+
headPushedAt
|
|
1566
1698
|
} = parsed;
|
|
1567
1699
|
if (typeof title !== "string") throw new Error("facts.title must be a string");
|
|
1568
1700
|
if (!isOptionalString(body)) throw new Error("facts.body must be a string");
|
|
1701
|
+
if (!isOptionalString(headPushedAt)) throw new Error("facts.headPushedAt must be a string");
|
|
1569
1702
|
if (draft !== void 0 && typeof draft !== "boolean") {
|
|
1570
1703
|
throw new Error("facts.draft must be a boolean");
|
|
1571
1704
|
}
|
|
@@ -1585,6 +1718,7 @@ function parseFacts(raw) {
|
|
|
1585
1718
|
if (parsedAuthor !== void 0) pr.author = parsedAuthor;
|
|
1586
1719
|
if (parsedBase !== void 0) pr.base = parsedBase;
|
|
1587
1720
|
if (draft !== void 0) pr.draft = draft;
|
|
1721
|
+
if (headPushedAt !== void 0) pr.headPushedAt = headPushedAt;
|
|
1588
1722
|
return pr;
|
|
1589
1723
|
}
|
|
1590
1724
|
|
|
@@ -1796,6 +1930,38 @@ async function postVerdict(target, headSha, evaluation) {
|
|
|
1796
1930
|
await postCommitStatus(target, headSha, evaluation);
|
|
1797
1931
|
}
|
|
1798
1932
|
|
|
1933
|
+
// src/github/head-push.ts
|
|
1934
|
+
async function lines(target, endpoint, jq) {
|
|
1935
|
+
const out = await ghCall({ argv: ["gh", "api", "--paginate", endpoint, "--jq", jq] }, null, {
|
|
1936
|
+
cwd: target.cwd
|
|
1937
|
+
});
|
|
1938
|
+
if (out === null) throw new Error(`could not read ${endpoint}`);
|
|
1939
|
+
return out.split("\n").filter((line) => line.trim() !== "");
|
|
1940
|
+
}
|
|
1941
|
+
function times(stamps) {
|
|
1942
|
+
return stamps.map((stamp) => Date.parse(stamp)).filter((ms) => !Number.isNaN(ms));
|
|
1943
|
+
}
|
|
1944
|
+
async function gatherHeadPushedAt(target, headSha) {
|
|
1945
|
+
const forcePushes = times(
|
|
1946
|
+
await lines(
|
|
1947
|
+
target,
|
|
1948
|
+
`repos/${target.repo}/issues/${target.pr}/events`,
|
|
1949
|
+
'.[] | select(.event == "head_ref_force_pushed") | .created_at'
|
|
1950
|
+
)
|
|
1951
|
+
);
|
|
1952
|
+
const suites = times(
|
|
1953
|
+
await lines(
|
|
1954
|
+
target,
|
|
1955
|
+
`repos/${target.repo}/commits/${headSha}/check-suites`,
|
|
1956
|
+
".check_suites[].created_at"
|
|
1957
|
+
)
|
|
1958
|
+
);
|
|
1959
|
+
const candidates = [...forcePushes];
|
|
1960
|
+
if (suites.length > 0) candidates.push(Math.min(...suites));
|
|
1961
|
+
if (candidates.length === 0) return void 0;
|
|
1962
|
+
return new Date(Math.max(...candidates)).toISOString();
|
|
1963
|
+
}
|
|
1964
|
+
|
|
1799
1965
|
// src/github/sign-offs.ts
|
|
1800
1966
|
async function listLabelEvents(target) {
|
|
1801
1967
|
const out = await ghCall(
|
|
@@ -1806,7 +1972,7 @@ async function listLabelEvents(target) {
|
|
|
1806
1972
|
"--paginate",
|
|
1807
1973
|
`repos/${target.repo}/issues/${target.pr}/events`,
|
|
1808
1974
|
"--jq",
|
|
1809
|
-
'.[] | select(.event == "labeled") | {label: .label.name, login: .actor.login, type: .actor.type}'
|
|
1975
|
+
'.[] | select(.event == "labeled") | {label: .label.name, login: .actor.login, type: .actor.type, at: .created_at}'
|
|
1810
1976
|
]
|
|
1811
1977
|
},
|
|
1812
1978
|
null,
|
|
@@ -1842,10 +2008,11 @@ async function gatherSignOffs(target, labels) {
|
|
|
1842
2008
|
return Promise.all(
|
|
1843
2009
|
present.map(async (label) => {
|
|
1844
2010
|
const event = latest.get(label);
|
|
1845
|
-
if (event === void 0
|
|
2011
|
+
if (event === void 0) return { label };
|
|
2012
|
+
if (event.login === null) return { label, appliedAt: event.at };
|
|
1846
2013
|
const type = event.type ?? "unknown actor";
|
|
1847
2014
|
const permission = type === "User" ? await lookupPermission(target, event.login) : "none";
|
|
1848
|
-
return { label, appliedBy: { login: event.login, type, permission } };
|
|
2015
|
+
return { label, appliedBy: { login: event.login, type, permission }, appliedAt: event.at };
|
|
1849
2016
|
})
|
|
1850
2017
|
);
|
|
1851
2018
|
}
|
|
@@ -1958,6 +2125,10 @@ async function gatherFacts(target) {
|
|
|
1958
2125
|
manifestChanges,
|
|
1959
2126
|
signOffs: await gatherSignOffs(target, labels)
|
|
1960
2127
|
};
|
|
2128
|
+
if (HEAD_BOUND_SIGN_OFFS.some((label) => labels.includes(label))) {
|
|
2129
|
+
const pushedAt = await gatherHeadPushedAt(target, headSha);
|
|
2130
|
+
if (pushedAt !== void 0) facts.headPushedAt = pushedAt;
|
|
2131
|
+
}
|
|
1961
2132
|
return { facts, headSha };
|
|
1962
2133
|
}
|
|
1963
2134
|
async function applyLabelEdits(target, evaluation) {
|
package/dist/index.d.ts
CHANGED
|
@@ -30,6 +30,8 @@ interface LabelActor {
|
|
|
30
30
|
interface SignOff {
|
|
31
31
|
label: string;
|
|
32
32
|
appliedBy?: LabelActor;
|
|
33
|
+
/** When its latest `labeled` event happened (ISO 8601), as GitHub records it. */
|
|
34
|
+
appliedAt?: string;
|
|
33
35
|
}
|
|
34
36
|
/** The account that opened a PR, as GitHub reports it (`dependabot[bot]`, `Bot`). */
|
|
35
37
|
interface PullRequestAuthor {
|
|
@@ -84,6 +86,13 @@ interface PullRequestFacts {
|
|
|
84
86
|
manifestChanges: readonly FileChange[];
|
|
85
87
|
/** Who applied each sign-off label present on the PR. */
|
|
86
88
|
signOffs: readonly SignOff[];
|
|
89
|
+
/**
|
|
90
|
+
* When the current head was pushed (ISO 8601), from times the author can't
|
|
91
|
+
* forge: the latest force-push event and the head commit's earliest check
|
|
92
|
+
* suite, never a commit date. `gatherFacts` sets it whenever a head-bound
|
|
93
|
+
* sign-off (`UAT passed`, `tested`) is on the PR; absent, those don't count.
|
|
94
|
+
*/
|
|
95
|
+
headPushedAt?: string;
|
|
87
96
|
}
|
|
88
97
|
/**
|
|
89
98
|
* What a finding does to the `pr-policy` check-run:
|
|
@@ -389,8 +398,9 @@ declare function evaluatePolicy(pr: PullRequestFacts, checks?: readonly PolicyCh
|
|
|
389
398
|
/**
|
|
390
399
|
* Parse and validate a JSON facts document into `PullRequestFacts`.
|
|
391
400
|
* `workflowChanges`, `manifestChanges`, and `signOffs` are optional and default
|
|
392
|
-
* to none; `body`, `author`, `base`, and `
|
|
393
|
-
* `signOffs`, no sign-off label counts
|
|
401
|
+
* to none; `body`, `author`, `base`, `draft`, and `headPushedAt` are optional and
|
|
402
|
+
* stay absent. With no `signOffs`, no sign-off label counts, and with no
|
|
403
|
+
* `headPushedAt`, no `UAT passed` does: trust fails closed.
|
|
394
404
|
*/
|
|
395
405
|
declare function parseFacts(raw: string): PullRequestFacts;
|
|
396
406
|
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rmartz/pr-policy",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Read-only PR content classifiers — CI-change classification, title-type rules, and more — reported as one blocking pr-policy check-run. Distributed as a pinned Action kept current by Dependabot.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pr-policy",
|