1
+ import logging
2
+
1
3
from . import settings
2
4
from .github import GitHub
3
5
from .utils import create_event
4
6
7
+
8
+ log = logging .getLogger (__name__ )
9
+
5
10
github = GitHub (settings .token )
6
11
7
12
@@ -25,42 +30,48 @@ def parse_comment(body):
25
30
'description' : body [pos :]}, None
26
31
27
32
28
- def process_issue_comment (body , issue_state , issue_api ) -> str :
33
+ def process_issue_comment (body , issue_state , issue_api , extra ) -> str :
29
34
action = body ['action' ]
30
35
if (action != 'created' and action != 'edited' ) or \
31
36
issue_state != 'open' :
37
+ log .info ('Not needed' , extra = extra )
32
38
return 'Not needed.'
33
39
comment = body ['comment' ]
34
40
author = comment ['user' ]['login' ]
35
41
comment , error = parse_comment (comment ['body' ])
36
42
if error :
37
- print ('Error during request processing: {}' . format ( error ) )
38
- github .send_comment (error , issue_api , author )
43
+ log . error ('Error during request processing: %s' , error , extra = extra )
44
+ github .send_comment (error , issue_api , author , extra )
39
45
elif comment :
40
- print ('Request is processed ok' )
46
+ log . info ('Request is processed ok' , extra = extra )
41
47
if action == 'edited' :
42
- github .send_comment ('Accept edited.' , issue_api , author )
48
+ github .send_comment ('Accept edited.' , issue_api , author , extra )
43
49
else :
44
- github .send_comment ('Accept.' , issue_api , author )
50
+ github .send_comment ('Accept.' , issue_api , author , extra )
45
51
else :
46
- print ('Ignore non-request comments' )
52
+ log .debug ('Ignore non-request comments' , extra = extra )
53
+ log .info ('Doc request is processed' , extra = extra )
47
54
return 'Doc request is processed.'
48
55
49
56
50
- def process_issue_state_change (body , issue_api , issue_url , doc_repo_url ):
57
+ def process_issue_state_change (body , issue_api , issue_url , doc_repo_url , extra ):
51
58
action = body ['action' ]
52
59
if action != 'closed' :
60
+ log .info ('Not needed' , extra = extra )
53
61
return 'Not needed.'
54
- comments = github .get_comments (issue_api )
62
+ comments = github .get_comments (issue_api , extra )
55
63
for c in comments :
56
64
comment , error = parse_comment (c ['body' ])
65
+ if error :
66
+ log .error ('Error during request processing: %s' , error , extra = extra )
57
67
if comment :
58
68
github .create_issue (comment ["title" ], comment ["description" ],
59
- issue_url , c ['user' ]['login' ], doc_repo_url )
69
+ issue_url , c ['user' ]['login' ], doc_repo_url , extra )
70
+ log .info ('Issue %s is processed' , comment ["title" ], extra = extra )
60
71
return 'Issue is processed.'
61
72
62
73
63
- def process_commit (c , is_master_push , doc_repo_url ):
74
+ def process_commit (c , is_master_push , doc_repo_url , extra ):
64
75
body = c ['message' ]
65
76
request_pos = body .find (settings .bot_name )
66
77
if request_pos == - 1 :
@@ -69,11 +80,14 @@ def process_commit(c, is_master_push, doc_repo_url):
69
80
author = c ['author' ]['username' ]
70
81
comment , error = parse_comment (request )
71
82
if error :
72
- print ('Error during request processing: {}' . format ( error ) )
83
+ log . error ('Error during request processing: %s' , error , extra = extra )
73
84
create_event (author , 'process_commit' , error )
74
85
else :
75
86
create_event (author , 'process_commit' , 'Accept' )
76
87
if is_master_push :
88
+ log .info (
89
+ 'Trying to create issue on Github %s' , comment ['title' ], extra = extra
90
+ )
77
91
github .create_issue (comment ['title' ],
78
92
comment ['description' ], c ['url' ],
79
- author , doc_repo_url )
93
+ author , doc_repo_url , extra )
0 commit comments