-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpr-contract.mjs
More file actions
637 lines (565 loc) · 22.1 KB
/
Copy pathpr-contract.mjs
File metadata and controls
637 lines (565 loc) · 22.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
import { execFileSync } from 'node:child_process';
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
const DEFAULT_BRANCH_PATTERN = '^(agent|feat|fix|chore|docs|ci|test|refactor|perf|release|dependabot)\\/[A-Za-z0-9._\\/-]+$';
const DEFAULT_DOC_EXTENSIONS = 'md|txt|png|jpg|jpeg|gif|svg|webp|bmp|ico|avif';
const DEFAULT_DOC_PREFIXES = ['.changelog/'];
const DEFAULT_REQUIRED_HEADINGS = [
{ level: 2, text: 'Summary' },
{ level: 2, text: 'Verification' },
{ level: 3, text: 'Verification Notes' },
{ level: 2, text: 'Docs / Changelog' },
];
const TITLE_RE = /^(feat|fix|refactor|test|docs|style|chore|perf|ci|build|revert)(\([^)]+\))?: .+/;
const ISSUE_RE = /\b(Closes|Fixes|Refs)\s+#\d+\b/i;
// "placeholder" is valid completed prose; reject explicit unfilled markers.
const PLACEHOLDER_RE = /\b(TODO|TBD|FIXME|FILL ME|FILL IN|REPLACE THIS|NOT YET|N\/A|NONE YET)\b|#\s*(?:___|<[^>]+>)|<set-before-merge>/i;
const CHECKED_RE = /^\s*[-*]\s+\[[xX]\]\s+(.+?)\s*$/;
const UNCHECKED_RE = /^\s*[-*]\s+\[\s\]\s+(.+?)\s*$/;
// Substance-only contract (owner decision 2026-07-01, #99): any non-empty
// bullet in `## Verification` counts as a verification item — the contract
// requires that something substantive is recorded, not a specific checkbox
// format. The negative lookahead keeps checkbox lines out of the plain-item
// match so each line is classified exactly once.
const ITEM_RE = /^\s*[-*]\s+(?!\[[ xX]\]\s)(.+?)\s*$/;
const GENERIC_VERIFICATION_RE = /\b(automated ci checks? green|ci[- ]?green|ci checks? pass(?:ed|es)?|checks? green|all checks? pass(?:ed|es)?|tests? pass(?:ed|es)?)\b/i;
/**
* Validate PR metadata against the ArchonVII ready-for-review contract.
*
* @param {object} input
* @param {string} input.title
* @param {string} input.body
* @param {string} input.branch
* @param {string[]} input.files
* @param {object} [options]
* @returns {{ok:boolean, errors:Array<{code:string,message:string,path:string}>, warnings:Array<{code:string,message:string,path:string}>, facts:object}}
*/
export function validatePrContract(input, options = {}) {
const rules = normalizeRules(options);
const data = {
title: input.title || '',
body: input.body || '',
branch: input.branch || '',
files: Array.isArray(input.files) ? input.files : [],
};
const errors = [];
const warnings = [];
const docsOnly = isDocsOnly(data.files, rules);
if (rules.requireTitle && !TITLE_RE.test(data.title)) {
errors.push(error(
'invalid_title',
'PR title must use Conventional Commits format, for example `feat(scope): summary`.',
'title',
));
}
if (rules.rejectPlaceholderTitle && hasPlaceholder(data.title)) {
errors.push(error('placeholder_title', 'PR title contains placeholder text.', 'title'));
}
if (rules.requireBranch && !rules.branchPattern.test(data.branch)) {
errors.push(error(
'invalid_branch',
`Head branch \`${data.branch || '(empty)'}\` does not match the required branch pattern.`,
'branch',
));
}
if (!docsOnly) {
validateBody(data.body, rules, errors, warnings);
}
const items = collectVerificationItems(data.body);
return {
ok: errors.length === 0,
errors,
warnings,
facts: {
docsOnly,
checkedVerificationCount: items.checked.length,
verificationItemCount: [...items.checked, ...items.unchecked, ...items.plain]
.filter((item) => item.claim.length > 0).length,
},
};
}
export function formatPrContractResult(result) {
if (result.ok) {
const suffix = result.facts.docsOnly ? ' (docs-only body ceremony skipped)' : '';
const lines = [`PR contract passed${suffix}.`];
if (result.warnings.length > 0) {
lines.push('', 'Advisories (non-blocking):');
for (const item of result.warnings) {
lines.push(`- [${item.code}] ${item.message}`);
}
}
return lines.join('\n');
}
const lines = ['PR contract failed.', '', 'Required fixes:'];
for (const item of result.errors) {
lines.push(`- [${item.code}] ${item.message}`);
}
if (result.warnings.length > 0) {
lines.push('', 'Advisories (non-blocking):');
for (const item of result.warnings) {
lines.push(`- [${item.code}] ${item.message}`);
}
}
return lines.join('\n');
}
/**
* Validate that a committed PR template can satisfy the contract's required
* heading structure (all required headings present, in the required order).
*
* Unlike validatePrContract, this checks STRUCTURE ONLY — not checked boxes,
* placeholders, or substantive content — because a template legitimately ships
* with unchecked boxes and TODO/comment placeholders. It catches the drift
* class where a repo's own .github/PULL_REQUEST_TEMPLATE.md cannot itself pass
* the gate it is subject to (e.g. a pre-strict template using `## Changelog`
* instead of `## Docs / Changelog`, or missing `### Verification Notes`).
* Source: /page-gm incident 2026-06-07 (ArchonVII/hudson-bend#43;
* ArchonVII/github-workflows#53).
*
* @param {string} templateBody Raw PULL_REQUEST_TEMPLATE.md contents.
* @param {object} [options]
* @param {Array} [options.requiredHeadings] Defaults to DEFAULT_REQUIRED_HEADINGS.
* @returns {{ok:boolean, errors:Array<{code:string,message:string,path:string}>, warnings:Array, facts:object}}
*/
export function validatePrTemplate(templateBody, options = {}) {
const required = normalizeHeadings(options.requiredHeadings || DEFAULT_REQUIRED_HEADINGS);
const errors = [];
const headings = parseHeadings(templateBody || '');
validateHeadingOrder(headings, required, errors);
return {
ok: errors.length === 0,
errors,
warnings: [],
facts: { headingCount: headings.length },
};
}
export function formatPrTemplateResult(result) {
if (result.ok) {
return 'PR template conforms to the required contract structure.';
}
const lines = [
'PR template does NOT conform to the strict PR contract structure.',
'Filling this template out verbatim would fail `repo-required-gate / pr contract`.',
'Sync `.github/PULL_REQUEST_TEMPLATE.md` from ArchonVII/repo-template.',
'',
'Structure issues:',
];
for (const item of result.errors) {
lines.push(`- [${item.code}] ${item.message}`);
}
return lines.join('\n');
}
export function loadPrFromGh({ repo, pr }) {
if (!repo) throw new Error('Missing required --repo owner/name argument.');
if (!pr) throw new Error('Missing required --pr number argument.');
const raw = execFileSync(
'gh',
['pr', 'view', String(pr), '--repo', repo, '--json', 'number,title,body,headRefName,isDraft,files,url'],
{ encoding: 'utf8' },
);
const parsed = JSON.parse(raw);
return {
number: parsed.number,
url: parsed.url,
title: parsed.title || '',
body: parsed.body || '',
branch: parsed.headRefName || '',
isDraft: Boolean(parsed.isDraft),
files: (parsed.files || []).map((file) => file.path || file.filename).filter(Boolean),
};
}
function validateBody(body, rules, errors, warnings) {
const headings = parseHeadings(body);
if (rules.requireIssueLink && !ISSUE_RE.test(body)) {
errors.push(error(
'missing_issue_link',
'PR body must link an issue with `Closes #N`, `Fixes #N`, or `Refs #N`.',
'body',
));
}
if (rules.rejectPlaceholders && hasPlaceholder(stripHtmlComments(body))) {
errors.push(error(
'placeholder_text',
'PR body contains placeholder text such as TODO, TBD, N/A, or an unset issue marker.',
'body',
));
}
// Heading presence/order is advisory since #99: sections are located by
// name, so the substance checks below still hard-fail when a section's
// content is genuinely missing — only the exact structure is soft.
validateHeadingOrder(headings, rules.requiredHeadings, warnings);
const summary = sectionContent(body, headings, 'Summary');
if (rules.requireSummary && !hasSubstantiveContent(summary)) {
errors.push(error('empty_summary', '`## Summary` must contain substantive content.', 'body'));
}
const notes = sectionContent(body, headings, 'Verification Notes');
if (rules.requireSubstantiveVerificationNotes && !hasSubstantiveContent(notes)) {
errors.push(error(
'empty_verification_notes',
'`### Verification Notes` must contain substantive non-placeholder verification detail.',
'body',
));
}
if (rules.rejectGenericVerificationNotes && GENERIC_VERIFICATION_RE.test(maskCodeAndQuotes(notes).trim())) {
errors.push(error(
'generic_verification_notes',
'`### Verification Notes` must not be a generic CI/tests-passed statement.',
'body',
));
}
const docs = sectionContent(body, headings, 'Docs / Changelog');
if (rules.requireDocsChangelog && !hasSubstantiveContent(docs)) {
errors.push(error('empty_docs_changelog', '`## Docs / Changelog` must describe docs or changelog handling.', 'body'));
}
const { verification, checked, unchecked, plain } = collectVerificationItems(body);
const allItems = [...checked, ...unchecked, ...plain];
const substantiveItems = allItems.filter((item) => item.claim.length > 0);
if (rules.requireCheckedVerification && substantiveItems.length === 0) {
errors.push(error(
'missing_verification_item',
'`## Verification` must include at least one verification item — a bullet or checkbox recording what was actually run or checked.',
'body',
));
}
for (const item of unchecked) {
warnings.push(error(
'unchecked_verification_item',
`Verification item is unchecked; it still counts as an item, but reads as not-done: "${item.claim}".`,
'body',
));
}
for (const item of allItems) {
if (GENERIC_VERIFICATION_RE.test(item.claim)) {
errors.push(error(
'generic_verification',
`Verification item is too generic: "${item.claim}". Record the actual command, check, or manual action.`,
'body',
));
}
}
for (const item of checked) {
if (rules.requireEvidenceBlocks && !hasEvidenceBlockAfter(verification, item.index)) {
warnings.push(error(
'missing_evidence_block',
`Checked verification item "${item.claim}" is not followed by a fenced \`\`\`evidence block (recommended shape; advisory since #99).`,
'body',
));
}
}
if (warnings.length === 0 && headings.length === 0 && body.trim() !== '') {
warnings.push(error('no_headings', 'PR body has no markdown headings.', 'body'));
}
}
function normalizeRules(options) {
const docPrefixes = Array.isArray(options.docOnlyPathPrefixes)
? options.docOnlyPathPrefixes
: String(options.docOnlyPathPrefixes || DEFAULT_DOC_PREFIXES.join('\n'))
.split(/\r?\n/)
.map((item) => item.trim())
.filter(Boolean);
return {
requireTitle: options.requireTitle !== false,
rejectPlaceholderTitle: options.rejectPlaceholderTitle !== false,
requireBranch: options.requireBranch !== false,
branchPattern: new RegExp(options.branchPattern || DEFAULT_BRANCH_PATTERN),
docExtensions: new RegExp(`\\.(${options.docOnlyExtensions || DEFAULT_DOC_EXTENSIONS})$`, 'i'),
docPrefixes,
requireIssueLink: options.requireIssueLink !== false,
rejectPlaceholders: options.rejectPlaceholders !== false,
requiredHeadings: normalizeHeadings(options.requiredHeadings || DEFAULT_REQUIRED_HEADINGS),
requireSummary: options.requireSummary !== false,
requireDocsChangelog: options.requireDocsChangelog !== false,
requireSubstantiveVerificationNotes: options.requireSubstantiveVerificationNotes !== false,
rejectGenericVerificationNotes: options.rejectGenericVerificationNotes !== false,
requireCheckedVerification: options.requireCheckedVerification !== false,
requireEvidenceBlocks: options.requireEvidenceBlocks !== false,
};
}
function normalizeHeadings(headings) {
return headings.map((heading) => {
if (typeof heading === 'string') {
const match = heading.match(/^(#{2,6})\s+(.+)$/);
if (!match) throw new Error(`Invalid required heading: ${heading}`);
return { level: match[1].length, text: cleanHeadingText(match[2]) };
}
return { level: heading.level, text: cleanHeadingText(heading.text) };
});
}
function parseHeadings(body) {
const headings = [];
const lines = (body || '').split(/\r?\n/);
let offset = 0;
for (let lineNumber = 0; lineNumber < lines.length; lineNumber++) {
const line = lines[lineNumber];
const match = line.match(/^(#{2,6})\s+(.+?)\s*#*\s*$/);
if (match) {
headings.push({
level: match[1].length,
text: cleanHeadingText(match[2]),
lineNumber,
start: offset,
});
}
offset += line.length + 1;
}
for (let i = 0; i < headings.length; i++) {
headings[i].end = i + 1 < headings.length ? headings[i + 1].start : body.length;
}
return headings;
}
function validateHeadingOrder(headings, required, errors) {
let cursor = -1;
for (const expected of required) {
const foundIndex = headings.findIndex(
(heading, index) => index > cursor && heading.level === expected.level && sameHeading(heading.text, expected.text),
);
if (foundIndex === -1) {
errors.push(error(
'missing_heading',
`PR body must include \`${'#'.repeat(expected.level)} ${expected.text}\` in the required order.`,
'body',
));
return;
}
cursor = foundIndex;
}
}
function sectionContent(body, headings, name, options = {}) {
const start = headings.find((heading) => sameHeading(heading.text, name));
if (!start) return '';
let end = start.end;
if (options.stopBefore) {
const stop = headings.find(
(heading) => heading.start > start.start && sameHeading(heading.text, options.stopBefore),
);
if (stop) end = stop.start;
}
const raw = body.slice(start.start, end);
return raw.split(/\r?\n/).slice(1).join('\n').trim();
}
function hasEvidenceBlockAfter(section, checkedLineIndex) {
const lines = section.split(/\r?\n/);
for (let i = checkedLineIndex + 1; i < lines.length; i++) {
const trimmed = lines[i].trim();
if (trimmed === '') continue;
return /^```\s*evidence\s*$/i.test(trimmed);
}
return false;
}
// Classify every line of the `## Verification` section (fenced blocks masked
// so evidence field values are never misread as items) into checked boxes,
// unchecked boxes, and plain bullets. Line indexes are preserved through the
// masking so evidence-adjacency checks still run against the raw section.
function collectVerificationItems(body) {
const headings = parseHeadings(body || '');
const verification = sectionContent(body || '', headings, 'Verification', { stopBefore: 'Verification Notes' });
const checked = [];
const unchecked = [];
const plain = [];
maskFencedLines(verification).forEach((line, index) => {
let match = line.match(CHECKED_RE);
if (match) {
checked.push({ claim: match[1].trim(), index });
return;
}
match = line.match(UNCHECKED_RE);
if (match) {
unchecked.push({ claim: match[1].trim(), index });
return;
}
match = line.match(ITEM_RE);
if (match) plain.push({ claim: match[1].trim(), index });
});
return { verification, checked, unchecked, plain };
}
// Blank out fence delimiters and fenced content while preserving line count,
// so indexes into the raw section stay valid.
function maskFencedLines(text) {
let inFence = false;
return String(text || '').split(/\r?\n/).map((line) => {
if (/^\s*```/.test(line)) {
inFence = !inFence;
return '';
}
return inFence ? '' : line;
});
}
function isDocsOnly(files, rules) {
return files.length > 0 && files.every((file) => {
const normalized = file.replace(/\\/g, '/');
return rules.docExtensions.test(normalized)
|| rules.docPrefixes.some((prefix) => normalized.startsWith(prefix));
});
}
function hasSubstantiveContent(text) {
const cleaned = stripHtmlComments(text)
.split(/\r?\n/)
.map((line) => line.replace(/^[-*]\s+\[[ xX]\]\s+/, '').trim())
.filter((line) => line && !line.startsWith('<!--') && !line.startsWith('```'))
.join(' ')
.trim();
return cleaned.length >= 20 && !hasPlaceholder(cleaned);
}
function hasPlaceholder(text) {
return PLACEHOLDER_RE.test(text || '') || hasLiteralPlaceholderFiller(text);
}
function hasLiteralPlaceholderFiller(text) {
const raw = stripHtmlComments(text);
const candidates = [
raw,
...raw.split(/\r?\n/),
];
return candidates.some((candidate) => {
const cleaned = normalizePlaceholderCandidate(candidate);
const words = cleaned.toLowerCase().match(/[a-z]+/g) || [];
return words.length > 0
&& (
words.every((word) => word === 'placeholder')
|| words.join(' ') === 'placeholder text'
);
});
}
function normalizePlaceholderCandidate(text) {
return String(text || '')
.replace(/^[-*]\s+\[[ xX]\]\s+/, '')
.replace(/^[-*]\s+/, '')
.replace(/^(?:feat|fix|refactor|test|docs|style|chore|perf|ci|build|revert)(?:\([^)]+\))?:\s*/i, '')
.replace(/^[A-Za-z][A-Za-z -]{0,40}:\s*/, '')
.replace(/[`"'[\]{}()<>]/g, ' ')
.trim();
}
// Remove HTML comments before placeholder scanning so a template's own
// instructional comment (which legitimately contains words like "placeholder"
// or "TODO") does not trip the contract. Evidence-block field values are NOT
// stripped, so `command: TODO` inside a ```evidence block still fails.
// Source: forensic analysis of session 019eccc1 (F4) + owner refinement 5.
function stripHtmlComments(text) {
return String(text || '').replace(/<!--[\s\S]*?-->/g, ' ');
}
// Mask fenced code/evidence blocks, inline code spans, and blockquoted lines
// from FREE PROSE before the generic-verification scan, so an explanatory note
// may quote a command or diagnostic (e.g. a cited `npm test` line) without being
// rejected as a generic "tests passed" claim. Checked checkbox claims are scanned
// raw (not masked), so `- [x] tests passed` still fails.
// Source: forensic analysis of session 019eccc1 (F7) + owner refinement 5.
function maskCodeAndQuotes(text) {
return String(text || '')
.replace(/```[\s\S]*?```/g, ' ')
.replace(/`[^`\n]*`/g, ' ')
.split(/\r?\n/)
.map((line) => (/^\s*>/.test(line) ? ' ' : line))
.join('\n');
}
function sameHeading(left, right) {
return cleanHeadingText(left).toLowerCase() === cleanHeadingText(right).toLowerCase();
}
function cleanHeadingText(text) {
return String(text || '').replace(/\s+/g, ' ').trim();
}
function error(code, message, path) {
return { code, message, path };
}
function parseArgs(argv) {
const args = {};
for (let i = 0; i < argv.length; i++) {
const item = argv[i];
if (item === '-h' || item === '--help') {
args.help = true;
continue;
}
if (!item.startsWith('--')) continue;
const key = item.slice(2);
if (key === 'json' || key === 'help') {
args[key] = true;
continue;
}
args[key] = argv[i + 1];
i += 1;
}
return args;
}
function loadInputFromEvent(eventPath, filesJson) {
const event = JSON.parse(readFileSync(eventPath, 'utf8'));
const pr = event.pull_request;
if (!pr) throw new Error('--event-path must point to a pull_request event payload.');
const files = filesJson ? JSON.parse(filesJson) : [];
return {
title: pr.title || '',
body: pr.body || '',
branch: pr.head?.ref || '',
files,
isDraft: Boolean(pr.draft),
number: pr.number,
url: pr.html_url,
};
}
// Pre-publish input adapter: validate a locally drafted body with NO remote PR.
// `--body-file -` reads the body from stdin so the agent never needs a temp file.
// Pair with --title / --branch / --files-json so the SAME contract that CI runs
// after creation can be run locally before `gh pr create`.
// Source: forensic analysis of session 019eccc1 (F2/F3) — the keystone that
// removes the push -> create -> amend -> re-scan loop.
function loadInputFromBodyFile(args) {
const source = args['body-file'];
const body = readFileSync(source === '-' ? 0 : source, 'utf8');
const files = args['files-json'] ? JSON.parse(args['files-json']) : [];
return {
title: args.title || '',
body,
branch: args.branch || '',
files,
isDraft: true,
number: null,
url: null,
};
}
function printUsage() {
process.stdout.write(`Usage: pr-contract.mjs <input-mode> [options]
Validate a PR against the ArchonVII ready-for-review contract. The same
validator runs locally (before a PR exists) and in CI (after) — identical rules.
Input modes (choose one):
--body-file <path|-> Validate a locally drafted body. '-' reads stdin.
Pair with --title, --branch, --files-json.
--repo <owner/name> --pr <n> Validate an existing remote PR (via gh pr view).
--event-path <path> Validate a pull_request event payload (CI).
Options:
--title <text> PR title (body-file mode).
--branch <name> Head branch (body-file mode).
--files-json <json> JSON array of changed file paths (docs-only detection).
--branch-pattern <regex> Override the allowed head-branch pattern.
--doc-only-extensions <exts> Override the docs-only file extensions.
--doc-only-path-prefixes <p> Override docs-only path prefixes (newline-separated).
--json Emit the full result object as JSON.
-h, --help Show this help.
Exit code: 0 = contract passes, 1 = fails.
`);
}
function main() {
const args = parseArgs(process.argv.slice(2));
if (args.help) {
printUsage();
return;
}
let input;
if (args['body-file']) {
input = loadInputFromBodyFile(args);
} else if (args['event-path']) {
input = loadInputFromEvent(args['event-path'], args['files-json'] || process.env.PR_CONTRACT_FILES_JSON);
} else {
input = loadPrFromGh({ repo: args.repo, pr: args.pr });
}
const result = validatePrContract(input, {
branchPattern: args['branch-pattern'],
docOnlyExtensions: args['doc-only-extensions'],
docOnlyPathPrefixes: args['doc-only-path-prefixes'],
});
if (args.json) {
process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
} else {
process.stdout.write(`${formatPrContractResult(result)}\n`);
}
process.exitCode = result.ok ? 0 : 1;
}
if (process.argv[1] && resolve(fileURLToPath(import.meta.url)) === resolve(process.argv[1])) {
main();
}