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.

80 lines
2.3 KiB

  1. #!/usr/bin/env 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)] "
  36. "(https://github.com/{USER}/{REPO}/tree/{BRANCH}/)\n".format(
  37. USER = USER,
  38. REPO = REPO,
  39. BRANCH = BRANCH
  40. )
  41. travis = "[![travis](https://travis-ci.org/{USER}/{REPO}.svg?branch={BRANCH})]" \
  42. "(https://travis-ci.org/{USER}/{REPO})\n".format(
  43. USER = USER,
  44. REPO = REPO,
  45. BRANCH = BRANCH
  46. )
  47. codacy = "[![codacy](https://img.shields.io/codacy/grade/{HASH}/{BRANCH}.svg)]" \
  48. "(https://www.codacy.com/app/{USER}/{REPO}/dashboard)\n".format(
  49. HASH = "c9496e25cf07434cba786b462cb15f49",
  50. USER = USER,
  51. REPO = REPO,
  52. BRANCH = BRANCH
  53. )
  54. lines = open(README).readlines()
  55. with open(README, "w") as fh:
  56. for line in lines:
  57. if "![travis]" in line:
  58. fh.write(travis)
  59. elif "![version]" in line:
  60. fh.write(version)
  61. elif "![branch]" in line:
  62. fh.write(branch)
  63. elif "![codacy]" in line:
  64. fh.write(codacy)
  65. else:
  66. fh.write(line)
  67. subprocess.check_output(["git", "add", README ])