@rmartz/pr-policy 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/bin/pr-policy.js +11 -3
- package/dist/{chunk-5M7UKSAV.js → chunk-RHHCFDMG.js} +57 -18
- package/dist/index.d.ts +36 -6
- package/dist/index.js +5 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -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 --pr 12 --repo rmartz/pr-policy --sign-off-status-creators "rmartz-merge-bot[bot]" # trust that App's pr-lifecycle/sign-off status
|
|
44
45
|
pr-policy evaluate --sha <sha> --repo rmartz/pr-policy # re-run every open PR at that head (status trigger)
|
|
45
46
|
```
|
|
46
47
|
|
package/dist/bin/pr-policy.js
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
postVerdict,
|
|
9
9
|
resolveRepoTarget,
|
|
10
10
|
selectChecks
|
|
11
|
-
} from "../chunk-
|
|
11
|
+
} from "../chunk-RHHCFDMG.js";
|
|
12
12
|
|
|
13
13
|
// src/bin/pr-policy.ts
|
|
14
14
|
import { readFile } from "fs/promises";
|
|
@@ -27,7 +27,11 @@ var USAGE = `Usage:
|
|
|
27
27
|
--facts Evaluate an offline JSON facts document ("-" reads stdin) and print
|
|
28
28
|
the evaluation. Exits 1 only on "failure" ("pending" exits 0).
|
|
29
29
|
--skip-uat
|
|
30
|
-
Don't run the UAT gate, for a repo with no user-acceptance testing
|
|
30
|
+
Don't run the UAT gate, for a repo with no user-acceptance testing.
|
|
31
|
+
--sign-off-status-creators <login,...>
|
|
32
|
+
GitHub App logins trusted to post the pr-lifecycle/sign-off status,
|
|
33
|
+
e.g. rmartz-merge-bot[bot]. Exact matches only; github-actions[bot]
|
|
34
|
+
is refused. A person who could merge is always trusted.`;
|
|
31
35
|
async function readInput(path) {
|
|
32
36
|
if (path !== "-") return readFile(path, "utf8");
|
|
33
37
|
const chunks = [];
|
|
@@ -45,6 +49,7 @@ async function main(argv) {
|
|
|
45
49
|
repo: { type: "string" },
|
|
46
50
|
json: { type: "boolean" },
|
|
47
51
|
"skip-uat": { type: "boolean" },
|
|
52
|
+
"sign-off-status-creators": { type: "string" },
|
|
48
53
|
help: { type: "boolean", short: "h" }
|
|
49
54
|
}
|
|
50
55
|
});
|
|
@@ -56,7 +61,10 @@ async function main(argv) {
|
|
|
56
61
|
console.error(USAGE);
|
|
57
62
|
return 2;
|
|
58
63
|
}
|
|
59
|
-
const checks = selectChecks({
|
|
64
|
+
const checks = selectChecks({
|
|
65
|
+
skipUat: values["skip-uat"],
|
|
66
|
+
signOffStatusCreators: (values["sign-off-status-creators"] ?? "").split(",")
|
|
67
|
+
});
|
|
60
68
|
if (values.facts !== void 0) {
|
|
61
69
|
const evaluation = await evaluatePolicy(parseFacts(await readInput(values.facts)), checks);
|
|
62
70
|
console.log(JSON.stringify(evaluation, null, 2));
|
|
@@ -88,16 +88,44 @@ function parseSignOffDescription(description) {
|
|
|
88
88
|
if (waiver === void 0) return "`requirement=uat` needs `waiver=current`, `stale`, or `absent`";
|
|
89
89
|
return { requirement, loosening, waiver };
|
|
90
90
|
}
|
|
91
|
-
|
|
91
|
+
var GITHUB_ACTIONS_BOT = "github-actions[bot]";
|
|
92
|
+
var CREATORS_OPTION = "`sign-off-status-creators` (CLI `--sign-off-status-creators`)";
|
|
93
|
+
function parseSignOffStatusCreators(entries) {
|
|
94
|
+
const logins = entries.map((entry) => entry.trim()).filter((entry) => entry !== "");
|
|
95
|
+
for (const login of logins) {
|
|
96
|
+
if (login.toLowerCase() === GITHUB_ACTIONS_BOT) {
|
|
97
|
+
throw new Error(
|
|
98
|
+
`${GITHUB_ACTIONS_BOT} can't be a sign-off status creator: any workflow in the repo can post as it.`
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
if (!login.endsWith("[bot]")) {
|
|
102
|
+
throw new Error(
|
|
103
|
+
`\`${login}\` isn't a GitHub App login: sign-off status creators end in \`[bot]\`. People are trusted by their repo permission, without being named.`
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return [...new Set(logins)];
|
|
108
|
+
}
|
|
109
|
+
function untrustedCreator(creator, trustedBots) {
|
|
110
|
+
if (creator.type === "Bot") {
|
|
111
|
+
if (trustedBots.includes(creator.login)) return void 0;
|
|
112
|
+
if (creator.login.toLowerCase() === GITHUB_ACTIONS_BOT) {
|
|
113
|
+
return `it was posted by \`${creator.login}\`, which any workflow in the repo can post as`;
|
|
114
|
+
}
|
|
115
|
+
return `it was posted by \`${creator.login}\`, a GitHub App this caller doesn't trust. If it is the repo's pr-lifecycle App, name it in ${CREATORS_OPTION}`;
|
|
116
|
+
}
|
|
117
|
+
const vetted = vet(creator);
|
|
118
|
+
return typeof vetted === "string" ? vetted : void 0;
|
|
119
|
+
}
|
|
120
|
+
function untrustedReason(status, trustedBots) {
|
|
92
121
|
if (status.state !== "success") return `its state is \`${status.state}\`, not \`success\``;
|
|
93
122
|
if (status.creator === void 0) return "GitHub names no account that posted it";
|
|
94
|
-
|
|
95
|
-
return typeof vetted === "string" ? vetted : void 0;
|
|
123
|
+
return untrustedCreator(status.creator, trustedBots);
|
|
96
124
|
}
|
|
97
|
-
function readSignOffStatus(pr) {
|
|
125
|
+
function readSignOffStatus(pr, trustedBots = []) {
|
|
98
126
|
const status = pr.signOffStatus;
|
|
99
127
|
if (status === void 0) return { kind: "absent" };
|
|
100
|
-
const untrusted = untrustedReason(status);
|
|
128
|
+
const untrusted = untrustedReason(status, trustedBots);
|
|
101
129
|
if (untrusted !== void 0) return { kind: "rejected", reason: untrusted };
|
|
102
130
|
const parsed = parseSignOffDescription(status.description);
|
|
103
131
|
if (typeof parsed === "string") return { kind: "rejected", reason: parsed };
|
|
@@ -625,8 +653,8 @@ var CI_CHANGE_CHECK = "ci-change";
|
|
|
625
653
|
function indicatorMessage(indicator) {
|
|
626
654
|
return `\`${indicator.file}\` \`${indicator.location}\` \u2014 ${indicator.kind} (${indicator.class}): ${indicator.detail}`;
|
|
627
655
|
}
|
|
628
|
-
function decideCiChange(classification, pr) {
|
|
629
|
-
const reading = readSignOffStatus(pr);
|
|
656
|
+
function decideCiChange(classification, pr, trustedBots = []) {
|
|
657
|
+
const reading = readSignOffStatus(pr, trustedBots);
|
|
630
658
|
switch (reading.kind) {
|
|
631
659
|
case "valid":
|
|
632
660
|
return decideFromStatus(classification, pr, reading.classification);
|
|
@@ -699,10 +727,13 @@ function decideWithoutStatus(classification, pr) {
|
|
|
699
727
|
labelsToRemove
|
|
700
728
|
};
|
|
701
729
|
}
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
730
|
+
function ciChangeCheckFor(trustedBots) {
|
|
731
|
+
return {
|
|
732
|
+
name: CI_CHANGE_CHECK,
|
|
733
|
+
evaluate: async (pr) => decideCiChange(classifyWorkflowChanges(pr.workflowChanges), pr, trustedBots)
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
var ciChangeCheck = ciChangeCheckFor([]);
|
|
706
737
|
|
|
707
738
|
// src/checks/dependabot/claims.ts
|
|
708
739
|
var NAME = /(?:\[([^\[\]\n]+)\]\([^()\n]*\)|`([^`]+)`|([^\s[\]`]+))/.source;
|
|
@@ -1597,8 +1628,8 @@ function staleReason(pr, label) {
|
|
|
1597
1628
|
if (Date.parse(appliedAt) > Date.parse(pr.headPushedAt)) return void 0;
|
|
1598
1629
|
return "it was applied before the current head was pushed, and a new head needs a person to test it again";
|
|
1599
1630
|
}
|
|
1600
|
-
function decideUat(pr) {
|
|
1601
|
-
const reading = readSignOffStatus(pr);
|
|
1631
|
+
function decideUat(pr, trustedBots = []) {
|
|
1632
|
+
const reading = readSignOffStatus(pr, trustedBots);
|
|
1602
1633
|
switch (reading.kind) {
|
|
1603
1634
|
case "absent":
|
|
1604
1635
|
return { findings: decideWithoutStatus2(pr) };
|
|
@@ -1661,10 +1692,10 @@ function signOffFindings(pr, setAside) {
|
|
|
1661
1692
|
}
|
|
1662
1693
|
return [waiting, ...why];
|
|
1663
1694
|
}
|
|
1664
|
-
|
|
1665
|
-
name: UAT_CHECK,
|
|
1666
|
-
|
|
1667
|
-
|
|
1695
|
+
function uatCheckFor(trustedBots) {
|
|
1696
|
+
return { name: UAT_CHECK, evaluate: async (pr) => decideUat(pr, trustedBots) };
|
|
1697
|
+
}
|
|
1698
|
+
var uatCheck = uatCheckFor([]);
|
|
1668
1699
|
|
|
1669
1700
|
// src/checks/index.ts
|
|
1670
1701
|
var CHECKS = [
|
|
@@ -1676,7 +1707,13 @@ var CHECKS = [
|
|
|
1676
1707
|
dependabotCheck
|
|
1677
1708
|
];
|
|
1678
1709
|
function selectChecks(options = {}) {
|
|
1679
|
-
|
|
1710
|
+
const trustedBots = parseSignOffStatusCreators(options.signOffStatusCreators ?? []);
|
|
1711
|
+
const configured = trustedBots.length === 0 ? CHECKS : CHECKS.map((check) => {
|
|
1712
|
+
if (check === uatCheck) return uatCheckFor(trustedBots);
|
|
1713
|
+
if (check === ciChangeCheck) return ciChangeCheckFor(trustedBots);
|
|
1714
|
+
return check;
|
|
1715
|
+
});
|
|
1716
|
+
return options.skipUat ? configured.filter((check) => check.name !== uatCheck.name) : configured;
|
|
1680
1717
|
}
|
|
1681
1718
|
|
|
1682
1719
|
// src/report.ts
|
|
@@ -2336,6 +2373,8 @@ export {
|
|
|
2336
2373
|
SIGN_OFF_REQUIREMENTS,
|
|
2337
2374
|
WAIVER_STATES,
|
|
2338
2375
|
parseSignOffDescription,
|
|
2376
|
+
GITHUB_ACTIONS_BOT,
|
|
2377
|
+
parseSignOffStatusCreators,
|
|
2339
2378
|
readSignOffStatus,
|
|
2340
2379
|
LOOSENING_INDICATORS,
|
|
2341
2380
|
AMBIGUOUS_INDICATORS,
|
package/dist/index.d.ts
CHANGED
|
@@ -166,8 +166,18 @@ declare const CHECKS: readonly PolicyCheck[];
|
|
|
166
166
|
interface PolicyOptions {
|
|
167
167
|
/** Drop the UAT gate, for a repo with no user-acceptance testing to wait on. */
|
|
168
168
|
skipUat?: boolean;
|
|
169
|
+
/**
|
|
170
|
+
* GitHub App logins (exact, ending in `[bot]`) trusted to post the
|
|
171
|
+
* `pr-lifecycle/sign-off` status, besides a person who could merge. Empty by
|
|
172
|
+
* default. `github-actions[bot]` is refused. Human sign-off labels are
|
|
173
|
+
* unaffected: they still need a trusted person.
|
|
174
|
+
*/
|
|
175
|
+
signOffStatusCreators?: readonly string[];
|
|
169
176
|
}
|
|
170
|
-
/**
|
|
177
|
+
/**
|
|
178
|
+
* The checks to run for a repo configured with `options`, in report order.
|
|
179
|
+
* Throws on an invalid `signOffStatusCreators` entry.
|
|
180
|
+
*/
|
|
171
181
|
declare function selectChecks(options?: PolicyOptions): readonly PolicyCheck[];
|
|
172
182
|
|
|
173
183
|
/**
|
|
@@ -266,8 +276,26 @@ type SignOffStatusReading = {
|
|
|
266
276
|
* pr-lifecycle bumps the version for any new key.
|
|
267
277
|
*/
|
|
268
278
|
declare function parseSignOffDescription(description: string): SignOffClassification | string;
|
|
269
|
-
/**
|
|
270
|
-
|
|
279
|
+
/**
|
|
280
|
+
* The Bot any workflow in a repo can post as with its `GITHUB_TOKEN`. It can
|
|
281
|
+
* never be trusted to post the status, so a caller can't name it.
|
|
282
|
+
*/
|
|
283
|
+
declare const GITHUB_ACTIONS_BOT = "github-actions[bot]";
|
|
284
|
+
/**
|
|
285
|
+
* Validate a caller's list of GitHub App logins trusted to post the status
|
|
286
|
+
* (rmartz/pr-policy#97). Each entry is an exact login ending in `[bot]`, such
|
|
287
|
+
* as `rmartz-merge-bot[bot]`; blanks are dropped. `github-actions[bot]` is
|
|
288
|
+
* refused in any case, because any workflow can post as it. Throws on a bad
|
|
289
|
+
* entry, so a misconfigured caller fails loudly rather than trusting less or
|
|
290
|
+
* more than it meant to.
|
|
291
|
+
*/
|
|
292
|
+
declare function parseSignOffStatusCreators(entries: readonly string[]): string[];
|
|
293
|
+
/**
|
|
294
|
+
* Read pr-lifecycle's sign-off status on the head, judging its creator and
|
|
295
|
+
* format. The creator must be a `User` who could merge, or a Bot named in
|
|
296
|
+
* `trustedBots` (validated by `parseSignOffStatusCreators`).
|
|
297
|
+
*/
|
|
298
|
+
declare function readSignOffStatus(pr: Pick<PullRequestFacts, 'signOffStatus'>, trustedBots?: readonly string[]): SignOffStatusReading;
|
|
271
299
|
|
|
272
300
|
/**
|
|
273
301
|
* The indicator vocabulary — the classifier's whole output surface.
|
|
@@ -330,9 +358,11 @@ type CiFacts = Pick<PullRequestFacts, 'labels' | 'signOffs' | 'signOffStatus'>;
|
|
|
330
358
|
* needed, and this check edits no label: pr-lifecycle writes `CI approval
|
|
331
359
|
* needed` then. Without one, or with one the gate can't trust (the `uat` check
|
|
332
360
|
* holds on that), this check classifies the workflow diff itself, as before
|
|
333
|
-
* the cutover.
|
|
361
|
+
* the cutover. `trustedBots` are the GitHub Apps the caller trusts to post the
|
|
362
|
+
* status, besides a trusted person.
|
|
334
363
|
*/
|
|
335
|
-
declare function decideCiChange(classification: Classification, pr: CiFacts): CheckResult;
|
|
364
|
+
declare function decideCiChange(classification: Classification, pr: CiFacts, trustedBots?: readonly string[]): CheckResult;
|
|
365
|
+
/** The CI-change check trusting only people to post the sign-off status. */
|
|
336
366
|
declare const ciChangeCheck: PolicyCheck;
|
|
337
367
|
|
|
338
368
|
/**
|
|
@@ -526,4 +556,4 @@ declare function statusBody(evaluation: PolicyEvaluation, runUrl: string | undef
|
|
|
526
556
|
/** Post the verdict: the `pr-policy` check-run, then the matching commit status. */
|
|
527
557
|
declare function postVerdict(target: PullRequestTarget, headSha: string, evaluation: PolicyEvaluation): Promise<void>;
|
|
528
558
|
|
|
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 };
|
|
559
|
+
export { AMBIGUOUS_INDICATORS, type AmbiguousIndicator, BLOCKED_LABEL, BLOCKING_LABELS, BREAKING_CHANGE_LABEL, CHECKS, CI_APPROVAL_NEEDED_LABEL, CI_CHANGE_APPROVED_LABEL, CI_CHANGE_CHECK, CI_CHANGE_VERDICTS, CI_SENSITIVE_PACKAGES, COMMIT_TYPES, type CheckResult, type CheckRunReport, type CiChangeVerdict, type Claim, type Classification, type CommitStatus, type CommitType, DEPENDABOT_CHECK, DEPENDABOT_LOGIN, DNM_LABEL, DO_NOT_MERGE_LABEL, ESCALATION_NEEDED_LABEL, FUNCTIONAL_TYPES, type FileChange, type Finding, GITHUB_ACTIONS_BOT, HOTFIX_LABEL, type Indicator, type IndicatorClass, type IndicatorKind, LOOSENING_INDICATORS, type LooseningIndicator, MERGE_BLOCK_CHECK, POLICY_OUTCOMES, PR_POLICY_CHECK_NAME, type ParsedTitle, type PolicyCheck, type PolicyEvaluation, type PolicyOptions, type PolicyOutcome, type PullRequestAuthor, type PullRequestFacts, type PullRequestTarget, RELEASE_PLEASE_PENDING_LABEL, SIGN_OFF_REQUIREMENTS, SIGN_OFF_STATUS_CONTEXT, SIGN_OFF_STATUS_VERSIONS, type SignOffClassification, type SignOffRequirement, type SignOffStatusReading, TITLE_CHECK, WAIVER_STATES, type WaiverState, type WorkflowFileChange, applyLabelEdits, buildReport, checkRunBody, ciChangeCheck, classifyWorkflowChanges, classifyWorkflowFile, decideCiChange, decideDependabot, decideMergeBlock, decideTitle, dependabotCheck, evaluatePolicy, gatherFacts, isManifestPath, isWorkflowPath, mergeBlockCheck, openPullRequestsAtHead, parseClaims, parseFacts, parseSignOffDescription, parseSignOffStatusCreators, parseTitle, postCheckRun, postVerdict, readSignOffStatus, selectChecks, sensitiveBumps, statusBody, titleCheck };
|
package/dist/index.js
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
DO_NOT_MERGE_LABEL,
|
|
17
17
|
ESCALATION_NEEDED_LABEL,
|
|
18
18
|
FUNCTIONAL_TYPES,
|
|
19
|
+
GITHUB_ACTIONS_BOT,
|
|
19
20
|
HOTFIX_LABEL,
|
|
20
21
|
LOOSENING_INDICATORS,
|
|
21
22
|
MERGE_BLOCK_CHECK,
|
|
@@ -47,6 +48,7 @@ import {
|
|
|
47
48
|
parseClaims,
|
|
48
49
|
parseFacts,
|
|
49
50
|
parseSignOffDescription,
|
|
51
|
+
parseSignOffStatusCreators,
|
|
50
52
|
parseTitle,
|
|
51
53
|
postCheckRun,
|
|
52
54
|
postVerdict,
|
|
@@ -55,7 +57,7 @@ import {
|
|
|
55
57
|
sensitiveBumps,
|
|
56
58
|
statusBody,
|
|
57
59
|
titleCheck
|
|
58
|
-
} from "./chunk-
|
|
60
|
+
} from "./chunk-RHHCFDMG.js";
|
|
59
61
|
export {
|
|
60
62
|
AMBIGUOUS_INDICATORS,
|
|
61
63
|
BLOCKED_LABEL,
|
|
@@ -74,6 +76,7 @@ export {
|
|
|
74
76
|
DO_NOT_MERGE_LABEL,
|
|
75
77
|
ESCALATION_NEEDED_LABEL,
|
|
76
78
|
FUNCTIONAL_TYPES,
|
|
79
|
+
GITHUB_ACTIONS_BOT,
|
|
77
80
|
HOTFIX_LABEL,
|
|
78
81
|
LOOSENING_INDICATORS,
|
|
79
82
|
MERGE_BLOCK_CHECK,
|
|
@@ -105,6 +108,7 @@ export {
|
|
|
105
108
|
parseClaims,
|
|
106
109
|
parseFacts,
|
|
107
110
|
parseSignOffDescription,
|
|
111
|
+
parseSignOffStatusCreators,
|
|
108
112
|
parseTitle,
|
|
109
113
|
postCheckRun,
|
|
110
114
|
postVerdict,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rmartz/pr-policy",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Read-only PR content classifiers — CI-change classification, title-type rules, and more — reported as one blocking pr-policy check-run. Distributed as a pinned Action kept current by Dependabot.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pr-policy",
|