1
# Copyright (c) 2010 Google Inc. All rights reserved.
3
# Redistribution and use in source and binary forms, with or without
4
# modification, are permitted provided that the following conditions are
7
# * Redistributions of source code must retain the above copyright
8
# notice, this list of conditions and the following disclaimer.
9
# * Redistributions in binary form must reproduce the above
10
# copyright notice, this list of conditions and the following disclaimer
11
# in the documentation and/or other materials provided with the
13
# * Neither the name of Google Inc. nor the names of its
14
# contributors may be used to endorse or promote products derived from
15
# this software without specific prior written permission.
17
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
from webkitpy.common.config import urls
30
from webkitpy.common.system.executive import ScriptError
31
from webkitpy.tool.grammar import join_with_separators
34
class Sheriff(object):
35
def __init__(self, tool, sheriffbot):
37
self._sheriffbot = sheriffbot
39
def responsible_nicknames_from_commit_info(self, commit_info):
40
nestedList = [party.irc_nicknames for party in commit_info.responsible_parties() if party.irc_nicknames]
41
return reduce(lambda list, childList: list + childList, nestedList)
43
def post_irc_warning(self, commit_info, builders):
44
irc_nicknames = sorted(self.responsible_nicknames_from_commit_info(commit_info))
45
irc_prefix = ": " if irc_nicknames else ""
46
irc_message = "%s%s%s might have broken %s" % (
47
", ".join(irc_nicknames),
49
urls.view_revision_url(commit_info.revision()),
50
join_with_separators([builder.name() for builder in builders]))
52
self._tool.irc().post(irc_message)
54
def post_irc_summary(self, failure_map):
55
failing_tests = failure_map.failing_tests()
59
irc_message = "New failures: %s" % ", ".join(sorted(failing_tests)[:test_list_limit])
60
failure_count = len(failing_tests)
61
if failure_count > test_list_limit:
62
irc_message += " (and %s more...)" % (failure_count - test_list_limit)
63
self._tool.irc().post(irc_message)
65
def post_rollout_patch(self, svn_revision_list, rollout_reason):
66
# Ensure that svn revisions are numbers (and not options to
69
svn_revisions = " ".join([str(int(revision)) for revision in svn_revision_list])
71
raise ScriptError(message="Invalid svn revision number \"%s\"."
72
% " ".join(svn_revision_list))
74
if rollout_reason.startswith("-"):
75
raise ScriptError(message="The rollout reason may not begin "
76
"with - (\"%s\")." % rollout_reason)
78
output = self._sheriffbot.run_webkit_patch([
81
# In principle, we should pass --non-interactive here, but it
82
# turns out that create-rollout doesn't need it yet. We can't
83
# pass it prophylactically because we reject unrecognized command
85
"--parent-command=sheriff-bot",
89
return urls.parse_bug_id(output)
91
def post_chromium_deps_roll(self, revision, revision_name):
93
"post-chromium-deps-roll",
96
"--parent-command=sheriff-bot",
98
# revision can be None, but revision_name is always something meaningful.
99
args += [revision, revision_name]
100
output = self._sheriffbot.run_webkit_patch(args)
101
return urls.parse_bug_id(output)
103
def post_blame_comment_on_bug(self, commit_info, builders, tests):
104
if not commit_info.bug_id():
106
comment = "%s might have broken %s" % (
107
urls.view_revision_url(commit_info.revision()),
108
join_with_separators([builder.name() for builder in builders]))
110
comment += "\nThe following tests are not passing:\n"
111
comment += "\n".join(tests)
112
self._tool.bugs.post_comment_to_bug(commit_info.bug_id(),
114
cc=self._sheriffbot.watchers)