@rmartz/pr-policy 1.2.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-XIDP7SRE.js → chunk-FYYCFBD7.js} +147 -39
- 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 `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.
|
|
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";
|
|
994
|
+
}
|
|
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";
|
|
939
1011
|
}
|
|
940
|
-
function
|
|
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,6 +1462,35 @@ 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];
|
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",
|