Created
May 19, 2016 16:24
-
-
Save jamesbibby/7b4b2f4d5f83db2911e6c7cfc198528f to your computer and use it in GitHub Desktop.
make this executable in your .git/hooks/pre-commit to automatically update the branch name in your coveralls and travis badges
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import subprocess | |
import fileinput | |
import re | |
GITHUB_USER="" #enter your username | |
REPO="" #enter the name of your repo | |
print "Starting pre-commit hook..." | |
BRANCH=subprocess.check_output(["git", | |
"rev-parse", | |
"--abbrev-ref", | |
"HEAD"]).strip() | |
# Output String with Variable substitution | |
travis="[![Build Status](https://travis-ci.org/{GITHUB_USER}/{REPO}.svg?branch={BRANCH})](https://travis-ci.org/{GITHUB_USER}/{REPO}) ".format(BRANCH=BRANCH, GITHUB_USER=GITHUB_USER, REPO=REPO) | |
coveralls = "[![Coverage Status](https://coveralls.io/repos/github/{GITHUB_USER}/{REPO}/badge.svg?branch={BRANCH})](https://coveralls.io/github/{GITHUB_USER}/{REPO}?branch={BRANCH})".format(BRANCH=BRANCH, GITHUB_USER=GITHUB_USER, REPO=REPO) | |
for line in fileinput.input("README.md", inplace=True): | |
line = re.sub(r'\[\!\[Build Status\]\(https[^\)]*\)\]\(https[^\)]*\)', travis, line.rstrip()) | |
line = re.sub(r'\[\!\[Coverage Status\]\(https[^\)]*\)\]\(https[^\)]*\)', coveralls, line.rstrip()) | |
print(line) | |
subprocess.check_output(["git", "add", "README.md" ]) | |
print "pre-commit hook complete." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment