11#!/usr/bin/env python3
22
3+ import appdirs
34import click
4- import console as labelbot_console
55import os
6+ import shutil
7+ import sys
68
7- from labelbot import LabelBot , UrlParam
8- from web import app
9+ from .console import run
10+ from .labelbot import LabelBot , UrlParam
11+ from .web import app
12+
13+ module_path = os .path .dirname (__file__ )
14+
15+
16+ class DummyLabelBot (object ):
17+ def __init__ (self , token_file , github_token , rules_file ,
18+ default_label , check_comments , skip_labeled ):
19+ self .token_file = token_file
20+ self .rules_file = rules_file
21+ self .github_token = github_token
22+ self .default_label = default_label
23+ self .check_comments = check_comments
24+ self .skip_labeled = skip_labeled
925
1026
1127@click .group ()
1430 type = click .Path (exists = True ,
1531 file_okay = True ,
1632 readable = True ),
17- default = 'token.cfg.sample' ,
1833 help = 'file containing GitHub token information' )
1934@click .option ('--rules-file' ,
2035 '-u' ,
2136 type = click .Path (exists = True ,
2237 file_okay = True ,
2338 readable = True ),
24- default = 'rules.cfg.sample' ,
2539 help = 'file containing issues labeling rules' )
2640@click .option ('--github-token' ,
2741 '-g' ,
4155@click .pass_context
4256def cli (ctx , token_file , github_token , rules_file , default_label ,
4357 check_comments , skip_labeled ):
44- ctx .obj = LabelBot (token_file , github_token , rules_file , default_label ,
45- check_comments , skip_labeled )
58+ # pass click context
59+ ctx .obj = DummyLabelBot (token_file , github_token , rules_file ,
60+ default_label , check_comments , skip_labeled )
4661
4762
4863@cli .command (short_help = 'Run console daemon periodically checking issues' )
@@ -57,15 +72,29 @@ def cli(ctx, token_file, github_token, rules_file, default_label,
5772 type = UrlParam ())
5873@click .pass_obj
5974def console (labelbot , interval , repo_urls ):
60- labelbot_console .run (labelbot , interval , repo_urls )
75+ labelbot = LabelBot (labelbot .token_file ,
76+ labelbot .github_token ,
77+ labelbot .rules_file ,
78+ labelbot .default_label ,
79+ labelbot .check_comments ,
80+ labelbot .skip_labeled ,)
81+ run (labelbot , interval , repo_urls )
6182
6283
6384@cli .command (short_help = 'Run web API listening for issue updates' )
6485@click .pass_obj
6586def web (labelbot ):
66- port = int (os .environ .get ('PORT' , 80 ))
67- app .config ['labelbot' ] = labelbot
68- app .run (host = '0.0.0.0' , port = port , debug = True )
87+ port = int (os .environ .get ('PORT' , 8080 ))
88+ app .config ['labelbot' ] = LabelBot (labelbot .token_file ,
89+ labelbot .github_token ,
90+ labelbot .rules_file ,
91+ labelbot .default_label ,
92+ labelbot .check_comments ,
93+ labelbot .skip_labeled ,)
94+ app .run (host = '0.0.0.0' , port = port )
95+
96+ cli (prog_name = 'labelbot' )
97+
6998
70- if __name__ == '__main__' :
99+ def main () :
71100 cli ()
0 commit comments