Created
December 5, 2020 19:36
-
-
Save HarlemSquirrel/dae7923024c456cb68b929037dd4bdd6 to your computer and use it in GitHub Desktop.
Filter a command like rubocop to look for issues only on modified lines.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## | |
# Filter a command like rubocop to look for issues only on modified lines. | |
# | |
# Inspired by http://takemikami.com/2018/01/30/RubocopPullRequestCI.html | |
# | |
BASE_REMOTE=origin | |
BASE_BRANCH=master | |
diff_list=() | |
commit_list=$(git --no-pager log --no-merges $BASE_REMOTE/$BASE_BRANCH...HEAD | grep -e '^commit' | sed -e "s/^commit \(.\{8\}\).*/\1/") | |
for f in $(git --no-pager diff $BASE_REMOTE/$BASE_BRANCH...HEAD --name-only --diff-filter=AM); do | |
for c in $commit_list; do | |
diffs=$(git --no-pager blame --show-name -s $f | grep $c | sed -e "s/^[^ ]* *\([^ ]*\) *\([0-9]*\)*).*$/\1:\2/") | |
for ln in $diffs; do | |
diff_list+=( $ln ) | |
done | |
done | |
done | |
err_count=0 | |
while read -r ln; do | |
for m in ${diff_list[@]}; do | |
if [[ ${ln} =~ ^$m ]]; then | |
echo $ln | |
err_count=$((err_count+1)) | |
break | |
fi | |
done | |
done < /dev/stdin | |
if [ $err_count -ne 0 ]; then | |
echo -e "\033[0;31mERROR FOUND, check above messages.\033[0;39m" | |
exit 1 | |
fi | |
echo "OK" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment