Changeset 139805 in webkit


Ignore:
Timestamp:
Jan 15, 2013 4:02:22 PM (11 years ago)
Author:
commit-queue@webkit.org
Message:

Extend sheriffbot's "help" command to be able to get help on individual commands
https://bugs.webkit.org/show_bug.cgi?id=106629

Patch by Alan Cutter <alancutter@chromium.org> on 2013-01-15
Reviewed by Eric Seidel.

Added a help command to sheriffbot.
Fixed some style issues and ordered the commands alphabetically.

  • Scripts/webkitpy/tool/bot/irc_command.py:

(IRCCommand):
(IRCCommand.execute):
(IRCCommand.usage):
(IRCCommand.help):
(CreateBug):
(CreateBug.execute):
(Help):
(Help.execute):
(Help._post_command_help):
(Hi):
(Hi.execute):
(Restart):
(RollChromiumDEPS):
(RollChromiumDEPS._parse_args):
(RollChromiumDEPS._expand_irc_nickname):
(RollChromiumDEPS.execute):
(Rollout):
(Rollout._extract_revisions):
(Rollout.execute):
(Sheriffs):
(Sheriffs.execute):
(Whois):
(Whois.execute):

  • Scripts/webkitpy/tool/bot/ircbot_unittest.py:

(IRCBotTest.test_help):

