commit-msg 615 B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env python3
  2. import sys
  3. commitmsg = ""
  4. with open('.git/COMMIT_EDITMSG', mode='r') as f:
  5. commitmsg = f.readline().strip()
  6. print("Commit message is: " + commitmsg)
  7. ALLOWED_COMMIT_TYPES = [
  8. "cicd",
  9. "test",
  10. "refactor",
  11. "depbump",
  12. "typo",
  13. "fmt",
  14. "doc",
  15. "bugfix",
  16. "security",
  17. "feature",
  18. ]
  19. for allowedType in ALLOWED_COMMIT_TYPES:
  20. if commitmsg.startswith(allowedType + ":"):
  21. print("Allowing commit type: ", allowedType)
  22. sys.exit(0)
  23. print("Commit message should start with commit type. One of: ", ", ".join(ALLOWED_COMMIT_TYPES))
  24. sys.exit(1)