44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
import json
|
|
from subprocess import check_output
|
|
|
|
|
|
def filter_schema(obj, schema):
|
|
if schema is True:
|
|
return obj
|
|
return {key: filter_schema(obj[key], value) for key, value in schema.items()}
|
|
|
|
|
|
entry_schema = {
|
|
"name": True,
|
|
"metrics": {
|
|
"halstead": {"bugs": True, "difficulty": True},
|
|
"loc": {"ploc": True, "cloc": True, "blank": True},
|
|
},
|
|
}
|
|
|
|
try:
|
|
with open("/code/cache.json", "r") as file:
|
|
cache = json.load(file)
|
|
except FileNotFoundError:
|
|
cache = {}
|
|
commits = check_output(["git", "log", "--pretty=%H"], text=True).splitlines()
|
|
entries = []
|
|
for i, commit in enumerate(commits):
|
|
if commit not in cache:
|
|
print("running", commit)
|
|
check_output(["git", "checkout", commit], text=True)
|
|
lines = check_output(
|
|
["rust-code-analysis-cli", "-m", "-p", "src", "-O", "json"], text=True
|
|
).splitlines()
|
|
print(len(lines))
|
|
commit_entries = []
|
|
for line in lines:
|
|
entry = json.loads(line)
|
|
commit_entries.append(filter_schema(entry, entry_schema))
|
|
cache[commit] = commit_entries
|
|
entries.extend((i, entry) for entry in cache[commit])
|
|
with open("/code/cache.json", "w") as file:
|
|
json.dump(cache, file)
|
|
with open("/code/metrics.json", "w") as file:
|
|
json.dump(entries, file)
|