Location:
trunk/Tools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r139796 r139805  
     12013-01-15  Alan Cutter  <alancutter@chromium.org>
     2
     3        Extend sheriffbot's "help" command to be able to get help on individual commands
     4        https://bugs.webkit.org/show_bug.cgi?id=106629
     5
     6        Reviewed by Eric Seidel.
     7
     8        Added a help command to sheriffbot.
     9        Fixed some style issues and ordered the commands alphabetically.
     10
     11        * Scripts/webkitpy/tool/bot/irc_command.py:
     12        (IRCCommand):
     13        (IRCCommand.execute):
     14        (IRCCommand.usage):
     15        (IRCCommand.help):
     16        (CreateBug):
     17        (CreateBug.execute):
     18        (Help):
     19        (Help.execute):
     20        (Help._post_command_help):
     21        (Hi):
     22        (Hi.execute):
     23        (Restart):
     24        (RollChromiumDEPS):
     25        (RollChromiumDEPS._parse_args):
     26        (RollChromiumDEPS._expand_irc_nickname):
     27        (RollChromiumDEPS.execute):
     28        (Rollout):
     29        (Rollout._extract_revisions):
     30        (Rollout.execute):
     31        (Sheriffs):
     32        (Sheriffs.execute):
     33        (Whois):
     34        (Whois.execute):
     35        * Scripts/webkitpy/tool/bot/ircbot_unittest.py:
     36        (IRCBotTest.test_help):
     37
    1382013-01-15  Enrica Casucci  <enrica@apple.com>
    239
  • trunk/Tools/Scripts/webkitpy/tool/bot/irc_command.py

    r139712 r139805  
    5050# FIXME: Merge with Command?
    5151class IRCCommand(object):
    52     def execute(self, nick, args, tool, sheriff):
    53         raise NotImplementedError, "subclasses must implement"
     52    usage_string = None
     53    help_string = None
     54
     55    def execute(self, nick, args, tool, sheriff):
     56        raise NotImplementedError("subclasses must implement")
     57
     58    @classmethod
     59    def usage(cls, nick):
     60        return "%s: Usage: %s" % (nick, cls.usage_string)
     61
     62    @classmethod
     63    def help(cls, nick):
     64        return "%s: %s" % (nick, cls.help_string)
     65
     66
     67class CreateBug(IRCCommand):
     68    usage_string = "create-bug BUG_TITLE"
     69    help_string = "Creates a Bugzilla bug with the given title."
     70
     71    def execute(self, nick, args, tool, sheriff):
     72        if not args:
     73            return self.usage(nick)
     74
     75        bug_title = " ".join(args)
     76        bug_description = "%s\nRequested by %s on %s." % (bug_title, nick, config_irc.channel)
     77
     78        # There happens to be a committers list hung off of Bugzilla, so
     79        # re-using that one makes things easiest for now.
     80        requester = tool.bugs.committers.contributor_by_irc_nickname(nick)
     81        requester_email = requester.bugzilla_email() if requester else None
     82
     83        try:
     84            bug_id = tool.bugs.create_bug(bug_title, bug_description, cc=requester_email, assignee=requester_email)
     85            bug_url = tool.bugs.bug_url_for_bug_id(bug_id)
     86            return "%s: Created bug: %s" % (nick, bug_url)
     87        except Exception, e:
     88            return "%s: Failed to create bug:\n%s" % (nick, e)
     89
     90
     91class Help(IRCCommand):
     92    usage_string = "help [COMMAND]"
     93    help_string = "Provides help on individual sheriffbot commands."
     94
     95    def execute(self, nick, args, tool, sheriff):
     96        if args:
     97            for command_name in args:
     98                if command_name in commands:
     99                    self._post_command_help(nick, tool, commands[command_name])
     100        else:
     101            tool.irc().post("%s: Available commands: %s" % (nick, ", ".join(sorted(visible_commands.keys()))))
     102            tool.irc().post('%s: Type "sheriffbot: help COMMAND" for help on individual commands.' % nick)
     103
     104    def _post_command_help(self, nick, tool, command):
     105        tool.irc().post(command.usage(nick))
     106        tool.irc().post(command.help(nick))
     107        aliases = " ".join(sorted(filter(lambda alias: commands[alias] == command and alias not in visible_commands, commands)))
     108        if aliases:
     109            tool.irc().post("%s: Aliases: %s" % (nick, aliases))
     110
     111
     112class Hi(IRCCommand):
     113    usage_string = "hi"
     114    help_string = "Retrieves a random quip from Bugzilla."
     115
     116    def execute(self, nick, args, tool, sheriff):
     117        quips = tool.bugs.quips()
     118        quips.append('"Only you can prevent forest fires." -- Smokey the Bear')
     119        return random.choice(quips)
    54120
    55121
    56122class Restart(IRCCommand):
     123    usage_string = "restart"
     124    help_string = "Restarts sherrifbot.  Will update its WebKit checkout, and re-join the channel momentarily."
     125
    57126    def execute(self, nick, args, tool, sheriff):
    58127        tool.irc().post("Restarting...")
     
    60129
    61130
     131class RollChromiumDEPS(IRCCommand):
     132    usage_string = "roll-chromium-deps [REVISION]"
     133    help_string = "Rolls WebKit's Chromium DEPS to the given revision or defaults to LKGR. Creates a patch and provides the bug URL."
     134
     135    def _parse_args(self, args):
     136        if not args:
     137            return
     138        revision = args[0].lstrip("r")
     139        if not revision.isdigit():
     140            return
     141        return revision
     142
     143    def _expand_irc_nickname(self, nick):
     144        contributor = CommitterList().contributor_by_irc_nickname(nick)
     145        if contributor:
     146            return str(contributor)
     147        return nick
     148
     149    def execute(self, nick, args, tool, sheriff):
     150        revision = self._parse_args(args)
     151
     152        roll_target = "r%s" % revision if revision else "last-known good revision"
     153        tool.irc().post("%s: Rolling Chromium DEPS to %s" % (nick, roll_target))
     154        changelog_message = "Unreviewed.  Rolled Chromium DEPS to %s.  Requested by %s via sheriffbot.\n\n" % (roll_target, self._expand_irc_nickname(nick))
     155
     156        try:
     157            bug_id = sheriff.post_chromium_deps_roll(revision, roll_target, changelog_message)
     158            bug_url = tool.bugs.bug_url_for_bug_id(bug_id)
     159            tool.irc().post("%s: Created DEPS roll: %s" % (nick, bug_url))
     160        except ScriptError, e:
     161            match = re.search(r"Current Chromium DEPS revision \d+ is newer than \d+\.", e.output)
     162            if match:
     163                tool.irc().post("%s: %s" % (nick, match.group(0)))
     164                return
     165            tool.irc().post("%s: Failed to create DEPS roll:" % nick)
     166            _post_error_and_check_for_bug_url(tool, nick, e)
     167
     168
    62169class Rollout(IRCCommand):
     170    usage_string = "rollout SVN_REVISION [SVN_REVISIONS] REASON"
     171    help_string = "Opens a rollout bug, CCing author + reviewer, and attaching the reverse-diff of the given revisions marked as commit-queue=?."
     172
    63173    def _extract_revisions(self, arg):
    64 
    65174        revision_list = []
    66175        possible_revisions = arg.split(",")
     
    119228
    120229        if (not svn_revision_list or not rollout_reason):
    121             # return is equivalent to an irc().post(), but makes for easier unit testing.
    122             return "%s: Usage: rollout SVN_REVISION [SVN_REVISIONS] REASON" % nick
     230            return self.usage(nick)
    123231
    124232        revision_urls_string = join_with_separators([urls.view_revision_url(revision) for revision in svn_revision_list])
     
    143251
    144252class Sheriffs(IRCCommand):
     253    usage_string = "sheriffs"
     254    help_string = "Retrieves who the current Chromium WebKit sheriffs are from: %s" % urls.chromium_webkit_sheriff_url
     255
    145256    def _retrieve_webkit_sheriffs(self, url):
    146257        try:
     
    177288
    178289
    179 class RollChromiumDEPS(IRCCommand):
    180     def _parse_args(self, args):
    181         if not args:
    182             return
    183         revision = args[0].lstrip("r")
    184         if not revision.isdigit():
    185             return
    186         return revision
    187 
    188     def _expand_irc_nickname(self, nick):
    189         contributor = CommitterList().contributor_by_irc_nickname(nick)
    190         if contributor:
    191             return str(contributor)
    192         return nick
    193 
    194     def execute(self, nick, args, tool, sheriff):
    195         revision = self._parse_args(args)
    196 
    197         roll_target = "r%s" % revision if revision else "last-known good revision"
    198         tool.irc().post("%s: Rolling Chromium DEPS to %s" % (nick, roll_target))
    199         changelog_message = "Unreviewed.  Rolled Chromium DEPS to %s.  Requested by %s via sheriffbot.\n\n" % (roll_target, self._expand_irc_nickname(nick))
    200 
    201         try:
    202             bug_id = sheriff.post_chromium_deps_roll(revision, roll_target, changelog_message)
    203             bug_url = tool.bugs.bug_url_for_bug_id(bug_id)
    204             tool.irc().post("%s: Created DEPS roll: %s" % (nick, bug_url))
    205         except ScriptError, e:
    206             match = re.search(r"Current Chromium DEPS revision \d+ is newer than \d+\.", e.output)
    207             if match:
    208                 tool.irc().post("%s: %s" % (nick, match.group(0)))
    209                 return
    210             tool.irc().post("%s: Failed to create DEPS roll:" % nick)
    211             _post_error_and_check_for_bug_url(tool, nick, e)
    212 
    213 
    214 class Help(IRCCommand):
    215     def execute(self, nick, args, tool, sheriff):
    216         return "%s: Available commands: %s" % (nick, ", ".join(sorted(visible_commands.keys())))
    217 
    218 
    219 class Hi(IRCCommand):
    220     def execute(self, nick, args, tool, sheriff):
    221         quips = tool.bugs.quips()
    222         quips.append('"Only you can prevent forest fires." -- Smokey the Bear')
    223         return random.choice(quips)
    224 
    225 
    226290class Whois(IRCCommand):
     291    usage_string = "whois SEARCH_STRING"
     292    help_string = "Searches known contributors and returns any matches with irc, email and full name."
     293
    227294    def _nick_or_full_record(self, contributor):
    228295        if contributor.irc_nicknames:
     
    232299    def execute(self, nick, args, tool, sheriff):
    233300        if len(args) != 1:
    234             return "%s: Usage: whois SEARCH_STRING" % nick
     301            return self.usage(nick)
    235302        search_string = args[0]
    236303        # FIXME: We should get the ContributorList off the tool somewhere.
     
    254321
    255322
    256 class CreateBug(IRCCommand):
    257     def execute(self, nick, args, tool, sheriff):
    258         if not args:
    259             return "%s: Usage: create-bug BUG_TITLE" % nick
    260 
    261         bug_title = " ".join(args)
    262         bug_description = "%s\nRequested by %s on %s." % (bug_title, nick, config_irc.channel)
    263 
    264         # There happens to be a committers list hung off of Bugzilla, so
    265         # re-using that one makes things easiest for now.
    266         requester = tool.bugs.committers.contributor_by_irc_nickname(nick)
    267         requester_email = requester.bugzilla_email() if requester else None
    268 
    269         try:
    270             bug_id = tool.bugs.create_bug(bug_title, bug_description, cc=requester_email, assignee=requester_email)
    271             bug_url = tool.bugs.bug_url_for_bug_id(bug_id)
    272             return "%s: Created bug: %s" % (nick, bug_url)
    273         except Exception, e:
    274             return "%s: Failed to create bug:\n%s" % (nick, e)
    275 
    276 
    277323# FIXME: Lame.  We should have an auto-registering CommandCenter.
    278324visible_commands = {
     325    "create-bug": CreateBug,
    279326    "help": Help,
    280327    "hi": Hi,
    281328    "restart": Restart,
     329    "roll-chromium-deps": RollChromiumDEPS,
    282330    "rollout": Rollout,
    283331    "sheriffs": Sheriffs,
    284332    "whois": Whois,
    285     "create-bug": CreateBug,
    286     "roll-chromium-deps": RollChromiumDEPS,
    287333}
    288334
     
    298344commands["sherifs"] = Sheriffs
    299345commands["sherrifs"] = Sheriffs
     346# "hello" Alias for "hi" command for the purposes of testing aliases
     347commands["hello"] = Hi
  • trunk/Tools/Scripts/webkitpy/tool/bot/ircbot_unittest.py

    r138617 r139805  
    8989
    9090    def test_help(self):
    91         expected_logs = "MOCK: irc.post: mock_nick: Available commands: create-bug, help, hi, restart, roll-chromium-deps, rollout, sheriffs, whois\n"
     91        expected_logs = 'MOCK: irc.post: mock_nick: Available commands: create-bug, help, hi, restart, roll-chromium-deps, rollout, sheriffs, whois\nMOCK: irc.post: mock_nick: Type "sheriffbot: help COMMAND" for help on individual commands.\n'
    9292        OutputCapture().assert_outputs(self, run, args=["help"], expected_logs=expected_logs)
     93        expected_logs = 'MOCK: irc.post: mock_nick: Usage: hi\nMOCK: irc.post: mock_nick: Retrieves a random quip from Bugzilla.\nMOCK: irc.post: mock_nick: Aliases: hello\n'
     94        OutputCapture().assert_outputs(self, run, args=["help hi"], expected_logs=expected_logs)
     95        OutputCapture().assert_outputs(self, run, args=["help hello"], expected_logs=expected_logs)
    9396
    9497    def test_restart(self):
Note: See TracChangeset for help on using the changeset viewer.