@rmartz/pr-policy 1.1.0 → 1.2.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 +1 -1
- package/dist/bin/pr-policy.js +1 -1
- package/dist/{chunk-YCBII74A.js → chunk-XIDP7SRE.js} +73 -10
- package/dist/index.d.ts +12 -2
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ new required-status name.
|
|
|
18
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
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
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 `UAT passed` (or `tested`)
|
|
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
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
23
|
| Domain labels (backlog) | Never blocks. Additive path-glob → domain-label map. |
|
|
24
24
|
| Milestone inheritance (backlog) | Never blocks. Issue → PR milestone. |
|
package/dist/bin/pr-policy.js
CHANGED
|
@@ -1386,9 +1386,20 @@ var baseBranchCheck = {
|
|
|
1386
1386
|
// src/checks/uat/index.ts
|
|
1387
1387
|
var UAT_CHECK = "uat";
|
|
1388
1388
|
var PASSING_LABELS = [UAT_PASSED_LABEL, LEGACY_UAT_PASSED_LABEL, NO_UAT_NEEDED_LABEL];
|
|
1389
|
+
var HEAD_BOUND_SIGN_OFFS = [UAT_PASSED_LABEL, LEGACY_UAT_PASSED_LABEL];
|
|
1389
1390
|
function info2(message) {
|
|
1390
1391
|
return { check: UAT_CHECK, message, effect: "info" };
|
|
1391
1392
|
}
|
|
1393
|
+
function staleReason(pr, label) {
|
|
1394
|
+
if (!HEAD_BOUND_SIGN_OFFS.includes(label)) return void 0;
|
|
1395
|
+
if (pr.headPushedAt === void 0) {
|
|
1396
|
+
return "the time the current head was pushed is unknown, so it may predate the head";
|
|
1397
|
+
}
|
|
1398
|
+
const appliedAt = pr.signOffs.find((signOff) => signOff.label === label)?.appliedAt;
|
|
1399
|
+
if (appliedAt === void 0) return "the time it was applied is unknown";
|
|
1400
|
+
if (Date.parse(appliedAt) > Date.parse(pr.headPushedAt)) return void 0;
|
|
1401
|
+
return "it was applied before the current head was pushed, and a new head needs a person to test it again";
|
|
1402
|
+
}
|
|
1392
1403
|
function decideUat(pr) {
|
|
1393
1404
|
const categories = trivialCategories(pr);
|
|
1394
1405
|
if (categories !== void 0) {
|
|
@@ -1398,7 +1409,12 @@ function decideUat(pr) {
|
|
|
1398
1409
|
if (parseTitle(pr.title)?.type === "refactor") {
|
|
1399
1410
|
return { findings: [info2("No UAT needed: a refactor changes no behaviour.")] };
|
|
1400
1411
|
}
|
|
1401
|
-
const
|
|
1412
|
+
const stale = PASSING_LABELS.flatMap((label) => {
|
|
1413
|
+
const reason = pr.labels.includes(label) ? staleReason(pr, label) : void 0;
|
|
1414
|
+
return reason === void 0 ? [] : [{ label, reason }];
|
|
1415
|
+
});
|
|
1416
|
+
const current = PASSING_LABELS.filter((label) => !stale.some((entry) => entry.label === label));
|
|
1417
|
+
const state = signOffState(pr, current);
|
|
1402
1418
|
if (state.status === "trusted") {
|
|
1403
1419
|
return {
|
|
1404
1420
|
findings: [
|
|
@@ -1414,7 +1430,10 @@ function decideUat(pr) {
|
|
|
1414
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}\`.`,
|
|
1415
1431
|
effect: "hold"
|
|
1416
1432
|
};
|
|
1417
|
-
const why =
|
|
1433
|
+
const why = stale.map(({ label, reason }) => info2(`\`${label}\` doesn't count: ${reason}.`));
|
|
1434
|
+
if (state.status === "untrusted") {
|
|
1435
|
+
why.push(info2(`\`${state.label}\` doesn't count: ${state.reason}.`));
|
|
1436
|
+
}
|
|
1418
1437
|
return { findings: [hold, ...why] };
|
|
1419
1438
|
}
|
|
1420
1439
|
var uatCheck = {
|
|
@@ -1454,10 +1473,10 @@ function buildReport(findings) {
|
|
|
1454
1473
|
outcome = "pending";
|
|
1455
1474
|
title = `Waiting on ${plural(holds.length, "human sign-off")}`;
|
|
1456
1475
|
}
|
|
1457
|
-
const
|
|
1476
|
+
const lines2 = findings.map(
|
|
1458
1477
|
(finding) => `- ${ICONS[finding.effect]} **${finding.check}**: ${finding.message}`
|
|
1459
1478
|
);
|
|
1460
|
-
const summary =
|
|
1479
|
+
const summary = lines2.length > 0 ? lines2.join("\n") : "No policy findings.";
|
|
1461
1480
|
return { outcome, title, summary, findings };
|
|
1462
1481
|
}
|
|
1463
1482
|
|
|
@@ -1511,10 +1530,14 @@ function parseSignOffs(value) {
|
|
|
1511
1530
|
return value.map((item, index) => {
|
|
1512
1531
|
const where = `facts.signOffs[${index}]`;
|
|
1513
1532
|
if (typeof item !== "object" || item === null) throw new Error(`${where} must be an object`);
|
|
1514
|
-
const { label, appliedBy } = item;
|
|
1533
|
+
const { label, appliedBy, appliedAt } = item;
|
|
1515
1534
|
if (typeof label !== "string") throw new Error(`${where}.label must be a string`);
|
|
1535
|
+
if (!isOptionalString(appliedAt)) throw new Error(`${where}.appliedAt must be a string`);
|
|
1536
|
+
const signOff = { label };
|
|
1516
1537
|
const actor = parseActor(`${where}.appliedBy`, appliedBy);
|
|
1517
|
-
|
|
1538
|
+
if (actor !== void 0) signOff.appliedBy = actor;
|
|
1539
|
+
if (appliedAt !== void 0) signOff.appliedAt = appliedAt;
|
|
1540
|
+
return signOff;
|
|
1518
1541
|
});
|
|
1519
1542
|
}
|
|
1520
1543
|
function parseAuthor(value) {
|
|
@@ -1562,10 +1585,12 @@ function parseFacts(raw) {
|
|
|
1562
1585
|
changedFiles,
|
|
1563
1586
|
workflowChanges,
|
|
1564
1587
|
manifestChanges,
|
|
1565
|
-
signOffs
|
|
1588
|
+
signOffs,
|
|
1589
|
+
headPushedAt
|
|
1566
1590
|
} = parsed;
|
|
1567
1591
|
if (typeof title !== "string") throw new Error("facts.title must be a string");
|
|
1568
1592
|
if (!isOptionalString(body)) throw new Error("facts.body must be a string");
|
|
1593
|
+
if (!isOptionalString(headPushedAt)) throw new Error("facts.headPushedAt must be a string");
|
|
1569
1594
|
if (draft !== void 0 && typeof draft !== "boolean") {
|
|
1570
1595
|
throw new Error("facts.draft must be a boolean");
|
|
1571
1596
|
}
|
|
@@ -1585,6 +1610,7 @@ function parseFacts(raw) {
|
|
|
1585
1610
|
if (parsedAuthor !== void 0) pr.author = parsedAuthor;
|
|
1586
1611
|
if (parsedBase !== void 0) pr.base = parsedBase;
|
|
1587
1612
|
if (draft !== void 0) pr.draft = draft;
|
|
1613
|
+
if (headPushedAt !== void 0) pr.headPushedAt = headPushedAt;
|
|
1588
1614
|
return pr;
|
|
1589
1615
|
}
|
|
1590
1616
|
|
|
@@ -1796,6 +1822,38 @@ async function postVerdict(target, headSha, evaluation) {
|
|
|
1796
1822
|
await postCommitStatus(target, headSha, evaluation);
|
|
1797
1823
|
}
|
|
1798
1824
|
|
|
1825
|
+
// src/github/head-push.ts
|
|
1826
|
+
async function lines(target, endpoint, jq) {
|
|
1827
|
+
const out = await ghCall({ argv: ["gh", "api", "--paginate", endpoint, "--jq", jq] }, null, {
|
|
1828
|
+
cwd: target.cwd
|
|
1829
|
+
});
|
|
1830
|
+
if (out === null) throw new Error(`could not read ${endpoint}`);
|
|
1831
|
+
return out.split("\n").filter((line) => line.trim() !== "");
|
|
1832
|
+
}
|
|
1833
|
+
function times(stamps) {
|
|
1834
|
+
return stamps.map((stamp) => Date.parse(stamp)).filter((ms) => !Number.isNaN(ms));
|
|
1835
|
+
}
|
|
1836
|
+
async function gatherHeadPushedAt(target, headSha) {
|
|
1837
|
+
const forcePushes = times(
|
|
1838
|
+
await lines(
|
|
1839
|
+
target,
|
|
1840
|
+
`repos/${target.repo}/issues/${target.pr}/events`,
|
|
1841
|
+
'.[] | select(.event == "head_ref_force_pushed") | .created_at'
|
|
1842
|
+
)
|
|
1843
|
+
);
|
|
1844
|
+
const suites = times(
|
|
1845
|
+
await lines(
|
|
1846
|
+
target,
|
|
1847
|
+
`repos/${target.repo}/commits/${headSha}/check-suites`,
|
|
1848
|
+
".check_suites[].created_at"
|
|
1849
|
+
)
|
|
1850
|
+
);
|
|
1851
|
+
const candidates = [...forcePushes];
|
|
1852
|
+
if (suites.length > 0) candidates.push(Math.min(...suites));
|
|
1853
|
+
if (candidates.length === 0) return void 0;
|
|
1854
|
+
return new Date(Math.max(...candidates)).toISOString();
|
|
1855
|
+
}
|
|
1856
|
+
|
|
1799
1857
|
// src/github/sign-offs.ts
|
|
1800
1858
|
async function listLabelEvents(target) {
|
|
1801
1859
|
const out = await ghCall(
|
|
@@ -1806,7 +1864,7 @@ async function listLabelEvents(target) {
|
|
|
1806
1864
|
"--paginate",
|
|
1807
1865
|
`repos/${target.repo}/issues/${target.pr}/events`,
|
|
1808
1866
|
"--jq",
|
|
1809
|
-
'.[] | select(.event == "labeled") | {label: .label.name, login: .actor.login, type: .actor.type}'
|
|
1867
|
+
'.[] | select(.event == "labeled") | {label: .label.name, login: .actor.login, type: .actor.type, at: .created_at}'
|
|
1810
1868
|
]
|
|
1811
1869
|
},
|
|
1812
1870
|
null,
|
|
@@ -1842,10 +1900,11 @@ async function gatherSignOffs(target, labels) {
|
|
|
1842
1900
|
return Promise.all(
|
|
1843
1901
|
present.map(async (label) => {
|
|
1844
1902
|
const event = latest.get(label);
|
|
1845
|
-
if (event === void 0
|
|
1903
|
+
if (event === void 0) return { label };
|
|
1904
|
+
if (event.login === null) return { label, appliedAt: event.at };
|
|
1846
1905
|
const type = event.type ?? "unknown actor";
|
|
1847
1906
|
const permission = type === "User" ? await lookupPermission(target, event.login) : "none";
|
|
1848
|
-
return { label, appliedBy: { login: event.login, type, permission } };
|
|
1907
|
+
return { label, appliedBy: { login: event.login, type, permission }, appliedAt: event.at };
|
|
1849
1908
|
})
|
|
1850
1909
|
);
|
|
1851
1910
|
}
|
|
@@ -1958,6 +2017,10 @@ async function gatherFacts(target) {
|
|
|
1958
2017
|
manifestChanges,
|
|
1959
2018
|
signOffs: await gatherSignOffs(target, labels)
|
|
1960
2019
|
};
|
|
2020
|
+
if (HEAD_BOUND_SIGN_OFFS.some((label) => labels.includes(label))) {
|
|
2021
|
+
const pushedAt = await gatherHeadPushedAt(target, headSha);
|
|
2022
|
+
if (pushedAt !== void 0) facts.headPushedAt = pushedAt;
|
|
2023
|
+
}
|
|
1961
2024
|
return { facts, headSha };
|
|
1962
2025
|
}
|
|
1963
2026
|
async function applyLabelEdits(target, evaluation) {
|
package/dist/index.d.ts
CHANGED
|
@@ -30,6 +30,8 @@ interface LabelActor {
|
|
|
30
30
|
interface SignOff {
|
|
31
31
|
label: string;
|
|
32
32
|
appliedBy?: LabelActor;
|
|
33
|
+
/** When its latest `labeled` event happened (ISO 8601), as GitHub records it. */
|
|
34
|
+
appliedAt?: string;
|
|
33
35
|
}
|
|
34
36
|
/** The account that opened a PR, as GitHub reports it (`dependabot[bot]`, `Bot`). */
|
|
35
37
|
interface PullRequestAuthor {
|
|
@@ -84,6 +86,13 @@ interface PullRequestFacts {
|
|
|
84
86
|
manifestChanges: readonly FileChange[];
|
|
85
87
|
/** Who applied each sign-off label present on the PR. */
|
|
86
88
|
signOffs: readonly SignOff[];
|
|
89
|
+
/**
|
|
90
|
+
* When the current head was pushed (ISO 8601), from times the author can't
|
|
91
|
+
* forge: the latest force-push event and the head commit's earliest check
|
|
92
|
+
* suite, never a commit date. `gatherFacts` sets it whenever a head-bound
|
|
93
|
+
* sign-off (`UAT passed`, `tested`) is on the PR; absent, those don't count.
|
|
94
|
+
*/
|
|
95
|
+
headPushedAt?: string;
|
|
87
96
|
}
|
|
88
97
|
/**
|
|
89
98
|
* What a finding does to the `pr-policy` check-run:
|
|
@@ -389,8 +398,9 @@ declare function evaluatePolicy(pr: PullRequestFacts, checks?: readonly PolicyCh
|
|
|
389
398
|
/**
|
|
390
399
|
* Parse and validate a JSON facts document into `PullRequestFacts`.
|
|
391
400
|
* `workflowChanges`, `manifestChanges`, and `signOffs` are optional and default
|
|
392
|
-
* to none; `body`, `author`, `base`, and `
|
|
393
|
-
* `signOffs`, no sign-off label counts
|
|
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.
|
|
394
404
|
*/
|
|
395
405
|
declare function parseFacts(raw: string): PullRequestFacts;
|
|
396
406
|
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rmartz/pr-policy",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.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",
|