Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.5 KiB

  1. #!/usr/bin/python
  2. """
  3. Referencing current branch in github README.md [1]
  4. This pre-commit hook [2] updates the README.md file's
  5. Travis badge with the current branch. Based on [4].
  6. [1] http://stackoverflow.com/questions/18673694/referencing-current-branch-in-github-readme-md
  7. [2] http://www.git-scm.com/book/en/v2/Customizing-Git-Git-Hooks
  8. [3] https://docs.travis-ci.com/user/status-images/
  9. [4] https://gist.github.com/dandye/dfe0870a6a1151c89ed9
  10. Copy this file to .git/hooks/
  11. """
  12. import os
  13. import sys
  14. import re
  15. import subprocess
  16. README = os.path.dirname(os.path.realpath(__file__)) + "/../../README.md"
  17. remote = subprocess.check_output(["git", "remote", "-v"]).strip().split('\n')[0]
  18. parts = re.split('[/\.: ]', remote)
  19. REPO = parts[ len(parts) - 3]
  20. USER = parts[ len(parts) - 4]
  21. BRANCH=subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"]).strip()
  22. branch_mark = "![branch]"
  23. branch = "![branch](https://img.shields.io/badge/branch-{BRANCH}-orange.svg)\n".format(
  24. BRANCH=BRANCH
  25. )
  26. travis_mark = "![travis]"
  27. travis = "[![travis](https://travis-ci.org/{USER}/{REPO}.svg?branch={BRANCH})]" \
  28. "(https://travis-ci.org/{USER}/{REPO})\n".format(
  29. USER=USER,
  30. REPO=REPO,
  31. BRANCH=BRANCH
  32. )
  33. lines = open(README).readlines()
  34. with open(README, "w") as fh:
  35. for line in lines:
  36. if travis_mark in line:
  37. fh.write(travis)
  38. elif branch_mark in line:
  39. fh.write(branch)
  40. else:
  41. fh.write(line)
  42. subprocess.check_output(["git", "add", README ])