|
| 1 | +import glob |
| 2 | +import re |
| 3 | +import os |
| 4 | +import sys |
| 5 | +from subprocess import Popen |
| 6 | + |
| 7 | +point_dict = { |
| 8 | + "cpprefjp/typo": 1, |
| 9 | + "cpprefjp/link": 2, |
| 10 | + "cpprefjp/addref": 20, |
| 11 | + "cpprefjp/addlang": 20, |
| 12 | + "cpprefjp/addpage": 20, |
| 13 | + "cpprefjp/fixs": 2, |
| 14 | + "cpprefjp/fixm": 5, |
| 15 | + "cpprefjp/fixl": 10, |
| 16 | + "cpprefjp/compiler": 2, |
| 17 | + "boostjp/typo": 1, |
| 18 | + "boostjp/releases": 2, |
| 19 | + "boostjp/releasem": 5, |
| 20 | + "boostjp/releasem": 10, |
| 21 | + "boostjp/releasel": 20, |
| 22 | + "boostjp/addrefs": 10, |
| 23 | + "boostjp/addrefm": 20, |
| 24 | + "boostjp/boosts": 5, |
| 25 | + "tool/fixbug": 30, |
| 26 | + "tool/improves": 10, |
| 27 | + "tool/improvem": 30, |
| 28 | + "tool/improvem": 50, |
| 29 | + "tool/updatelib": 20, |
| 30 | + "tool/updatelang": 10, |
| 31 | + "tool/updatelang": 30, |
| 32 | + "tool/updatelang": 50, |
| 33 | + "tool/adds": 30, |
| 34 | + "tool/addm": 50, |
| 35 | + "tool/addl": 100, |
| 36 | +} |
| 37 | + |
| 38 | +def stats_contribution(text: str, filename: str) -> set[str]: |
| 39 | + user_name: str | None = None |
| 40 | + user_point = 0 |
| 41 | + commit_set = set() |
| 42 | + |
| 43 | + users = dict() |
| 44 | + for line in text.split("\n"): |
| 45 | + m = re.fullmatch(r'## (.*?)', line) |
| 46 | + if m: |
| 47 | + user_name = m.group(1) |
| 48 | + user_point = 0 |
| 49 | + continue |
| 50 | + |
| 51 | + if not user_name: |
| 52 | + continue |
| 53 | + |
| 54 | + if line.startswith("| ["): |
| 55 | + cols = line.split("|") |
| 56 | + |
| 57 | + commits = cols[1].split(",") |
| 58 | + for commit in commits: |
| 59 | + m = re.fullmatch(r'\[(.*?)\]\((.*?)/commit/(.*?)\)', commit.strip()) |
| 60 | + full_commit_id = m.group(3) |
| 61 | + commit_set.add(full_commit_id) |
| 62 | + |
| 63 | + points = cols[2].split(",") |
| 64 | + for point in points: |
| 65 | + point_values = point.split(":") |
| 66 | + point_name = point_values[0].strip() |
| 67 | + point_quantity = int(point_values[1].strip()) |
| 68 | + point_value = point_dict.get(point_name) |
| 69 | + if not point_value: |
| 70 | + raise KeyError("{}: invalid point tag `{}`".format(filename, point_name)) |
| 71 | + user_point += point_value * point_quantity |
| 72 | + users[user_name] = user_point |
| 73 | + |
| 74 | + for name, point in sorted(users.items(), key=lambda item: item[1], reverse=True): |
| 75 | + print("{}: {}".format(name, point)) |
| 76 | + return commit_set |
| 77 | + |
| 78 | +def check_commit_set(commit_set: set[str]) -> None: |
| 79 | + repos = [ |
| 80 | + "cpprefjp/site", |
| 81 | + "cpprefjp/site_generator", |
| 82 | + "cpprefjp/kunai", |
| 83 | + "cpprefjp/kunai_config", |
| 84 | + "cpprefjp/crsearch", |
| 85 | + "cpprefjp/markdown_to_html", |
| 86 | + "boostjp/site", |
| 87 | + ] |
| 88 | + |
| 89 | + commit_log_set = set() |
| 90 | + for repo in repos: |
| 91 | + wd = os.getcwd() |
| 92 | + command = "git log --after \'2023-01-01\' --pretty=oneline --no-merges".split(" ") |
| 93 | + os.chdir(repo) |
| 94 | + proc = Popen(command, stdin=-1,stdout=-1,stderr=-1) |
| 95 | + out, err = proc.communicate() |
| 96 | + if len(err) > 0: |
| 97 | + print(err) |
| 98 | + return |
| 99 | + os.chdir(wd) |
| 100 | + |
| 101 | + for line in out.decode().split("\n"): |
| 102 | + if len(line) <= 0: |
| 103 | + continue |
| 104 | + cols = line.split(" ") |
| 105 | + full_commit_id = cols[0] |
| 106 | + commit_log_set.add(full_commit_id) |
| 107 | + |
| 108 | + diff = commit_log_set - commit_set |
| 109 | + if len(diff) > 0: |
| 110 | + print("unstats commits: {}".format(diff)) |
| 111 | + |
| 112 | +if __name__ == '__main__': |
| 113 | + commit_set = set() |
| 114 | + for p in sorted(list(glob.glob("cpprefjp/site/start_editing/*.md", recursive=True))): |
| 115 | + filename = os.path.basename(p) |
| 116 | + if not filename.startswith("contribution_stats_"): |
| 117 | + continue |
| 118 | + |
| 119 | + with open(p) as f: |
| 120 | + text = f.read() |
| 121 | + |
| 122 | + commit_set = commit_set.union(stats_contribution(text, p)) |
| 123 | + |
| 124 | + check_commit_set(commit_set) |
0 commit comments