summaryrefslogtreecommitdiffstats
path: root/third_party/rust/jsparagus/.metrics/fuzzbug_date_badge.py
blob: a2d2b88c09b7b10c2ff655beb2ad3bc89b849027 (plain)
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
#!/usr/bin/python
import json
from datetime import datetime

read_filename = 'count/fuzzbug.json'
write_since = 'badges/since-last-fuzzbug.json'

days_since = None
with open(read_filename, 'r') as f:
    filedata = json.load(f)
    count = len(filedata)
    # the last time we saw a fuzzbug regardless of status
    if count > 0:
        dt_format = "%Y-%m-%dT%H:%M:%SZ"
        fuzzbug_opened = filedata[0]["created_at"]
        fuzzbug_date = datetime.strptime(fuzzbug_opened, dt_format)
        today = datetime.today()
        days_since = (today - fuzzbug_date).days


# Write days since last fuzzbug

def get_color(days):
    if days_since is None or days_since > 100:
        return "green"
    elif days_since > 10:
        return "yellow"
    else:
        return "red"


data = {
    "schemaVersion": 1,
    "label": "Days since last FuzzBug",
    "message": str(days_since) if days_since is not None else "Forever",
    "color": get_color(days_since),
}

with open(write_since, 'w') as f:
    json.dump(data, f, indent=4)