checklog.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env python
  2. ''' Mercurial hook ensuring ChangeLog QA
  3. The hook intended to be used as a reminder for Gentoo overlay maintainers and
  4. commiters. It checks going-to-be changeset for changes in *.ebuild files
  5. and discards commit if no corresponding ChangeLog found.
  6. Usage: add it to [hooks] section of your repo's `hgrc` file like this:
  7. [hooks]
  8. pretxncommit.chlog = `hg root`/Documentation/checklog.py
  9. '''
  10. import os
  11. import subprocess
  12. import sys
  13. hg_process = subprocess.Popen(["hg", "tip", "--template", "{files}"],
  14. stdout=subprocess.PIPE)
  15. eb_dirs = []
  16. chl_dirs = []
  17. for ci_file in hg_process.stdout:
  18. #TODO: deal with Py3k bytetype returned from stdout (shlex.split)
  19. dir = os.path.dirname(ci_file)
  20. if ci_file.endswith('.ebuild') and dir not in eb_dirs:
  21. eb_dirs.append(dir)
  22. elif os.path.basename(ci_file) == "ChangeLog" and dir not in eb_dirs:
  23. chl_dirs.append(dir)
  24. for path in eb_dirs:
  25. if path not in chl_dirs:
  26. eb_dirs.remove(path)
  27. if eb_dirs:
  28. print("\n * Ebuilds in following directories were changed")
  29. print(" * but no changelogs commited")
  30. for i in eb_dirs:
  31. print(i)
  32. print('')
  33. sys.exit(1)