aboutsummaryrefslogtreecommitdiffstats
path: root/python/fatcat_review.py
blob: 40bc70414dc9ed5bb530845f48681942f6b7e1fd (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3

import sys
import argparse
import datetime
import raven

from fatcat_tools import authenticated_api
from fatcat_tools.reviewers import DummyReviewBot, ReviewBot

# Yep, a global. Gets DSN from `SENTRY_DSN` environment variable
sentry_client = raven.Client()


def run_dummy(args):
    reviewer = DummyReviewBot(args.api, poll_interval=args.poll_interval,
        verbose=args.debug)
    if args.editgroup:
        annotation = reviewer.run_single(args.editgroup, args.annotate)
        print(annotation)
    elif args.continuous:
        reviewer.run()

def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--debug',
        action='store_true',
        help="enable debug logging")
    parser.add_argument('--api-host-url',
        default="http://localhost:9411/v0",
        help="fatcat API host/port to use")
    parser.add_argument('--poll-interval',
        help="how long to wait between polling (seconds)",
        default=10.0, type=float)
    subparsers = parser.add_subparsers()

    sub_dummy = subparsers.add_parser('dummy')
    sub_dummy.set_defaults(func=run_dummy)
    sub_dummy.add_argument("--continuous",
        action="store_true",
        help="run forever, polling for new reviewable editgroups")
    sub_dummy.add_argument("--editgroup",
        help="single editgroup ID to review")
    sub_dummy.add_argument("--annotate",
        action="store_true",
        help="for single editgroups, pushes result as annotation")

    args = parser.parse_args()
    if not args.__dict__.get("func"):
        print("tell me what to do!")
        sys.exit(-1)
    if (args.editgroup and args.continuous) or not (args.editgroup or args.continuous):
        print("need to run on a single editgroup, or continuous")
        sys.exit(-1)

    args.api = authenticated_api(args.api_host_url)
    args.func(args)

if __name__ == '__main__':
    main()