Created
February 8, 2016 16:21
-
-
Save kyoh86/b833b63ee7f6893f1187 to your computer and use it in GitHub Desktop.
golintと闘いたいけど心の折れてしまった勇者のための隠しダンジョン ref: http://qiita.com/kyoh86/items/1f2022b63372b84f1a27
This file contains 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
owner= # 対象リポジトリ名(オーナー名)を設定 | |
repos= # 対象リポジトリ名を設定 | |
min_confidence=0.9 # 警告のレベル | |
head=$(git rev-parse --abbrev-ref @) # 現在のブランチを取得 | |
if [ -n "${head}" ] | |
then | |
# 現在のブランチをheadとするpull-requestを探す | |
base=$(gogh pr ls --repo ${owner}/${repos} --head ${owner}:${head} --state open --row-format $'{{.Base.Ref}}') | |
if [ -z "${base}" ] | |
then | |
# pull-requestが見つからなければそのまま終了 | |
echo "pull-request is not found" | |
else | |
# pull-requestのbaseブランチと、差分のあるファイルの一覧を取得 | |
tmpfile=$(mktemp) | |
git fetch origin ${base}:${base} | |
git diff ${base}...${head} --name-only | grep -v > ${tmpfile} | |
# golintを実行して、差分のあるファイルに関する部分だけを抽出する | |
lint=$(golint --min_confidence=${min_confidence} ./... | grep -F -f ${tmpfile}) | |
rm ${tmpfile} | |
# lintの結果、何かしらの出力があればエラーとする | |
if [ -n "${lint}" ] | |
then | |
echo "${lint}" | |
exit 1 | |
fi | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment