~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Tools/Scripts/webkitpy/tool/bot/sheriff.py

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2010 Google Inc. All rights reserved.
 
2
#
 
3
# Redistribution and use in source and binary forms, with or without
 
4
# modification, are permitted provided that the following conditions are
 
5
# met:
 
6
#
 
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
 
12
# distribution.
 
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.
 
16
#
 
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.
 
28
 
 
29
from webkitpy.common.config import urls
 
30
from webkitpy.common.system.executive import ScriptError
 
31
from webkitpy.tool.grammar import join_with_separators
 
32
 
 
33
 
 
34
class Sheriff(object):
 
35
    def __init__(self, tool, sheriffbot):
 
36
        self._tool = tool
 
37
        self._sheriffbot = sheriffbot
 
38
 
 
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)
 
42
 
 
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),
 
48
            irc_prefix,
 
49
            urls.view_revision_url(commit_info.revision()),
 
50
            join_with_separators([builder.name() for builder in builders]))
 
51
 
 
52
        self._tool.irc().post(irc_message)
 
53
 
 
54
    def post_irc_summary(self, failure_map):
 
55
        failing_tests = failure_map.failing_tests()
 
56
        if not failing_tests:
 
57
            return
 
58
        test_list_limit = 5
 
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)
 
64
 
 
65
    def post_rollout_patch(self, svn_revision_list, rollout_reason):
 
66
        # Ensure that svn revisions are numbers (and not options to
 
67
        # create-rollout).
 
68
        try:
 
69
            svn_revisions = " ".join([str(int(revision)) for revision in svn_revision_list])
 
70
        except:
 
71
            raise ScriptError(message="Invalid svn revision number \"%s\"."
 
72
                              % " ".join(svn_revision_list))
 
73
 
 
74
        if rollout_reason.startswith("-"):
 
75
            raise ScriptError(message="The rollout reason may not begin "
 
76
                              "with - (\"%s\")." % rollout_reason)
 
77
 
 
78
        output = self._sheriffbot.run_webkit_patch([
 
79
            "create-rollout",
 
80
            "--force-clean",
 
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
 
84
            # line switches.
 
85
            "--parent-command=sheriff-bot",
 
86
            svn_revisions,
 
87
            rollout_reason,
 
88
        ])
 
89
        return urls.parse_bug_id(output)
 
90
 
 
91
    def post_chromium_deps_roll(self, revision, revision_name):
 
92
        args = [
 
93
            "post-chromium-deps-roll",
 
94
            "--force-clean",
 
95
            "--non-interactive",
 
96
            "--parent-command=sheriff-bot",
 
97
        ]
 
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)
 
102
 
 
103
    def post_blame_comment_on_bug(self, commit_info, builders, tests):
 
104
        if not commit_info.bug_id():
 
105
            return
 
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]))
 
109
        if tests:
 
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(),
 
113
                                            comment,
 
114
                                            cc=self._sheriffbot.watchers)