Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(676)

Side by Side Diff: reviewbot/handlers/policy_checklist/__init__.py

Issue 20518002: Implement mail dispatcher app. (Closed) Base URL: https://src.chromium.org/chrome/trunk/tools/
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
agable 2013/08/20 08:42:41 I dislike having this much logic in __init__ (as o
Mattias Nissler (ping if slow) 2013/08/22 12:44:23 Fair enough, moved the code out to handler.py
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 """Handler for chrome/app/policy/policy_templates.json
6
7 This handler examines changes to the policy_templates.json file and posts
8 comments with checklists for the patch author and reviewer to go through to
9 avoid common pitfalls.
10 """
11
12 import os
13
14 import jinja2
15
16 import model.app_config
17 import util
18 import handlers.policy_checklist.parser
19
20
21 POLICY_TEMPLATES_FILE = 'chrome/app/policy/policy_templates.json'
22 MAX_INLINE_COMMENTS = 10
23
24
25 REVIEW_MESSAGE_TEMPLATE = 'review_message.txt'
26 ADDITION_COMMENT_TEMPLATE = 'addition_comment.txt'
27 MODIFICATION_COMMENT_TEMPLATE = 'modification_comment.txt'
28
29
30 JINJA_ENVIRONMENT = jinja2.Environment(
31 loader=jinja2.FileSystemLoader(os.path.dirname(__file__)))
32
33
34 def process(addr, message, review, rietveld):
35 """Handles reviews for chrome/app/policy/policy_templates.json.
36
37 This looks at the patch to identify additions/modifications to policy
38 definitions and posts comments with a checklist intended for the author and
39 reviewer to go through in order to catch common mistakes.
40 """
41
42 if POLICY_TEMPLATES_FILE not in review.latest_patchset.files:
43 return
44
45 # Only process the change if the mail is directly to us or we haven't
46 # processed this review yet.
47 client_id = model.app_config.get().client_id
48 if (not addr in util.get_emails(getattr(message, 'to', '')) and
49 client_id in [m.sender for m in review.issue_data.messages]):
50 return
51
52 # Don't process reverts.
53 if 'revert' in review.issue_data.description.lower():
54 return
55
56 # Parse the patch, look at the chunks and generate inline comments.
57 chunks = handlers.policy_checklist.parser.parse(
58 review.latest_patchset.files[POLICY_TEMPLATES_FILE].patch.lines)
59 for chunk in chunks[0:MAX_INLINE_COMMENTS]:
60 if chunk.additions and not chunk.removals:
61 template = JINJA_ENVIRONMENT.get_template(ADDITION_COMMENT_TEMPLATE)
62 else:
63 template = JINJA_ENVIRONMENT.get_template(MODIFICATION_COMMENT_TEMPLATE)
64
65 if chunk.comment_pos[1] is not None:
66 line, side = chunk.comment_pos[1], 'b'
67 elif chunk.comment_pos[0] is not None:
68 line, side = chunk.comment_pos[0], 'a'
69 else:
70 # No suitable position?
71 continue
72
73 rietveld.add_inline_comment(
74 review.issue_id, review.latest_patchset.patchset,
75 review.latest_patchset.files[POLICY_TEMPLATES_FILE].id,
76 line, side, template.render(review=review, chunk=chunk))
77
78 # Finally, post all inline comments.
79 if len(chunks) > 0:
80 template = JINJA_ENVIRONMENT.get_template(REVIEW_MESSAGE_TEMPLATE)
81 rietveld.post_comment(review.issue_id, template.render(review=review), True)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698