Skip to content

Instantly share code, notes, and snippets.

@mattmontgomery
Created May 13, 2016 17:49
Show Gist options
  • Save mattmontgomery/4b8cd0cd9357c3470a900e0159da81ab to your computer and use it in GitHub Desktop.
Save mattmontgomery/4b8cd0cd9357c3470a900e0159da81ab to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import sys
import subprocess
import re
from distutils.util import strtobool
output = subprocess.check_output(['git', 'branch'])
lines = output.split('\n')
branch_name = ''
prog = re.compile('^\*')
for line in lines:
if prog.match(line):
branch_name = line.replace('* ','')
print "Currently on branch %s" % branch_name
print "* Running lint"
try:
subprocess.check_output(['npm', 'run', 'lint'])
except subprocess.CalledProcessError as e:
print "lint failed; exiting"
print e
exit(1)
print "* lint passed"
print "* Running tests"
try:
subprocess.check_output(['npm', 'run', 'test-v1'])
except subprocess.CalledProcessError as e:
print "v1 Tests failed"
print e
exit(1)
try:
subprocess.check_output(['npm', 'run', 'test-v2'])
except subprocess.CalledProcessError as e:
print "v2 Tests failed"
print e
exit(1)
print "* Tests passed"
if branch_name == "master":
print "If you really want to commit to master, use git commit -n"
exit(1)
print "* OK to commit"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment