Skip to content

Commit

Permalink
fix: conventional commits for PR titles
Browse files Browse the repository at this point in the history
  • Loading branch information
simjak committed Jan 5, 2024
1 parent 1b2013d commit 7d9cc0a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
35 changes: 17 additions & 18 deletions .github/workflows/conventional_commits.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
# Enforces conventional commits on pull requests
# Ref: https://github.com/marketplace/actions/conventional-pull-request

name: Conventional Commits

name: Conventional commits pull request
on:
pull_request:
branches: [main]
types: [opened, edited, synchronize]

jobs:
build:
lint-pr:
if: "${{ !contains(github.event.pull_request.title, 'chore(main): release') }}"
name: Conventional Commits
name: Lint PR
runs-on: ubuntu-latest
timeout-minutes: ${{ fromJSON(vars.DEFAULT_JOB_TIMEOUT_MINUTES) }}
steps:
- uses: actions/checkout@v3
- name: Install commitlint
run: |
npm install @commitlint/cli @commitlint/config-conventional
- name: Fetch merge commit message
id: merge_commit
run: |
MERGE_COMMIT_MESSAGE=$(git log --merges -n 1 --pretty=format:"%s")
echo "::set-output name=message::$MERGE_COMMIT_MESSAGE"
- name: Validate merge commit message
run: |
echo "${{ steps.merge_commit.outputs.message }}" | npx commitlint
- name: Checkout repository
uses: actions/checkout@v4

- name: Validate
uses: CondeNast/conventional-pull-request-action@v0.2.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
commitlintRulesPath: "./commitlint.config.js"
# if the PR contains a single commit, fail if the commit message and the PR title do not match
commitTitleMatch: "false" # default: 'true'
# if you squash merge PRs and enabled "Default to PR title for squash merge commits", you can disable all linting of commits
ignoreCommits: "false" # default: 'false'
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,9 @@ repos:
stages:
- post-commit
- push

- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
rev: v9.11.0
hooks:
- id: commitlint
stages: [commit-msg]
2 changes: 1 addition & 1 deletion commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'subject-case': [2, 'always', 'sentence-case'],
'subject-case': [0, 'never'],
'subject-max-length': [2, 'always', 60],
'type-enum': [2, 'always', ['build', 'chore', 'ci', 'docs', 'feat', 'fix', 'perf', 'refactor', 'style', 'test']],
},
Expand Down

0 comments on commit 7d9cc0a

Please sign in to comment.