|
1 | 1 | #!/bin/bash
|
2 |
| -if [ "$CI_PULL_REQUEST" == false ] || [ -z "$CI_PULL_REQUEST" ]; then |
| 2 | + |
| 3 | +# Test if pull request |
| 4 | +if [ "$TRAVIS_PULL_REQUEST" = "false" ] || [ -z "$TRAVIS_PULL_REQUEST" ]; then |
3 | 5 | echo 'not pull request.'
|
4 | 6 | exit 0
|
5 | 7 | fi
|
6 | 8 |
|
| 9 | +# Fetch other branch |
| 10 | +# To avoid ambiguous argument |
| 11 | +# http://stackoverflow.com/questions/37303969/git-fatal-ambiguous-argument-head-unknown-revision-or-path-not-in-the-workin |
| 12 | +if [ "$TRAVIS" == "true" ]; then |
| 13 | + #resolving `detached HEAD` by attaching HEAD to the `TRAVIS_FROM_BRANCH` branch |
| 14 | + TRAVIS_FROM_BRANCH="travis_from_branch" |
| 15 | + git branch $TRAVIS_FROM_BRANCH |
| 16 | + git checkout $TRAVIS_FROM_BRANCH |
| 17 | + |
| 18 | + #fetching `TRAVIS_BRANCH` branch |
| 19 | + git fetch origin $TRAVIS_BRANCH |
| 20 | + git checkout -qf FETCH_HEAD |
| 21 | + git branch $TRAVIS_BRANCH |
| 22 | + git checkout $TRAVIS_BRANCH |
| 23 | + |
| 24 | + #switch to `TRAVIS_FROM_BRANCH` |
| 25 | + git checkout $TRAVIS_FROM_BRANCH |
| 26 | +fi |
| 27 | + |
| 28 | +# Install saddler |
| 29 | +# https://github.com/packsaddle/ruby-saddler |
| 30 | +# Need secret env: `GITHUB_ACCESS_TOKEN=xxx` |
7 | 31 | gem install --no-document checkstyle_filter-git saddler saddler-reporter-github
|
8 | 32 |
|
9 | 33 | # Diff Target Branch
|
10 | 34 | # diff HEAD...target
|
11 | 35 | # http://stackoverflow.com/questions/3161204/find-the-parent-branch-of-a-git-branch
|
12 | 36 | # http://qiita.com/upinetree/items/0b74b08b64442f0a89b9
|
13 |
| -diffBranchName=$(git show-branch | grep '*' | grep -v "$(git rev-parse --abbrev-ref HEAD)" | head -1 | awk -F'[]~^[]' '{print $2}') |
14 |
| -# 変更行のみを対象にする |
| 37 | +declare diffBranchName=$(git show-branch | grep '*' | grep -v "$(git rev-parse --abbrev-ref HEAD)" | head -1 | awk -F'[]~^[]' '{print $2}') |
| 38 | + |
| 39 | +# filter files and lint |
| 40 | +echo "${diffBranchName}...HEAD" |
| 41 | +echo "textlint -> review_comments" |
15 | 42 | git diff --name-only --diff-filter=ACMR ${diffBranchName} \
|
16 |
| -| grep -a '*.md$' \ |
| 43 | +| grep -a '.*.md$' \ |
17 | 44 | | xargs $(npm bin)/textlint -f checkstyle \
|
18 | 45 | | checkstyle_filter-git diff ${diffBranchName} \
|
19 | 46 | | saddler report \
|
|
0 commit comments