@rmartz/pr-policy 0.2.0 → 0.9.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 +12 -8
- package/dist/bin/pr-policy.js +17 -12
- package/dist/{chunk-QINHHFJN.js → chunk-PVXDVMME.js} +767 -80
- package/dist/index.d.ts +122 -5
- package/dist/index.js +33 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @rmartz/pr-policy
|
|
2
2
|
|
|
3
3
|
**Is this pull request's content acceptable under policy?** `pr-policy` answers
|
|
4
|
-
that on every PR, statically, from the PR's diff, title, and changed paths. It
|
|
4
|
+
that on every PR, statically, from the PR's diff, title, description, and changed paths. It
|
|
5
5
|
doesn't rely on a reviewer remembering to check.
|
|
6
6
|
|
|
7
7
|
Each policy rule is a small read-only classifier. All of them report into **one**
|
|
@@ -12,12 +12,15 @@ new required-status name.
|
|
|
12
12
|
|
|
13
13
|
## Checks
|
|
14
14
|
|
|
15
|
-
| Check
|
|
16
|
-
|
|
|
17
|
-
| **
|
|
18
|
-
| **
|
|
19
|
-
|
|
|
20
|
-
|
|
|
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
|
+
| **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, or types a linter/formatter bump as a non-release, non-`ci` type. |
|
|
20
|
+
| **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`) or `no UAT needed` (shows as pending). |
|
|
21
|
+
| **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). |
|
|
22
|
+
| Domain labels (backlog) | Never blocks. Additive path-glob → domain-label map. |
|
|
23
|
+
| Milestone inheritance (backlog) | Never blocks. Issue → PR milestone. |
|
|
21
24
|
|
|
22
25
|
The design, and why this is separate from `merge-safety` and `pr-lifecycle`, is
|
|
23
26
|
in [docs/decisions.md](docs/decisions.md).
|
|
@@ -33,9 +36,10 @@ is in its [consumer guide](https://github.com/rmartz/pr-policy-action/blob/main/
|
|
|
33
36
|
Every check is importable. The `ai-pr-policy` CLI is a thin wrapper around them:
|
|
34
37
|
|
|
35
38
|
```bash
|
|
36
|
-
ai-pr-policy evaluate --pr 12 --repo rmartz/pr-policy # post the check-run + labels
|
|
39
|
+
ai-pr-policy evaluate --pr 12 --repo rmartz/pr-policy # post the check-run, status + labels
|
|
37
40
|
ai-pr-policy evaluate --pr 12 --repo rmartz/pr-policy --json # evaluate only, change nothing
|
|
38
41
|
ai-pr-policy evaluate --facts pr.json # offline, from a JSON facts file
|
|
42
|
+
ai-pr-policy evaluate --pr 12 --repo rmartz/pr-policy --skip-uat # for a repo with no UAT
|
|
39
43
|
```
|
|
40
44
|
|
|
41
45
|
## Documentation
|
package/dist/bin/pr-policy.js
CHANGED
|
@@ -4,22 +4,25 @@ import {
|
|
|
4
4
|
evaluatePolicy,
|
|
5
5
|
gatherFacts,
|
|
6
6
|
parseFacts,
|
|
7
|
-
|
|
8
|
-
resolveRepoTarget
|
|
9
|
-
|
|
7
|
+
postVerdict,
|
|
8
|
+
resolveRepoTarget,
|
|
9
|
+
selectChecks
|
|
10
|
+
} from "../chunk-PVXDVMME.js";
|
|
10
11
|
|
|
11
12
|
// src/bin/pr-policy.ts
|
|
12
13
|
import { readFile } from "fs/promises";
|
|
13
14
|
import { parseArgs } from "util";
|
|
14
15
|
var USAGE = `Usage:
|
|
15
|
-
ai-pr-policy evaluate --pr <n> [--repo <owner/repo>] [--json]
|
|
16
|
-
ai-pr-policy evaluate --facts <path|->
|
|
16
|
+
ai-pr-policy evaluate --pr <n> [--repo <owner/repo>] [--json] [--skip-uat]
|
|
17
|
+
ai-pr-policy evaluate --facts <path|-> [--skip-uat]
|
|
17
18
|
|
|
18
|
-
--pr Evaluate a live PR, post the pr-policy check-run
|
|
19
|
-
apply the label edits the checks planned. --json
|
|
20
|
-
evaluation instead and changes nothing.
|
|
19
|
+
--pr Evaluate a live PR, post the pr-policy check-run and commit status on
|
|
20
|
+
its head, and apply the label edits the checks planned. --json
|
|
21
|
+
prints the evaluation instead and changes nothing.
|
|
21
22
|
--facts Evaluate an offline JSON facts document ("-" reads stdin) and print
|
|
22
|
-
the evaluation. Exits 1 only on "failure" ("pending" exits 0)
|
|
23
|
+
the evaluation. Exits 1 only on "failure" ("pending" exits 0).
|
|
24
|
+
--skip-uat
|
|
25
|
+
Don't run the UAT gate, for a repo with no user-acceptance testing.`;
|
|
23
26
|
async function readInput(path) {
|
|
24
27
|
if (path !== "-") return readFile(path, "utf8");
|
|
25
28
|
const chunks = [];
|
|
@@ -35,6 +38,7 @@ async function main(argv) {
|
|
|
35
38
|
pr: { type: "string" },
|
|
36
39
|
repo: { type: "string" },
|
|
37
40
|
json: { type: "boolean" },
|
|
41
|
+
"skip-uat": { type: "boolean" },
|
|
38
42
|
help: { type: "boolean", short: "h" }
|
|
39
43
|
}
|
|
40
44
|
});
|
|
@@ -46,8 +50,9 @@ async function main(argv) {
|
|
|
46
50
|
console.error(USAGE);
|
|
47
51
|
return 2;
|
|
48
52
|
}
|
|
53
|
+
const checks = selectChecks({ skipUat: values["skip-uat"] });
|
|
49
54
|
if (values.facts !== void 0) {
|
|
50
|
-
const evaluation2 = await evaluatePolicy(parseFacts(await readInput(values.facts)));
|
|
55
|
+
const evaluation2 = await evaluatePolicy(parseFacts(await readInput(values.facts)), checks);
|
|
51
56
|
console.log(JSON.stringify(evaluation2, null, 2));
|
|
52
57
|
return evaluation2.outcome === "failure" ? 1 : 0;
|
|
53
58
|
}
|
|
@@ -63,13 +68,13 @@ async function main(argv) {
|
|
|
63
68
|
}
|
|
64
69
|
const target = { repo, pr };
|
|
65
70
|
const { facts, headSha } = await gatherFacts(target);
|
|
66
|
-
const evaluation = await evaluatePolicy(facts);
|
|
71
|
+
const evaluation = await evaluatePolicy(facts, checks);
|
|
67
72
|
if (values.json) {
|
|
68
73
|
console.log(JSON.stringify(evaluation, null, 2));
|
|
69
74
|
return 0;
|
|
70
75
|
}
|
|
71
76
|
await applyLabelEdits(target, evaluation);
|
|
72
|
-
await
|
|
77
|
+
await postVerdict(target, headSha, evaluation);
|
|
73
78
|
console.log(`${repo}#${pr}: ${evaluation.outcome} \u2014 ${evaluation.title}`);
|
|
74
79
|
return 0;
|
|
75
80
|
}
|