@rmartz/pr-policy 1.3.0 → 1.4.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 +11 -10
- package/dist/bin/pr-policy.js +24 -10
- package/dist/{chunk-FYYCFBD7.js → chunk-5M7UKSAV.js} +244 -58
- package/dist/index.d.ts +141 -45
- package/dist/index.js +15 -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,7 @@ 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 --sha <sha> --repo rmartz/pr-policy # re-run every open PR at that head (status trigger)
|
|
44
45
|
```
|
|
45
46
|
|
|
46
47
|
## Documentation
|
package/dist/bin/pr-policy.js
CHANGED
|
@@ -3,22 +3,27 @@ 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-5M7UKSAV.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
|
|
@@ -36,6 +41,7 @@ async function main(argv) {
|
|
|
36
41
|
options: {
|
|
37
42
|
facts: { type: "string" },
|
|
38
43
|
pr: { type: "string" },
|
|
44
|
+
sha: { type: "string" },
|
|
39
45
|
repo: { type: "string" },
|
|
40
46
|
json: { type: "boolean" },
|
|
41
47
|
"skip-uat": { type: "boolean" },
|
|
@@ -52,12 +58,13 @@ async function main(argv) {
|
|
|
52
58
|
}
|
|
53
59
|
const checks = selectChecks({ skipUat: values["skip-uat"] });
|
|
54
60
|
if (values.facts !== void 0) {
|
|
55
|
-
const
|
|
56
|
-
console.log(JSON.stringify(
|
|
57
|
-
return
|
|
61
|
+
const evaluation = await evaluatePolicy(parseFacts(await readInput(values.facts)), checks);
|
|
62
|
+
console.log(JSON.stringify(evaluation, null, 2));
|
|
63
|
+
return evaluation.outcome === "failure" ? 1 : 0;
|
|
58
64
|
}
|
|
59
65
|
const pr = Number(values.pr);
|
|
60
|
-
|
|
66
|
+
const bySha = values.sha !== void 0 && values.pr === void 0;
|
|
67
|
+
if (!bySha && (!Number.isInteger(pr) || pr <= 0)) {
|
|
61
68
|
console.error(USAGE);
|
|
62
69
|
return 2;
|
|
63
70
|
}
|
|
@@ -66,17 +73,24 @@ async function main(argv) {
|
|
|
66
73
|
console.error("Could not resolve owner/repo \u2014 pass --repo <owner/repo>.");
|
|
67
74
|
return 2;
|
|
68
75
|
}
|
|
69
|
-
const
|
|
76
|
+
const prs = bySha ? await openPullRequestsAtHead({ repo }, values.sha ?? "") : [pr];
|
|
77
|
+
if (bySha && prs.length === 0)
|
|
78
|
+
console.log(`${repo}@${values.sha ?? ""}: no open PR at that head`);
|
|
79
|
+
for (const number of prs) {
|
|
80
|
+
await evaluateOne({ repo, pr: number }, checks, values.json === true);
|
|
81
|
+
}
|
|
82
|
+
return 0;
|
|
83
|
+
}
|
|
84
|
+
async function evaluateOne(target, checks, json) {
|
|
70
85
|
const { facts, headSha } = await gatherFacts(target);
|
|
71
86
|
const evaluation = await evaluatePolicy(facts, checks);
|
|
72
|
-
if (
|
|
87
|
+
if (json) {
|
|
73
88
|
console.log(JSON.stringify(evaluation, null, 2));
|
|
74
|
-
return
|
|
89
|
+
return;
|
|
75
90
|
}
|
|
76
91
|
await applyLabelEdits(target, evaluation);
|
|
77
92
|
await postVerdict(target, headSha, evaluation);
|
|
78
|
-
console.log(`${repo}#${pr}: ${evaluation.outcome} \u2014 ${evaluation.title}`);
|
|
79
|
-
return 0;
|
|
93
|
+
console.log(`${target.repo}#${target.pr}: ${evaluation.outcome} \u2014 ${evaluation.title}`);
|
|
80
94
|
}
|
|
81
95
|
try {
|
|
82
96
|
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,84 @@ 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
|
+
function untrustedReason(status) {
|
|
92
|
+
if (status.state !== "success") return `its state is \`${status.state}\`, not \`success\``;
|
|
93
|
+
if (status.creator === void 0) return "GitHub names no account that posted it";
|
|
94
|
+
const vetted = vet(status.creator);
|
|
95
|
+
return typeof vetted === "string" ? vetted : void 0;
|
|
96
|
+
}
|
|
97
|
+
function readSignOffStatus(pr) {
|
|
98
|
+
const status = pr.signOffStatus;
|
|
99
|
+
if (status === void 0) return { kind: "absent" };
|
|
100
|
+
const untrusted = untrustedReason(status);
|
|
101
|
+
if (untrusted !== void 0) return { kind: "rejected", reason: untrusted };
|
|
102
|
+
const parsed = parseSignOffDescription(status.description);
|
|
103
|
+
if (typeof parsed === "string") return { kind: "rejected", reason: parsed };
|
|
104
|
+
return { kind: "valid", classification: parsed, postedBy: status.creator?.login ?? "" };
|
|
105
|
+
}
|
|
106
|
+
function rejectedStatusMessage(reason) {
|
|
107
|
+
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.`;
|
|
108
|
+
}
|
|
109
|
+
|
|
31
110
|
// src/checks/ci-change/indicators.ts
|
|
32
111
|
var LOOSENING_INDICATORS = [
|
|
33
112
|
"workflow-removed",
|
|
@@ -541,39 +620,54 @@ function classifyWorkflowChanges(changes) {
|
|
|
541
620
|
return { verdict: indicators.length > 0 ? "loosening" : "tightening", indicators };
|
|
542
621
|
}
|
|
543
622
|
|
|
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
623
|
// src/checks/ci-change/index.ts
|
|
572
624
|
var CI_CHANGE_CHECK = "ci-change";
|
|
573
625
|
function indicatorMessage(indicator) {
|
|
574
626
|
return `\`${indicator.file}\` \`${indicator.location}\` \u2014 ${indicator.kind} (${indicator.class}): ${indicator.detail}`;
|
|
575
627
|
}
|
|
576
628
|
function decideCiChange(classification, pr) {
|
|
629
|
+
const reading = readSignOffStatus(pr);
|
|
630
|
+
switch (reading.kind) {
|
|
631
|
+
case "valid":
|
|
632
|
+
return decideFromStatus(classification, pr, reading.classification);
|
|
633
|
+
case "absent":
|
|
634
|
+
case "rejected":
|
|
635
|
+
return decideWithoutStatus(classification, pr);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
function untrustedApproval(approval) {
|
|
639
|
+
return approval.status === "untrusted" ? [
|
|
640
|
+
{
|
|
641
|
+
check: CI_CHANGE_CHECK,
|
|
642
|
+
message: `\`${approval.label}\` doesn't count: ${approval.reason}.`,
|
|
643
|
+
effect: "info"
|
|
644
|
+
}
|
|
645
|
+
] : [];
|
|
646
|
+
}
|
|
647
|
+
function evidenceOf(classification) {
|
|
648
|
+
return classification.indicators.map((indicator) => ({
|
|
649
|
+
check: CI_CHANGE_CHECK,
|
|
650
|
+
message: indicatorMessage(indicator),
|
|
651
|
+
effect: "info"
|
|
652
|
+
}));
|
|
653
|
+
}
|
|
654
|
+
function decideFromStatus(classification, pr, status) {
|
|
655
|
+
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;
|
|
656
|
+
if (why === void 0) return { findings: [] };
|
|
657
|
+
const approval = signOffState(pr, [CI_CHANGE_APPROVED_LABEL]);
|
|
658
|
+
const headline = approval.status === "trusted" ? {
|
|
659
|
+
check: CI_CHANGE_CHECK,
|
|
660
|
+
message: `CI change signed off with \`${CI_CHANGE_APPROVED_LABEL}\` by \`${approval.appliedBy.login}\``,
|
|
661
|
+
effect: "info",
|
|
662
|
+
headline: true
|
|
663
|
+
} : {
|
|
664
|
+
check: CI_CHANGE_CHECK,
|
|
665
|
+
message: `Waiting for a CI sign-off: ${why}. A person reviews the change and applies \`${CI_CHANGE_APPROVED_LABEL}\`. No code change clears this.`,
|
|
666
|
+
effect: "hold"
|
|
667
|
+
};
|
|
668
|
+
return { findings: [headline, ...untrustedApproval(approval), ...evidenceOf(classification)] };
|
|
669
|
+
}
|
|
670
|
+
function decideWithoutStatus(classification, pr) {
|
|
577
671
|
const approval = signOffState(pr, [CI_CHANGE_APPROVED_LABEL]);
|
|
578
672
|
const signedOff = approval.status === "trusted";
|
|
579
673
|
const flagged = pr.labels.includes(CI_APPROVAL_NEEDED_LABEL);
|
|
@@ -599,19 +693,11 @@ function decideCiChange(classification, pr) {
|
|
|
599
693
|
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
694
|
effect: "hold"
|
|
601
695
|
};
|
|
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 };
|
|
696
|
+
return {
|
|
697
|
+
findings: [headline, ...untrustedApproval(approval), ...evidenceOf(classification)],
|
|
698
|
+
labelsToAdd,
|
|
699
|
+
labelsToRemove
|
|
700
|
+
};
|
|
615
701
|
}
|
|
616
702
|
var ciChangeCheck = {
|
|
617
703
|
name: CI_CHANGE_CHECK,
|
|
@@ -1498,6 +1584,9 @@ var HEAD_BOUND_SIGN_OFFS = [UAT_PASSED_LABEL, LEGACY_UAT_PASSED_LABEL];
|
|
|
1498
1584
|
function info2(message) {
|
|
1499
1585
|
return { check: UAT_CHECK, message, effect: "info" };
|
|
1500
1586
|
}
|
|
1587
|
+
function hold(message) {
|
|
1588
|
+
return { check: UAT_CHECK, message, effect: "hold" };
|
|
1589
|
+
}
|
|
1501
1590
|
function staleReason(pr, label) {
|
|
1502
1591
|
if (!HEAD_BOUND_SIGN_OFFS.includes(label)) return void 0;
|
|
1503
1592
|
if (pr.headPushedAt === void 0) {
|
|
@@ -1509,40 +1598,68 @@ function staleReason(pr, label) {
|
|
|
1509
1598
|
return "it was applied before the current head was pushed, and a new head needs a person to test it again";
|
|
1510
1599
|
}
|
|
1511
1600
|
function decideUat(pr) {
|
|
1601
|
+
const reading = readSignOffStatus(pr);
|
|
1602
|
+
switch (reading.kind) {
|
|
1603
|
+
case "absent":
|
|
1604
|
+
return { findings: decideWithoutStatus2(pr) };
|
|
1605
|
+
case "rejected":
|
|
1606
|
+
return { findings: [hold(rejectedStatusMessage(reading.reason))] };
|
|
1607
|
+
case "valid":
|
|
1608
|
+
return { findings: decideFromStatus2(pr, reading.classification) };
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
function decideFromStatus2(pr, status) {
|
|
1612
|
+
switch (status.requirement) {
|
|
1613
|
+
case "none":
|
|
1614
|
+
return [info2("No UAT needed: pr-lifecycle classified this head as needing no sign-off.")];
|
|
1615
|
+
case "ci":
|
|
1616
|
+
return [info2("No UAT needed: this head needs a CI sign-off instead (`ci-change`).")];
|
|
1617
|
+
case "uat": {
|
|
1618
|
+
const waiver = status.waiver === "current" ? [] : [
|
|
1619
|
+
{
|
|
1620
|
+
label: NO_UAT_NEEDED_LABEL,
|
|
1621
|
+
reason: `pr-lifecycle reports the waiver as \`${status.waiver}\` for this head`
|
|
1622
|
+
}
|
|
1623
|
+
];
|
|
1624
|
+
return signOffFindings(pr, waiver);
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
function decideWithoutStatus2(pr) {
|
|
1512
1629
|
const categories = trivialCategories(pr);
|
|
1513
1630
|
if (categories !== void 0) {
|
|
1514
1631
|
const kinds = categories.length > 0 ? categories.join(", ") : "no files";
|
|
1515
|
-
return
|
|
1632
|
+
return [info2(`No UAT needed: the PR changes only ${kinds}.`)];
|
|
1516
1633
|
}
|
|
1517
1634
|
if (parseTitle(pr.title)?.type === "refactor") {
|
|
1518
|
-
return
|
|
1635
|
+
return [info2("No UAT needed: a refactor changes no behaviour.")];
|
|
1519
1636
|
}
|
|
1637
|
+
return signOffFindings(pr, []);
|
|
1638
|
+
}
|
|
1639
|
+
function signOffFindings(pr, setAside) {
|
|
1520
1640
|
const stale = PASSING_LABELS.flatMap((label) => {
|
|
1521
|
-
|
|
1641
|
+
if (!pr.labels.includes(label)) return [];
|
|
1642
|
+
const reason = setAside.find((entry) => entry.label === label)?.reason ?? staleReason(pr, label);
|
|
1522
1643
|
return reason === void 0 ? [] : [{ label, reason }];
|
|
1523
1644
|
});
|
|
1524
1645
|
const current = PASSING_LABELS.filter((label) => !stale.some((entry) => entry.label === label));
|
|
1525
1646
|
const state = signOffState(pr, current);
|
|
1526
1647
|
if (state.status === "trusted") {
|
|
1527
|
-
return
|
|
1528
|
-
|
|
1529
|
-
{
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
]
|
|
1534
|
-
};
|
|
1648
|
+
return [
|
|
1649
|
+
{
|
|
1650
|
+
...info2(`UAT signed off with \`${state.label}\` by \`${state.appliedBy.login}\``),
|
|
1651
|
+
headline: true
|
|
1652
|
+
}
|
|
1653
|
+
];
|
|
1535
1654
|
}
|
|
1536
|
-
const
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
effect: "hold"
|
|
1540
|
-
};
|
|
1655
|
+
const waiting = hold(
|
|
1656
|
+
`Waiting for UAT. A person applies \`${UAT_PASSED_LABEL}\` after testing, or the review agent or a person applies \`${NO_UAT_NEEDED_LABEL}\`.`
|
|
1657
|
+
);
|
|
1541
1658
|
const why = stale.map(({ label, reason }) => info2(`\`${label}\` doesn't count: ${reason}.`));
|
|
1542
1659
|
if (state.status === "untrusted") {
|
|
1543
1660
|
why.push(info2(`\`${state.label}\` doesn't count: ${state.reason}.`));
|
|
1544
1661
|
}
|
|
1545
|
-
return
|
|
1662
|
+
return [waiting, ...why];
|
|
1546
1663
|
}
|
|
1547
1664
|
var uatCheck = {
|
|
1548
1665
|
name: UAT_CHECK,
|
|
@@ -1678,6 +1795,17 @@ function parseBase(value) {
|
|
|
1678
1795
|
}
|
|
1679
1796
|
return { branch, defaultBranch, headOf: (headOf ?? []).map(parseOpenPullRequest) };
|
|
1680
1797
|
}
|
|
1798
|
+
function parseSignOffStatus(value) {
|
|
1799
|
+
if (value === void 0) return void 0;
|
|
1800
|
+
const where = "facts.signOffStatus";
|
|
1801
|
+
if (typeof value !== "object" || value === null) throw new Error(`${where} must be an object`);
|
|
1802
|
+
const { state, description, creator } = value;
|
|
1803
|
+
if (typeof state !== "string" || typeof description !== "string") {
|
|
1804
|
+
throw new Error(`${where}.state / description must be strings`);
|
|
1805
|
+
}
|
|
1806
|
+
const actor = parseActor(`${where}.creator`, creator);
|
|
1807
|
+
return actor === void 0 ? { state, description } : { state, description, creator: actor };
|
|
1808
|
+
}
|
|
1681
1809
|
function parseFacts(raw) {
|
|
1682
1810
|
const parsed = JSON.parse(raw);
|
|
1683
1811
|
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
@@ -1694,7 +1822,8 @@ function parseFacts(raw) {
|
|
|
1694
1822
|
workflowChanges,
|
|
1695
1823
|
manifestChanges,
|
|
1696
1824
|
signOffs,
|
|
1697
|
-
headPushedAt
|
|
1825
|
+
headPushedAt,
|
|
1826
|
+
signOffStatus
|
|
1698
1827
|
} = parsed;
|
|
1699
1828
|
if (typeof title !== "string") throw new Error("facts.title must be a string");
|
|
1700
1829
|
if (!isOptionalString(body)) throw new Error("facts.body must be a string");
|
|
@@ -1719,6 +1848,8 @@ function parseFacts(raw) {
|
|
|
1719
1848
|
if (parsedBase !== void 0) pr.base = parsedBase;
|
|
1720
1849
|
if (draft !== void 0) pr.draft = draft;
|
|
1721
1850
|
if (headPushedAt !== void 0) pr.headPushedAt = headPushedAt;
|
|
1851
|
+
const parsedStatus = parseSignOffStatus(signOffStatus);
|
|
1852
|
+
if (parsedStatus !== void 0) pr.signOffStatus = parsedStatus;
|
|
1722
1853
|
return pr;
|
|
1723
1854
|
}
|
|
1724
1855
|
|
|
@@ -2017,6 +2148,33 @@ async function gatherSignOffs(target, labels) {
|
|
|
2017
2148
|
);
|
|
2018
2149
|
}
|
|
2019
2150
|
|
|
2151
|
+
// src/github/sign-off-status.ts
|
|
2152
|
+
async function gatherSignOffStatus(target, sha) {
|
|
2153
|
+
const endpoint = `repos/${target.repo}/commits/${sha}/statuses`;
|
|
2154
|
+
const out = await ghCall(
|
|
2155
|
+
{
|
|
2156
|
+
argv: [
|
|
2157
|
+
"gh",
|
|
2158
|
+
"api",
|
|
2159
|
+
"--paginate",
|
|
2160
|
+
endpoint,
|
|
2161
|
+
"--jq",
|
|
2162
|
+
".[] | {context, state, description, login: .creator.login, type: .creator.type}"
|
|
2163
|
+
]
|
|
2164
|
+
},
|
|
2165
|
+
null,
|
|
2166
|
+
{ cwd: target.cwd }
|
|
2167
|
+
);
|
|
2168
|
+
if (out === null) throw new Error(`could not read ${endpoint}`);
|
|
2169
|
+
const latest = out.split("\n").filter((line) => line.trim() !== "").map((line) => JSON.parse(line)).find((status2) => status2.context === SIGN_OFF_STATUS_CONTEXT);
|
|
2170
|
+
if (latest === void 0) return void 0;
|
|
2171
|
+
const status = { state: latest.state, description: latest.description ?? "" };
|
|
2172
|
+
if (latest.login === null) return status;
|
|
2173
|
+
const type = latest.type ?? "unknown actor";
|
|
2174
|
+
const permission = type === "User" ? await lookupPermission(target, latest.login) : "none";
|
|
2175
|
+
return { ...status, creator: { login: latest.login, type, permission } };
|
|
2176
|
+
}
|
|
2177
|
+
|
|
2020
2178
|
// src/github/pull-request.ts
|
|
2021
2179
|
async function ghJson(target, argv) {
|
|
2022
2180
|
const out = await ghCall({ argv }, null, { cwd: target.cwd });
|
|
@@ -2129,8 +2287,29 @@ async function gatherFacts(target) {
|
|
|
2129
2287
|
const pushedAt = await gatherHeadPushedAt(target, headSha);
|
|
2130
2288
|
if (pushedAt !== void 0) facts.headPushedAt = pushedAt;
|
|
2131
2289
|
}
|
|
2290
|
+
const signOffStatus = await gatherSignOffStatus(target, headSha);
|
|
2291
|
+
if (signOffStatus !== void 0) facts.signOffStatus = signOffStatus;
|
|
2132
2292
|
return { facts, headSha };
|
|
2133
2293
|
}
|
|
2294
|
+
async function openPullRequestsAtHead(target, sha) {
|
|
2295
|
+
const endpoint = `repos/${target.repo}/commits/${sha}/pulls`;
|
|
2296
|
+
const out = await ghCall(
|
|
2297
|
+
{
|
|
2298
|
+
argv: [
|
|
2299
|
+
"gh",
|
|
2300
|
+
"api",
|
|
2301
|
+
"--paginate",
|
|
2302
|
+
endpoint,
|
|
2303
|
+
"--jq",
|
|
2304
|
+
'.[] | select(.state == "open") | {number, head: .head.sha}'
|
|
2305
|
+
]
|
|
2306
|
+
},
|
|
2307
|
+
null,
|
|
2308
|
+
{ cwd: target.cwd }
|
|
2309
|
+
);
|
|
2310
|
+
if (out === null) throw new Error(`could not read ${endpoint}`);
|
|
2311
|
+
return out.split("\n").filter((line) => line.trim() !== "").map((line) => JSON.parse(line)).filter((pull) => pull.head === sha).map((pull) => pull.number);
|
|
2312
|
+
}
|
|
2134
2313
|
async function applyLabelEdits(target, evaluation) {
|
|
2135
2314
|
if (evaluation.labelsToAdd.length > 0) {
|
|
2136
2315
|
await addLabels(target.repo, target.pr, evaluation.labelsToAdd, { cwd: target.cwd });
|
|
@@ -2142,6 +2321,7 @@ async function applyLabelEdits(target, evaluation) {
|
|
|
2142
2321
|
|
|
2143
2322
|
export {
|
|
2144
2323
|
PR_POLICY_CHECK_NAME,
|
|
2324
|
+
SIGN_OFF_STATUS_CONTEXT,
|
|
2145
2325
|
CI_APPROVAL_NEEDED_LABEL,
|
|
2146
2326
|
CI_CHANGE_APPROVED_LABEL,
|
|
2147
2327
|
DO_NOT_MERGE_LABEL,
|
|
@@ -2152,6 +2332,11 @@ export {
|
|
|
2152
2332
|
BREAKING_CHANGE_LABEL,
|
|
2153
2333
|
HOTFIX_LABEL,
|
|
2154
2334
|
RELEASE_PLEASE_PENDING_LABEL,
|
|
2335
|
+
SIGN_OFF_STATUS_VERSIONS,
|
|
2336
|
+
SIGN_OFF_REQUIREMENTS,
|
|
2337
|
+
WAIVER_STATES,
|
|
2338
|
+
parseSignOffDescription,
|
|
2339
|
+
readSignOffStatus,
|
|
2155
2340
|
LOOSENING_INDICATORS,
|
|
2156
2341
|
AMBIGUOUS_INDICATORS,
|
|
2157
2342
|
CI_CHANGE_VERDICTS,
|
|
@@ -2190,5 +2375,6 @@ export {
|
|
|
2190
2375
|
statusBody,
|
|
2191
2376
|
postVerdict,
|
|
2192
2377
|
gatherFacts,
|
|
2378
|
+
openPullRequestsAtHead,
|
|
2193
2379
|
applyLabelEdits
|
|
2194
2380
|
};
|
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:
|
|
@@ -153,6 +170,105 @@ interface PolicyOptions {
|
|
|
153
170
|
/** The checks to run for a repo configured with `options`, in report order. */
|
|
154
171
|
declare function selectChecks(options?: PolicyOptions): readonly PolicyCheck[];
|
|
155
172
|
|
|
173
|
+
/**
|
|
174
|
+
* Names read outside this repo. Each is a fleet contract: consumers' rulesets
|
|
175
|
+
* require the check-run by literal name, the coordinator's gate model parks a PR
|
|
176
|
+
* on the label, and a human applies the sign-off label by hand. Renaming any of
|
|
177
|
+
* them is a coordinated cross-repo migration, never a local refactor — see
|
|
178
|
+
* docs/check-run-contract.md. `test/contract.test.ts` pins every value.
|
|
179
|
+
*/
|
|
180
|
+
/**
|
|
181
|
+
* The one check-run this package posts. Every policy check reports into it, so
|
|
182
|
+
* adding a check never adds a required-status name.
|
|
183
|
+
*/
|
|
184
|
+
declare const PR_POLICY_CHECK_NAME = "pr-policy";
|
|
185
|
+
/**
|
|
186
|
+
* The commit status pr-lifecycle posts on each head with its classification of
|
|
187
|
+
* the sign-off that head needs. Read here, never written; pr-lifecycle owns the
|
|
188
|
+
* name and the description format (rmartz/pr-lifecycle#119).
|
|
189
|
+
*/
|
|
190
|
+
declare const SIGN_OFF_STATUS_CONTEXT = "pr-lifecycle/sign-off";
|
|
191
|
+
/** The merge-gate label the CI-change check applies to an unsigned loosening. */
|
|
192
|
+
declare const CI_APPROVAL_NEEDED_LABEL = "CI approval needed";
|
|
193
|
+
/**
|
|
194
|
+
* The human sign-off on a CI loosening. Read-only here: this package never
|
|
195
|
+
* applies it.
|
|
196
|
+
*/
|
|
197
|
+
declare const CI_CHANGE_APPROVED_LABEL = "CI change approved";
|
|
198
|
+
/**
|
|
199
|
+
* Labels a person puts on a PR to stop it merging. The merge-block check holds
|
|
200
|
+
* `pr-policy` while any of them is present, and never applies or removes one.
|
|
201
|
+
* `dnm` is shorthand for `do not merge`.
|
|
202
|
+
*/
|
|
203
|
+
declare const DO_NOT_MERGE_LABEL = "do not merge";
|
|
204
|
+
declare const DNM_LABEL = "dnm";
|
|
205
|
+
declare const BLOCKED_LABEL = "blocked";
|
|
206
|
+
declare const ESCALATION_NEEDED_LABEL = "escalation needed";
|
|
207
|
+
declare const BLOCKING_LABELS: readonly ["do not merge", "dnm", "blocked", "escalation needed"];
|
|
208
|
+
/**
|
|
209
|
+
* Labels the title check reads and never writes. They belong to the review and
|
|
210
|
+
* release flow: `breaking change` must agree with the title's `!`, which is what
|
|
211
|
+
* the release and merge-safety read; `hotfix` implies one; and release-please
|
|
212
|
+
* marks its release PRs with `autorelease: pending`.
|
|
213
|
+
*/
|
|
214
|
+
declare const BREAKING_CHANGE_LABEL = "breaking change";
|
|
215
|
+
declare const HOTFIX_LABEL = "hotfix";
|
|
216
|
+
declare const RELEASE_PLEASE_PENDING_LABEL = "autorelease: pending";
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* pr-lifecycle's sign-off status: the one signal pr-lifecycle sends this gate.
|
|
220
|
+
* pr-lifecycle classifies each head and posts a `pr-lifecycle/sign-off` commit
|
|
221
|
+
* status on it whose description says which human sign-off the head needs, for
|
|
222
|
+
* example `v1 requirement=uat waiver=current`. The format is pr-lifecycle's
|
|
223
|
+
* contract (its docs/sign-off-status.md, rmartz/pr-lifecycle#119); the two
|
|
224
|
+
* must stay compatible.
|
|
225
|
+
*
|
|
226
|
+
* GitHub ties a status to its SHA, so a push can never leave the gate reading a
|
|
227
|
+
* classification of an older head. The gate never reads pr-lifecycle's labels.
|
|
228
|
+
*
|
|
229
|
+
* Everything here fails closed: an unknown version, an unknown key or value, a
|
|
230
|
+
* status that isn't `success`, or a creator who couldn't sign off a PR is
|
|
231
|
+
* `rejected`, and the checks hold. Only a missing status is `absent`, which
|
|
232
|
+
* keeps the checks on their own classification until the repo cuts over.
|
|
233
|
+
*/
|
|
234
|
+
|
|
235
|
+
/** The description format versions this gate understands. */
|
|
236
|
+
declare const SIGN_OFF_STATUS_VERSIONS: readonly ["v1"];
|
|
237
|
+
declare const SIGN_OFF_REQUIREMENTS: readonly ["none", "ci", "uat"];
|
|
238
|
+
type SignOffRequirement = (typeof SIGN_OFF_REQUIREMENTS)[number];
|
|
239
|
+
declare const WAIVER_STATES: readonly ["current", "stale", "absent"];
|
|
240
|
+
type WaiverState = (typeof WAIVER_STATES)[number];
|
|
241
|
+
/** A parsed, valid sign-off status. */
|
|
242
|
+
type SignOffClassification = {
|
|
243
|
+
requirement: 'none';
|
|
244
|
+
loosening: boolean;
|
|
245
|
+
} | {
|
|
246
|
+
requirement: 'ci';
|
|
247
|
+
loosening: boolean;
|
|
248
|
+
} | {
|
|
249
|
+
requirement: 'uat';
|
|
250
|
+
loosening: boolean;
|
|
251
|
+
waiver: WaiverState;
|
|
252
|
+
};
|
|
253
|
+
type SignOffStatusReading = {
|
|
254
|
+
kind: 'absent';
|
|
255
|
+
} | {
|
|
256
|
+
kind: 'rejected';
|
|
257
|
+
reason: string;
|
|
258
|
+
} | {
|
|
259
|
+
kind: 'valid';
|
|
260
|
+
classification: SignOffClassification;
|
|
261
|
+
postedBy: string;
|
|
262
|
+
};
|
|
263
|
+
/**
|
|
264
|
+
* Parse a status description, or say why it can't be trusted. Strict on
|
|
265
|
+
* purpose: a key this gate doesn't know could change what the status means, so
|
|
266
|
+
* pr-lifecycle bumps the version for any new key.
|
|
267
|
+
*/
|
|
268
|
+
declare function parseSignOffDescription(description: string): SignOffClassification | string;
|
|
269
|
+
/** Read pr-lifecycle's sign-off status on the head, judging its creator and format. */
|
|
270
|
+
declare function readSignOffStatus(pr: Pick<PullRequestFacts, 'signOffStatus'>): SignOffStatusReading;
|
|
271
|
+
|
|
156
272
|
/**
|
|
157
273
|
* The indicator vocabulary — the classifier's whole output surface.
|
|
158
274
|
*
|
|
@@ -207,8 +323,16 @@ declare function classifyWorkflowFile(change: WorkflowFileChange): Indicator[];
|
|
|
207
323
|
declare function classifyWorkflowChanges(changes: readonly WorkflowFileChange[]): Classification;
|
|
208
324
|
|
|
209
325
|
declare const CI_CHANGE_CHECK = "ci-change";
|
|
210
|
-
|
|
211
|
-
|
|
326
|
+
type CiFacts = Pick<PullRequestFacts, 'labels' | 'signOffs' | 'signOffStatus'>;
|
|
327
|
+
/**
|
|
328
|
+
* Decide the findings and label edits for one classified PR. With a valid
|
|
329
|
+
* `pr-lifecycle/sign-off` status, that status says whether a CI sign-off is
|
|
330
|
+
* needed, and this check edits no label: pr-lifecycle writes `CI approval
|
|
331
|
+
* needed` then. Without one, or with one the gate can't trust (the `uat` check
|
|
332
|
+
* holds on that), this check classifies the workflow diff itself, as before
|
|
333
|
+
* the cutover.
|
|
334
|
+
*/
|
|
335
|
+
declare function decideCiChange(classification: Classification, pr: CiFacts): CheckResult;
|
|
212
336
|
declare const ciChangeCheck: PolicyCheck;
|
|
213
337
|
|
|
214
338
|
/**
|
|
@@ -325,45 +449,6 @@ declare function isManifestPath(path: string): boolean;
|
|
|
325
449
|
*/
|
|
326
450
|
declare function sensitiveBumps(changes: readonly FileChange[]): string[];
|
|
327
451
|
|
|
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
452
|
/**
|
|
368
453
|
* The overall result of one evaluation. `pending` posts the check-run as
|
|
369
454
|
* `in_progress` (no conclusion), so a PR waiting on a human sign-off shows as
|
|
@@ -398,9 +483,10 @@ declare function evaluatePolicy(pr: PullRequestFacts, checks?: readonly PolicyCh
|
|
|
398
483
|
/**
|
|
399
484
|
* Parse and validate a JSON facts document into `PullRequestFacts`.
|
|
400
485
|
* `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
|
|
486
|
+
* to none; `body`, `author`, `base`, `draft`, `headPushedAt`, and
|
|
487
|
+
* `signOffStatus` are optional and stay absent. With no `signOffs`, no sign-off
|
|
488
|
+
* label counts, and with no `headPushedAt`, no `UAT passed` does: trust fails
|
|
489
|
+
* closed. With no `signOffStatus`, the checks classify the PR themselves.
|
|
404
490
|
*/
|
|
405
491
|
declare function parseFacts(raw: string): PullRequestFacts;
|
|
406
492
|
|
|
@@ -418,6 +504,16 @@ declare function gatherFacts(target: PullRequestTarget): Promise<{
|
|
|
418
504
|
facts: PullRequestFacts;
|
|
419
505
|
headSha: string;
|
|
420
506
|
}>;
|
|
507
|
+
/**
|
|
508
|
+
* The open PRs whose head is `sha`. A `status` event carries a SHA, not a PR,
|
|
509
|
+
* so this is how a caller re-evaluates when pr-lifecycle posts its sign-off
|
|
510
|
+
* status. A PR whose head has since moved isn't returned: its newer head gets
|
|
511
|
+
* its own status. A failed lookup throws.
|
|
512
|
+
*/
|
|
513
|
+
declare function openPullRequestsAtHead(target: {
|
|
514
|
+
repo: string;
|
|
515
|
+
cwd?: string;
|
|
516
|
+
}, sha: string): Promise<number[]>;
|
|
421
517
|
/** Apply the label edits the checks planned (labels this package owns). */
|
|
422
518
|
declare function applyLabelEdits(target: PullRequestTarget, evaluation: PolicyEvaluation): Promise<void>;
|
|
423
519
|
|
|
@@ -430,4 +526,4 @@ declare function statusBody(evaluation: PolicyEvaluation, runUrl: string | undef
|
|
|
430
526
|
/** Post the verdict: the `pr-policy` check-run, then the matching commit status. */
|
|
431
527
|
declare function postVerdict(target: PullRequestTarget, headSha: string, evaluation: PolicyEvaluation): Promise<void>;
|
|
432
528
|
|
|
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 };
|
|
529
|
+
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, 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, parseTitle, postCheckRun, postVerdict, readSignOffStatus, selectChecks, sensitiveBumps, statusBody, titleCheck };
|
package/dist/index.js
CHANGED
|
@@ -22,7 +22,11 @@ import {
|
|
|
22
22
|
POLICY_OUTCOMES,
|
|
23
23
|
PR_POLICY_CHECK_NAME,
|
|
24
24
|
RELEASE_PLEASE_PENDING_LABEL,
|
|
25
|
+
SIGN_OFF_REQUIREMENTS,
|
|
26
|
+
SIGN_OFF_STATUS_CONTEXT,
|
|
27
|
+
SIGN_OFF_STATUS_VERSIONS,
|
|
25
28
|
TITLE_CHECK,
|
|
29
|
+
WAIVER_STATES,
|
|
26
30
|
applyLabelEdits,
|
|
27
31
|
buildReport,
|
|
28
32
|
checkRunBody,
|
|
@@ -39,16 +43,19 @@ import {
|
|
|
39
43
|
isManifestPath,
|
|
40
44
|
isWorkflowPath,
|
|
41
45
|
mergeBlockCheck,
|
|
46
|
+
openPullRequestsAtHead,
|
|
42
47
|
parseClaims,
|
|
43
48
|
parseFacts,
|
|
49
|
+
parseSignOffDescription,
|
|
44
50
|
parseTitle,
|
|
45
51
|
postCheckRun,
|
|
46
52
|
postVerdict,
|
|
53
|
+
readSignOffStatus,
|
|
47
54
|
selectChecks,
|
|
48
55
|
sensitiveBumps,
|
|
49
56
|
statusBody,
|
|
50
57
|
titleCheck
|
|
51
|
-
} from "./chunk-
|
|
58
|
+
} from "./chunk-5M7UKSAV.js";
|
|
52
59
|
export {
|
|
53
60
|
AMBIGUOUS_INDICATORS,
|
|
54
61
|
BLOCKED_LABEL,
|
|
@@ -73,7 +80,11 @@ export {
|
|
|
73
80
|
POLICY_OUTCOMES,
|
|
74
81
|
PR_POLICY_CHECK_NAME,
|
|
75
82
|
RELEASE_PLEASE_PENDING_LABEL,
|
|
83
|
+
SIGN_OFF_REQUIREMENTS,
|
|
84
|
+
SIGN_OFF_STATUS_CONTEXT,
|
|
85
|
+
SIGN_OFF_STATUS_VERSIONS,
|
|
76
86
|
TITLE_CHECK,
|
|
87
|
+
WAIVER_STATES,
|
|
77
88
|
applyLabelEdits,
|
|
78
89
|
buildReport,
|
|
79
90
|
checkRunBody,
|
|
@@ -90,11 +101,14 @@ export {
|
|
|
90
101
|
isManifestPath,
|
|
91
102
|
isWorkflowPath,
|
|
92
103
|
mergeBlockCheck,
|
|
104
|
+
openPullRequestsAtHead,
|
|
93
105
|
parseClaims,
|
|
94
106
|
parseFacts,
|
|
107
|
+
parseSignOffDescription,
|
|
95
108
|
parseTitle,
|
|
96
109
|
postCheckRun,
|
|
97
110
|
postVerdict,
|
|
111
|
+
readSignOffStatus,
|
|
98
112
|
selectChecks,
|
|
99
113
|
sensitiveBumps,
|
|
100
114
|
statusBody,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rmartz/pr-policy",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.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",
|