forked from thammi/digger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git_to_json.py
executable file
·73 lines (52 loc) · 1.39 KB
/
git_to_json.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python
from os import listdir
from os.path import split, join, isdir
import git
import sys
def load(path="data"):
res = []
for f in listdir(path):
full_path = join(path, f)
if isdir(full_path):
res.append(load_dir(full_path))
return res
def load_dir(path):
res = {}
dir_name = split(path)[1]
res['group'] = int(dir_name.split('-')[1])
res['commits'] = load_commits(path)
#res['metrics'] = load_metrics(path)
return res
def load_metrics(path):
return {}
def load_commits(path):
sys.stderr.write("[%s]\n" % path)
repo = git.Repo(path)
count = repo.commit_count()
commits = repo.commits(max_count=count)
return [read_commit(c) for c in commits]
def read_commit(commit):
res = {}
res['author'] = commit.author.name
date = list(commit.authored_date)
date[3] = (date[3] + 2) % 24
res['date'] = date
# TODO: crashes!!!
# TODO: is there a better way?
#add = 0
#remove = 0
#print commit
#print commit.diffs
#for diff in commit.diffs:
#lines = diff.diff.split('\n')[3:]
#for line in lines:
#if line.startswith('+'):
#add += 1
#elif line.startswith('-'):
#remove += 1
#res['added'] = add
#res['removed'] = remove
return res
raw = load()
import json
print json.dumps(raw)