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