Skip to content

Instantly share code, notes, and snippets.

@kyoh86
Created February 8, 2016 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyoh86/b833b63ee7f6893f1187 to your computer and use it in GitHub Desktop.
Save kyoh86/b833b63ee7f6893f1187 to your computer and use it in GitHub Desktop.
golintと闘いたいけど心の折れてしまった勇者のための隠しダンジョン ref: http://qiita.com/kyoh86/items/1f2022b63372b84f1a27
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