@rmartz/pr-policy 0.14.0 → 1.1.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.
@@ -7,7 +7,7 @@ import {
7
7
  postVerdict,
8
8
  resolveRepoTarget,
9
9
  selectChecks
10
- } from "../chunk-USVRZJHF.js";
10
+ } from "../chunk-YCBII74A.js";
11
11
 
12
12
  // src/bin/pr-policy.ts
13
13
  import { readFile } from "fs/promises";
@@ -1215,6 +1215,19 @@ function typePathViolation(type, changedFiles) {
1215
1215
  return void 0;
1216
1216
  }
1217
1217
 
1218
+ // src/checks/title/wip.ts
1219
+ var WIP_MARKERS = [/^\[wip\]\s*/i, /^WIP(?::|\s|$)\s*/, /\s*\[wip\]$/i, /(?:^|\s)WIP$/];
1220
+ function stripWipMarker(title) {
1221
+ let text = title.trim();
1222
+ let marked = false;
1223
+ for (; ; ) {
1224
+ const next = WIP_MARKERS.reduce((current, marker) => current.replace(marker, "").trim(), text);
1225
+ if (next === text) return { title: text, marked };
1226
+ marked = true;
1227
+ text = next;
1228
+ }
1229
+ }
1230
+
1218
1231
  // src/checks/title/index.ts
1219
1232
  var TITLE_CHECK = "title";
1220
1233
  var FUNCTIONAL = FUNCTIONAL_TYPES.map((type) => `\`${type}\``).join("/");
@@ -1222,16 +1235,25 @@ function block2(message) {
1222
1235
  return { check: TITLE_CHECK, message, effect: "block" };
1223
1236
  }
