@rmartz/pr-policy 1.2.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 CHANGED
@@ -12,16 +12,16 @@ new required-status name.
12
12
 
13
13
  ## Checks
14
14
 
15
- | Check | Blocks when |
16
- | --------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
17
- | **Blocking labels** ([docs](docs/checks/merge-block.md)) | The PR carries `do not merge`, `dnm`, `blocked`, or `escalation needed` (shows as pending). |
18
- | **CI-change classification** ([docs](docs/checks/ci-change.md)) | A `.github/workflows/**` change loosens CI (a removed job, `continue-on-error`, a narrowed trigger, …) and no human has applied `CI change approved` (shows as pending). Owns `CI approval needed`. |
19
- | **Base branch** ([docs](docs/checks/base-branch.md)) | The PR targets a branch other than the default and it isn't a non-epic PR on an open epic's branch. A stacked PR waits for its base PR (shows as pending); a base no open PR heads blocks. |
20
- | **Title-type rules** ([docs](docs/checks/title.md)) | The squash title isn't a valid Conventional Commit, puts `!` on a non-functional type, disagrees with the `breaking change` label, or types a linter/formatter bump as a non-release, non-`ci` type. |
21
- | **UAT sign-off** ([docs](docs/checks/uat.md)) | The PR isn't docs, tests, CI, dependency-only, or repo metadata, and no trusted user has applied `no UAT needed`, or `UAT passed` (or `tested`) since the last push (shows as pending). |
22
- | **Dependabot claim verification** ([docs](docs/checks/dependabot.md)) | A Dependabot PR touches a non-dependency path, changes a dependency its description doesn't claim, pins a version other than the claimed one, or edits anything Dependabot never edits (a `package.json` script, a workflow step). |
23
- | Domain labels (backlog) | Never blocks. Additive path-glob → domain-label map. |
24
- | Milestone inheritance (backlog) | Never blocks. Issue → PR milestone. |
15
+ | Check | Blocks when |
16
+ | --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
17
+ | **Blocking labels** ([docs](docs/checks/merge-block.md)) | The PR carries `do not merge`, `dnm`, `blocked`, or `escalation needed` (shows as pending). |
18
+ | **CI-change classification** ([docs](docs/checks/ci-change.md)) | 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
@@ -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-XIDP7SRE.js";
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 evaluation2 = await evaluatePolicy(parseFacts(await readInput(values.facts)), checks);
56
- console.log(JSON.stringify(evaluation2, null, 2));
57
- return evaluation2.outcome === "failure" ? 1 : 0;
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
- if (!Number.isInteger(pr) || pr <= 0) {
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 target = { repo, pr };
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 (values.json) {
87
+ if (json) {
73
88
  console.log(JSON.stringify(evaluation, null, 2));
74
- return 0;
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
- const untrusted = approval.status === "untrusted" ? [
603
- {
604
- check: CI_CHANGE_CHECK,
605
- message: `\`${approval.label}\` doesn't count: ${approval.reason}.`,
606
- effect: "info"
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,
@@ -904,8 +990,7 @@ function isTestPath(path) {
904
990
  return parts.slice(0, -1).some((dir) => TEST_DIRS.has(dir)) || TEST_FILE.test(name);
905
991
  }
906
992
 
907
- // src/checks/uat/trivial.ts
908
- var TRIVIAL_CATEGORIES = ["docs", "tests", "ci", "dependencies", "metadata"];
993
+ // src/checks/path-kinds.ts
909
994
  var LOCKFILES = /* @__PURE__ */ new Set([
910
995
  "pnpm-lock.yaml",
911
996
  "package-lock.json",
@@ -918,53 +1003,115 @@ var LOCKFILES = /* @__PURE__ */ new Set([
918
1003
  "go.sum"
919
1004
  ]);
920
1005
  var ROOT_METADATA = /^(LICEN[CS]E|COPYING)(\..+)?$|^CODEOWNERS$|^\.(gitignore|gitattributes|editorconfig)$/;
921
- function isDependencyOnlyManifest(change) {
922
- if (change?.baseText === void 0 || change.headText === void 0) return false;
923
- const strip = (text) => {
924
- let parsed;
925
- try {
926
- parsed = JSON.parse(text);
927
- } catch {
928
- return void 0;
929
- }
930
- const record = asRecord(parsed);
931
- if (record === void 0) return void 0;
1006
+ var TOOLING_CONFIG = new RegExp(
1007
+ [
1008
+ String.raw`^eslint\.config\.[cm]?[jt]s$`,
1009
+ String.raw`^\.eslintrc(\..+)?$`,
1010
+ String.raw`^\.eslintignore$`,
1011
+ String.raw`^prettier\.config\.[cm]?[jt]s$`,
1012
+ String.raw`^\.prettierrc(\..+)?$`,
1013
+ String.raw`^\.prettierignore$`,
1014
+ String.raw`^(vitest|jest|playwright|cypress)\.config\.[cm]?[jt]s$`,
1015
+ String.raw`^vitest\.workspace\.[cm]?[jt]s$`,
1016
+ String.raw`^\.?ruff\.toml$`,
1017
+ String.raw`^\.flake8$`,
1018
+ String.raw`^\.?pylintrc$`,
1019
+ String.raw`^\.?mypy\.ini$`,
1020
+ String.raw`^pytest\.ini$`,
1021
+ String.raw`^\.coveragerc$`,
1022
+ String.raw`^\.markdownlint(-cli2)?(\..+)?$`,
1023
+ String.raw`^\.yamllint(\..+)?$`,
1024
+ String.raw`^\.pre-commit-config\.ya?ml$`,
1025
+ String.raw`^\.repo-hygiene\.ya?ml$`,
1026
+ String.raw`^\.releaserc(\..+)?$`,
1027
+ String.raw`^release\.config\.[cm]?[jt]s$`,
1028
+ String.raw`^commitlint\.config\.[cm]?[jt]s$`,
1029
+ String.raw`^\.commitlintrc(\..+)?$`,
1030
+ String.raw`^\.lintstagedrc(\..+)?$`,
1031
+ String.raw`^lint-staged\.config\.[cm]?[jt]s$`,
1032
+ String.raw`^\.?codecov\.ya?ml$`
1033
+ ].join("|")
1034
+ );
1035
+ var DEV_REQUIREMENTS_FILE = /^requirements[-_.](dev|test|tests|lint|ci)([-_.][\w.-]*)?\.txt$/;
1036
+ function basename2(path) {
1037
+ return path.slice(path.lastIndexOf("/") + 1);
1038
+ }
1039
+ function isLockfile(path) {
1040
+ return LOCKFILES.has(basename2(path));
1041
+ }
1042
+ function changedDependencies(change) {
1043
+ if (change.baseText === void 0 || change.headText === void 0) return void 0;
1044
+ const before = manifestVersions(change.path, change.baseText);
1045
+ const after = manifestVersions(change.path, change.headText);
1046
+ if (before === null || after === null) return void 0;
1047
+ const names = /* @__PURE__ */ new Set([...before.keys(), ...after.keys()]);
1048
+ return [...names].filter((name) => before.get(name) !== after.get(name));
1049
+ }
1050
+ function parseRecord(text) {
1051
+ try {
1052
+ return asRecord(JSON.parse(text));
1053
+ } catch {
1054
+ return void 0;
1055
+ }
1056
+ }
1057
+ function packageJsonScope(change) {
1058
+ if (change.baseText === void 0 || change.headText === void 0) return void 0;
1059
+ const before = parseRecord(change.baseText);
1060
+ const after = parseRecord(change.headText);
1061
+ if (before === void 0 || after === void 0) return void 0;
1062
+ const without = (record, fields) => {
932
1063
  const rest = { ...record };
933
- for (const field of [...DEPENDENCY_FIELDS, "packageManager"]) delete rest[field];
1064
+ for (const field of fields) delete rest[field];
934
1065
  return rest;
935
1066
  };
936
- const before = strip(change.baseText);
937
- const after = strip(change.headText);
938
- return before !== void 0 && after !== void 0 && deepEqual(before, after);
1067
+ const versionFields = [...DEPENDENCY_FIELDS, "packageManager"];
1068
+ if (!deepEqual(without(before, versionFields), without(after, versionFields))) return void 0;
1069
+ const runtimeFields = DEPENDENCY_FIELDS.filter((field) => field !== "devDependencies");
1070
+ const sensitive = new Set(CI_SENSITIVE_PACKAGES);
1071
+ for (const field of runtimeFields) {
1072
+ const was = asRecord(before[field]) ?? {};
1073
+ const now = asRecord(after[field]) ?? {};
1074
+ const names = /* @__PURE__ */ new Set([...Object.keys(was), ...Object.keys(now)]);
1075
+ for (const name of names) {
1076
+ if (!deepEqual(was[name], now[name]) && !sensitive.has(name)) return "runtime";
1077
+ }
1078
+ }
1079
+ return "tooling";
1080
+ }
1081
+ function requirementsScope(change) {
1082
+ if (change === void 0) return "runtime";
1083
+ if (DEV_REQUIREMENTS_FILE.test(basename2(change.path))) return "tooling";
1084
+ const changed = changedDependencies(change);
1085
+ const sensitive = new Set(CI_SENSITIVE_PACKAGES);
1086
+ return changed !== void 0 && changed.every((name) => sensitive.has(name)) ? "tooling" : "runtime";
939
1087
  }
940
- function categoryOf(path, pr) {
1088
+ function manifestKind(path, context) {
1089
+ const change = context.manifestChanges.find((file) => file.path === path);
1090
+ if (basename2(path) !== "package.json") {
1091
+ return requirementsScope(change) === "tooling" ? "tooling-manifest" : "runtime-manifest";
1092
+ }
1093
+ if (change === void 0) return void 0;
1094
+ const scope = packageJsonScope(change);
1095
+ if (scope === void 0) return void 0;
1096
+ return scope === "tooling" ? "tooling-manifest" : "runtime-manifest";
1097
+ }
1098
+ function pathKind(path, context) {
941
1099
  const parts = path.split("/");
942
- const name = parts[parts.length - 1] ?? "";
1100
+ const name = parts.at(-1) ?? "";
943
1101
  if (name.endsWith(".md") || parts[0] === "docs") return "docs";
944
1102
  if (isTestPath(path)) return "tests";
945
1103
  if (path.startsWith(".github/workflows/") || path.startsWith(".github/actions/")) {
946
- const change = pr.workflowChanges.find((file) => file.path === path);
1104
+ const change = context.workflowChanges.find((file) => file.path === path);
947
1105
  return change !== void 0 && isShippedReusableWorkflow(change) ? void 0 : "ci";
948
1106
  }
949
- if (LOCKFILES.has(name)) return "dependencies";
950
- if (isManifestPath(path)) {
951
- if (name !== "package.json") return "dependencies";
952
- const change = pr.manifestChanges.find((file) => file.path === path);
953
- return isDependencyOnlyManifest(change) ? "dependencies" : void 0;
954
- }
1107
+ if (LOCKFILES.has(name)) return "lockfile";
1108
+ if (isManifestPath(path)) return manifestKind(path, context);
955
1109
  if (parts[0] === ".github" || parts[0] === ".vscode") return "metadata";
956
1110
  if (parts.length === 1 && ROOT_METADATA.test(name)) return "metadata";
1111
+ if (TOOLING_CONFIG.test(name)) return "tooling-config";
1112
+ if (parts[0] === "scripts" && parts.length > 1) return "repo-script";
957
1113
  return void 0;
958
1114
  }
959
- function trivialCategories(pr) {
960
- const found = /* @__PURE__ */ new Set();
961
- for (const path of pr.changedFiles) {
962
- const category = categoryOf(path, pr);
963
- if (category === void 0) return void 0;
964
- found.add(category);
965
- }
966
- return TRIVIAL_CATEGORIES.filter((category) => found.has(category));
967
- }
968
1115
 
969
1116
  // src/checks/dependabot/paths.ts
970
1117
  var OTHER_ECOSYSTEM_FILES = /* @__PURE__ */ new Set([
@@ -986,8 +1133,8 @@ var DOCKERFILE = /^(Dockerfile|Containerfile)([.-].+)?$|\.Dockerfile$|^docker-co
986
1133
  function dependencyPathKind(path) {
987
1134
  if (isWorkflowPath(path)) return "workflow";
988
1135
  if (isManifestPath(path)) return "manifest";
1136
+ if (isLockfile(path)) return "lockfile";
989
1137
  const name = path.slice(path.lastIndexOf("/") + 1);
990
- if (LOCKFILES.has(name)) return "lockfile";
991
1138
  if (OTHER_ECOSYSTEM_FILES.has(name) || DOCKERFILE.test(name)) return "other-ecosystem";
992
1139
  return void 0;
993
1140
  }
@@ -1190,13 +1337,23 @@ function majorBumps(changes) {
1190
1337
  function isMarkdownPath(path) {
1191
1338
  return path.toLowerCase().endsWith(".md");
1192
1339
  }
1340
+ var CI_KINDS = /* @__PURE__ */ new Set([
1341
+ "docs",
1342
+ "tests",
1343
+ "ci",
1344
+ "tooling-config",
1345
+ "repo-script",
1346
+ "lockfile",
1347
+ "tooling-manifest",
1348
+ "metadata"
1349
+ ]);
1193
1350
  var quote = (paths) => {
1194
1351
  const shown = paths.slice(0, 5).map((path) => `\`${path}\``);
1195
1352
  if (paths.length > 5) shown.push(`and ${paths.length - 5} more`);
1196
1353
  return shown.join(", ");
1197
1354
  };
1198
- function typePathViolation(type, changedFiles) {
1199
- const paths = [...new Set(changedFiles)];
1355
+ function typePathViolation(type, facts) {
1356
+ const paths = [...new Set(facts.changedFiles)];
1200
1357
  if (type === "docs") {
1201
1358
  const offending = paths.filter((path) => !isMarkdownPath(path));
1202
1359
  if (offending.length === 0) return void 0;
@@ -1212,6 +1369,14 @@ function typePathViolation(type, changedFiles) {
1212
1369
  if (offending.length === 0) return void 0;
1213
1370
  return `A \`test\` PR may change only test files and docs, so it locks in current behaviour without changing it, but this one changes ${quote(offending)}. \`test\` doesn't release, so that change would never ship. Retitle to the type of the non-test change, or split it into its own PR.`;
1214
1371
  }
1372
+ if (type === "ci") {
1373
+ const offending = paths.filter((path) => {
1374
+ const kind = pathKind(path, facts);
1375
+ return kind === void 0 || !CI_KINDS.has(kind);
1376
+ });
1377
+ if (offending.length === 0) return void 0;
1378
+ return `A \`ci\` PR may change only CI and tooling (\`.github/\`, linter, formatter, and test-runner config, \`scripts/\`, lockfiles, dev-tool versions, tests, and docs), but this one changes ${quote(offending)}. A \`package.json\` counts only when nothing but dev-dependency or lint/format tool versions changed. \`ci\` doesn't release and needs no UAT, so that change would ship untested in someone else's release. Retitle to the type of that change, or split it into its own PR.`;
1379
+ }
1215
1380
  return void 0;
1216
1381
  }
1217
1382
 
@@ -1318,7 +1483,7 @@ function titleRules(pr, text) {
1318
1483
  );
1319
1484
  }
1320
1485
  }
1321
- const pathViolation = typePathViolation(title.type, pr.changedFiles);
1486
+ const pathViolation = typePathViolation(title.type, pr);
1322
1487
  if (pathViolation !== void 0) findings.push(block2(pathViolation));
1323
1488
  const mayRetitle = !functional && title.type !== "ci";
1324
1489
  const workflows = substantiveWorkflowChanges(pr.workflowChanges);
@@ -1383,6 +1548,35 @@ var baseBranchCheck = {
1383
1548
  evaluate: async (pr) => decideBaseBranch(pr)
1384
1549
  };
1385
1550
 
1551
+ // src/checks/uat/trivial.ts
1552
+ var TRIVIAL_CATEGORIES = ["docs", "tests", "ci", "dependencies", "metadata"];
1553
+ function categoryOf(kind) {
1554
+ switch (kind) {
1555
+ case "docs":
1556
+ case "tests":
1557
+ case "ci":
1558
+ case "metadata":
1559
+ return kind;
1560
+ case "lockfile":
1561
+ case "tooling-manifest":
1562
+ case "runtime-manifest":
1563
+ return "dependencies";
1564
+ case "tooling-config":
1565
+ case "repo-script":
1566
+ case void 0:
1567
+ return void 0;
1568
+ }
1569
+ }
1570
+ function trivialCategories(pr) {
1571
+ const found = /* @__PURE__ */ new Set();
1572
+ for (const path of pr.changedFiles) {
1573
+ const category = categoryOf(pathKind(path, pr));
1574
+ if (category === void 0) return void 0;
1575
+ found.add(category);
1576
+ }
1577
+ return TRIVIAL_CATEGORIES.filter((category) => found.has(category));
1578
+ }
1579
+
1386
1580
  // src/checks/uat/index.ts
1387
1581
  var UAT_CHECK = "uat";
1388
1582
  var PASSING_LABELS = [UAT_PASSED_LABEL, LEGACY_UAT_PASSED_LABEL, NO_UAT_NEEDED_LABEL];
@@ -1390,6 +1584,9 @@ var HEAD_BOUND_SIGN_OFFS = [UAT_PASSED_LABEL, LEGACY_UAT_PASSED_LABEL];
1390
1584
  function info2(message) {
1391
1585
  return { check: UAT_CHECK, message, effect: "info" };
1392
1586
  }
1587
+ function hold(message) {
1588
+ return { check: UAT_CHECK, message, effect: "hold" };
1589
+ }
1393
1590
  function staleReason(pr, label) {
1394
1591
  if (!HEAD_BOUND_SIGN_OFFS.includes(label)) return void 0;
1395
1592
  if (pr.headPushedAt === void 0) {
@@ -1401,40 +1598,68 @@ function staleReason(pr, label) {
1401
1598
  return "it was applied before the current head was pushed, and a new head needs a person to test it again";
1402
1599
  }
1403
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) {
1404
1629
  const categories = trivialCategories(pr);
1405
1630
  if (categories !== void 0) {
1406
1631
  const kinds = categories.length > 0 ? categories.join(", ") : "no files";
1407
- return { findings: [info2(`No UAT needed: the PR changes only ${kinds}.`)] };
1632
+ return [info2(`No UAT needed: the PR changes only ${kinds}.`)];
1408
1633
  }
1409
1634
  if (parseTitle(pr.title)?.type === "refactor") {
1410
- return { findings: [info2("No UAT needed: a refactor changes no behaviour.")] };
1635
+ return [info2("No UAT needed: a refactor changes no behaviour.")];
1411
1636
  }
1637
+ return signOffFindings(pr, []);
1638
+ }
1639
+ function signOffFindings(pr, setAside) {
1412
1640
  const stale = PASSING_LABELS.flatMap((label) => {
1413
- const reason = pr.labels.includes(label) ? staleReason(pr, label) : void 0;
1641
+ if (!pr.labels.includes(label)) return [];
1642
+ const reason = setAside.find((entry) => entry.label === label)?.reason ?? staleReason(pr, label);
1414
1643
  return reason === void 0 ? [] : [{ label, reason }];
1415
1644
  });
1416
1645
  const current = PASSING_LABELS.filter((label) => !stale.some((entry) => entry.label === label));
1417
1646
  const state = signOffState(pr, current);
1418
1647
  if (state.status === "trusted") {
1419
- return {
1420
- findings: [
1421
- {
1422
- ...info2(`UAT signed off with \`${state.label}\` by \`${state.appliedBy.login}\``),
1423
- headline: true
1424
- }
1425
- ]
1426
- };
1648
+ return [
1649
+ {
1650
+ ...info2(`UAT signed off with \`${state.label}\` by \`${state.appliedBy.login}\``),
1651
+ headline: true
1652
+ }
1653
+ ];
1427
1654
  }
1428
- const hold = {
1429
- check: UAT_CHECK,
1430
- message: `Waiting for UAT. A person applies \`${UAT_PASSED_LABEL}\` after testing, or the review agent or a person applies \`${NO_UAT_NEEDED_LABEL}\`.`,
1431
- effect: "hold"
1432
- };
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
+ );
1433
1658
  const why = stale.map(({ label, reason }) => info2(`\`${label}\` doesn't count: ${reason}.`));
1434
1659
  if (state.status === "untrusted") {
1435
1660
  why.push(info2(`\`${state.label}\` doesn't count: ${state.reason}.`));
1436
1661
  }
1437
- return { findings: [hold, ...why] };
1662
+ return [waiting, ...why];
1438
1663
  }
1439
1664
  var uatCheck = {
1440
1665
  name: UAT_CHECK,
@@ -1570,6 +1795,17 @@ function parseBase(value) {
1570
1795
  }
1571
1796
  return { branch, defaultBranch, headOf: (headOf ?? []).map(parseOpenPullRequest) };
1572
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
+ }
1573
1809
  function parseFacts(raw) {
1574
1810
  const parsed = JSON.parse(raw);
1575
1811
  if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
@@ -1586,7 +1822,8 @@ function parseFacts(raw) {
1586
1822
  workflowChanges,
1587
1823
  manifestChanges,
1588
1824
  signOffs,
1589
- headPushedAt
1825
+ headPushedAt,
1826
+ signOffStatus
1590
1827
  } = parsed;
1591
1828
  if (typeof title !== "string") throw new Error("facts.title must be a string");
1592
1829
  if (!isOptionalString(body)) throw new Error("facts.body must be a string");
@@ -1611,6 +1848,8 @@ function parseFacts(raw) {
1611
1848
  if (parsedBase !== void 0) pr.base = parsedBase;
1612
1849
  if (draft !== void 0) pr.draft = draft;
1613
1850
  if (headPushedAt !== void 0) pr.headPushedAt = headPushedAt;
1851
+ const parsedStatus = parseSignOffStatus(signOffStatus);
1852
+ if (parsedStatus !== void 0) pr.signOffStatus = parsedStatus;
1614
1853
  return pr;
1615
1854
  }
1616
1855
 
@@ -1909,6 +2148,33 @@ async function gatherSignOffs(target, labels) {
1909
2148
  );
1910
2149
  }
1911
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
+
1912
2178
  // src/github/pull-request.ts
1913
2179
  async function ghJson(target, argv) {
1914
2180
  const out = await ghCall({ argv }, null, { cwd: target.cwd });
@@ -2021,8 +2287,29 @@ async function gatherFacts(target) {
2021
2287
  const pushedAt = await gatherHeadPushedAt(target, headSha);
2022
2288
  if (pushedAt !== void 0) facts.headPushedAt = pushedAt;
2023
2289
  }
2290
+ const signOffStatus = await gatherSignOffStatus(target, headSha);
2291
+ if (signOffStatus !== void 0) facts.signOffStatus = signOffStatus;
2024
2292
  return { facts, headSha };
2025
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
+ }
2026
2313
  async function applyLabelEdits(target, evaluation) {
2027
2314
  if (evaluation.labelsToAdd.length > 0) {
2028
2315
  await addLabels(target.repo, target.pr, evaluation.labelsToAdd, { cwd: target.cwd });
@@ -2034,6 +2321,7 @@ async function applyLabelEdits(target, evaluation) {
2034
2321
 
2035
2322
  export {
2036
2323
  PR_POLICY_CHECK_NAME,
2324
+ SIGN_OFF_STATUS_CONTEXT,
2037
2325
  CI_APPROVAL_NEEDED_LABEL,
2038
2326
  CI_CHANGE_APPROVED_LABEL,
2039
2327
  DO_NOT_MERGE_LABEL,
@@ -2044,6 +2332,11 @@ export {
2044
2332
  BREAKING_CHANGE_LABEL,
2045
2333
  HOTFIX_LABEL,
2046
2334
  RELEASE_PLEASE_PENDING_LABEL,
2335
+ SIGN_OFF_STATUS_VERSIONS,
2336
+ SIGN_OFF_REQUIREMENTS,
2337
+ WAIVER_STATES,
2338
+ parseSignOffDescription,
2339
+ readSignOffStatus,
2047
2340
  LOOSENING_INDICATORS,
2048
2341
  AMBIGUOUS_INDICATORS,
2049
2342
  CI_CHANGE_VERDICTS,
@@ -2082,5 +2375,6 @@ export {
2082
2375
  statusBody,
2083
2376
  postVerdict,
2084
2377
  gatherFacts,
2378
+ openPullRequestsAtHead,
2085
2379
  applyLabelEdits
2086
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
- /** Decide the findings and label edits for one classified PR. */
211
- declare function decideCiChange(classification: Classification, pr: Pick<PullRequestFacts, 'labels' | 'signOffs'>): CheckResult;
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`, and `headPushedAt` are optional and
402
- * stay absent. With no `signOffs`, no sign-off label counts, and with no
403
- * `headPushedAt`, no `UAT passed` does: trust fails closed.
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-XIDP7SRE.js";
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.2.0",
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",