Skip to content
This repository has been archived by the owner on May 4, 2022. It is now read-only.

ci(travis): run commitlint on travis ci #581

Merged
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
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ addons:
firefox: latest

before_install:
- git fetch --unshallow # needed for commitlint
- nvm i node
- npm install
- npm install -g greenkeeper-lockfile@1
Expand All @@ -31,6 +32,7 @@ before_script: greenkeeper-lockfile-update
script :
- npm run build-static
- npm test -- --browsers $BROWSERS
- bash tools/lint-commits.sh # script lint commit messages, handles commits from forks and same repo
- npm run lint-js
- npm run lint-css
- npm run lint-md
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"version": "6.1.0",
"description": "Application Framework for uPortal",
"scripts": {
"commitmsg": "commitlint -e",
"cz": "git-cz",
"test": "karma start components/karma.conf.js --single-run",
"build-static": "node tools/static/build.js",
Expand Down
48 changes: 48 additions & 0 deletions tools/lint-commits.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash
#
# Licensed to Apereo under one or more contributor license
# agreements. See the NOTICE file distributed with this work
# for additional information regarding copyright ownership.
# Apereo licenses this file to you under the Apache License,
# Version 2.0 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a
# copy of the License at the following location:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

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
echo this is a pull request from fork
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
echo this is an internal pull request
# 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)
echo $TRAVIS_BRANCH
echo $TO
npx commitlint --from="$TRAVIS_BRANCH" --to="$TO"

# Always lint the triggerig commit
# - Covers direct commits
echo $TRAVIS_COMMIT
npx commitlint --from="$TRAVIS_COMMIT"