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.

67 lines
1.9 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. BASE = os.path.dirname(os.path.realpath(__file__)) + "/../../"
  17. README = BASE + "README.md"
  18. remote = subprocess.check_output(["git", "remote", "-v"]).strip().split('\n')[0]
  19. parts = re.split('[/\.: ]', remote)
  20. REPO = parts[ len(parts) - 3]
  21. USER = parts[ len(parts) - 4]
  22. BRANCH = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"]).strip()
  23. def getVersion():
  24. file_name = BASE + "code/espurna/config/version.h"
  25. lines = open(file_name).readlines()
  26. for line in lines:
  27. if "APP_VERSION" in line:
  28. parts = line.split('"')
  29. return parts[1]
  30. return "unknown"
  31. VERSION = getVersion()
  32. version = "[![version](https://img.shields.io/badge/version-{VERSION}-brightgreen.svg)](CHANGELOG.md)\n".format(
  33. VERSION = VERSION
  34. )
  35. branch = "![branch](https://img.shields.io/badge/branch-{BRANCH}-orange.svg)\n".format(
  36. BRANCH = BRANCH
  37. )
  38. travis = "[![travis](https://travis-ci.org/{USER}/{REPO}.svg?branch={BRANCH})]" \
  39. "(https://travis-ci.org/{USER}/{REPO})\n".format(
  40. USER = USER,
  41. REPO = REPO,
  42. BRANCH = BRANCH
  43. )
  44. lines = open(README).readlines()
  45. with open(README, "w") as fh:
  46. for line in lines:
  47. if "![travis]" in line:
  48. fh.write(travis)
  49. elif "![version]" in line:
  50. fh.write(version)
  51. elif "![branch]" in line:
  52. fh.write(branch)
  53. else:
  54. fh.write(line)
  55. subprocess.check_output(["git", "add", README ])