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
36 changes: 36 additions & 0 deletions .github/workflows/pr-title.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Check PR Title

on:
pull_request:
types: [opened, edited]

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
lint-pr-title:
name: Lint PR title
runs-on: ubuntu-latest

if: ${{ (github.event.action == 'opened' || github.event.changes.title != null) && github.actor != 'renovate[bot]' }}

steps:
- name: Checkout
uses: actions/checkout@v5
with:
persist-credentials: false
# Only fetch the config file from the repository
sparse-checkout-cone-mode: false
sparse-checkout: commitlint.config.ts

- name: Install dependencies
run: npm install -D @commitlint/cli @commitlint/config-conventional

- name: Validate PR title with commitlint
run: echo "$PR_TITLE" | npx commitlint
env:
PR_TITLE: ${{ github.event.pull_request.title }}
38 changes: 38 additions & 0 deletions commitlint.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type { Rule, UserConfig } from '@commitlint/types'
import { RuleConfigSeverity } from '@commitlint/types'

// #region Rules

/**
* Rule to ensure the first letter of the commit subject is lowercase.
*
* @param parsed - Parsed commit object containing commit message parts.
* @returns A tuple where the first element is a boolean indicating
* if the rule passed, and the second is an optional error message.
*/
const subjectLowercaseFirst: Rule = async (parsed) => {
const firstChar = parsed.subject!.match(/[a-z]/i)?.[0]
if (firstChar && firstChar === firstChar.toUpperCase()) {
return [false, 'Subject must start with a lowercase letter']
}
return [true]
}

// #endregion

const Configuration: UserConfig = {
extends: ['@commitlint/config-conventional'],
rules: {
'subject-case': [RuleConfigSeverity.Disabled],
'subject-lowercase-first': [RuleConfigSeverity.Error, 'always'],
},
plugins: [
{
rules: {
'subject-lowercase-first': subjectLowercaseFirst,
},
},
],
}

export default Configuration
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
},
"devDependencies": {
"@antfu/eslint-config": "^6.2.0",
"@commitlint/types": "^20.0.0",
"@types/node": "^24.10.1",
"automd": "^0.4.2",
"bumpp": "^10.3.1",
Expand Down
25 changes: 25 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.