dco.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env python
  2. import re
  3. import subprocess
  4. import yaml
  5. from env import commit_range
  6. commit_format = '-%n hash: %h%n author: %aN <%aE>%n message: |%n%w(0,2,2)%B'
  7. gitlog = subprocess.check_output([
  8. 'git', 'log', '--reverse',
  9. '--format=format:'+commit_format,
  10. '..'.join(commit_range), '--',
  11. ])
  12. commits = yaml.load(gitlog)
  13. if not commits:
  14. exit(0) # what? how can we have no commits?
  15. DCO = 'Docker-DCO-1.0-Signed-off-by:'
  16. p = re.compile(r'^{0} ([^<]+) <([^<>@]+@[^<>]+)> \(github: (\S+)\)$'.format(re.escape(DCO)), re.MULTILINE|re.UNICODE)
  17. failed_commits = 0
  18. for commit in commits:
  19. m = p.search(commit['message'])
  20. if not m:
  21. print 'Commit {1} does not have a properly formatted "{0}" marker.'.format(DCO, commit['hash'])
  22. failed_commits += 1
  23. continue # print ALL the commits that don't have a proper DCO
  24. (name, email, github) = m.groups()
  25. # TODO verify that "github" is the person who actually made this commit via the GitHub API
  26. if failed_commits > 0:
  27. exit(failed_commits)
  28. print 'All commits have a valid "{0}" marker.'.format(DCO)
  29. exit(0)