Skip to content

Commit 4a22911

Browse files
feat: support to and from arguments for commitlint
1 parent b294694 commit 4a22911

File tree

4 files changed

+51
-7
lines changed

4 files changed

+51
-7
lines changed

package-lock.json

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/commitlint/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"license": "ISC",
1212
"dependencies": {
1313
"@dotcom-tool-kit/base": "^1.3.0",
14-
"@dotcom-tool-kit/logger": "^4.2.2"
14+
"@dotcom-tool-kit/logger": "^4.2.2",
15+
"zod": "^3.25.76"
1516
},
1617
"repository": {
1718
"type": "git",

plugins/commitlint/readme.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,12 @@ By default the plugin will run on the `git:commitmsg` command. There are no furt
2525
### `Commitlint`
2626

2727
Lint commit messages.
28+
#### Task options
29+
30+
| Property | Description | Type |
31+
| :------- | :---------------------------------------------------------------------------------------------------------------------------------------------- | :------- |
32+
| `from` | The start of the commit range to lint. If neither `from` or `to` are specified, Commitlint will lint the commit message currently being edited. | `string` |
33+
| `to` | The end of the commit range to lint. | `string` |
34+
35+
_All properties are optional._
2836
<!-- end autogenerated docs -->

plugins/commitlint/src/tasks/commitlint.ts

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,43 @@
11
import { fork } from 'child_process'
2-
import { hookFork, waitOnExit } from '@dotcom-tool-kit/logger'
2+
import { hookFork, waitOnExit, styles as s } from '@dotcom-tool-kit/logger'
33
import { Task, TaskRunContext } from '@dotcom-tool-kit/base'
4+
import { z } from 'zod'
45

56
const commitlintCLIPath = require.resolve('.bin/commitlint')
67

7-
export default class Commitlint extends Task {
8-
static description = 'Lint commit messages.'
8+
const CommitlintSchema = z
9+
.object({
10+
from: z
11+
.string()
12+
.optional()
13+
.describe(
14+
'The start of the commit range to lint. If neither `from` or `to` are specified, Commitlint will lint the commit message currently being edited.'
15+
),
16+
to: z.string().optional().describe('The end of the commit range to lint.')
17+
})
18+
.describe('Lint commit messages.')
919

20+
export { CommitlintSchema as schema }
21+
22+
export default class Commitlint extends Task<{ task: typeof CommitlintSchema }> {
1023
async run({ cwd }: TaskRunContext): Promise<void> {
11-
const child = fork(commitlintCLIPath, ['--edit'], { silent: true, cwd })
24+
const args: string[] = []
25+
26+
if (this.options.from) {
27+
args.push('--from', this.options.from)
28+
}
29+
30+
if (this.options.to) {
31+
args.push('--to', this.options.to)
32+
}
33+
34+
if (args.length === 0) {
35+
args.push('--edit')
36+
}
37+
38+
this.logger.info(`running ${s.command(`commitlint ${args.join(' ')}`)}`)
39+
40+
const child = fork(commitlintCLIPath, args, { silent: true, cwd })
1241
hookFork(this.logger, 'commitlint', child)
1342
return waitOnExit('commitlint', child)
1443
}

0 commit comments

Comments
 (0)