From 31b83a33503eeb8ecc20d7fa8b03ff65aa91ea6a Mon Sep 17 00:00:00 2001 From: Greg Taylor Date: Tue, 24 May 2016 13:20:50 -0700 Subject: [PATCH] Incorporating PEP8 checking on PRs. --- .drone.yml | 4 +++- scripts/stylecheck_git_diff.sh | 37 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100755 scripts/stylecheck_git_diff.sh diff --git a/.drone.yml b/.drone.yml index 483253088..49549fee5 100644 --- a/.drone.yml +++ b/.drone.yml @@ -42,7 +42,7 @@ build: # https://github.com/reddit/docker-reddit-py # Dependency changes in the install scripts can be optionally mirrored to the # image for speedups, but abstaining from doing so won't break the builds. - image: reddit/reddit-py:2.7.6-v1 + image: reddit/reddit-py:2.7.6-v2 environment: DEBIAN_FRONTEND: noninteractive commands: @@ -50,6 +50,8 @@ build: - install/drone.sh - cd r2 - nosetests -v . + - cd .. + - ./scripts/stylecheck_git_diff.sh # These plugins are triggered after a build failure/success. notify: diff --git a/scripts/stylecheck_git_diff.sh b/scripts/stylecheck_git_diff.sh new file mode 100755 index 000000000..9231a48be --- /dev/null +++ b/scripts/stylecheck_git_diff.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +############################################################################### +# git diff style checker +# ---------------------- +# This script runs a style check within our Drone setup, or within the +# `drone exec` runner. +# +# Since the codebase has a substantial body of non-conformant code, style +# checks are only ran on the diffs (compared to master). As a consequence of +# this, style checks also only run on non-master branches. +############################################################################### + +if [[ ${CI_BRANCH} = "master" ]]; then + echo "Skipping style checks on commit(s) to the master branch." + exit 0 +fi + +if [[ ${CI_REPO:=} = "" ]]; then + # This assumed to be `drone exec`. + echo "Running style checks on staged local changes..." + git diff --cached | pep8 --diff +else + echo "Running style checks within Drone..." + git fetch --no-tags --depth=10 origin master + git diff origin/${CI_BRANCH} origin/master | pep8 --diff +fi +error_encountered=$? + +if [[ ${error_encountered} = 1 ]]; then + echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + echo "pep8 issues found. reddit follows pep8: https://github.com/reddit/styleguide" + echo " Please commit a fix or ignore inline with: noqa" + echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + exit 1 +fi + +echo "Style checks passed. Good jerb!"