Title: [96685] trunk/Tools
Revision
96685
Author
le...@chromium.org
Date
2011-10-05 02:21:54 -0700 (Wed, 05 Oct 2011)

Log Message

watchlist: Don't add the same message to a bug more than once.
https://bugs.webkit.org/show_bug.cgi?id=69303

Reviewed by Adam Barth.

* Scripts/webkitpy/common/net/bugzilla/bug.py: Added a way to determine
if a message is in the comments already.
* Scripts/webkitpy/common/net/bugzilla/bug_unittest.py: A test for the above.
* Scripts/webkitpy/tool/commands/applywatchlistlocal_unittest.py:
Pick a bug supplied by the mock. Change the test due to different output
from the mock watch list tool.
* Scripts/webkitpy/tool/mocktool.py: Change the mock watch list to return
another email so it will be filtered out, fix bugs to have the cc and comment fields,
and fix fetch_bug to handle bug_id's which are text (because that took me way too long
to debug).
* Scripts/webkitpy/tool/steps/applywatchlist.py: Change to filter out comments
and/or cc's that are already in the bug.
* Scripts/webkitpy/tool/steps/applywatchlist_unittest.py: Pick a bug supplied by the mock,
and remove a comment that is filtered out.

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (96684 => 96685)


--- trunk/Tools/ChangeLog	2011-10-05 09:09:33 UTC (rev 96684)
+++ trunk/Tools/ChangeLog	2011-10-05 09:21:54 UTC (rev 96685)
@@ -1,3 +1,25 @@
+2011-10-05  David Levin  <le...@chromium.org>
+
+        watchlist: Don't add the same message to a bug more than once.
+        https://bugs.webkit.org/show_bug.cgi?id=69303
+
+        Reviewed by Adam Barth.
+
+        * Scripts/webkitpy/common/net/bugzilla/bug.py: Added a way to determine
+        if a message is in the comments already.
+        * Scripts/webkitpy/common/net/bugzilla/bug_unittest.py: A test for the above.
+        * Scripts/webkitpy/tool/commands/applywatchlistlocal_unittest.py:
+        Pick a bug supplied by the mock. Change the test due to different output
+        from the mock watch list tool.
+        * Scripts/webkitpy/tool/mocktool.py: Change the mock watch list to return
+        another email so it will be filtered out, fix bugs to have the cc and comment fields,
+        and fix fetch_bug to handle bug_id's which are text (because that took me way too long
+        to debug).
+        * Scripts/webkitpy/tool/steps/applywatchlist.py: Change to filter out comments
+        and/or cc's that are already in the bug.
+        * Scripts/webkitpy/tool/steps/applywatchlist_unittest.py: Pick a bug supplied by the mock,
+        and remove a comment that is filtered out.
+
 2011-10-05  Balazs Kelemen  <kbal...@webkit.org>
 
         [Qt][WK2] Unreviewed build fix after r96643.

Modified: trunk/Tools/Scripts/webkitpy/common/net/bugzilla/bug.py (96684 => 96685)


--- trunk/Tools/Scripts/webkitpy/common/net/bugzilla/bug.py	2011-10-05 09:09:33 UTC (rev 96684)
+++ trunk/Tools/Scripts/webkitpy/common/net/bugzilla/bug.py	2011-10-05 09:21:54 UTC (rev 96685)
@@ -116,3 +116,10 @@
 
     def comments(self):
         return self.bug_dictionary["comments"]
+
+    def is_in_comments(self, message):
+        for comment in self.comments():
+            if message in comment["text"]:
+                return True
+        return False
+

Modified: trunk/Tools/Scripts/webkitpy/common/net/bugzilla/bug_unittest.py (96684 => 96685)


--- trunk/Tools/Scripts/webkitpy/common/net/bugzilla/bug_unittest.py	2011-10-05 09:09:33 UTC (rev 96684)
+++ trunk/Tools/Scripts/webkitpy/common/net/bugzilla/bug_unittest.py	2011-10-05 09:21:54 UTC (rev 96685)
@@ -38,3 +38,10 @@
             self.assertTrue(bug.is_unassigned())
         bug = Bug({"assigned_to_email": "t...@test.com"}, bugzilla=None)
         self.assertFalse(bug.is_unassigned())
