gather_git_credits.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/env python3
  2. import subprocess
  3. import re
  4. from collections import defaultdict
  5. codefiles = r"(\.[ch](pp)?|\.lua|\.md|\.cmake|\.java|\.gradle|Makefile|CMakeLists\.txt)$"
  6. # two minor versions back, for "Active Contributors"
  7. REVS_ACTIVE = "5.6.0..HEAD"
  8. # all time, for "Previous Contributors"
  9. REVS_PREVIOUS = "HEAD"
  10. CUTOFF_ACTIVE = 3
  11. CUTOFF_PREVIOUS = 21
  12. # For a description of the points system see:
  13. # https://github.com/minetest/minetest/pull/9593#issue-398677198
  14. def load(revs):
  15. points = defaultdict(int)
  16. p = subprocess.Popen(["git", "log", "--mailmap", "--pretty=format:%h %aN <%aE>", revs],
  17. stdout=subprocess.PIPE, universal_newlines=True)
  18. for line in p.stdout:
  19. hash, author = line.strip().split(" ", 1)
  20. n = 0
  21. p2 = subprocess.Popen(["git", "show", "--numstat", "--pretty=format:", hash],
  22. stdout=subprocess.PIPE, universal_newlines=True)
  23. for line in p2.stdout:
  24. added, deleted, filename = re.split(r"\s+", line.strip(), 2)
  25. if re.search(codefiles, filename) and added != "-":
  26. n += int(added)
  27. p2.wait()
  28. if n == 0:
  29. continue
  30. if n > 1200:
  31. n = 8
  32. elif n > 700:
  33. n = 4
  34. elif n > 100:
  35. n = 2
  36. else:
  37. n = 1
  38. points[author] += n
  39. p.wait()
  40. # Some authors duplicate? Don't add manual workarounds here, edit the .mailmap!
  41. for author in ("updatepo.sh <script@mt>", "Weblate <42@minetest.ru>"):
  42. points.pop(author, None)
  43. return points
  44. points_active = load(REVS_ACTIVE)
  45. points_prev = load(REVS_PREVIOUS)
  46. with open("results.txt", "w") as f:
  47. for author, points in sorted(points_active.items(), key=(lambda e: e[1]), reverse=True):
  48. if points < CUTOFF_ACTIVE: break
  49. points_prev.pop(author, None) # active authors don't appear in previous
  50. f.write("%d\t%s\n" % (points, author))
  51. f.write('\n---------\n\n')
  52. once = True
  53. for author, points in sorted(points_prev.items(), key=(lambda e: e[1]), reverse=True):
  54. if points < CUTOFF_PREVIOUS and once:
  55. f.write('\n---------\n\n')
  56. once = False
  57. f.write("%d\t%s\n" % (points, author))