~qeef/damn-client.py

ref: 008f97255d638613faebc379be8b52f6531aa2e5 damn-client.py/abandoned_areas.py -rwxr-xr-x 1.1 KiB
008f9725Jiri Vlasak Update requirements 4 months ago
                                                                                
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
#!/usr/bin/env python3
"""This script finds all the abandoned areas.

Use the damn server URI as the first and only argument.

An abandoned area is an area that has less than `TOO_FEW_COMMITS` in
`LAST_FEW_DAYS` with default values of ``5`` and ``90`` respectively.
"""
import sys
from datetime import datetime, timedelta, timezone
from damn_client.api import DamnAPI

TOO_FEW_COMMITS = 5
LAST_FEW_DAYS = 90

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print(__doc__)
        sys.exit(1)
    abandoned_since = (
        datetime.now(timezone.utc)
        - timedelta(days=LAST_FEW_DAYS)
    ).strftime("%Y-%m-%dT%H:%M:%S")
    s = DamnAPI(sys.argv[1])
    s.get_areas()
    print("Areas abandoned on {} since {}.".format(
        s.DAMN_SERVER,
        abandoned_since,
    ))
    print("In last {} days:".format(LAST_FEW_DAYS))
    for a in s.areas.values():
        s.get_commits(a["aid"], abandoned_since)
        if len(a["commits"]) < TOO_FEW_COMMITS:
            print("- {} has only {} commits".format(
                a["aid"],
                len(a["commits"]),
            ))
    print("Finished.")