+
+    def test_is_in_comments(self):
+        bug = Bug({"comments": [{"text": "Message1."},
+                                {"text": "Message2. Message3. Message4."}, ], },
+                  bugzilla=None)
+        self.assertTrue(bug.is_in_comments("Message3."))
+        self.assertFalse(bug.is_in_comments("Message."))

Modified: trunk/Tools/Scripts/webkitpy/tool/commands/applywatchlistlocal_unittest.py (96684 => 96685)


--- trunk/Tools/Scripts/webkitpy/tool/commands/applywatchlistlocal_unittest.py	2011-10-05 09:09:33 UTC (rev 96684)
+++ trunk/Tools/Scripts/webkitpy/tool/commands/applywatchlistlocal_unittest.py	2011-10-05 09:21:54 UTC (rev 96685)
@@ -26,6 +26,7 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+
 from webkitpy.tool.commands.commandtest import CommandsTest
 from webkitpy.tool.commands.applywatchlistlocal import ApplyWatchListLocal
 
@@ -36,8 +37,14 @@
         self.assert_execute_outputs(ApplyWatchListLocal(), [''], expected_stderr=expected_stderr)
 
     def test_args_parsing_with_bug(self):
-        expected_stderr = "MockWatchList: determine_cc_and_messages\nMOCK bug comment: bug_id=1234, cc=['le...@chromium.org']\n--- Begin comment ---\nMessage1.\n\nMessage2.\n--- End comment ---\n\n"
-        self.assert_execute_outputs(ApplyWatchListLocal(), ['1234'], expected_stderr=expected_stderr)
+        expected_stderr = """MockWatchList: determine_cc_and_messages
+MOCK bug comment: bug_id=50002, cc=set(['le...@chromium.org', 'aba...@webkit.org'])
+--- Begin comment ---
+Message1.
 
+Message2.
+--- End comment ---\n\n"""
+        self.assert_execute_outputs(ApplyWatchListLocal(), ['50002'], expected_stderr=expected_stderr)
+
     def test_args_parsing_with_two_bugs(self):
         self._assertRaisesRegexp('Too many arguments given: 1234 5678', self.assert_execute_outputs, ApplyWatchListLocal(), ['1234', '5678'])

Modified: trunk/Tools/Scripts/webkitpy/tool/mocktool.py (96684 => 96685)


--- trunk/Tools/Scripts/webkitpy/tool/mocktool.py	2011-10-05 09:09:33 UTC (rev 96684)
+++ trunk/Tools/Scripts/webkitpy/tool/mocktool.py	2011-10-05 09:21:54 UTC (rev 96685)
@@ -26,6 +26,7 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+import datetime
 import os
 import StringIO
 import threading
@@ -156,8 +157,10 @@
              "invalid commit-queue setter.",
     "reporter_email": "f...@foo.com",
     "assigned_to_email": _unassigned_email,
+    "cc_emails": [],
     "attachments": [_patch1, _patch2],
     "bug_status": "UNCONFIRMED",
+    "comments": [],
 }
 
 
@@ -166,8 +169,14 @@
     "title": "Bug with a patch needing review.",
     "reporter_email": "f...@foo.com",
     "assigned_to_email": "f...@foo.com",
+    "cc_emails": ["aba...@webkit.org", ],
     "attachments": [_patch3],
     "bug_status": "ASSIGNED",
+    "comments": [{"comment_date":  datetime.datetime(2011, 6, 11, 9, 4, 3),
+                  "comment_email": "b...@foo.com",
+                  "text": "Message1.",
+        },
+    ],
 }
 
 
@@ -176,8 +185,10 @@
     "title": "The third bug",
     "reporter_email": "f...@foo.com",
     "assigned_to_email": _unassigned_email,
+    "cc_emails": [],
     "attachments": [_patch7],
     "bug_status": "NEW",
+    "comments": [],
 }
 
 
@@ -186,8 +197,10 @@
     "title": "The fourth bug",
     "reporter_email": "f...@foo.com",
     "assigned_to_email": "f...@foo.com",
+    "cc_emails": [],
     "attachments": [_patch4, _patch5, _patch6],
     "bug_status": "REOPENED",
