#!/bin/bash
# Copyright: 2017 - 2018 - MIT License
# Source: https://github.com/envygeeks/devfiles
# Author: Jordon Bedwell
[ "$DEBUG" = "true" ] && set -x
set -e

f=script/script.d/report
[ "$SKIP_SCRIPTD" != "true" ] && [ -x $f ] && exec $f "$@"
if [ "$TRAVIS_PULL_REQUEST" = "false" ] && [ "$TRAVIS" = "true" ]; then
  if [ "$1" = "before" ]; then
    # TODO: Start tracking the SHA sum, this is crazy..
    url=https://codeclimate.com/downloads/test-reporter
    url=$url/test-reporter-latest-linux-amd64
    curl -sL $url > ./cctr

    # --
    # Eventually they should make this the default on Travis-CI
    #   this way I don't worry about some strange stuff going on with
    #   a possible compromise, and an invalid SHA.
    # --

    chmod +x ./cctr && ./cctr before-build
  else
    ./cctr after-build --exit-code \
      $TRAVIS_TEST_RESULT
  fi
fi
