Skip to content

Commit

Permalink
chore: commit message linter for changelog\n
Browse files Browse the repository at this point in the history
Enforce conventional commit style messages needed for automatic changelogs
  • Loading branch information
virkt25 committed Sep 12, 2017
1 parent 8e8603e commit 02f2900
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,13 @@ before_script:

after_success:
- npm run coverage:ci

jobs:
include:
- stage: commit linting
before_install: git fetch --unshallow
before_script: skip
script: /bin/bash ./bin/lint-commits.sh
after_success: skip
node_js:
- "8"
25 changes: 25 additions & 0 deletions bin/lint-commits.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# lint-commits.sh
#!/bin/bash
set -e
set -u

if [[ $TRAVIS_PULL_REQUEST_SLUG != "" && $TRAVIS_PULL_REQUEST_SLUG != $TRAVIS_REPO_SLUG ]]; then
# This is a Pull Request from a different slug, hence a forked repository
git remote add "$TRAVIS_PULL_REQUEST_SLUG" "https://github.com/$TRAVIS_PULL_REQUEST_SLUG.git"
git fetch "$TRAVIS_PULL_REQUEST_SLUG"

# Use the fetched remote pointing to the source clone for comparison
TO="$TRAVIS_PULL_REQUEST_SLUG/$TRAVIS_PULL_REQUEST_BRANCH"
else
# This is a Pull Request from the same remote, no clone repository
TO=$TRAVIS_COMMIT
fi

# Lint all commits in the PR
# - Covers fork pull requests (when TO=slug/branch)
# - Covers branch pull requests (when TO=branch)
./node_modules/.bin/commitlint --from="$TRAVIS_BRANCH" --to="$TO"

# Always lint the triggerig commit
# - Covers direct commits
./node_modules/.bin/commitlint --from="$TRAVIS_COMMIT"
16 changes: 16 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
extends: [
'@commitlint/config-angular',
'@commitlint/config-lerna-scopes'
],
rules: {
'header-max-length': [2, 'always', 100],
'footer-max-length': [2, 'always', 100],
'body-tense': [2, 'always', ['present-imperative']],
'footer-tense': [2, 'always', ['present-imperative']],
'subject-tense': [2, 'always', ['present-imperative']],
'lang': [0, 'always', 'eng'],
'body-leading-blank': [2, 'always'],
'footer-leading-blank': [2, 'always'],
}
}
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@
"@types/node": "^8.0.27",
"@types/request": "^2.0.3",
"@types/request-promise": "^4.1.37",
"@commitlint/cli": "^3.2.0",
"@commitlint/config-angular": "^3.1.1",
"@commitlint/config-lerna-scopes": "^3.1.1",
"coveralls": "^2.13.1",
"lerna": "^2.1.2",
"cz-conventional-changelog": "^2.0.0",
"mocha": "^3.4.0",
"nyc": "^11.2.1",
"request": "^2.79.0",
Expand Down Expand Up @@ -55,5 +59,10 @@
"reporter": [
"html"
]
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}

0 comments on commit 02f2900

Please sign in to comment.