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.

77 lines
2.2 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)\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. codacy = "[![codacy](https://img.shields.io/codacy/grade/{HASH}/{BRANCH}.svg)]" \
  45. "(https://www.codacy.com/app/{USER}/{REPO}/dashboard)\n".format(
  46. HASH = "c9496e25cf07434cba786b462cb15f49",
  47. USER = USER,
  48. REPO = REPO,
  49. BRANCH = BRANCH
  50. )
  51. lines = open(README).readlines()
  52. with open(README, "w") as fh:
  53. for line in lines:
  54. if "![travis]" in line:
  55. fh.write(travis)
  56. elif "![version]" in line:
  57. fh.write(version)
  58. elif "![branch]" in line:
  59. fh.write(branch)
  60. elif "![codacy]" in line:
  61. fh.write(codacy)
  62. else:
  63. fh.write(line)
  64. subprocess.check_output(["git", "add", README ])