rbbz: add 5 lines of context to single-line reviews (bug 1255278) r?mdoglio draft
authorbyron jones <glob@mozilla.com>
Thu, 10 Mar 2016 13:03:51 +0800
changeset 7462 c61d86295172f4682f1898487477e5d5c8f79ba8
parent 7461 313520cf0834116f79bbcf4d8e1694872edee8ef
push id686
push userbjones@mozilla.com
push dateThu, 10 Mar 2016 05:04:24 +0000
reviewersmdoglio
bugs1255278
rbbz: add 5 lines of context to single-line reviews (bug 1255278) r?mdoglio When a review has selected a single line for context, add an additional 5 lines of context to the comment created in Bugzilla. This provides parity with Splinter, and falls in line with most user's expectations. MozReview-Commit-ID: LoudBFRSgWz
pylib/rbbz/rbbz/diffs.py
--- a/pylib/rbbz/rbbz/diffs.py
+++ b/pylib/rbbz/rbbz/diffs.py
@@ -245,25 +245,38 @@ def render_comment_plain(comment, contex
         else:
             last_reply = parent_comment
 
         lines = ["> %s" % line for line in str(last_reply).split('\n')]
         lines.append("\n%s" % comment)
 
         return "\n".join(lines)
 
+    # If the reviewer selected a single line, comment with
+    # 5 lines of context.
+    if comment.num_lines == 1:
+        if comment.first_line < 6:
+            first_line = 1
+            num_lines = comment.first_line
+        else:
+            first_line = comment.first_line - 5
+            num_lines = 6
+    else:
+        first_line = comment.first_line
+        num_lines = comment.num_lines
+
     # This is the base comment of a review, so we
     # should quote the code the comment is adressing.
     parser = HTMLParser.HTMLParser()
     chunks = list(get_file_chunks_in_range_custom(
         context,
         comment.filediff,
         comment.interfilediff,
-        comment.first_line,
-        comment.num_lines))
+        first_line,
+        num_lines))
 
     dest_lineno = None
     for chunk in chunks:
         for line in chunk['lines']:
             if line[0] == comment.first_line:
                 # this is an empty string if the line does not exist in
                 # the destination file
                 dest_lineno = line[4]