Initial commit.
Browse files- app.py +142 -0
- requirements.txt +1 -0
app.py
ADDED
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from git import Repo, Git
|
3 |
+
import datetime
|
4 |
+
import argparse
|
5 |
+
from collections import Counter
|
6 |
+
import os
|
7 |
+
|
8 |
+
|
9 |
+
def greet(name):
|
10 |
+
with tempfile.TemporaryDirectory() as d:
|
11 |
+
Repo.clone_from(name,d,)
|
12 |
+
|
13 |
+
return check_repo(d, datetime.datetime(2022, 01, 01), 10)
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
def check():
|
18 |
+
parser = argparse.ArgumentParser(
|
19 |
+
prog = 'ProgramName',
|
20 |
+
description = 'What the program does',
|
21 |
+
epilog = 'Text at the bottom of help')
|
22 |
+
parser.add_argument('repo', nargs='?', default=default_repo()) # option that takes a value
|
23 |
+
parser.add_argument('--since',
|
24 |
+
type=lambda d: datetime.datetime.strptime(d, '%Y-%m-%d'),
|
25 |
+
default=None,
|
26 |
+
help='Set a start date')
|
27 |
+
parser.add_argument('--filter',
|
28 |
+
type=lambda d: d.split(","),
|
29 |
+
default=None,
|
30 |
+
help='Set a comma separated filter')
|
31 |
+
parser.add_argument('--mincount',
|
32 |
+
type=int,
|
33 |
+
default=10,
|
34 |
+
help='Set a comma separated filter')
|
35 |
+
args = parser.parse_args()
|
36 |
+
if "/" not in args.repo:
|
37 |
+
args.repo = f"/home/nicolas/src/{args.repo}"
|
38 |
+
with cd(args.repo):
|
39 |
+
check_repo(args.repo, args.since, args.mincount)
|
40 |
+
|
41 |
+
class cd:
|
42 |
+
"""Context manager for changing the current working directory"""
|
43 |
+
|
44 |
+
def __init__(self, newPath):
|
45 |
+
self.newPath = os.path.expanduser(newPath)
|
46 |
+
|
47 |
+
def __enter__(self):
|
48 |
+
self.savedPath = os.getcwd()
|
49 |
+
os.chdir(self.newPath)
|
50 |
+
|
51 |
+
def __exit__(self, etype, value, traceback):
|
52 |
+
os.chdir(self.savedPath)
|
53 |
+
|
54 |
+
def default_repo():
|
55 |
+
return os.getcwd()
|
56 |
+
|
57 |
+
|
58 |
+
|
59 |
+
def check_repo(repo_path, since, mincount):
|
60 |
+
repo_path = args.repo
|
61 |
+
most_common = 10
|
62 |
+
bugwords = [("revert", 1), ("bug", 1), ("fix", 1)]
|
63 |
+
|
64 |
+
repo = Repo(repo_path)
|
65 |
+
c = Counter()
|
66 |
+
git = Git()
|
67 |
+
commits = []
|
68 |
+
for commit in repo.iter_commits():
|
69 |
+
if args.since and commit.committed_datetime < args.since.astimezone():
|
70 |
+
break
|
71 |
+
commits.append(commit.hexsha[:6])
|
72 |
+
|
73 |
+
|
74 |
+
files = Counter()
|
75 |
+
bugfiles = Counter()
|
76 |
+
current_commit = 0
|
77 |
+
current_files = []
|
78 |
+
out = git.show('--stat', '--oneline', '--name-only', f"{commits[-1]}..")
|
79 |
+
|
80 |
+
is_bug = 0
|
81 |
+
for i, line in enumerate(out.split("\n")):
|
82 |
+
line = line.strip()
|
83 |
+
if not line:
|
84 |
+
continue
|
85 |
+
if line.startswith(commits[current_commit]):
|
86 |
+
# files[commits[current_commit]] = files.copy()
|
87 |
+
commit, message = line.lower().split(" ", 1)
|
88 |
+
found = False
|
89 |
+
for (bugword, count) in bugwords:
|
90 |
+
if bugword in message:
|
91 |
+
is_bug = count
|
92 |
+
found = True
|
93 |
+
break
|
94 |
+
if not found:
|
95 |
+
is_bug = 0
|
96 |
+
current_commit += 1
|
97 |
+
else:
|
98 |
+
found = True
|
99 |
+
if args.filter:
|
100 |
+
found = False
|
101 |
+
for filter_ in args.filter:
|
102 |
+
if filter_ in line:
|
103 |
+
found = True
|
104 |
+
break
|
105 |
+
if not found:
|
106 |
+
continue
|
107 |
+
|
108 |
+
files[line] += 1
|
109 |
+
if is_bug:
|
110 |
+
bugfiles[line] += is_bug
|
111 |
+
|
112 |
+
string = ""
|
113 |
+
|
114 |
+
string += "=====" + "\n"
|
115 |
+
string += "Most commonly changed files" + "\n"
|
116 |
+
string += + "\n"
|
117 |
+
for (filename, count) in files.most_common(most_common):
|
118 |
+
string += f"{filename}: {count}" + "\n"
|
119 |
+
string += + "\n"
|
120 |
+
string += + "\n"
|
121 |
+
|
122 |
+
string += "=====" + "\n"
|
123 |
+
string += "Most commonly bugged files" + "\n"
|
124 |
+
for (filename, count) in bugfiles.most_common(most_common):
|
125 |
+
string += f"{filename}: {count}" + "\n"
|
126 |
+
|
127 |
+
string += + "\n"
|
128 |
+
string += + "\n"
|
129 |
+
string += "=====" + "\n"
|
130 |
+
string += "Most commonly bugged files (adjusted)" + "\n"
|
131 |
+
adjusted = {}
|
132 |
+
for (filename, count) in bugfiles.items():
|
133 |
+
if count < args.mincount:
|
134 |
+
continue
|
135 |
+
percentage = count / files[filename]
|
136 |
+
adjusted[filename] = (percentage, count)
|
137 |
+
for (filename, (percentage, count)) in sorted(adjusted.items(), key=lambda x: x[1], reverse=True)[:most_common]:
|
138 |
+
string += f"{filename}: {percentage} ({count})" + "\n"
|
139 |
+
return string
|
140 |
+
|
141 |
+
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
142 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
gitpython
|