Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ coverage/
.DS_Store
# Written by Claude Code when it loads the mod from a folder it hot-reloads.
packages/mod/.claude-plugin/types/
# Agents' git worktrees.
.agents/worktrees/
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"files": {
"ignoreUnknown": true,
"includes": ["**", "!**/*.md", "!fixtures/claude-code", "!packages/mod/vendor"]
"includes": ["**", "!**/*.md", "!fixtures/claude-code", "!packages/mod/vendor", "!.release-please-manifest.json"]
},
"formatter": {
"indentStyle": "space",
Expand Down
2 changes: 1 addition & 1 deletion docs/adr/0031-conventional-commits-and-release-please.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Options considered:
- **The check** is `scripts/check-commits.ts` (subject rules in `scripts/lib/commit-message.ts`), not commitlint,
which would add many dependencies for a few rules. The `commits` job in `ci.yml` checks every commit of a pull
request except merges; `.githooks/commit-msg` checks one before it is pushed. Dependabot writes `build(deps)` and
`ci(deps)` subjects.
`ci(deps)` subjects; a bot's subject may be longer than 72, since we do not choose its words.
- **release-please** (`release-please-config.json`, `.release-please-manifest.json`, release type `node`, tags
`v<version>`) runs as the first job of `release.yml` on each push to `main`, with `GITHUB_TOKEN` only. It writes
the root `package.json` version, so ADR 30's one version stays. A tag made with `GITHUB_TOKEN` starts no other
Expand Down
15 changes: 9 additions & 6 deletions scripts/check-commits.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
/**
* Check commit messages against Conventional Commits (ADR 31).
* `check-commits.ts <base>..<head>`: every commit in the range but merges (CI, on a pull request).
* A commit whose author is a GitHub bot (`…[bot]@users.noreply.github.com`) may have a longer subject.
* `check-commits.ts --file <path>`: one message file (the `.githooks/commit-msg` hook).
*/
import { execFileSync } from "node:child_process";
import { readFileSync } from "node:fs";
import { checkCommitMessage } from "./lib/commit-message.ts";

const [first = "", second] = process.argv.slice(2);
let messages: { name: string; text: string }[];
let messages: { name: string; text: string; bot?: boolean }[];
if (first === "--file" && second) {
messages = [{ name: second, text: readFileSync(second, "utf8") }];
} else if (first.includes("..") && second === undefined) {
const log = execFileSync("git", ["log", "--no-merges", "--format=%h %s%x00%B%x1e", first], { encoding: "utf8" });
const log = execFileSync("git", ["log", "--no-merges", "--format=%h %s%x00%ae%x00%B%x1e", first], {
encoding: "utf8",
});
messages = log
.split("\x1e")
.filter((entry) => entry.trim() !== "")
.map((entry) => {
const [name = "", text = ""] = entry.trim().split("\0");
return { name, text };
const [name = "", email = "", text = ""] = entry.trim().split("\0");
return { name, text, bot: email.endsWith("[bot]@users.noreply.github.com") };
});
} else {
console.error("usage: check-commits.ts <base>..<head> | --file <path>");
process.exit(2);
}

let bad = 0;
for (const { name, text } of messages) {
const problems = checkCommitMessage(text);
for (const { name, text, bot } of messages) {
const problems = checkCommitMessage(text, { bot });
if (problems.length === 0) continue;
bad++;
console.error(`${name}\n${problems.map((p) => ` - ${p}`).join("\n")}`);
Expand Down
7 changes: 7 additions & 0 deletions scripts/lib/commit-message.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@ describe("checkCommitMessage", () => {
expect(problems.length).toBeGreaterThan(0);
expect(problems.join("\n")).toMatch(reason);
});

test("a bot's subject may be longer than 72, but still needs a type", () => {
const long = "build(deps-dev): bump the development group across 1 directory with 4 updates";
expect(checkCommitMessage(long, { bot: true })).toEqual([]);
expect(checkCommitMessage(long)).not.toEqual([]);
expect(checkCommitMessage("Bump vite from 7.1.0 to 7.1.1", { bot: true }).join("\n")).toMatch(/type/);
});
});
7 changes: 4 additions & 3 deletions scripts/lib/commit-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ const HEADER = new RegExp(`^(?:${COMMIT_TYPES.join("|")})(?:\\([a-z0-9-]+\\))?!?
/**
* The problems with one commit message, empty when it is fine. Lines that start with `#` are git's
* comments and do not count. Checks the subject (type, optional scope, `!`, at most 72 characters, no
* final period) and the blank line after it; the body is free text.
* final period) and the blank line after it; the body is free text. A bot (Dependabot) writes its own
* subjects, often longer than 72, so for a bot the length is not checked.
*/
export function checkCommitMessage(message: string): string[] {
export function checkCommitMessage(message: string, { bot = false } = {}): string[] {
const lines = message.split("\n").filter((line) => !line.startsWith("#"));
const subject = lines[0]?.trim() ?? "";
if (subject === "") return ["the message is empty"];
Expand All @@ -18,7 +19,7 @@ export function checkCommitMessage(message: string): string[] {
problems.push(
`the subject must start with "<type>: " or "<type>(<scope>): ", type one of ${COMMIT_TYPES.join(", ")}`,
);
if (subject.length > 72) problems.push(`the subject has ${subject.length} characters, at most 72`);
if (!bot && subject.length > 72) problems.push(`the subject has ${subject.length} characters, at most 72`);
if (subject.endsWith(".")) problems.push("the subject ends with a period");
if ((lines[1] ?? "").trim() !== "") problems.push("the second line must be blank");
return problems;
Expand Down
Loading