Don't send mail for policy_checklist comments.
This changes the policy_checklist review handler to not send mail when
publishing comments. This is so patch authors don't receive nag mail,
but reviewers have the review bot comments for reference.
BUG=None
R=agable@chromium.org
Review URL: https://codereview.chromium.org/23576004
git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/reviewbot@219800 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/handlers/policy_checklist/handler.py b/handlers/policy_checklist/handler.py
index ec26e37..a2153eb 100644
--- a/handlers/policy_checklist/handler.py
+++ b/handlers/policy_checklist/handler.py
@@ -31,6 +31,16 @@
loader=jinja2.FileSystemLoader(os.path.dirname(__file__)))
+def prepare_address_list(addr, email_list):
+ """Prepares |email_list| for use as rietveld query parameter.
+
+ Canonicalizes the entries in |email_list|, removes any occurrences of |addr|,
+ joins the entries with commas and returns the result.
+ """
+ return ','.join([util.canonicalize_email(entry)
+ for entry in email_list if entry != addr])
+
+
def process(addr, message, review, rietveld):
"""Handles reviews for chrome/app/policy/policy_templates.json.
@@ -78,4 +88,7 @@
# Finally, post all inline comments.
if len(chunks) > 0:
template = JINJA_ENVIRONMENT.get_template(REVIEW_MESSAGE_TEMPLATE)
- rietveld.post_comment(review.issue_id, template.render(review=review), True)
+ rietveld.publish_inline_comments(
+ review.issue_id, template.render(review=review),
+ prepare_address_list(addr, review.issue_data.reviewers),
+ prepare_address_list(addr, review.issue_data.cc))
diff --git a/rietveld.py b/rietveld.py
index 0e3d405..8cf29e6 100644
--- a/rietveld.py
+++ b/rietveld.py
@@ -66,14 +66,18 @@
def post_issue_data(self, issue, req, payload):
return self.post_data('%s/%s' % (issue, req), payload)
- def post_comment(self, issue, comment, submit_inline_comments=False):
+ def publish_inline_comments(self, issue, comment, reviewers, cc,
+ subject=None, send_mail=False):
publish_payload = {
- 'message_only': 0 if submit_inline_comments else 1,
- 'send_mail': 1,
- 'add_as_reviewer': 0,
+ 'cc': cc,
'message': comment,
+ 'message_only': 0,
'no_redirect': 1,
+ 'reviewers': reviewers,
+ 'send_mail': 1 if send_mail else 0,
}
+ if subject is not None:
+ publish_payload['subject'] = subject
self.post_issue_data(issue, 'publish', publish_payload)
def add_inline_comment(self, issue_id, patchset_id, patch_id, line, a_or_b,
diff --git a/util.py b/util.py
index 85c7687..3eb5934 100644
--- a/util.py
+++ b/util.py
@@ -86,3 +86,10 @@
[ 'test@example.com', 'committers@chromium.org' ]
"""
return [entry[1] for entry in email.utils.getaddresses([string])]
+
+
+def canonicalize_email(address):
+ """Takes an email address and returns its canonicalized form."""
+ emails = get_emails(address)
+ assert len(emails) == 1
+ return emails[0]