Skip to content

Commit d4bf158

Browse files
committed
できた
1 parent 27f1ff3 commit d4bf158

File tree

4 files changed

+176
-0
lines changed

4 files changed

+176
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cpprefjp/
2+
boostjp/

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
# stats_contribution
22
貢献ポイントの集計スクリプト
3+
4+
```bash
5+
sh run.sh
6+
```
7+
8+
`run.sh` のcpprefjp/siteのcheckoutブランチは年ごとに変えること
9+

run.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
mkdir -p cpprefjp
2+
cd cpprefjp
3+
git clone https://github.com/cpprefjp/site.git
4+
cd site
5+
git pull
6+
git checkout contribution_stats_2023
7+
cd ..
8+
9+
git clone https://github.com/cpprefjp/site_generator.git
10+
cd site_generator
11+
git pull
12+
cd ..
13+
14+
git clone https://github.com/cpprefjp/kunai.git
15+
cd kunai
16+
git pull
17+
cd ..
18+
19+
git clone https://github.com/cpprefjp/kunai_config.git
20+
cd kunai_config
21+
git pull
22+
cd ..
23+
24+
git clone https://github.com/cpprefjp/crsearch.git
25+
cd crsearch
26+
git pull
27+
cd ..
28+
29+
git clone https://github.com/cpprefjp/markdown_to_html.git
30+
cd markdown_to_html
31+
git pull
32+
cd ..
33+
34+
cd ..
35+
mkdir -p boostjp
36+
cd boostjp
37+
git clone https://github.com/boostjp/site.git
38+
cd site
39+
git pull
40+
cd ..
41+
42+
cd ..
43+
python3 stats_contribution.py

stats_contribution.py

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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

Comments
 (0)