-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathupload-stat
executable file
·69 lines (60 loc) · 2.16 KB
/
upload-stat
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
#! /usr/bin/env python3
#
# Parse the stat.txt file from lang-stat and upload to the metrics collection endpoint
import sys
import urllib.request
HOST = "https://dashboard.semgrep.dev"
def parse_stat_file(in_file):
stats = []
with open(in_file) as f:
lines = [line.rstrip("\n") for line in f]
lang = None
line_count = None
parse_success = None
for line in lines:
if line.startswith("Language: "):
lang = line.replace("Language: ", "")
continue
elif line.startswith("Line count: "):
line_count = line.replace("Line count: ", "")
continue
elif line.startswith("Line coverage: "):
parse_success = line.replace("Line coverage: ", "").replace("%", "")
continue
else:
if (
lang is not None
and line_count is not None
and parse_success is not None
):
stats.append(
{
"lang": lang,
"line_count": line_count,
"parse_success": parse_success,
}
)
lang = None
line_count = None
parse_success = None
if lang is not None and line_count is not None and parse_success is not None:
stats.append(
{"lang": lang, "line_count": line_count, "parse_success": parse_success}
)
return stats
def upload_stats(stats):
for stat in stats:
url = f"{HOST}/api/metric/semgrep.tree-sitter.{stat['lang']}.parse.pct"
r = urllib.request.urlopen(url=url, data=stat["parse_success"].encode("ascii"))
print(r.read().decode())
url = f"{HOST}/api/metric/semgrep.tree-sitter.{stat['lang']}.parse-coverage-lines.num"
r = urllib.request.urlopen(url=url, data=stat["line_count"].encode("ascii"))
print(r.read().decode())
if __name__ == "__main__":
if len(sys.argv) > 1:
in_file = sys.argv[1]
stats = parse_stat_file(in_file)
upload_stats(stats)
else:
print("please give a path to stat.txt as the first argument")
sys.exit(1)