@rmartz/pr-policy 1.3.0 → 1.5.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 -10
- package/dist/bin/pr-policy.js +34 -12
- package/dist/{chunk-FYYCFBD7.js → chunk-RHHCFDMG.js} +294 -69
- package/dist/index.d.ts +172 -46
- package/dist/index.js +19 -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)) |
|
|
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)) |
|
|
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)) | pr-lifecycle's `pr-lifecycle/sign-off` status asks for a CI sign-off (or, before a repo cuts over, a `.github/workflows/**` change loosens CI), and no human has applied `CI change approved` (shows as pending). |
|
|
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)) | pr-lifecycle's sign-off status says the head needs UAT (or, before a repo cuts over, the PR isn't docs, tests, CI, dependency-only, or repo metadata), or the status can't be trusted, 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).
|
|
@@ -41,6 +41,8 @@ pr-policy evaluate --pr 12 --repo rmartz/pr-policy # post the check-r
|
|
|
41
41
|
pr-policy evaluate --pr 12 --repo rmartz/pr-policy --json # evaluate only, change nothing
|
|
42
42
|
pr-policy evaluate --facts pr.json # offline, from a JSON facts file
|
|
43
43
|
pr-policy evaluate --pr 12 --repo rmartz/pr-policy --skip-uat # for a repo with no UAT
|
|
44
|
+
pr-policy evaluate --pr 12 --repo rmartz/pr-policy --sign-off-status-creators "rmartz-merge-bot[bot]" # trust that App's pr-lifecycle/sign-off status
|
|
45
|
+
pr-policy evaluate --sha <sha> --repo rmartz/pr-policy # re-run every open PR at that head (status trigger)
|
|
44
46
|
```
|
|
45
47
|
|
|
46
48
|
## Documentation
|
package/dist/bin/pr-policy.js
CHANGED
|
@@ -3,26 +3,35 @@ import {
|
|
|
3
3
|
applyLabelEdits,
|
|
4
4
|
evaluatePolicy,
|
|
5
5
|
gatherFacts,
|
|
6
|
+
openPullRequestsAtHead,
|
|
6
7
|
parseFacts,
|
|
7
8
|
postVerdict,
|
|
8
9
|
resolveRepoTarget,
|
|
9
10
|
selectChecks
|
|
10
|
-
} from "../chunk-
|
|
11
|
+
} from "../chunk-RHHCFDMG.js";
|
|
11
12
|
|
|
12
13
|
// src/bin/pr-policy.ts
|
|
13
14
|
import { readFile } from "fs/promises";
|
|
14
15
|
import { parseArgs } from "util";
|
|
15
16
|
var USAGE = `Usage:
|
|
16
17
|
pr-policy evaluate --pr <n> [--repo <owner/repo>] [--json] [--skip-uat]
|
|
18
|
+
pr-policy evaluate --sha <sha> [--repo <owner/repo>] [--json] [--skip-uat]
|
|
17
19
|
pr-policy evaluate --facts <path|-> [--skip-uat]
|
|
18
20
|
|
|
19
21
|
--pr Evaluate a live PR, post the pr-policy check-run and commit status on
|
|
20
22
|
its head, and apply the label edits the checks planned. --json
|
|
21
23
|
prints the evaluation instead and changes nothing.
|
|
24
|
+
--sha Evaluate every open PR whose head is <sha>, as --pr does. For a
|
|
25
|
+
caller's "status" trigger, which carries a SHA, not a PR: re-run when
|
|
26
|
+
pr-lifecycle posts its pr-lifecycle/sign-off status.
|
|
22
27
|
--facts Evaluate an offline JSON facts document ("-" reads stdin) and print
|
|
23
28
|
the evaluation. Exits 1 only on "failure" ("pending" exits 0).
|
|
24
29
|
--skip-uat
|
|
25
|
-
Don't run the UAT gate, for a repo with no user-acceptance testing
|
|
30
|
+
Don't run the UAT gate, for a repo with no user-acceptance testing.
|
|
31
|
+
--sign-off-status-creators <login,...>
|
|
32
|
+
GitHub App logins trusted to post the pr-lifecycle/sign-off status,
|
|
33
|
+
e.g. rmartz-merge-bot[bot]. Exact matches only; github-actions[bot]
|
|
34
|
+
is refused. A person who could merge is always trusted.`;
|
|
26
35
|
async function readInput(path) {
|
|
27
36
|
if (path !== "-") return readFile(path, "utf8");
|
|
28
37
|
const chunks = [];
|
|
@@ -36,9 +45,11 @@ async function main(argv) {
|
|
|
36
45
|
options: {
|
|
37
46
|
facts: { type: "string" },
|
|
38
47
|
pr: { type: "string" },
|
|
48
|
+
sha: { type: "string" },
|
|
39
49
|
repo: { type: "string" },
|
|
40
50
|
json: { type: "boolean" },
|
|
41
51
|
"skip-uat": { type: "boolean" },
|
|
52
|
+
"sign-off-status-creators": { type: "string" },
|
|
42
53
|
help: { type: "boolean", short: "h" }
|
|
43
54
|
}
|
|
44
55
|
});
|
|
@@ -50,14 +61,18 @@ async function main(argv) {
|
|
|
50
61
|
console.error(USAGE);
|
|
51
62
|
return 2;
|
|
52
63
|
}
|
|
53
|
-
const checks = selectChecks({
|
|
64
|
+
const checks = selectChecks({
|
|
65
|
+
skipUat: values["skip-uat"],
|
|
66
|
+
signOffStatusCreators: (values["sign-off-status-creators"] ?? "").split(",")
|
|
67
|
+
});
|
|
54
68
|
if (values.facts !== void 0) {
|
|
55
|
-
const
|
|
56
|
-
console.log(JSON.stringify(
|
|
57
|
-
return
|
|
69
|
+
const evaluation = await evaluatePolicy(parseFacts(await readInput(values.facts)), checks);
|
|
70
|
+
console.log(JSON.stringify(evaluation, null, 2));
|
|
71
|
+
return evaluation.outcome === "failure" ? 1 : 0;
|
|
58
72
|
}
|
|
59
73
|
const pr = Number(values.pr);
|
|
60
|
-
|
|
74
|
+
const bySha = values.sha !== void 0 && values.pr === void 0;
|
|
75
|
+
if (!bySha && (!Number.isInteger(pr) || pr <= 0)) {
|
|
61
76
|
console.error(USAGE);
|
|
62
77
|
return 2;
|
|
63
78
|
}
|
|
@@ -66,17 +81,24 @@ async function main(argv) {
|
|
|
66
81
|
console.error("Could not resolve owner/repo \u2014 pass --repo <owner/repo>.");
|
|
67
82
|
return 2;
|
|
68
83
|
}
|
|
69
|
-
const
|
|
84
|
+
const prs = bySha ? await openPullRequestsAtHead({ repo }, values.sha ?? "") : [pr];
|
|
85
|
+
if (bySha && prs.length === 0)
|
|
86
|
+
console.log(`${repo}@${values.sha ?? ""}: no open PR at that head`);
|
|
87
|
+
for (const number of prs) {
|
|
88
|
+
await evaluateOne({ repo, pr: number }, checks, values.json === true);
|
|
89
|
+
}
|
|
90
|
+
return 0;
|
|
91
|
+
}
|
|
92
|
+
async function evaluateOne(target, checks, json) {
|
|
70
93
|
const { facts, headSha } = await gatherFacts(target);
|
|
71
94
|
const evaluation = await evaluatePolicy(facts, checks);
|
|
72
|
-
if (
|
|
95
|
+
if (json) {
|
|
73
96
|
console.log(JSON.stringify(evaluation, null, 2));
|
|
74
|
-
return
|
|
97
|
+
return;
|
|
75
98
|
}
|
|
76
99
|
await applyLabelEdits(target, evaluation);
|
|
77
100
|
await postVerdict(target, headSha, evaluation);
|
|
78
|
-
console.log(`${repo}#${pr}: ${evaluation.outcome} \u2014 ${evaluation.title}`);
|
|
79
|
-
return 0;
|
|
101
|
+
console.log(`${target.repo}#${target.pr}: ${evaluation.outcome} \u2014 ${evaluation.title}`);
|
|
80
102
|
}
|
|
81
103
|
try {
|
|
82
104
|
process.exitCode = await main(process.argv.slice(2));
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/contract.ts
|
|
2
2
|
var PR_POLICY_CHECK_NAME = "pr-policy";
|
|
3
|
+
var SIGN_OFF_STATUS_CONTEXT = "pr-lifecycle/sign-off";
|
|
3
4
|
var CI_APPROVAL_NEEDED_LABEL = "CI approval needed";
|
|
4
5
|
var CI_CHANGE_APPROVED_LABEL = "CI change approved";
|
|
5
6
|
var UAT_PASSED_LABEL = "UAT passed";
|
|
@@ -28,6 +29,112 @@ var BREAKING_CHANGE_LABEL = "breaking change";
|
|
|
28
29
|
var HOTFIX_LABEL = "hotfix";
|
|
29
30
|
var RELEASE_PLEASE_PENDING_LABEL = "autorelease: pending";
|
|
30
31
|
|
|
32
|
+
// src/policy.ts
|
|
33
|
+
var REPO_PERMISSIONS = ["admin", "maintain", "write", "triage", "read", "none"];
|
|
34
|
+
|
|
35
|
+
// src/sign-off.ts
|
|
36
|
+
function isRepoPermission(value) {
|
|
37
|
+
return REPO_PERMISSIONS.some((permission) => permission === value);
|
|
38
|
+
}
|
|
39
|
+
var MERGE_PERMISSIONS = /* @__PURE__ */ new Set(["admin", "maintain", "write"]);
|
|
40
|
+
function vet(actor) {
|
|
41
|
+
if (actor === void 0) return "no labeling event names a live account";
|
|
42
|
+
if (actor.type !== "User") return `\`${actor.login}\` is a ${actor.type}, not a person`;
|
|
43
|
+
if (!MERGE_PERMISSIONS.has(actor.permission)) {
|
|
44
|
+
return `\`${actor.login}\` has \`${actor.permission}\` permission; write, maintain, or admin is required`;
|
|
45
|
+
}
|
|
46
|
+
return actor;
|
|
47
|
+
}
|
|
48
|
+
function signOffState(pr, names) {
|
|
49
|
+
const present = names.filter((name) => pr.labels.includes(name));
|
|
50
|
+
let untrusted;
|
|
51
|
+
for (const label of present) {
|
|
52
|
+
const vetted = vet(pr.signOffs.find((signOff) => signOff.label === label)?.appliedBy);
|
|
53
|
+
if (typeof vetted !== "string") return { status: "trusted", label, appliedBy: vetted };
|
|
54
|
+
untrusted ??= { status: "untrusted", label, reason: vetted };
|
|
55
|
+
}
|
|
56
|
+
return untrusted ?? { status: "absent" };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// src/sign-off-status.ts
|
|
60
|
+
var SIGN_OFF_STATUS_VERSIONS = ["v1"];
|
|
61
|
+
var SIGN_OFF_REQUIREMENTS = ["none", "ci", "uat"];
|
|
62
|
+
var WAIVER_STATES = ["current", "stale", "absent"];
|
|
63
|
+
var KNOWN_KEYS = /* @__PURE__ */ new Set(["requirement", "waiver", "loosening"]);
|
|
64
|
+
var member = (values, value) => values.find((candidate) => candidate === value);
|
|
65
|
+
function parseSignOffDescription(description) {
|
|
66
|
+
const [version, ...pairs] = description.trim().split(/\s+/);
|
|
67
|
+
if (member(SIGN_OFF_STATUS_VERSIONS, version) === void 0) {
|
|
68
|
+
return `its format version \`${version ?? ""}\` is not one this pr-policy understands (${SIGN_OFF_STATUS_VERSIONS.join(", ")})`;
|
|
69
|
+
}
|
|
70
|
+
const fields = /* @__PURE__ */ new Map();
|
|
71
|
+
for (const pair of pairs) {
|
|
72
|
+
const [key = "", value, ...rest] = pair.split("=");
|
|
73
|
+
if (value === void 0 || rest.length > 0) return `\`${pair}\` is not a \`key=value\` pair`;
|
|
74
|
+
if (!KNOWN_KEYS.has(key)) return `\`${key}\` is not a known key`;
|
|
75
|
+
if (fields.has(key)) return `\`${key}\` appears twice`;
|
|
76
|
+
fields.set(key, value);
|
|
77
|
+
}
|
|
78
|
+
const requirement = member(SIGN_OFF_REQUIREMENTS, fields.get("requirement"));
|
|
79
|
+
if (requirement === void 0) return "`requirement` must be `none`, `ci`, or `uat`";
|
|
80
|
+
const looseningText = fields.get("loosening") ?? "no";
|
|
81
|
+
if (looseningText !== "yes" && looseningText !== "no") return "`loosening` must be `yes` or `no`";
|
|
82
|
+
const loosening = looseningText === "yes";
|
|
83
|
+
if (requirement !== "uat") {
|
|
84
|
+
if (fields.has("waiver")) return "`waiver` is only meaningful with `requirement=uat`";
|
|
85
|
+
return { requirement, loosening };
|
|
86
|
+
}
|
|
87
|
+
const waiver = member(WAIVER_STATES, fields.get("waiver"));
|
|
88
|
+
if (waiver === void 0) return "`requirement=uat` needs `waiver=current`, `stale`, or `absent`";
|
|
89
|
+
return { requirement, loosening, waiver };
|
|
90
|
+
}
|
|
91
|
+
var GITHUB_ACTIONS_BOT = "github-actions[bot]";
|
|
92
|
+
var CREATORS_OPTION = "`sign-off-status-creators` (CLI `--sign-off-status-creators`)";
|
|
93
|
+
function parseSignOffStatusCreators(entries) {
|
|
94
|
+
const logins = entries.map((entry) => entry.trim()).filter((entry) => entry !== "");
|
|
95
|
+
for (const login of logins) {
|
|
96
|
+
if (login.toLowerCase() === GITHUB_ACTIONS_BOT) {
|
|
97
|
+
throw new Error(
|
|
98
|
+
`${GITHUB_ACTIONS_BOT} can't be a sign-off status creator: any workflow in the repo can post as it.`
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
if (!login.endsWith("[bot]")) {
|
|
102
|
+
throw new Error(
|
|
103
|
+
`\`${login}\` isn't a GitHub App login: sign-off status creators end in \`[bot]\`. People are trusted by their repo permission, without being named.`
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return [...new Set(logins)];
|
|
108
|
+
}
|
|
109
|
+
function untrustedCreator(creator, trustedBots) {
|
|
110
|
+
if (creator.type === "Bot") {
|
|
111
|
+
if (trustedBots.includes(creator.login)) return void 0;
|
|
112
|
+
if (creator.login.toLowerCase() === GITHUB_ACTIONS_BOT) {
|
|
113
|
+
return `it was posted by \`${creator.login}\`, which any workflow in the repo can post as`;
|
|
114
|
+
}
|
|
115
|
+
return `it was posted by \`${creator.login}\`, a GitHub App this caller doesn't trust. If it is the repo's pr-lifecycle App, name it in ${CREATORS_OPTION}`;
|
|
116
|
+
}
|
|
117
|
+
const vetted = vet(creator);
|
|
118
|
+
return typeof vetted === "string" ? vetted : void 0;
|
|
119
|
+
}
|
|
120
|
+
function untrustedReason(status, trustedBots) {
|
|
121
|
+
if (status.state !== "success") return `its state is \`${status.state}\`, not \`success\``;
|
|
122
|
+
if (status.creator === void 0) return "GitHub names no account that posted it";
|
|
123
|
+
return untrustedCreator(status.creator, trustedBots);
|
|
124
|
+
}
|
|
125
|
+
function readSignOffStatus(pr, trustedBots = []) {
|
|
126
|
+
const status = pr.signOffStatus;
|
|
127
|
+
if (status === void 0) return { kind: "absent" };
|
|
128
|
+
const untrusted = untrustedReason(status, trustedBots);
|
|
129
|
+
if (untrusted !== void 0) return { kind: "rejected", reason: untrusted };
|
|
130
|
+
const parsed = parseSignOffDescription(status.description);
|
|
131
|
+
if (typeof parsed === "string") return { kind: "rejected", reason: parsed };
|
|
132
|
+
return { kind: "valid", classification: parsed, postedBy: status.creator?.login ?? "" };
|
|
133
|
+
}
|
|
134
|
+
function rejectedStatusMessage(reason) {
|
|
135
|
+
return `Waiting on pr-lifecycle: its \`${SIGN_OFF_STATUS_CONTEXT}\` status on this head can't be used, because ${reason}. pr-lifecycle posts a fresh one on its next run.`;
|
|
136
|
+
}
|
|
137
|
+
|
|
31
138
|
// src/checks/ci-change/indicators.ts
|
|
32
139
|
var LOOSENING_INDICATORS = [
|
|
33
140
|
"workflow-removed",
|
|
@@ -541,39 +648,54 @@ function classifyWorkflowChanges(changes) {
|
|
|
541
648
|
return { verdict: indicators.length > 0 ? "loosening" : "tightening", indicators };
|
|
542
649
|
}
|
|
543
650
|
|
|
544
|
-
// src/policy.ts
|
|
545
|
-
var REPO_PERMISSIONS = ["admin", "maintain", "write", "triage", "read", "none"];
|
|
546
|
-
|
|
547
|
-
// src/sign-off.ts
|
|
548
|
-
function isRepoPermission(value) {
|
|
549
|
-
return REPO_PERMISSIONS.some((permission) => permission === value);
|
|
550
|
-
}
|
|
551
|
-
var MERGE_PERMISSIONS = /* @__PURE__ */ new Set(["admin", "maintain", "write"]);
|
|
552
|
-
function vet(actor) {
|
|
553
|
-
if (actor === void 0) return "no labeling event names a live account";
|
|
554
|
-
if (actor.type !== "User") return `\`${actor.login}\` is a ${actor.type}, not a person`;
|
|
555
|
-
if (!MERGE_PERMISSIONS.has(actor.permission)) {
|
|
556
|
-
return `\`${actor.login}\` has \`${actor.permission}\` permission; write, maintain, or admin is required`;
|
|
557
|
-
}
|
|
558
|
-
return actor;
|
|
559
|
-
}
|
|
560
|
-
function signOffState(pr, names) {
|
|
561
|
-
const present = names.filter((name) => pr.labels.includes(name));
|
|
562
|
-
let untrusted;
|
|
563
|
-
for (const label of present) {
|
|
564
|
-
const vetted = vet(pr.signOffs.find((signOff) => signOff.label === label)?.appliedBy);
|
|
565
|
-
if (typeof vetted !== "string") return { status: "trusted", label, appliedBy: vetted };
|
|
566
|
-
untrusted ??= { status: "untrusted", label, reason: vetted };
|
|
567
|
-
}
|
|
568
|
-
return untrusted ?? { status: "absent" };
|
|
569
|
-
}
|
|
570
|
-
|
|
571
651
|
// src/checks/ci-change/index.ts
|
|
572
652
|
var CI_CHANGE_CHECK = "ci-change";
|
|
573
653
|
function indicatorMessage(indicator) {
|
|
574
654
|
return `\`${indicator.file}\` \`${indicator.location}\` \u2014 ${indicator.kind} (${indicator.class}): ${indicator.detail}`;
|
|
575
655
|
}
|
|
576
|
-
function decideCiChange(classification, pr) {
|
|
656
|
+
function decideCiChange(classification, pr, trustedBots = []) {
|
|
657
|
+
const reading = readSignOffStatus(pr, trustedBots);
|
|
658
|
+
switch (reading.kind) {
|
|
659
|
+
case "valid":
|
|
660
|
+
return decideFromStatus(classification, pr, reading.classification);
|
|
661
|
+
case "absent":
|
|
662
|
+
case "rejected":
|
|
663
|
+
return decideWithoutStatus(classification, pr);
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
function untrustedApproval(approval) {
|
|
667
|
+
return approval.status === "untrusted" ? [
|
|
668
|
+
{
|
|
669
|
+
check: CI_CHANGE_CHECK,
|
|
670
|
+
message: `\`${approval.label}\` doesn't count: ${approval.reason}.`,
|
|
671
|
+
effect: "info"
|
|
672
|
+
}
|
|
673
|
+
] : [];
|
|
674
|
+
}
|
|
675
|
+
function evidenceOf(classification) {
|
|
676
|
+
return classification.indicators.map((indicator) => ({
|
|
677
|
+
check: CI_CHANGE_CHECK,
|
|
678
|
+
message: indicatorMessage(indicator),
|
|
679
|
+
effect: "info"
|
|
680
|
+
}));
|
|
681
|
+
}
|
|
682
|
+
function decideFromStatus(classification, pr, status) {
|
|
683
|
+
const why = status.requirement === "ci" ? "pr-lifecycle classified this `ci` PR as needing a CI sign-off" : status.loosening ? "pr-lifecycle reports that this PR loosens CI" : void 0;
|
|
684
|
+
if (why === void 0) return { findings: [] };
|
|
685
|
+
const approval = signOffState(pr, [CI_CHANGE_APPROVED_LABEL]);
|
|
686
|
+
const headline = approval.status === "trusted" ? {
|
|
687
|
+
check: CI_CHANGE_CHECK,
|
|
688
|
+
message: `CI change signed off with \`${CI_CHANGE_APPROVED_LABEL}\` by \`${approval.appliedBy.login}\``,
|
|
689
|
+
effect: "info",
|
|
690
|
+
headline: true
|
|
691
|
+
} : {
|
|
692
|
+
check: CI_CHANGE_CHECK,
|
|
693
|
+
message: `Waiting for a CI sign-off: ${why}. A person reviews the change and applies \`${CI_CHANGE_APPROVED_LABEL}\`. No code change clears this.`,
|
|
694
|
+
effect: "hold"
|
|
695
|
+
};
|
|
696
|
+
return { findings: [headline, ...untrustedApproval(approval), ...evidenceOf(classification)] };
|
|
697
|
+
}
|
|
698
|
+
function decideWithoutStatus(classification, pr) {
|
|
577
699
|
const approval = signOffState(pr, [CI_CHANGE_APPROVED_LABEL]);
|
|
578
700
|
const signedOff = approval.status === "trusted";
|
|
579
701
|
const flagged = pr.labels.includes(CI_APPROVAL_NEEDED_LABEL);
|
|
@@ -599,24 +721,19 @@ function decideCiChange(classification, pr) {
|
|
|
599
721
|
message: `This PR loosens CI and is waiting for a human to review the change and apply \`${CI_CHANGE_APPROVED_LABEL}\`. No code change clears this. Ambiguous indicators are treated as loosening because a miss skips the sign-off entirely.`,
|
|
600
722
|
effect: "hold"
|
|
601
723
|
};
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
}
|
|
608
|
-
] : [];
|
|
609
|
-
const evidence = classification.indicators.map((indicator) => ({
|
|
610
|
-
check: CI_CHANGE_CHECK,
|
|
611
|
-
message: indicatorMessage(indicator),
|
|
612
|
-
effect: "info"
|
|
613
|
-
}));
|
|
614
|
-
return { findings: [headline, ...untrusted, ...evidence], labelsToAdd, labelsToRemove };
|
|
724
|
+
return {
|
|
725
|
+
findings: [headline, ...untrustedApproval(approval), ...evidenceOf(classification)],
|
|
726
|
+
labelsToAdd,
|
|
727
|
+
labelsToRemove
|
|
728
|
+
};
|
|
615
729
|
}
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
730
|
+
function ciChangeCheckFor(trustedBots) {
|
|
731
|
+
return {
|
|
732
|
+
name: CI_CHANGE_CHECK,
|
|
733
|
+
evaluate: async (pr) => decideCiChange(classifyWorkflowChanges(pr.workflowChanges), pr, trustedBots)
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
var ciChangeCheck = ciChangeCheckFor([]);
|
|
620
737
|
|
|
621
738
|
// src/checks/dependabot/claims.ts
|
|
622
739
|
var NAME = /(?:\[([^\[\]\n]+)\]\([^()\n]*\)|`([^`]+)`|([^\s[\]`]+))/.source;
|
|
@@ -1498,6 +1615,9 @@ var HEAD_BOUND_SIGN_OFFS = [UAT_PASSED_LABEL, LEGACY_UAT_PASSED_LABEL];
|
|
|
1498
1615
|
function info2(message) {
|
|
1499
1616
|
return { check: UAT_CHECK, message, effect: "info" };
|
|
1500
1617
|
}
|
|
1618
|
+
function hold(message) {
|
|
1619
|
+
return { check: UAT_CHECK, message, effect: "hold" };
|
|
1620
|
+
}
|
|
1501
1621
|
function staleReason(pr, label) {
|
|
1502
1622
|
if (!HEAD_BOUND_SIGN_OFFS.includes(label)) return void 0;
|
|
1503
1623
|
if (pr.headPushedAt === void 0) {
|
|
@@ -1508,46 +1628,74 @@ function staleReason(pr, label) {
|
|
|
1508
1628
|
if (Date.parse(appliedAt) > Date.parse(pr.headPushedAt)) return void 0;
|
|
1509
1629
|
return "it was applied before the current head was pushed, and a new head needs a person to test it again";
|
|
1510
1630
|
}
|
|
1511
|
-
function decideUat(pr) {
|
|
1631
|
+
function decideUat(pr, trustedBots = []) {
|
|
1632
|
+
const reading = readSignOffStatus(pr, trustedBots);
|
|
1633
|
+
switch (reading.kind) {
|
|
1634
|
+
case "absent":
|
|
1635
|
+
return { findings: decideWithoutStatus2(pr) };
|
|
1636
|
+
case "rejected":
|
|
1637
|
+
return { findings: [hold(rejectedStatusMessage(reading.reason))] };
|
|
1638
|
+
case "valid":
|
|
1639
|
+
return { findings: decideFromStatus2(pr, reading.classification) };
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
function decideFromStatus2(pr, status) {
|
|
1643
|
+
switch (status.requirement) {
|
|
1644
|
+
case "none":
|
|
1645
|
+
return [info2("No UAT needed: pr-lifecycle classified this head as needing no sign-off.")];
|
|
1646
|
+
case "ci":
|
|
1647
|
+
return [info2("No UAT needed: this head needs a CI sign-off instead (`ci-change`).")];
|
|
1648
|
+
case "uat": {
|
|
1649
|
+
const waiver = status.waiver === "current" ? [] : [
|
|
1650
|
+
{
|
|
1651
|
+
label: NO_UAT_NEEDED_LABEL,
|
|
1652
|
+
reason: `pr-lifecycle reports the waiver as \`${status.waiver}\` for this head`
|
|
1653
|
+
}
|
|
1654
|
+
];
|
|
1655
|
+
return signOffFindings(pr, waiver);
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
function decideWithoutStatus2(pr) {
|
|
1512
1660
|
const categories = trivialCategories(pr);
|
|
1513
1661
|
if (categories !== void 0) {
|
|
1514
1662
|
const kinds = categories.length > 0 ? categories.join(", ") : "no files";
|
|
1515
|
-
return
|
|
1663
|
+
return [info2(`No UAT needed: the PR changes only ${kinds}.`)];
|
|
1516
1664
|
}
|
|
1517
1665
|
if (parseTitle(pr.title)?.type === "refactor") {
|
|
1518
|
-
return
|
|
1666
|
+
return [info2("No UAT needed: a refactor changes no behaviour.")];
|
|
1519
1667
|
}
|
|
1668
|
+
return signOffFindings(pr, []);
|
|
1669
|
+
}
|
|
1670
|
+
function signOffFindings(pr, setAside) {
|
|
1520
1671
|
const stale = PASSING_LABELS.flatMap((label) => {
|
|
1521
|
-
|
|
1672
|
+
if (!pr.labels.includes(label)) return [];
|
|
1673
|
+
const reason = setAside.find((entry) => entry.label === label)?.reason ?? staleReason(pr, label);
|
|
1522
1674
|
return reason === void 0 ? [] : [{ label, reason }];
|
|
1523
1675
|
});
|
|
1524
1676
|
const current = PASSING_LABELS.filter((label) => !stale.some((entry) => entry.label === label));
|
|
1525
1677
|
const state = signOffState(pr, current);
|
|
1526
1678
|
if (state.status === "trusted") {
|
|
1527
|
-
return
|
|
1528
|
-
|
|
1529
|
-
{
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
]
|
|
1534
|
-
};
|
|
1679
|
+
return [
|
|
1680
|
+
{
|
|
1681
|
+
...info2(`UAT signed off with \`${state.label}\` by \`${state.appliedBy.login}\``),
|
|
1682
|
+
headline: true
|
|
1683
|
+
}
|
|
1684
|
+
];
|
|
1535
1685
|
}
|
|
1536
|
-
const
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
effect: "hold"
|
|
1540
|
-
};
|
|
1686
|
+
const waiting = hold(
|
|
1687
|
+
`Waiting for UAT. A person applies \`${UAT_PASSED_LABEL}\` after testing, or the review agent or a person applies \`${NO_UAT_NEEDED_LABEL}\`.`
|
|
1688
|
+
);
|
|
1541
1689
|
const why = stale.map(({ label, reason }) => info2(`\`${label}\` doesn't count: ${reason}.`));
|
|
1542
1690
|
if (state.status === "untrusted") {
|
|
1543
1691
|
why.push(info2(`\`${state.label}\` doesn't count: ${state.reason}.`));
|
|
1544
1692
|
}
|
|
1545
|
-
return
|
|
1693
|
+
return [waiting, ...why];
|
|
1546
1694
|
}
|
|
1547
|
-
|
|
1548
|
-
name: UAT_CHECK,
|
|
1549
|
-
|
|
1550
|
-
|
|
1695
|
+
function uatCheckFor(trustedBots) {
|
|
1696
|
+
return { name: UAT_CHECK, evaluate: async (pr) => decideUat(pr, trustedBots) };
|
|
1697
|
+
}
|
|
1698
|
+
var uatCheck = uatCheckFor([]);
|
|
1551
1699
|
|
|
1552
1700
|
// src/checks/index.ts
|
|
1553
1701
|
var CHECKS = [
|
|
@@ -1559,7 +1707,13 @@ var CHECKS = [
|
|
|
1559
1707
|
dependabotCheck
|
|
1560
1708
|
];
|
|
1561
1709
|
function selectChecks(options = {}) {
|
|
1562
|
-
|
|
1710
|
+
const trustedBots = parseSignOffStatusCreators(options.signOffStatusCreators ?? []);
|
|
1711
|
+
const configured = trustedBots.length === 0 ? CHECKS : CHECKS.map((check) => {
|
|
1712
|
+
if (check === uatCheck) return uatCheckFor(trustedBots);
|
|
1713
|
+
if (check === ciChangeCheck) return ciChangeCheckFor(trustedBots);
|
|
1714
|
+
return check;
|
|
1715
|
+
});
|
|
1716
|
+
return options.skipUat ? configured.filter((check) => check.name !== uatCheck.name) : configured;
|
|
1563
1717
|
}
|
|
1564
1718
|
|
|
1565
1719
|
// src/report.ts
|
|
@@ -1678,6 +1832,17 @@ function parseBase(value) {
|
|
|
1678
1832
|
}
|
|
1679
1833
|
return { branch, defaultBranch, headOf: (headOf ?? []).map(parseOpenPullRequest) };
|
|
1680
1834
|
}
|
|
1835
|
+
function parseSignOffStatus(value) {
|
|
1836
|
+
if (value === void 0) return void 0;
|
|
1837
|
+
const where = "facts.signOffStatus";
|
|
1838
|
+
if (typeof value !== "object" || value === null) throw new Error(`${where} must be an object`);
|
|
1839
|
+
const { state, description, creator } = value;
|
|
1840
|
+
if (typeof state !== "string" || typeof description !== "string") {
|
|
1841
|
+
throw new Error(`${where}.state / description must be strings`);
|
|
1842
|
+
}
|
|
1843
|
+
const actor = parseActor(`${where}.creator`, creator);
|
|
1844
|
+
return actor === void 0 ? { state, description } : { state, description, creator: actor };
|
|
1845
|
+
}
|
|
1681
1846
|
function parseFacts(raw) {
|
|
1682
1847
|
const parsed = JSON.parse(raw);
|
|
1683
1848
|
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
@@ -1694,7 +1859,8 @@ function parseFacts(raw) {
|
|
|
1694
1859
|
workflowChanges,
|
|
1695
1860
|
manifestChanges,
|
|
1696
1861
|
signOffs,
|
|
1697
|
-
headPushedAt
|
|
1862
|
+
headPushedAt,
|
|
1863
|
+
signOffStatus
|
|
1698
1864
|
} = parsed;
|
|
1699
1865
|
if (typeof title !== "string") throw new Error("facts.title must be a string");
|
|
1700
1866
|
if (!isOptionalString(body)) throw new Error("facts.body must be a string");
|
|
@@ -1719,6 +1885,8 @@ function parseFacts(raw) {
|
|
|
1719
1885
|
if (parsedBase !== void 0) pr.base = parsedBase;
|
|
1720
1886
|
if (draft !== void 0) pr.draft = draft;
|
|
1721
1887
|
if (headPushedAt !== void 0) pr.headPushedAt = headPushedAt;
|
|
1888
|
+
const parsedStatus = parseSignOffStatus(signOffStatus);
|
|
1889
|
+
if (parsedStatus !== void 0) pr.signOffStatus = parsedStatus;
|
|
1722
1890
|
return pr;
|
|
1723
1891
|
}
|
|
1724
1892
|
|
|
@@ -2017,6 +2185,33 @@ async function gatherSignOffs(target, labels) {
|
|
|
2017
2185
|
);
|
|
2018
2186
|
}
|
|
2019
2187
|
|
|
2188
|
+
// src/github/sign-off-status.ts
|
|
2189
|
+
async function gatherSignOffStatus(target, sha) {
|
|
2190
|
+
const endpoint = `repos/${target.repo}/commits/${sha}/statuses`;
|
|
2191
|
+
const out = await ghCall(
|
|
2192
|
+
{
|
|
2193
|
+
argv: [
|
|
2194
|
+
"gh",
|
|
2195
|
+
"api",
|
|
2196
|
+
"--paginate",
|
|
2197
|
+
endpoint,
|
|
2198
|
+
"--jq",
|
|
2199
|
+
".[] | {context, state, description, login: .creator.login, type: .creator.type}"
|
|
2200
|
+
]
|
|
2201
|
+
},
|
|
2202
|
+
null,
|
|
2203
|
+
{ cwd: target.cwd }
|
|
2204
|
+
);
|
|
2205
|
+
if (out === null) throw new Error(`could not read ${endpoint}`);
|
|
2206
|
+
const latest = out.split("\n").filter((line) => line.trim() !== "").map((line) => JSON.parse(line)).find((status2) => status2.context === SIGN_OFF_STATUS_CONTEXT);
|
|
2207
|
+
if (latest === void 0) return void 0;
|
|
2208
|
+
const status = { state: latest.state, description: latest.description ?? "" };
|
|
2209
|
+
if (latest.login === null) return status;
|
|
2210
|
+
const type = latest.type ?? "unknown actor";
|
|
2211
|
+
const permission = type === "User" ? await lookupPermission(target, latest.login) : "none";
|
|
2212
|
+
return { ...status, creator: { login: latest.login, type, permission } };
|
|
2213
|
+
}
|
|
2214
|
+
|
|
2020
2215
|
// src/github/pull-request.ts
|
|
2021
2216
|
async function ghJson(target, argv) {
|
|
2022
2217
|
const out = await ghCall({ argv }, null, { cwd: target.cwd });
|
|
@@ -2129,8 +2324,29 @@ async function gatherFacts(target) {
|
|
|
2129
2324
|
const pushedAt = await gatherHeadPushedAt(target, headSha);
|
|
2130
2325
|
if (pushedAt !== void 0) facts.headPushedAt = pushedAt;
|
|
2131
2326
|
}
|
|
2327
|
+
const signOffStatus = await gatherSignOffStatus(target, headSha);
|
|
2328
|
+
if (signOffStatus !== void 0) facts.signOffStatus = signOffStatus;
|
|
2132
2329
|
return { facts, headSha };
|
|
2133
2330
|
}
|
|
2331
|
+
async function openPullRequestsAtHead(target, sha) {
|
|
2332
|
+
const endpoint = `repos/${target.repo}/commits/${sha}/pulls`;
|
|
2333
|
+
const out = await ghCall(
|
|
2334
|
+
{
|
|
2335
|
+
argv: [
|
|
2336
|
+
"gh",
|
|
2337
|
+
"api",
|
|
2338
|
+
"--paginate",
|
|
2339
|
+
endpoint,
|
|
2340
|
+
"--jq",
|
|
2341
|
+
'.[] | select(.state == "open") | {number, head: .head.sha}'
|
|
2342
|
+
]
|
|
2343
|
+
},
|
|
2344
|
+
null,
|
|
2345
|
+
{ cwd: target.cwd }
|
|
2346
|
+
);
|
|
2347
|
+
if (out === null) throw new Error(`could not read ${endpoint}`);
|
|
2348
|
+
return out.split("\n").filter((line) => line.trim() !== "").map((line) => JSON.parse(line)).filter((pull) => pull.head === sha).map((pull) => pull.number);
|
|
2349
|
+
}
|
|
2134
2350
|
async function applyLabelEdits(target, evaluation) {
|
|
2135
2351
|
if (evaluation.labelsToAdd.length > 0) {
|
|
2136
2352
|
await addLabels(target.repo, target.pr, evaluation.labelsToAdd, { cwd: target.cwd });
|
|
@@ -2142,6 +2358,7 @@ async function applyLabelEdits(target, evaluation) {
|
|
|
2142
2358
|
|
|
2143
2359
|
export {
|
|
2144
2360
|
PR_POLICY_CHECK_NAME,
|
|
2361
|
+
SIGN_OFF_STATUS_CONTEXT,
|
|
2145
2362
|
CI_APPROVAL_NEEDED_LABEL,
|
|
2146
2363
|
CI_CHANGE_APPROVED_LABEL,
|
|
2147
2364
|
DO_NOT_MERGE_LABEL,
|
|
@@ -2152,6 +2369,13 @@ export {
|
|
|
2152
2369
|
BREAKING_CHANGE_LABEL,
|
|
2153
2370
|
HOTFIX_LABEL,
|
|
2154
2371
|
RELEASE_PLEASE_PENDING_LABEL,
|
|
2372
|
+
SIGN_OFF_STATUS_VERSIONS,
|
|
2373
|
+
SIGN_OFF_REQUIREMENTS,
|
|
2374
|
+
WAIVER_STATES,
|
|
2375
|
+
parseSignOffDescription,
|
|
2376
|
+
GITHUB_ACTIONS_BOT,
|
|
2377
|
+
parseSignOffStatusCreators,
|
|
2378
|
+
readSignOffStatus,
|
|
2155
2379
|
LOOSENING_INDICATORS,
|
|
2156
2380
|
AMBIGUOUS_INDICATORS,
|
|
2157
2381
|
CI_CHANGE_VERDICTS,
|
|
@@ -2190,5 +2414,6 @@ export {
|
|
|
2190
2414
|
statusBody,
|
|
2191
2415
|
postVerdict,
|
|
2192
2416
|
gatherFacts,
|
|
2417
|
+
openPullRequestsAtHead,
|
|
2193
2418
|
applyLabelEdits
|
|
2194
2419
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -33,6 +33,16 @@ interface SignOff {
|
|
|
33
33
|
/** When its latest `labeled` event happened (ISO 8601), as GitHub records it. */
|
|
34
34
|
appliedAt?: string;
|
|
35
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* The latest commit status on the head SHA for one context, as GitHub reports
|
|
38
|
+
* it. `creator` is absent when GitHub names no live account.
|
|
39
|
+
*/
|
|
40
|
+
interface CommitStatus {
|
|
41
|
+
/** `success`, `pending`, `failure`, or `error`. */
|
|
42
|
+
state: string;
|
|
43
|
+
description: string;
|
|
44
|
+
creator?: LabelActor;
|
|
45
|
+
}
|
|
36
46
|
/** The account that opened a PR, as GitHub reports it (`dependabot[bot]`, `Bot`). */
|
|
37
47
|
interface PullRequestAuthor {
|
|
38
48
|
login: string;
|
|
@@ -93,6 +103,13 @@ interface PullRequestFacts {
|
|
|
93
103
|
* sign-off (`UAT passed`, `tested`) is on the PR; absent, those don't count.
|
|
94
104
|
*/
|
|
95
105
|
headPushedAt?: string;
|
|
106
|
+
/**
|
|
107
|
+
* The latest `pr-lifecycle/sign-off` status on the head SHA: pr-lifecycle's
|
|
108
|
+
* classification of which human sign-off this head needs. Absent when
|
|
109
|
+
* pr-lifecycle hasn't posted one, which keeps the checks on their own
|
|
110
|
+
* classification until the repo cuts over (src/sign-off-status.ts).
|
|
111
|
+
*/
|
|
112
|
+
signOffStatus?: CommitStatus;
|
|
96
113
|
}
|
|
97
114
|
/**
|
|
98
115
|
* What a finding does to the `pr-policy` check-run:
|
|
@@ -149,10 +166,137 @@ declare const CHECKS: readonly PolicyCheck[];
|
|
|
149
166
|
interface PolicyOptions {
|
|
150
167
|
/** Drop the UAT gate, for a repo with no user-acceptance testing to wait on. */
|
|
151
168
|
skipUat?: boolean;
|
|
169
|
+
/**
|
|
170
|
+
* GitHub App logins (exact, ending in `[bot]`) trusted to post the
|
|
171
|
+
* `pr-lifecycle/sign-off` status, besides a person who could merge. Empty by
|
|
172
|
+
* default. `github-actions[bot]` is refused. Human sign-off labels are
|
|
173
|
+
* unaffected: they still need a trusted person.
|
|
174
|
+
*/
|
|
175
|
+
signOffStatusCreators?: readonly string[];
|
|
152
176
|
}
|
|
153
|
-
/**
|
|
177
|
+
/**
|
|
178
|
+
* The checks to run for a repo configured with `options`, in report order.
|
|
179
|
+
* Throws on an invalid `signOffStatusCreators` entry.
|
|
180
|
+
*/
|
|
154
181
|
declare function selectChecks(options?: PolicyOptions): readonly PolicyCheck[];
|
|
155
182
|
|
|
183
|
+
/**
|
|
184
|
+
* Names read outside this repo. Each is a fleet contract: consumers' rulesets
|
|
185
|
+
* require the check-run by literal name, the coordinator's gate model parks a PR
|
|
186
|
+
* on the label, and a human applies the sign-off label by hand. Renaming any of
|
|
187
|
+
* them is a coordinated cross-repo migration, never a local refactor — see
|
|
188
|
+
* docs/check-run-contract.md. `test/contract.test.ts` pins every value.
|
|
189
|
+
*/
|
|
190
|
+
/**
|
|
191
|
+
* The one check-run this package posts. Every policy check reports into it, so
|
|
192
|
+
* adding a check never adds a required-status name.
|
|
193
|
+
*/
|
|
194
|
+
declare const PR_POLICY_CHECK_NAME = "pr-policy";
|
|
195
|
+
/**
|
|
196
|
+
* The commit status pr-lifecycle posts on each head with its classification of
|
|
197
|
+
* the sign-off that head needs. Read here, never written; pr-lifecycle owns the
|
|
198
|
+
* name and the description format (rmartz/pr-lifecycle#119).
|
|
199
|
+
*/
|
|
200
|
+
declare const SIGN_OFF_STATUS_CONTEXT = "pr-lifecycle/sign-off";
|
|
201
|
+
/** The merge-gate label the CI-change check applies to an unsigned loosening. */
|
|
202
|
+
declare const CI_APPROVAL_NEEDED_LABEL = "CI approval needed";
|
|
203
|
+
/**
|
|
204
|
+
* The human sign-off on a CI loosening. Read-only here: this package never
|
|
205
|
+
* applies it.
|
|
206
|
+
*/
|
|
207
|
+
declare const CI_CHANGE_APPROVED_LABEL = "CI change approved";
|
|
208
|
+
/**
|
|
209
|
+
* Labels a person puts on a PR to stop it merging. The merge-block check holds
|
|
210
|
+
* `pr-policy` while any of them is present, and never applies or removes one.
|
|
211
|
+
* `dnm` is shorthand for `do not merge`.
|
|
212
|
+
*/
|
|
213
|
+
declare const DO_NOT_MERGE_LABEL = "do not merge";
|
|
214
|
+
declare const DNM_LABEL = "dnm";
|
|
215
|
+
declare const BLOCKED_LABEL = "blocked";
|
|
216
|
+
declare const ESCALATION_NEEDED_LABEL = "escalation needed";
|
|
217
|
+
declare const BLOCKING_LABELS: readonly ["do not merge", "dnm", "blocked", "escalation needed"];
|
|
218
|
+
/**
|
|
219
|
+
* Labels the title check reads and never writes. They belong to the review and
|
|
220
|
+
* release flow: `breaking change` must agree with the title's `!`, which is what
|
|
221
|
+
* the release and merge-safety read; `hotfix` implies one; and release-please
|
|
222
|
+
* marks its release PRs with `autorelease: pending`.
|
|
223
|
+
*/
|
|
224
|
+
declare const BREAKING_CHANGE_LABEL = "breaking change";
|
|
225
|
+
declare const HOTFIX_LABEL = "hotfix";
|
|
226
|
+
declare const RELEASE_PLEASE_PENDING_LABEL = "autorelease: pending";
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* pr-lifecycle's sign-off status: the one signal pr-lifecycle sends this gate.
|
|
230
|
+
* pr-lifecycle classifies each head and posts a `pr-lifecycle/sign-off` commit
|
|
231
|
+
* status on it whose description says which human sign-off the head needs, for
|
|
232
|
+
* example `v1 requirement=uat waiver=current`. The format is pr-lifecycle's
|
|
233
|
+
* contract (its docs/sign-off-status.md, rmartz/pr-lifecycle#119); the two
|
|
234
|
+
* must stay compatible.
|
|
235
|
+
*
|
|
236
|
+
* GitHub ties a status to its SHA, so a push can never leave the gate reading a
|
|
237
|
+
* classification of an older head. The gate never reads pr-lifecycle's labels.
|
|
238
|
+
*
|
|
239
|
+
* Everything here fails closed: an unknown version, an unknown key or value, a
|
|
240
|
+
* status that isn't `success`, or a creator who couldn't sign off a PR is
|
|
241
|
+
* `rejected`, and the checks hold. Only a missing status is `absent`, which
|
|
242
|
+
* keeps the checks on their own classification until the repo cuts over.
|
|
243
|
+
*/
|
|
244
|
+
|
|
245
|
+
/** The description format versions this gate understands. */
|
|
246
|
+
declare const SIGN_OFF_STATUS_VERSIONS: readonly ["v1"];
|
|
247
|
+
declare const SIGN_OFF_REQUIREMENTS: readonly ["none", "ci", "uat"];
|
|
248
|
+
type SignOffRequirement = (typeof SIGN_OFF_REQUIREMENTS)[number];
|
|
249
|
+
declare const WAIVER_STATES: readonly ["current", "stale", "absent"];
|
|
250
|
+
type WaiverState = (typeof WAIVER_STATES)[number];
|
|
251
|
+
/** A parsed, valid sign-off status. */
|
|
252
|
+
type SignOffClassification = {
|
|
253
|
+
requirement: 'none';
|
|
254
|
+
loosening: boolean;
|
|
255
|
+
} | {
|
|
256
|
+
requirement: 'ci';
|
|
257
|
+
loosening: boolean;
|
|
258
|
+
} | {
|
|
259
|
+
requirement: 'uat';
|
|
260
|
+
loosening: boolean;
|
|
261
|
+
waiver: WaiverState;
|
|
262
|
+
};
|
|
263
|
+
type SignOffStatusReading = {
|
|
264
|
+
kind: 'absent';
|
|
265
|
+
} | {
|
|
266
|
+
kind: 'rejected';
|
|
267
|
+
reason: string;
|
|
268
|
+
} | {
|
|
269
|
+
kind: 'valid';
|
|
270
|
+
classification: SignOffClassification;
|
|
271
|
+
postedBy: string;
|
|
272
|
+
};
|
|
273
|
+
/**
|
|
274
|
+
* Parse a status description, or say why it can't be trusted. Strict on
|
|
275
|
+
* purpose: a key this gate doesn't know could change what the status means, so
|
|
276
|
+
* pr-lifecycle bumps the version for any new key.
|
|
277
|
+
*/
|
|
278
|
+
declare function parseSignOffDescription(description: string): SignOffClassification | string;
|
|
279
|
+
/**
|
|
280
|
+
* The Bot any workflow in a repo can post as with its `GITHUB_TOKEN`. It can
|
|
281
|
+
* never be trusted to post the status, so a caller can't name it.
|
|
282
|
+
*/
|
|
283
|
+
declare const GITHUB_ACTIONS_BOT = "github-actions[bot]";
|
|
284
|
+
/**
|
|
285
|
+
* Validate a caller's list of GitHub App logins trusted to post the status
|
|
286
|
+
* (rmartz/pr-policy#97). Each entry is an exact login ending in `[bot]`, such
|
|
287
|
+
* as `rmartz-merge-bot[bot]`; blanks are dropped. `github-actions[bot]` is
|
|
288
|
+
* refused in any case, because any workflow can post as it. Throws on a bad
|
|
289
|
+
* entry, so a misconfigured caller fails loudly rather than trusting less or
|
|
290
|
+
* more than it meant to.
|
|
291
|
+
*/
|
|
292
|
+
declare function parseSignOffStatusCreators(entries: readonly string[]): string[];
|
|
293
|
+
/**
|
|
294
|
+
* Read pr-lifecycle's sign-off status on the head, judging its creator and
|
|
295
|
+
* format. The creator must be a `User` who could merge, or a Bot named in
|
|
296
|
+
* `trustedBots` (validated by `parseSignOffStatusCreators`).
|
|
297
|
+
*/
|
|
298
|
+
declare function readSignOffStatus(pr: Pick<PullRequestFacts, 'signOffStatus'>, trustedBots?: readonly string[]): SignOffStatusReading;
|
|
299
|
+
|
|
156
300
|
/**
|
|
157
301
|
* The indicator vocabulary — the classifier's whole output surface.
|
|
158
302
|
*
|
|
@@ -207,8 +351,18 @@ declare function classifyWorkflowFile(change: WorkflowFileChange): Indicator[];
|
|
|
207
351
|
declare function classifyWorkflowChanges(changes: readonly WorkflowFileChange[]): Classification;
|
|
208
352
|
|
|
209
353
|
declare const CI_CHANGE_CHECK = "ci-change";
|
|
210
|
-
|
|
211
|
-
|
|
354
|
+
type CiFacts = Pick<PullRequestFacts, 'labels' | 'signOffs' | 'signOffStatus'>;
|
|
355
|
+
/**
|
|
356
|
+
* Decide the findings and label edits for one classified PR. With a valid
|
|
357
|
+
* `pr-lifecycle/sign-off` status, that status says whether a CI sign-off is
|
|
358
|
+
* needed, and this check edits no label: pr-lifecycle writes `CI approval
|
|
359
|
+
* needed` then. Without one, or with one the gate can't trust (the `uat` check
|
|
360
|
+
* holds on that), this check classifies the workflow diff itself, as before
|
|
361
|
+
* the cutover. `trustedBots` are the GitHub Apps the caller trusts to post the
|
|
362
|
+
* status, besides a trusted person.
|
|
363
|
+
*/
|
|
364
|
+
declare function decideCiChange(classification: Classification, pr: CiFacts, trustedBots?: readonly string[]): CheckResult;
|
|
365
|
+
/** The CI-change check trusting only people to post the sign-off status. */
|
|
212
366
|
declare const ciChangeCheck: PolicyCheck;
|
|
213
367
|
|
|
214
368
|
/**
|
|
@@ -325,45 +479,6 @@ declare function isManifestPath(path: string): boolean;
|
|
|
325
479
|
*/
|
|
326
480
|
declare function sensitiveBumps(changes: readonly FileChange[]): string[];
|
|
327
481
|
|
|
328
|
-
/**
|
|
329
|
-
* Names read outside this repo. Each is a fleet contract: consumers' rulesets
|
|
330
|
-
* require the check-run by literal name, the coordinator's gate model parks a PR
|
|
331
|
-
* on the label, and a human applies the sign-off label by hand. Renaming any of
|
|
332
|
-
* them is a coordinated cross-repo migration, never a local refactor — see
|
|
333
|
-
* docs/check-run-contract.md. `test/contract.test.ts` pins every value.
|
|
334
|
-
*/
|
|
335
|
-
/**
|
|
336
|
-
* The one check-run this package posts. Every policy check reports into it, so
|
|
337
|
-
* adding a check never adds a required-status name.
|
|
338
|
-
*/
|
|
339
|
-
declare const PR_POLICY_CHECK_NAME = "pr-policy";
|
|
340
|
-
/** The merge-gate label the CI-change check applies to an unsigned loosening. */
|
|
341
|
-
declare const CI_APPROVAL_NEEDED_LABEL = "CI approval needed";
|
|
342
|
-
/**
|
|
343
|
-
* The human sign-off on a CI loosening. Read-only here: this package never
|
|
344
|
-
* applies it.
|
|
345
|
-
*/
|
|
346
|
-
declare const CI_CHANGE_APPROVED_LABEL = "CI change approved";
|
|
347
|
-
/**
|
|
348
|
-
* Labels a person puts on a PR to stop it merging. The merge-block check holds
|
|
349
|
-
* `pr-policy` while any of them is present, and never applies or removes one.
|
|
350
|
-
* `dnm` is shorthand for `do not merge`.
|
|
351
|
-
*/
|
|
352
|
-
declare const DO_NOT_MERGE_LABEL = "do not merge";
|
|
353
|
-
declare const DNM_LABEL = "dnm";
|
|
354
|
-
declare const BLOCKED_LABEL = "blocked";
|
|
355
|
-
declare const ESCALATION_NEEDED_LABEL = "escalation needed";
|
|
356
|
-
declare const BLOCKING_LABELS: readonly ["do not merge", "dnm", "blocked", "escalation needed"];
|
|
357
|
-
/**
|
|
358
|
-
* Labels the title check reads and never writes. They belong to the review and
|
|
359
|
-
* release flow: `breaking change` must agree with the title's `!`, which is what
|
|
360
|
-
* the release and merge-safety read; `hotfix` implies one; and release-please
|
|
361
|
-
* marks its release PRs with `autorelease: pending`.
|
|
362
|
-
*/
|
|
363
|
-
declare const BREAKING_CHANGE_LABEL = "breaking change";
|
|
364
|
-
declare const HOTFIX_LABEL = "hotfix";
|
|
365
|
-
declare const RELEASE_PLEASE_PENDING_LABEL = "autorelease: pending";
|
|
366
|
-
|
|
367
482
|
/**
|
|
368
483
|
* The overall result of one evaluation. `pending` posts the check-run as
|
|
369
484
|
* `in_progress` (no conclusion), so a PR waiting on a human sign-off shows as
|
|
@@ -398,9 +513,10 @@ declare function evaluatePolicy(pr: PullRequestFacts, checks?: readonly PolicyCh
|
|
|
398
513
|
/**
|
|
399
514
|
* Parse and validate a JSON facts document into `PullRequestFacts`.
|
|
400
515
|
* `workflowChanges`, `manifestChanges`, and `signOffs` are optional and default
|
|
401
|
-
* to none; `body`, `author`, `base`, `draft`,
|
|
402
|
-
* stay absent. With no `signOffs`, no sign-off
|
|
403
|
-
* `headPushedAt`, no `UAT passed` does: trust fails
|
|
516
|
+
* to none; `body`, `author`, `base`, `draft`, `headPushedAt`, and
|
|
517
|
+
* `signOffStatus` are optional and stay absent. With no `signOffs`, no sign-off
|
|
518
|
+
* label counts, and with no `headPushedAt`, no `UAT passed` does: trust fails
|
|
519
|
+
* closed. With no `signOffStatus`, the checks classify the PR themselves.
|
|
404
520
|
*/
|
|
405
521
|
declare function parseFacts(raw: string): PullRequestFacts;
|
|
406
522
|
|
|
@@ -418,6 +534,16 @@ declare function gatherFacts(target: PullRequestTarget): Promise<{
|
|
|
418
534
|
facts: PullRequestFacts;
|
|
419
535
|
headSha: string;
|
|
420
536
|
}>;
|
|
537
|
+
/**
|
|
538
|
+
* The open PRs whose head is `sha`. A `status` event carries a SHA, not a PR,
|
|
539
|
+
* so this is how a caller re-evaluates when pr-lifecycle posts its sign-off
|
|
540
|
+
* status. A PR whose head has since moved isn't returned: its newer head gets
|
|
541
|
+
* its own status. A failed lookup throws.
|
|
542
|
+
*/
|
|
543
|
+
declare function openPullRequestsAtHead(target: {
|
|
544
|
+
repo: string;
|
|
545
|
+
cwd?: string;
|
|
546
|
+
}, sha: string): Promise<number[]>;
|
|
421
547
|
/** Apply the label edits the checks planned (labels this package owns). */
|
|
422
548
|
declare function applyLabelEdits(target: PullRequestTarget, evaluation: PolicyEvaluation): Promise<void>;
|
|
423
549
|
|
|
@@ -430,4 +556,4 @@ declare function statusBody(evaluation: PolicyEvaluation, runUrl: string | undef
|
|
|
430
556
|
/** Post the verdict: the `pr-policy` check-run, then the matching commit status. */
|
|
431
557
|
declare function postVerdict(target: PullRequestTarget, headSha: string, evaluation: PolicyEvaluation): Promise<void>;
|
|
432
558
|
|
|
433
|
-
export { AMBIGUOUS_INDICATORS, type AmbiguousIndicator, BLOCKED_LABEL, BLOCKING_LABELS, BREAKING_CHANGE_LABEL, CHECKS, CI_APPROVAL_NEEDED_LABEL, CI_CHANGE_APPROVED_LABEL, CI_CHANGE_CHECK, CI_CHANGE_VERDICTS, CI_SENSITIVE_PACKAGES, COMMIT_TYPES, type CheckResult, type CheckRunReport, type CiChangeVerdict, type Claim, type Classification, type CommitType, DEPENDABOT_CHECK, DEPENDABOT_LOGIN, DNM_LABEL, DO_NOT_MERGE_LABEL, ESCALATION_NEEDED_LABEL, FUNCTIONAL_TYPES, type FileChange, type Finding, HOTFIX_LABEL, type Indicator, type IndicatorClass, type IndicatorKind, LOOSENING_INDICATORS, type LooseningIndicator, MERGE_BLOCK_CHECK, POLICY_OUTCOMES, PR_POLICY_CHECK_NAME, type ParsedTitle, type PolicyCheck, type PolicyEvaluation, type PolicyOptions, type PolicyOutcome, type PullRequestAuthor, type PullRequestFacts, type PullRequestTarget, RELEASE_PLEASE_PENDING_LABEL, TITLE_CHECK, type WorkflowFileChange, applyLabelEdits, buildReport, checkRunBody, ciChangeCheck, classifyWorkflowChanges, classifyWorkflowFile, decideCiChange, decideDependabot, decideMergeBlock, decideTitle, dependabotCheck, evaluatePolicy, gatherFacts, isManifestPath, isWorkflowPath, mergeBlockCheck, parseClaims, parseFacts, parseTitle, postCheckRun, postVerdict, selectChecks, sensitiveBumps, statusBody, titleCheck };
|
|
559
|
+
export { AMBIGUOUS_INDICATORS, type AmbiguousIndicator, BLOCKED_LABEL, BLOCKING_LABELS, BREAKING_CHANGE_LABEL, CHECKS, CI_APPROVAL_NEEDED_LABEL, CI_CHANGE_APPROVED_LABEL, CI_CHANGE_CHECK, CI_CHANGE_VERDICTS, CI_SENSITIVE_PACKAGES, COMMIT_TYPES, type CheckResult, type CheckRunReport, type CiChangeVerdict, type Claim, type Classification, type CommitStatus, type CommitType, DEPENDABOT_CHECK, DEPENDABOT_LOGIN, DNM_LABEL, DO_NOT_MERGE_LABEL, ESCALATION_NEEDED_LABEL, FUNCTIONAL_TYPES, type FileChange, type Finding, GITHUB_ACTIONS_BOT, HOTFIX_LABEL, type Indicator, type IndicatorClass, type IndicatorKind, LOOSENING_INDICATORS, type LooseningIndicator, MERGE_BLOCK_CHECK, POLICY_OUTCOMES, PR_POLICY_CHECK_NAME, type ParsedTitle, type PolicyCheck, type PolicyEvaluation, type PolicyOptions, type PolicyOutcome, type PullRequestAuthor, type PullRequestFacts, type PullRequestTarget, RELEASE_PLEASE_PENDING_LABEL, SIGN_OFF_REQUIREMENTS, SIGN_OFF_STATUS_CONTEXT, SIGN_OFF_STATUS_VERSIONS, type SignOffClassification, type SignOffRequirement, type SignOffStatusReading, TITLE_CHECK, WAIVER_STATES, type WaiverState, type WorkflowFileChange, applyLabelEdits, buildReport, checkRunBody, ciChangeCheck, classifyWorkflowChanges, classifyWorkflowFile, decideCiChange, decideDependabot, decideMergeBlock, decideTitle, dependabotCheck, evaluatePolicy, gatherFacts, isManifestPath, isWorkflowPath, mergeBlockCheck, openPullRequestsAtHead, parseClaims, parseFacts, parseSignOffDescription, parseSignOffStatusCreators, parseTitle, postCheckRun, postVerdict, readSignOffStatus, selectChecks, sensitiveBumps, statusBody, titleCheck };
|
package/dist/index.js
CHANGED
|
@@ -16,13 +16,18 @@ import {
|
|
|
16
16
|
DO_NOT_MERGE_LABEL,
|
|
17
17
|
ESCALATION_NEEDED_LABEL,
|
|
18
18
|
FUNCTIONAL_TYPES,
|
|
19
|
+
GITHUB_ACTIONS_BOT,
|
|
19
20
|
HOTFIX_LABEL,
|
|
20
21
|
LOOSENING_INDICATORS,
|
|
21
22
|
MERGE_BLOCK_CHECK,
|
|
22
23
|
POLICY_OUTCOMES,
|
|
23
24
|
PR_POLICY_CHECK_NAME,
|
|
24
25
|
RELEASE_PLEASE_PENDING_LABEL,
|
|
26
|
+
SIGN_OFF_REQUIREMENTS,
|
|
27
|
+
SIGN_OFF_STATUS_CONTEXT,
|
|
28
|
+
SIGN_OFF_STATUS_VERSIONS,
|
|
25
29
|
TITLE_CHECK,
|
|
30
|
+
WAIVER_STATES,
|
|
26
31
|
applyLabelEdits,
|
|
27
32
|
buildReport,
|
|
28
33
|
checkRunBody,
|
|
@@ -39,16 +44,20 @@ import {
|
|
|
39
44
|
isManifestPath,
|
|
40
45
|
isWorkflowPath,
|
|
41
46
|
mergeBlockCheck,
|
|
47
|
+
openPullRequestsAtHead,
|
|
42
48
|
parseClaims,
|
|
43
49
|
parseFacts,
|
|
50
|
+
parseSignOffDescription,
|
|
51
|
+
parseSignOffStatusCreators,
|
|
44
52
|
parseTitle,
|
|
45
53
|
postCheckRun,
|
|
46
54
|
postVerdict,
|
|
55
|
+
readSignOffStatus,
|
|
47
56
|
selectChecks,
|
|
48
57
|
sensitiveBumps,
|
|
49
58
|
statusBody,
|
|
50
59
|
titleCheck
|
|
51
|
-
} from "./chunk-
|
|
60
|
+
} from "./chunk-RHHCFDMG.js";
|
|
52
61
|
export {
|
|
53
62
|
AMBIGUOUS_INDICATORS,
|
|
54
63
|
BLOCKED_LABEL,
|
|
@@ -67,13 +76,18 @@ export {
|
|
|
67
76
|
DO_NOT_MERGE_LABEL,
|
|
68
77
|
ESCALATION_NEEDED_LABEL,
|
|
69
78
|
FUNCTIONAL_TYPES,
|
|
79
|
+
GITHUB_ACTIONS_BOT,
|
|
70
80
|
HOTFIX_LABEL,
|
|
71
81
|
LOOSENING_INDICATORS,
|
|
72
82
|
MERGE_BLOCK_CHECK,
|
|
73
83
|
POLICY_OUTCOMES,
|
|
74
84
|
PR_POLICY_CHECK_NAME,
|
|
75
85
|
RELEASE_PLEASE_PENDING_LABEL,
|
|
86
|
+
SIGN_OFF_REQUIREMENTS,
|
|
87
|
+
SIGN_OFF_STATUS_CONTEXT,
|
|
88
|
+
SIGN_OFF_STATUS_VERSIONS,
|
|
76
89
|
TITLE_CHECK,
|
|
90
|
+
WAIVER_STATES,
|
|
77
91
|
applyLabelEdits,
|
|
78
92
|
buildReport,
|
|
79
93
|
checkRunBody,
|
|
@@ -90,11 +104,15 @@ export {
|
|
|
90
104
|
isManifestPath,
|
|
91
105
|
isWorkflowPath,
|
|
92
106
|
mergeBlockCheck,
|
|
107
|
+
openPullRequestsAtHead,
|
|
93
108
|
parseClaims,
|
|
94
109
|
parseFacts,
|
|
110
|
+
parseSignOffDescription,
|
|
111
|
+
parseSignOffStatusCreators,
|
|
95
112
|
parseTitle,
|
|
96
113
|
postCheckRun,
|
|
97
114
|
postVerdict,
|
|
115
|
+
readSignOffStatus,
|
|
98
116
|
selectChecks,
|
|
99
117
|
sensitiveBumps,
|
|
100
118
|
statusBody,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rmartz/pr-policy",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.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",
|