Skip to content

Commit

Permalink
chore: stricter commitlint checks for pr merge
Browse files Browse the repository at this point in the history
Signed-off-by: Tiago Castro <tiagolobocastro@gmail.com>
  • Loading branch information
tiagolobocastro committed Jan 25, 2024
1 parent 23d2581 commit 9ee3348
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/pr-commitlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,14 @@ jobs:
if [ ! ${{ github.ref }} = "refs/heads/staging" ]; then
first_commit=${{ github.event.pull_request.base.sha }}
last_commit=${{ github.event.pull_request.head.sha }}
# Ensure code-review commits don't get merged
sed "s/code-review-rule': \[0/code-review-rule': [2/g" -i commitlint.config.js
npx commitlint --from $first_commit --to $last_commit -V
git log --pretty=format:%s $first_commit..$last_commit > ./subjects
duplicates="$(cat ./subjects | sort | uniq -D)"
if [ "$duplicates" != "" ]; then
echo -e "Duplicate commits found:\n$duplicates" >&2
exit 1
fi
fi
21 changes: 18 additions & 3 deletions commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,25 @@ module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'type-enum': [2, 'always', ['build', 'chore', 'ci', 'docs', 'feat', 'fix', 'perf', 'refactor', 'revert', 'style', 'test', 'example']],
'code-review-rule': [0, 'always'],
},
defaultIgnores: false,
ignores: [
(message) => message.startsWith('chore(bors): merge pull request #'),
(message) => message.startsWith('Merge #')
]
(message) => message.startsWith('chore(bors): merge pull request #'),
(message) => message.startsWith('Merge #')
],
plugins: [
{
rules: {
'code-review-rule': ({subject}) => {
const REVIEW_COMMENTS = `Please don't merge code-review commits, instead squash them in the parent commit`;
if (subject.includes('code-review')) return [ false, REVIEW_COMMENTS ];
if (subject.includes('review comment')) return [ false, REVIEW_COMMENTS ];
if (subject.includes('address comment')) return [ false, REVIEW_COMMENTS ];
if (subject.includes('addressed comment')) return [ false, REVIEW_COMMENTS ];
return [ true ];
},
},
},
],
}

0 comments on commit 9ee3348

Please sign in to comment.