+    "comments": [],
 }
 
 
@@ -196,9 +209,11 @@
     "title": "The fifth bug",
     "reporter_email": _commit_queue_email,
     "assigned_to_email": "f...@foo.com",
+    "cc_emails": [],
     "attachments": [],
     "bug_status": "RESOLVED",
     "dup_id": 50002,
+    "comments": [],
 }
 
 
@@ -293,7 +308,7 @@
         return ["Good artists copy. Great artists steal. - Pablo Picasso"]
 
     def fetch_bug(self, bug_id):
-        return Bug(self.bug_cache.get(bug_id), self)
+        return Bug(self.bug_cache.get(int(bug_id)), self)
 
     def set_override_patch(self, patch):
         self._override_patch = patch
@@ -808,7 +823,7 @@
 class MockWatchList(object):
     def determine_cc_and_messages(self, diff):
         log("MockWatchList: determine_cc_and_messages")
-        return {'cc_list': ['le...@chromium.org'], 'messages': ['Message1.', 'Message2.'], }
+        return {'cc_list': ['aba...@webkit.org', 'le...@chromium.org'], 'messages': ['Message1.', 'Message2.'], }
 
 
 class MockWorkspace(object):

Modified: trunk/Tools/Scripts/webkitpy/tool/steps/applywatchlist.py (96684 => 96685)


--- trunk/Tools/Scripts/webkitpy/tool/steps/applywatchlist.py	2011-10-05 09:09:33 UTC (rev 96684)
+++ trunk/Tools/Scripts/webkitpy/tool/steps/applywatchlist.py	2011-10-05 09:21:54 UTC (rev 96685)
@@ -43,15 +43,24 @@
 
     def run(self, state):
         diff = self.cached_lookup(state, 'diff')
-        bug_id = state.get("bug_id")
+        bug_id = state.get('bug_id')
 
         cc_and_messages = self._tool.watch_list().determine_cc_and_messages(diff)
-        cc_list = cc_and_messages['cc_list']
-        comment_text = '\n\n'.join(cc_and_messages['messages'])
+        cc_emails = cc_and_messages['cc_list']
+        messages = cc_and_messages['messages']
         if bug_id:
-            self._tool.bugs.post_comment_to_bug(bug_id, comment_text, cc_list)
+            # Remove emails and cc's which are already in the bug.
+            bug = self._tool.bugs.fetch_bug(bug_id)
+
+            messages = filter(lambda message: not bug.is_in_comments(message), messages)
+            cc_emails = set(cc_emails).difference(bug.cc_emails())
+
+        comment_text = '\n\n'.join(messages)
+        if bug_id:
+            if cc_emails or comment_text:
+                self._tool.bugs.post_comment_to_bug(bug_id, comment_text, cc_emails)
             log_result = _log.debug
         else:
             _log.info('No bug was updated because no id was given.')
             log_result = _log.info
-        log_result('Result of watchlist: cc "%s" messages "%s"' % (', '.join(cc_list), comment_text))
+        log_result('Result of watchlist: cc "%s" messages "%s"' % (', '.join(cc_emails), comment_text))

Modified: trunk/Tools/Scripts/webkitpy/tool/steps/applywatchlist_unittest.py (96684 => 96685)


--- trunk/Tools/Scripts/webkitpy/tool/steps/applywatchlist_unittest.py	2011-10-05 09:09:33 UTC (rev 96684)
+++ trunk/Tools/Scripts/webkitpy/tool/steps/applywatchlist_unittest.py	2011-10-05 09:21:54 UTC (rev 96685)
@@ -38,14 +38,12 @@
         capture = OutputCapture()
         step = ApplyWatchList(MockTool(log_executive=True), MockOptions())
         state = {
-            'bug_id': '14397',
+            'bug_id': '50001',
             'diff': 'The diff',
         }
         expected_stderr = """MockWatchList: determine_cc_and_messages
-MOCK bug comment: bug_id=14397, cc=['le...@chromium.org']
+MOCK bug comment: bug_id=50001, cc=set(['le...@chromium.org'])
 --- Begin comment ---
-Message1.
-
 Message2.
 --- End comment ---
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to