Title: [94990] trunk/Tools
Revision
94990
Author
e...@webkit.org
Date
2011-09-12 16:43:08 -0700 (Mon, 12 Sep 2011)

Log Message

sheriffbot whois should be smarter
https://bugs.webkit.org/show_bug.cgi?id=67971

Reviewed by Adam Barth.

This makes sheriffbot whois basically grep the committers list
making it much easier to find a contributor by name.

Unfortunately the current unittests depend on the real committers.py
file, so as we add more eric's to the project, this unittest result will
change.  I think that's OK for now.  We'll fix it when it breaks.

* Scripts/webkitpy/common/config/committers.py:
* Scripts/webkitpy/tool/bot/irc_command.py:
* Scripts/webkitpy/tool/bot/irc_command_unittest.py:

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (94989 => 94990)


--- trunk/Tools/ChangeLog	2011-09-12 23:38:46 UTC (rev 94989)
+++ trunk/Tools/ChangeLog	2011-09-12 23:43:08 UTC (rev 94990)
@@ -1,3 +1,21 @@
+2011-09-12  Eric Seidel  <e...@webkit.org>
+
+        sheriffbot whois should be smarter
+        https://bugs.webkit.org/show_bug.cgi?id=67971
+
+        Reviewed by Adam Barth.
+
+        This makes sheriffbot whois basically grep the committers list
+        making it much easier to find a contributor by name.
+
+        Unfortunately the current unittests depend on the real committers.py
+        file, so as we add more eric's to the project, this unittest result will
+        change.  I think that's OK for now.  We'll fix it when it breaks.
+
+        * Scripts/webkitpy/common/config/committers.py:
+        * Scripts/webkitpy/tool/bot/irc_command.py:
+        * Scripts/webkitpy/tool/bot/irc_command_unittest.py:
+
 2011-09-12  Sheriff Bot  <webkit.review....@gmail.com>
 
         Unreviewed, rolling out r94976.

Modified: trunk/Tools/Scripts/webkitpy/common/config/committers.py (94989 => 94990)


--- trunk/Tools/Scripts/webkitpy/common/config/committers.py	2011-09-12 23:38:46 UTC (rev 94989)
+++ trunk/Tools/Scripts/webkitpy/common/config/committers.py	2011-09-12 23:43:08 UTC (rev 94990)
@@ -51,7 +51,17 @@
     def __str__(self):
         return '"%s" <%s>' % (self.full_name, self.emails[0])
 
+    def contains_string(self, string):
+        if string in self.full_name:
+            return True
+        if self.irc_nickname and string in self.irc_nickname:
+            return True
+        for email in self.emails:
+            if string in email:
+                return True
+        return False
 
+
 class Committer(Contributor):
     def __init__(self, name, email_or_emails, irc_nickname=None):
         Contributor.__init__(self, name, email_or_emails, irc_nickname)
@@ -450,6 +460,9 @@
                 return contributor
         return None
 
+    def contributors_by_search_string(self, string):
+        return filter(lambda contributor: contributor.contains_string(string), self.contributors())
+
     def contributor_by_email(self, email):
         return self._email_to_contributor_map().get(email)
 

Modified: trunk/Tools/Scripts/webkitpy/tool/bot/irc_command.py (94989 => 94990)


--- trunk/Tools/Scripts/webkitpy/tool/bot/irc_command.py	2011-09-12 23:38:46 UTC (rev 94989)
+++ trunk/Tools/Scripts/webkitpy/tool/bot/irc_command.py	2011-09-12 23:43:08 UTC (rev 94990)
@@ -172,17 +172,29 @@
 
 
 class Whois(IRCCommand):
+    def _nick_or_full_record(self, contributor):
+        if contributor.irc_nickname:
+            return contributor.irc_nickname
+        return unicode(contributor)
+
     def execute(self, nick, args, tool, sheriff):
         if len(args) != 1:
-            return "%s: Usage: whois BUGZILLA_EMAIL" % nick
-        email = args[0]
+            return "%s: Usage: whois SEARCH_STRING" % nick
+        search_string = args[0]
         # FIXME: We should get the ContributorList off the tool somewhere.
-        committer = CommitterList().contributor_by_email(email)
-        if not committer:
-            return "%s: Sorry, I don't know %s. Maybe you could introduce me?" % (nick, email)
-        if not committer.irc_nickname:
-            return "%s: %s hasn't told me their nick. Boo hoo :-(" % (nick, email)
-        return "%s: %s is %s. Why do you ask?" % (nick, email, committer.irc_nickname)
+        contributors = CommitterList().contributors_by_search_string(search_string)
+        if not contributors:
+            return "%s: Sorry, I don't know any contributors matching '%s'." % (nick, search_string)
+        if len(contributors) > 5:
+            return "More than 5 contributors match '%s', can you be more specific?"
+        if len(contributors) == 1:
+            contributor = contributors[0]
+            if not contributor.irc_nickname:
+                return "%s: %s hasn't told me their nick. Boo hoo :-(" % (nick, contributor)
+            return "%s: %s is %s. Why do you ask?" % (nick, search_string, contributor.irc_nickname)
+        contributor_nicks = map(self._nick_or_full_record, contributors)
+        contributors_string = join_with_separators(contributor_nicks, _only_two_separator_=" or ", last_separator=', or ')
+        return "%s: I'm not sure who you mean?  %s could be '%s'." % (nick, contributors_string, search_string)
 
 
 class Eliza(IRCCommand):

Modified: trunk/Tools/Scripts/webkitpy/tool/bot/irc_command_unittest.py (94989 => 94990)


--- trunk/Tools/Scripts/webkitpy/tool/bot/irc_command_unittest.py	2011-09-12 23:38:46 UTC (rev 94989)
+++ trunk/Tools/Scripts/webkitpy/tool/bot/irc_command_unittest.py	2011-09-12 23:43:08 UTC (rev 94990)
@@ -41,16 +41,18 @@
 
     def test_whois(self):
         whois = Whois()
-        self.assertEquals("tom: Usage: whois BUGZILLA_EMAIL",
+        self.assertEquals("tom: Usage: whois SEARCH_STRING",
                           whois.execute("tom", [], None, None))
-        self.assertEquals("tom: Usage: whois BUGZILLA_EMAIL",
+        self.assertEquals("tom: Usage: whois SEARCH_STRING",
                           whois.execute("tom", ["Adam", "Barth"], None, None))
-        self.assertEquals("tom: Sorry, I don't know unkn...@example.com. Maybe you could introduce me?",
+        self.assertEquals("tom: Sorry, I don't know any contributors matching 'unkn...@example.com'.",
                           whois.execute("tom", ["unkn...@example.com"], None, None))
         self.assertEquals("tom: to...@chromium.org is tonyg-cr. Why do you ask?",
                           whois.execute("tom", ["to...@chromium.org"], None, None))
-        self.assertEquals("tom: vi...@apple.com hasn't told me their nick. Boo hoo :-(",
+        self.assertEquals('tom: "Vicki Murley" <vi...@apple.com> hasn\'t told me their nick. Boo hoo :-(',
                           whois.execute("tom", ["vi...@apple.com"], None, None))
+        self.assertEquals('tom: I\'m not sure who you mean?  ericu, "Eric Carlson" <eric.carl...@apple.com>, or eseidel could be \'eric\'.',
+                          whois.execute("tom", ["eric"], None, None))
 
     def test_create_bug(self):
         create_bug = CreateBug()
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to