1224
1237
  function decideTitle(pr) {
1238
+ const { title, marked } = stripWipMarker(pr.title);
1239
+ const { findings } = titleRules(pr, title);
1240
+ if (!marked || pr.draft === true) return { findings };
1241
+ const wip = block2(
1242
+ `The title carries a WIP marker, but the PR isn't a draft, so it could merge unfinished. Convert the PR to a draft while the work is in progress, or remove the marker from the title when it's done.`
1243
+ );
1244
+ return { findings: [wip, ...findings] };
1245
+ }
1246
+ function titleRules(pr, text) {
1225
1247
  const labels = new Set(pr.labels.map((label) => label.toLowerCase()));
1226
- if (labels.has(RELEASE_PLEASE_PENDING_LABEL) || isReleasePleaseTitle(pr.title)) {
1248
+ if (labels.has(RELEASE_PLEASE_PENDING_LABEL) || isReleasePleaseTitle(text)) {
1227
1249
  return { findings: [] };
1228
1250
  }
1229
- const title = parseTitle(pr.title);
1251
+ const title = parseTitle(text);
1230
1252
  if (title === null) {
1231
1253
  return {
1232
1254
  findings: [
1233
1255
  block2(
1234
- `\`${pr.title}\` is not a Conventional Commit. Expected \`<type>[(<scope>)][!]: <subject>\` with a type of ${COMMIT_TYPES.join(", ")}. Edit the title; it becomes the squash commit on \`main\`.`
1256
+ `\`${text}\` is not a Conventional Commit. Expected \`<type>[(<scope>)][!]: <subject>\` with a type of ${COMMIT_TYPES.join(", ")}. Edit the title; it becomes the squash commit on \`main\`.`
1235
1257
  )
1236
1258
  ]
1237
1259
  };
@@ -1535,6 +1557,7 @@ function parseFacts(raw) {
1535
1557
  body,
1536
1558
  author,
1537
1559
  base,
1560
+ draft,
1538
1561
  labels,
1539
1562
  changedFiles,
1540
1563
  workflowChanges,
@@ -1543,6 +1566,9 @@ function parseFacts(raw) {
1543
1566
  } = parsed;
1544
1567
  if (typeof title !== "string") throw new Error("facts.title must be a string");
1545
1568
  if (!isOptionalString(body)) throw new Error("facts.body must be a string");
1569
+ if (draft !== void 0 && typeof draft !== "boolean") {
1570
+ throw new Error("facts.draft must be a boolean");
1571
+ }
1546
1572
  if (!isStringArray(labels)) throw new Error("facts.labels must be a string array");
1547
1573
  if (!isStringArray(changedFiles)) throw new Error("facts.changedFiles must be a string array");
1548
1574
  const pr = {
@@ -1558,6 +1584,7 @@ function parseFacts(raw) {
1558
1584
  if (body !== void 0) pr.body = body;
1559
1585
  if (parsedAuthor !== void 0) pr.author = parsedAuthor;
1560
1586
  if (parsedBase !== void 0) pr.base = parsedBase;
1587
+ if (draft !== void 0) pr.draft = draft;
1561
1588
  return pr;
1562
1589
  }
1563
1590
 
@@ -1921,6 +1948,7 @@ async function gatherFacts(target) {
1921
1948
  body: view.body ?? "",
1922
1949
  author: { login: view.user.login, type: view.user.type },
1923
1950
  base: await gatherBase(target, view),
1951
+ draft: view.draft,
1924
1952
  labels,
1925
1953
  // A rename's old path counts too: moving code into docs/ is not docs-only.
1926
1954
  changedFiles: files.flatMap(
package/dist/index.d.ts CHANGED
@@ -70,6 +70,11 @@ interface PullRequestFacts {
70
70
  author?: PullRequestAuthor;
71
71
  /** The branch the PR merges into. `gatherFacts` always sets it. */
72
72
  base?: PullRequestBase;
73
+ /**
74
+ * Whether the PR is a draft, which GitHub won't merge. `gatherFacts` always
75
+ * sets it; absent reads as ready for review, so a WIP title fails closed.
76
+ */
77
+ draft?: boolean;
73
78
  labels: readonly string[];
74
79
  /** Every path the PR touches, including the old path of a rename. */
75
80
  changedFiles: readonly string[];
@@ -264,14 +269,19 @@ declare const mergeBlockCheck: PolicyCheck;
264
269
  declare function isWorkflowPath(path: string): boolean;
265
270
 
266
271
  declare const TITLE_CHECK = "title";
267
- /** Every title rule violated by this PR's current title, labels, and diff. */
272
+ /**
273
+ * Every title rule violated by this PR's current title, labels, and diff. A WIP
274
+ * marker requires the PR to be a draft, which GitHub won't merge; a WIP draft is
275
+ * fine. The other rules judge the title without the marker, so a leading one
276
+ * reads as "not ready" rather than "not a Conventional Commit".
277
+ */
268
278
  declare function decideTitle(pr: PullRequestFacts): CheckResult;
269
279
  declare const titleCheck: PolicyCheck;
270
280
 
271
281
  /**
272
282
  * The Conventional-Commit grammar a squash subject must satisfy. It mirrors the
273
- * fleet's `pr-title-lint.yml` and `commit-convention.yml` exactly, so a title
274
- * this accepts is one the post-merge tripwire accepts too.
283
+ * fleet's `commit-convention.yml`, the post-merge tripwire, exactly, so a title
284
+ * this accepts is one the tripwire accepts too.
275
285
  */
276
286
  declare const COMMIT_TYPES: readonly ["feat", "fix", "docs", "chore", "refactor", "test", "style", "perf", "ci", "build", "revert"];
277
287
  type CommitType = (typeof COMMIT_TYPES)[number];
@@ -379,7 +389,7 @@ declare function evaluatePolicy(pr: PullRequestFacts, checks?: readonly PolicyCh
379
389
  /**
380
390
  * Parse and validate a JSON facts document into `PullRequestFacts`.
381
391
  * `workflowChanges`, `manifestChanges`, and `signOffs` are optional and default
382
- * to none; `body`, `author`, and `base` are optional and stay absent. With no
392
+ * to none; `body`, `author`, `base`, and `draft` are optional and stay absent. With no
383
393
  * `signOffs`, no sign-off label counts: trust fails closed.
384
394
  */
385
395
  declare function parseFacts(raw: string): PullRequestFacts;
package/dist/index.js CHANGED
@@ -48,7 +48,7 @@ import {
48
48
  sensitiveBumps,
49
49
  statusBody,
50
50
  titleCheck
51
- } from "./chunk-USVRZJHF.js";
51
+ } from "./chunk-YCBII74A.js";
52
52
  export {
53
53
  AMBIGUOUS_INDICATORS,
54
54
  BLOCKED_LABEL,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rmartz/pr-policy",
3
- "version": "0.14.0",
3
+ "version": "1.1.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",