dco.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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.1-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. commit['stat'] = subprocess.check_output([
  20. 'git', 'log', '--format=format:', '--max-count=1',
  21. '--name-status', commit['hash'], '--',
  22. ])
  23. if commit['stat'] == '':
  24. print 'Commit {0} has no actual changed content, skipping.'.format(commit['hash'])
  25. continue
  26. m = p.search(commit['message'])
  27. if not m:
  28. print 'Commit {1} does not have a properly formatted "{0}" marker.'.format(DCO, commit['hash'])
  29. failed_commits += 1
  30. continue # print ALL the commits that don't have a proper DCO
  31. (name, email, github) = m.groups()
  32. # TODO verify that "github" is the person who actually made this commit via the GitHub API
  33. if failed_commits > 0:
  34. exit(failed_commits)
  35. print 'All commits have a valid "{0}" marker.'.format(DCO)
  36. exit(0)