Skip to content

Commit

Permalink
chore(ci): add commit lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Morten Henriksen committed Nov 28, 2017
1 parent db95bf9 commit 777b891
Show file tree
Hide file tree
Showing 4 changed files with 315 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ cache:
node_js:
- '8'

before_install: git fetch --unshallow

install:
- npm install
- curl https://install.meteor.com/ | sh
Expand All @@ -19,6 +21,7 @@ stages:
- release

script:
- ./bin/lint-commit.sh
- npm test
- if [ "$TRAVIS_BRANCH" == "master" ]; then npm run semantic-release; fi

Expand Down
25 changes: 25 additions & 0 deletions bin/lint-commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/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"
H
Loading

0 comments on commit 777b891

Please sign in to comment.