#!/bin/sh

set -eo pipefail

code_path=$(pwd)

# docker run --tty will merge stderr and stdout, we don't need this on CI or
# it will break codequality json file
[ "$CI" != "" ] || docker_tty="--tty"

docker pull registry.gitlab.com/nolith/codeclimate-gocyclo > /dev/null
docker tag registry.gitlab.com/nolith/codeclimate-gocyclo codeclimate/codeclimate-gocyclo > /dev/null
exec docker run --rm $docker_tty --env CODECLIMATE_CODE="$code_path" \
	--volume "$code_path":/code \
	--volume /var/run/docker.sock:/var/run/docker.sock \
	--volume /tmp/cc:/tmp/cc \
	codeclimate/codeclimate:0.70.3 "$@"
