From 6a6f446ad74531a0cad67d105c9957f1a7bfa83c Mon Sep 17 00:00:00 2001 From: Michael Pearce Date: Tue, 17 Nov 2026 20:13:54 -0800 Subject: [PATCH 1/3] Require typed pull request titles and the template's sections --- .github/pull_request_template.md | 9 ++- .github/workflows/changelog.yml | 17 ----- .github/workflows/pull-request.yml | 32 ++++++++ CONTRIBUTING.md | 63 +++++++++++++++ README.md | 11 ++- docs/documentation.md | 22 +++--- scripts/check-changelog.mjs | 28 ++++--- scripts/check-pull-request.mjs | 22 ++++++ scripts/pull-request-rules.d.mts | 11 +++ scripts/pull-request-rules.mjs | 98 ++++++++++++++++++++++++ tests/unit/pull-request-rules.test.ts | 106 ++++++++++++++++++++++++++ 11 files changed, 371 insertions(+), 48 deletions(-) delete mode 100644 .github/workflows/changelog.yml create mode 100644 .github/workflows/pull-request.yml create mode 100644 CONTRIBUTING.md create mode 100644 scripts/check-pull-request.mjs create mode 100644 scripts/pull-request-rules.d.mts create mode 100644 scripts/pull-request-rules.mjs create mode 100644 tests/unit/pull-request-rules.test.ts diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 5f89812..cc77cdb 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,3 +1,10 @@ + + ## Summary - @@ -9,4 +16,4 @@ ## Release notes - [ ] Added a release to `src/docs/changelog.ts` describing what changed for users -- [ ] Bumped the version with `npm version minor --no-git-tag-version` (features) or `patch` (fixes), matching the new release +- [ ] Bumped the version to match the title type with `npm version --no-git-tag-version` diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml deleted file mode 100644 index 3a69757..0000000 --- a/.github/workflows/changelog.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: Changelog - -on: - pull_request: - branches: [main] - -jobs: - changelog: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - uses: actions/setup-node@v4 - with: - node-version: 22 - - run: node scripts/check-changelog.mjs origin/${{ github.base_ref }} diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml new file mode 100644 index 0000000..e053c39 --- /dev/null +++ b/.github/workflows/pull-request.yml @@ -0,0 +1,32 @@ +name: Pull request + +on: + pull_request: + branches: [main] + types: [opened, edited, reopened, synchronize] + +jobs: + format: + name: Title and description + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + - run: node scripts/check-pull-request.mjs + + changelog: + name: Changelog and version + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: actions/setup-node@v4 + with: + node-version: 22 + - run: node scripts/check-changelog.mjs "origin/$BASE_REF" + env: + BASE_REF: ${{ github.base_ref }} + PR_TITLE: ${{ github.event.pull_request.title }} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..6b1e191 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,63 @@ +# Contributing + +Pull requests to `main` must pass the **Pull request** checks. They verify the title, +the description, and the release notes. + +## Title + +Start the title with a type, then a colon and a sentence-case summary with no +period: + +```text +feat: Add the Warp tool for closing gaps in scanned parts +fix(drive): Keep Drive connected after a reload +``` + +| Type | Use for | Version | +| ---------- | ----------------------------------- | ------- | +| `feat` | A new feature | minor | +| `fix` | A bug fix | patch | +| `perf` | A performance improvement | patch | +| `docs` | Documentation only | patch | +| `refactor` | Code changes with the same behavior | patch | +| `test` | Tests only | patch | +| `build` | Build, dependencies, or tooling | patch | +| `ci` | Continuous integration | patch | +| `chore` | Other maintenance | patch | + +An optional scope in parentheses, such as `fix(drive):`, narrows the area. Add `!` +after the type, as in `feat!:`, for a breaking change; that is a major version. + +## Description + +Use the [pull request template](.github/pull_request_template.md). The description +starts with these sections, in this order: + +1. `## Summary`: bullets describing what changed and why. +2. `## Testing`: what you ran and what passed, plus anything not tested. +3. `## Release notes`: the template's checklist, with every item checked. + +You can add other sections, such as a review log, after the summary. + +## Release notes and version + +Every pull request adds a release to the documentation's What's new page: + +1. Bump the version to match the title type, for example + `npm version minor --no-git-tag-version` for `feat`. This updates `package.json` + and `package-lock.json`. +2. Add a release with the same version at the top of `src/docs/changelog.ts`, + describing what changed for people using Kitbasher. + +The check compares against `main`: a `feat` pull request on 1.18.0 must be 1.19.0, +and a `fix` must be 1.18.1. If another pull request merges first, merge `main` and +bump again. See [maintaining the documentation](docs/documentation.md#whats-new) +for the release fields. + +## Check locally + +```sh +npm test +PR_TITLE="feat: Add pins" PR_BODY_FILE=body.md node scripts/check-pull-request.mjs +PR_TITLE="feat: Add pins" node scripts/check-changelog.mjs origin/main +``` diff --git a/README.md b/README.md index ea11ab3..21d592a 100644 --- a/README.md +++ b/README.md @@ -951,12 +951,11 @@ See [design specification](docs/design.md) and [verification notes](docs/verific ## Contributing -Every pull request must add a release to the documentation's **What's new** page. -Bump the version with `npm version minor --no-git-tag-version` for features or -`patch` for fixes, then add a release with the same version at the top of -`src/docs/changelog.ts` describing what changed for users. The Changelog check on -pull requests fails until both are done. See -[maintaining the documentation](docs/documentation.md#whats-new). +Pull request titles start with a type such as `feat:`, `fix:`, `perf:`, or `docs:`, +descriptions follow the template's Summary, Testing, and Release notes sections, and +every pull request adds a release to the documentation's **What's new** page with a +matching version bump. Checks on pull requests enforce all three. See +[CONTRIBUTING.md](CONTRIBUTING.md). ## License diff --git a/docs/documentation.md b/docs/documentation.md index 189d06b..0df8e71 100644 --- a/docs/documentation.md +++ b/docs/documentation.md @@ -36,21 +36,17 @@ client-side navigation enhancement. workbench header's What's new button shows the three newest releases and marks one the visitor hasn't opened yet. -Every pull request adds one release at the top of the list: - -1. Run `npm version minor --no-git-tag-version` for a new feature, or `patch` for - a fix or small improvement. This updates `package.json` and `package-lock.json`. -2. Add a release with the same `version`, today's `date`, a short `title`, and one - entry per user-visible change. Mark each `new`, `improved`, or `fixed`, and set - `guide` to an article ID to link to it. +Every pull request adds one release at the top of the list, with the version +bump its title type calls for (see [CONTRIBUTING.md](../CONTRIBUTING.md)). Give the +release the same `version` as `package.json`, today's `date`, a short `title`, and +one entry per user-visible change. Mark each `new`, `improved`, or `fixed`, and set +`guide` to an article ID to link to it. Write for people using Kitbasher, not for reviewers: what they can now do, or what -works differently. The Changelog workflow runs `scripts/check-changelog.mjs`, which -fails a pull request that leaves the changelog untouched, does not raise the -version above `main`, or lets `package.json`, `package-lock.json`, and the newest -release disagree. `tests/unit/changelog.test.ts` checks ordering, dates, and guide -links. If two open pull requests take the same version, the one merged second must -move to the next version. +works differently. `scripts/check-changelog.mjs` fails a pull request that leaves the +changelog untouched, sets a version other than the one its title type calls for, or +lets `package.json`, `package-lock.json`, and the newest release disagree. +`tests/unit/changelog.test.ts` checks ordering, dates, and guide links. ## Images diff --git a/scripts/check-changelog.mjs b/scripts/check-changelog.mjs index 1cd68f3..2032530 100644 --- a/scripts/check-changelog.mjs +++ b/scripts/check-changelog.mjs @@ -1,18 +1,14 @@ import { execFileSync } from 'node:child_process'; import { readFileSync } from 'node:fs'; +import { bumpVersion, expectedBump, isNewer } from './pull-request-rules.mjs'; const changelogPath = 'src/docs/changelog.ts'; const base = process.argv[2] ?? process.env.CHANGELOG_BASE ?? 'origin/main'; +const title = process.env.PR_TITLE; const git = (...args) => execFileSync('git', args, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }); const failures = []; -const parse = (version) => version.split('.').map(Number); -const newer = (a, b) => { - const [x, y] = [parse(a), parse(b)]; - for (let i = 0; i < 3; i++) if (x[i] !== y[i]) return x[i] > y[i]; - return false; -}; const latestIn = (source) => source.match(/version:\s*'(\d+\.\d+\.\d+)'/)?.[1]; const show = (path) => { try { @@ -31,7 +27,8 @@ const version = JSON.parse(readFileSync('package.json', 'utf8')).version; const lockVersion = JSON.parse(readFileSync('package-lock.json', 'utf8')).version; const latest = latestIn(readFileSync(changelogPath, 'utf8')); const baseVersion = JSON.parse(show('package.json') ?? '{"version":"0.0.0"}').version; -const baseLatest = latestIn(show(changelogPath) ?? '') ?? '0.0.0'; +const baseChangelog = show(changelogPath); +const baseLatest = latestIn(baseChangelog ?? '') ?? '0.0.0'; if (latest !== version) failures.push( @@ -39,15 +36,24 @@ if (latest !== version) ); if (lockVersion !== version) failures.push(`package-lock.json is ${lockVersion}, but package.json is ${version}.`); -if (!newer(version, baseVersion)) - failures.push(`Bump package.json above ${baseVersion}, the version on ${base}.`); -if (!newer(latest ?? '0.0.0', baseLatest)) +if (!isNewer(latest ?? '0.0.0', baseLatest)) failures.push(`Add a release newer than ${baseLatest} at the top of ${changelogPath}.`); +// The pull request that introduces the changelog also backfills earlier versions. +const level = title && baseChangelog ? expectedBump(title) : undefined; +if (level) { + const expected = bumpVersion(baseVersion, level); + if (version !== expected) + failures.push( + `A "${title.split(':')[0]}" pull request is a ${level} release: set the version to ${expected}, not ${version}.`, + ); +} else if (!isNewer(version, baseVersion)) + failures.push(`Bump package.json above ${baseVersion}, the version on ${base}.`); + if (failures.length) { console.error(`Changelog check failed against ${base}:\n- ${failures.join('\n- ')}`); console.error( - '\nRun `npm version minor --no-git-tag-version` (or patch for fixes) and add a matching release to src/docs/changelog.ts.', + `\nRun \`npm version ${level ?? 'minor'} --no-git-tag-version\` and add a matching release to ${changelogPath}.`, ); process.exit(1); } diff --git a/scripts/check-pull-request.mjs b/scripts/check-pull-request.mjs new file mode 100644 index 0000000..b3f4be3 --- /dev/null +++ b/scripts/check-pull-request.mjs @@ -0,0 +1,22 @@ +import { readFileSync } from 'node:fs'; +import { checkBody, checkTitle, pullRequestTypes } from './pull-request-rules.mjs'; + +const event = process.env.GITHUB_EVENT_PATH + ? JSON.parse(readFileSync(process.env.GITHUB_EVENT_PATH, 'utf8')).pull_request + : undefined; +const title = process.env.PR_TITLE ?? event?.title ?? ''; +const body = process.env.PR_BODY_FILE + ? readFileSync(process.env.PR_BODY_FILE, 'utf8') + : (process.env.PR_BODY ?? event?.body ?? ''); + +const failures = [...checkTitle(title), ...checkBody(body)]; +if (failures.length) { + console.error(`Pull request format check failed:\n- ${failures.join('\n- ')}`); + console.error( + `\nTitle types:\n${Object.entries(pullRequestTypes) + .map(([type, { label }]) => ` ${type}: ${label}`) + .join('\n')}\nSee CONTRIBUTING.md and .github/pull_request_template.md.`, + ); + process.exit(1); +} +console.log(`Pull request format is valid: ${title}`); diff --git a/scripts/pull-request-rules.d.mts b/scripts/pull-request-rules.d.mts new file mode 100644 index 0000000..7c51022 --- /dev/null +++ b/scripts/pull-request-rules.d.mts @@ -0,0 +1,11 @@ +export type VersionBump = 'major' | 'minor' | 'patch'; +export const pullRequestTypes: Record; +export const requiredSections: string[]; +export function parseTitle( + title: string, +): { type: string; breaking: boolean; subject: string } | undefined; +export function checkTitle(title: string): string[]; +export function checkBody(body: string | null | undefined): string[]; +export function bumpVersion(version: string, level: VersionBump): string; +export function isNewer(a: string, b: string): boolean; +export function expectedBump(title: string): VersionBump | undefined; diff --git a/scripts/pull-request-rules.mjs b/scripts/pull-request-rules.mjs new file mode 100644 index 0000000..26727b6 --- /dev/null +++ b/scripts/pull-request-rules.mjs @@ -0,0 +1,98 @@ +export const pullRequestTypes = { + feat: { label: 'New feature', bump: 'minor' }, + fix: { label: 'Bug fix', bump: 'patch' }, + perf: { label: 'Performance', bump: 'patch' }, + docs: { label: 'Documentation', bump: 'patch' }, + refactor: { label: 'Refactor with no change in behavior', bump: 'patch' }, + test: { label: 'Tests only', bump: 'patch' }, + build: { label: 'Build, dependencies, or tooling', bump: 'patch' }, + ci: { label: 'Continuous integration', bump: 'patch' }, + chore: { label: 'Maintenance', bump: 'patch' }, +}; + +export const requiredSections = ['Summary', 'Testing', 'Release notes']; + +const titlePattern = new RegExp( + `^(${Object.keys(pullRequestTypes).join('|')})(\\([a-z0-9-]+\\))?(!)?: (.+)$`, +); + +export function parseTitle(title) { + const match = title.trim().match(titlePattern); + return match ? { type: match[1], breaking: !!match[3], subject: match[4] } : undefined; +} + +export function checkTitle(title) { + const parsed = parseTitle(title); + if (!parsed) + return [ + `Start the title with a type, such as "feat: Add the Warp tool". Types: ${Object.keys(pullRequestTypes).join(', ')}.`, + ]; + const failures = []; + if (!/^[A-Z]/.test(parsed.subject)) + failures.push('Start the title after the type with a capital letter.'); + if (/[.\s]$/.test(parsed.subject)) failures.push('End the title without a period or space.'); + if (title.trim().length > 80) failures.push('Keep the title to 80 characters or fewer.'); + return failures; +} + +const meaningful = (text) => + text + .split('\n') + .map((line) => line.replace(/^\s*(?:[-*]|\d+\.)\s*/, '').trim()) + .some(Boolean); + +export function checkBody(body) { + const text = (body ?? '').replace(//g, '').replace(/\r\n/g, '\n'); + const sections = [...text.matchAll(/^## +(.+?)\s*$/gm)].map((match, i, all) => ({ + title: match[1], + content: text.slice(match.index + match[0].length, all[i + 1]?.index ?? text.length), + })); + const found = sections.map((section) => section.title); + const failures = []; + const positions = requiredSections.map((title) => found.indexOf(title)); + for (const [i, title] of requiredSections.entries()) + if (positions[i] < 0) failures.push(`Add a "## ${title}" section.`); + if ( + positions.every((position) => position >= 0) && + positions.some((p, i) => i && p < positions[i - 1]) + ) + failures.push( + `Order the sections ${requiredSections.map((title) => `"${title}"`).join(', ')}.`, + ); + if (found[0] !== undefined && found[0] !== 'Summary') + failures.push('Start the description with the "## Summary" section.'); + const content = (title) => sections.find((section) => section.title === title)?.content ?? ''; + for (const title of ['Summary', 'Testing']) + if (found.includes(title) && !meaningful(content(title))) + failures.push(`Fill in the "${title}" section.`); + if (found.includes('Release notes')) { + const notes = content('Release notes'); + if (/^\s*[-*] \[ \]/m.test(notes)) failures.push('Check every item under "Release notes".'); + else if (!/^\s*[-*] \[[xX]\]/m.test(notes)) + failures.push('Keep the checklist from the template under "Release notes".'); + } + return failures; +} + +const parseVersion = (version) => version.split('.').map(Number); + +export function bumpVersion(version, level) { + const [major, minor, patch] = parseVersion(version); + return level === 'major' + ? `${major + 1}.0.0` + : level === 'minor' + ? `${major}.${minor + 1}.0` + : `${major}.${minor}.${patch + 1}`; +} + +export function isNewer(a, b) { + const [x, y] = [parseVersion(a), parseVersion(b)]; + for (let i = 0; i < 3; i++) if (x[i] !== y[i]) return x[i] > y[i]; + return false; +} + +export function expectedBump(title) { + const parsed = parseTitle(title); + if (!parsed) return undefined; + return parsed.breaking ? 'major' : pullRequestTypes[parsed.type].bump; +} diff --git a/tests/unit/pull-request-rules.test.ts b/tests/unit/pull-request-rules.test.ts new file mode 100644 index 0000000..8494e30 --- /dev/null +++ b/tests/unit/pull-request-rules.test.ts @@ -0,0 +1,106 @@ +import { readFileSync } from 'node:fs'; +import { describe, expect, it } from 'vitest'; +import { + bumpVersion, + checkBody, + checkTitle, + expectedBump, +} from '../../scripts/pull-request-rules.mjs'; + +const template = readFileSync('.github/pull_request_template.md', 'utf8'); +const filled = `## Summary + +- Add the Warp tool. + +## Testing + +- \`npm test\` passed. + +## Council review + +Approved. + +## Release notes + +- [x] Added a release to \`src/docs/changelog.ts\` +- [x] Bumped the version +`; + +describe('pull request titles', () => { + it('accepts a type, optional scope or breaking marker, and a sentence-case subject', () => { + for (const title of [ + 'feat: Add the Warp tool for closing gaps in scanned parts', + 'fix(drive): Keep Drive connected after a reload', + 'perf: Speed up remeshing', + 'docs: Add editor screenshots to guides', + 'feat!: Replace the scene format', + ]) + expect(checkTitle(title), title).toEqual([]); + }); + + it('rejects titles without a known type or with a malformed subject', () => { + expect(checkTitle('Add the Warp tool')).toHaveLength(1); + expect(checkTitle('feature: Add the Warp tool')).toHaveLength(1); + expect(checkTitle('feat: add the Warp tool')).toEqual([ + 'Start the title after the type with a capital letter.', + ]); + expect(checkTitle('fix: Keep Drive connected.')).toEqual([ + 'End the title without a period or space.', + ]); + expect(checkTitle(`feat: ${'A'.repeat(80)}`)).toContain( + 'Keep the title to 80 characters or fewer.', + ); + }); + + it('maps the type to a version bump', () => { + expect(expectedBump('feat: Add pins')).toBe('minor'); + expect(expectedBump('fix: Keep pins')).toBe('patch'); + expect(expectedBump('docs: Explain pins')).toBe('patch'); + expect(expectedBump('feat!: Replace pins')).toBe('major'); + expect(expectedBump('Add pins')).toBeUndefined(); + expect(bumpVersion('1.18.3', 'minor')).toBe('1.19.0'); + expect(bumpVersion('1.18.3', 'patch')).toBe('1.18.4'); + expect(bumpVersion('1.18.3', 'major')).toBe('2.0.0'); + }); +}); + +describe('pull request descriptions', () => { + it('accepts the filled-in template, with extra sections allowed after the summary', () => { + expect(checkBody(filled)).toEqual([]); + }); + + it('rejects the unfilled template', () => { + expect(checkBody(template)).toEqual([ + 'Fill in the "Summary" section.', + 'Fill in the "Testing" section.', + 'Check every item under "Release notes".', + ]); + }); + + it('requires every section, in order, starting with the summary', () => { + expect(checkBody('')).toEqual([ + 'Add a "## Summary" section.', + 'Add a "## Testing" section.', + 'Add a "## Release notes" section.', + ]); + const reordered = filled + .replace('## Summary', '## Tmp') + .replace('## Testing', '## Summary') + .replace('## Tmp', '## Testing'); + expect(checkBody(reordered)).toContain( + 'Order the sections "Summary", "Testing", "Release notes".', + ); + expect(checkBody(`## Notes\n\nHi\n\n${filled}`)).toContain( + 'Start the description with the "## Summary" section.', + ); + }); + + it('requires the release notes checklist to be kept and checked', () => { + expect(checkBody(filled.replace('- [x] Bumped', '- [ ] Bumped'))).toEqual([ + 'Check every item under "Release notes".', + ]); + expect(checkBody(filled.replace(/- \[x\].*\n/g, 'Done.\n'))).toEqual([ + 'Keep the checklist from the template under "Release notes".', + ]); + }); +}); From c11431a177fce4fff00d80ec8fd9994408b1cf16 Mon Sep 17 00:00:00 2001 From: Michael Pearce Date: Tue, 17 Nov 2026 21:15:29 -0800 Subject: [PATCH 2/3] Add the 1.18.1 release for typed pull request titles --- package-lock.json | 4 ++-- package.json | 2 +- src/docs/changelog.ts | 11 +++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1a312d4..bb5a071 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "kitbasher", - "version": "1.18.0", + "version": "1.18.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "kitbasher", - "version": "1.18.0", + "version": "1.18.1", "license": "MIT", "dependencies": { "@fontsource-variable/inter": "^5.3.0", diff --git a/package.json b/package.json index 8664871..febb6c6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kitbasher", - "version": "1.18.0", + "version": "1.18.1", "description": "A local-first 3D assembly workbench for multipart models", "scripts": { "dev": "vite", diff --git a/src/docs/changelog.ts b/src/docs/changelog.ts index 3de3094..1b63c26 100644 --- a/src/docs/changelog.ts +++ b/src/docs/changelog.ts @@ -15,6 +15,17 @@ export interface Release { // Newest first. Every pull request adds a release here and sets the same version in package.json. export const releases: Release[] = [ + { + version: '1.18.1', + date: '2026-11-17', + title: 'Version numbers', + changes: [ + { + kind: 'improved', + text: 'Version numbers follow the kind of change in each release: new features raise the middle number, and fixes and smaller changes raise the last one.', + }, + ], + }, { version: '1.18.0', date: '2026-11-17', From cd2bdb46c77576f531053d9b7f1e7c1e3b101e2a Mon Sep 17 00:00:00 2001 From: Michael Pearce Date: Tue, 17 Nov 2026 21:59:45 -0800 Subject: [PATCH 3/3] Put the pull request type in parentheses --- .github/pull_request_template.md | 4 ++-- CONTRIBUTING.md | 16 ++++++------- README.md | 2 +- scripts/check-changelog.mjs | 4 ++-- scripts/pull-request-rules.mjs | 8 +++---- tests/unit/pull-request-rules.test.ts | 34 +++++++++++++++------------ 6 files changed, 35 insertions(+), 33 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index cc77cdb..48228c0 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,8 +1,8 @@ ## Summary diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6b1e191..3b6f422 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,12 +5,12 @@ the description, and the release notes. ## Title -Start the title with a type, then a colon and a sentence-case summary with no -period: +Start the title with a type in parentheses, then a space and a sentence-case summary +with no period: ```text -feat: Add the Warp tool for closing gaps in scanned parts -fix(drive): Keep Drive connected after a reload +(feat) Add the Warp tool for closing gaps in scanned parts +(fix) Keep Drive connected after a reload ``` | Type | Use for | Version | @@ -25,8 +25,8 @@ fix(drive): Keep Drive connected after a reload | `ci` | Continuous integration | patch | | `chore` | Other maintenance | patch | -An optional scope in parentheses, such as `fix(drive):`, narrows the area. Add `!` -after the type, as in `feat!:`, for a breaking change; that is a major version. +Add `!` after the type, as in `(feat!)`, for a breaking change; that is a major +version. ## Description @@ -58,6 +58,6 @@ for the release fields. ```sh npm test -PR_TITLE="feat: Add pins" PR_BODY_FILE=body.md node scripts/check-pull-request.mjs -PR_TITLE="feat: Add pins" node scripts/check-changelog.mjs origin/main +PR_TITLE="(feat) Add pins" PR_BODY_FILE=body.md node scripts/check-pull-request.mjs +PR_TITLE="(feat) Add pins" node scripts/check-changelog.mjs origin/main ``` diff --git a/README.md b/README.md index 21d592a..b9b336a 100644 --- a/README.md +++ b/README.md @@ -951,7 +951,7 @@ See [design specification](docs/design.md) and [verification notes](docs/verific ## Contributing -Pull request titles start with a type such as `feat:`, `fix:`, `perf:`, or `docs:`, +Pull request titles start with a type in parentheses, such as `(feat)` or `(fix)`, descriptions follow the template's Summary, Testing, and Release notes sections, and every pull request adds a release to the documentation's **What's new** page with a matching version bump. Checks on pull requests enforce all three. See diff --git a/scripts/check-changelog.mjs b/scripts/check-changelog.mjs index 2032530..0891b81 100644 --- a/scripts/check-changelog.mjs +++ b/scripts/check-changelog.mjs @@ -1,6 +1,6 @@ import { execFileSync } from 'node:child_process'; import { readFileSync } from 'node:fs'; -import { bumpVersion, expectedBump, isNewer } from './pull-request-rules.mjs'; +import { bumpVersion, expectedBump, isNewer, parseTitle } from './pull-request-rules.mjs'; const changelogPath = 'src/docs/changelog.ts'; const base = process.argv[2] ?? process.env.CHANGELOG_BASE ?? 'origin/main'; @@ -45,7 +45,7 @@ if (level) { const expected = bumpVersion(baseVersion, level); if (version !== expected) failures.push( - `A "${title.split(':')[0]}" pull request is a ${level} release: set the version to ${expected}, not ${version}.`, + `A "(${parseTitle(title).type})" pull request is a ${level} release: set the version to ${expected}, not ${version}.`, ); } else if (!isNewer(version, baseVersion)) failures.push(`Bump package.json above ${baseVersion}, the version on ${base}.`); diff --git a/scripts/pull-request-rules.mjs b/scripts/pull-request-rules.mjs index 26727b6..52192a0 100644 --- a/scripts/pull-request-rules.mjs +++ b/scripts/pull-request-rules.mjs @@ -12,20 +12,18 @@ export const pullRequestTypes = { export const requiredSections = ['Summary', 'Testing', 'Release notes']; -const titlePattern = new RegExp( - `^(${Object.keys(pullRequestTypes).join('|')})(\\([a-z0-9-]+\\))?(!)?: (.+)$`, -); +const titlePattern = new RegExp(`^\\((${Object.keys(pullRequestTypes).join('|')})(!)?\\) (.+)$`); export function parseTitle(title) { const match = title.trim().match(titlePattern); - return match ? { type: match[1], breaking: !!match[3], subject: match[4] } : undefined; + return match ? { type: match[1], breaking: !!match[2], subject: match[3] } : undefined; } export function checkTitle(title) { const parsed = parseTitle(title); if (!parsed) return [ - `Start the title with a type, such as "feat: Add the Warp tool". Types: ${Object.keys(pullRequestTypes).join(', ')}.`, + `Start the title with a type in parentheses, such as "(feat) Add the Warp tool". Types: ${Object.keys(pullRequestTypes).join(', ')}.`, ]; const failures = []; if (!/^[A-Z]/.test(parsed.subject)) diff --git a/tests/unit/pull-request-rules.test.ts b/tests/unit/pull-request-rules.test.ts index 8494e30..7186ad2 100644 --- a/tests/unit/pull-request-rules.test.ts +++ b/tests/unit/pull-request-rules.test.ts @@ -27,36 +27,40 @@ Approved. `; describe('pull request titles', () => { - it('accepts a type, optional scope or breaking marker, and a sentence-case subject', () => { + it('accepts a type in parentheses, an optional breaking marker, and a sentence-case subject', () => { for (const title of [ - 'feat: Add the Warp tool for closing gaps in scanned parts', - 'fix(drive): Keep Drive connected after a reload', - 'perf: Speed up remeshing', - 'docs: Add editor screenshots to guides', - 'feat!: Replace the scene format', + '(feat) Add the Warp tool for closing gaps in scanned parts', + '(fix) Keep Drive connected after a reload', + '(perf) Speed up remeshing', + '(docs) Add editor screenshots to guides', + '(feat!) Replace the scene format', ]) expect(checkTitle(title), title).toEqual([]); }); - it('rejects titles without a known type or with a malformed subject', () => { + it('rejects titles without a known type in parentheses or with a malformed subject', () => { expect(checkTitle('Add the Warp tool')).toHaveLength(1); - expect(checkTitle('feature: Add the Warp tool')).toHaveLength(1); - expect(checkTitle('feat: add the Warp tool')).toEqual([ + expect(checkTitle('feat: Add the Warp tool')).toHaveLength(1); + expect(checkTitle('(feat): Add the Warp tool')).toHaveLength(1); + expect(checkTitle('(fix/drive) Keep Drive connected')).toHaveLength(1); + expect(checkTitle('(feature) Add the Warp tool')).toHaveLength(1); + expect(checkTitle('(feat) add the Warp tool')).toEqual([ 'Start the title after the type with a capital letter.', ]); - expect(checkTitle('fix: Keep Drive connected.')).toEqual([ + expect(checkTitle('(fix) Keep Drive connected.')).toEqual([ 'End the title without a period or space.', ]); - expect(checkTitle(`feat: ${'A'.repeat(80)}`)).toContain( + expect(checkTitle(`(feat) ${'A'.repeat(80)}`)).toContain( 'Keep the title to 80 characters or fewer.', ); }); it('maps the type to a version bump', () => { - expect(expectedBump('feat: Add pins')).toBe('minor'); - expect(expectedBump('fix: Keep pins')).toBe('patch'); - expect(expectedBump('docs: Explain pins')).toBe('patch'); - expect(expectedBump('feat!: Replace pins')).toBe('major'); + expect(expectedBump('(feat) Add pins')).toBe('minor'); + expect(expectedBump('(fix) Keep pins')).toBe('patch'); + expect(expectedBump('(docs) Explain pins')).toBe('patch'); + expect(expectedBump('(feat!) Replace pins')).toBe('major'); + expect(expectedBump('feat: Add pins')).toBeUndefined(); expect(expectedBump('Add pins')).toBeUndefined(); expect(bumpVersion('1.18.3', 'minor')).toBe('1.19.0'); expect(bumpVersion('1.18.3', 'patch')).toBe('1.18.4');