#!/bin/sh

set -e
set -u

target="$1"; shift;

report_file="$(mktemp)";

git fetch origin "+refs/heads/master:refs/remotes/origin/master";

# Run twistedchecker and store the output to a file
type twistedchecker 2> /dev/null;  # Error out if executable isn't found.
twistedchecker \
    --output-format=parseable \
    "${target}" \
    > "${report_file}" \
    || true;

# Diff the result against master
diff-quality \
    --violations=pylint \
    --fail-under=100 \
    --compare-branch=origin/master \
    "${report_file}";

rm "${report_file}";
