1dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# Copyright (C) 2010 Google Inc. All rights reserved.
2dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block#
3dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# Redistribution and use in source and binary forms, with or without
4dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# modification, are permitted provided that the following conditions are
5dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# met:
6dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block#
7dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block#     * Redistributions of source code must retain the above copyright
8dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# notice, this list of conditions and the following disclaimer.
9dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block#     * Redistributions in binary form must reproduce the above
10dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# copyright notice, this list of conditions and the following disclaimer
11dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# in the documentation and/or other materials provided with the
12dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# distribution.
13dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block#     * Neither the name of Google Inc. nor the names of its
14dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# contributors may be used to endorse or promote products derived from
15dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# this software without specific prior written permission.
16dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block#
17dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block
29dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blockimport os
30dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blockimport re
31dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block
32dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blockfrom webkitpy.common.checkout.changelog import ChangeLog
33dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blockfrom webkitpy.tool.steps.abstractstep import AbstractStep
3421939df44de1705786c545cd1bf519d47250322dBen Murdochfrom webkitpy.tool.steps.options import Options
35dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blockfrom webkitpy.common.system.deprecated_logging import error, log
36dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block
37dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block
38dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# FIXME: Some of this logic should probably be unified with CommitterValidator?
39dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blockclass ValidateReviewer(AbstractStep):
40dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    # FIXME: This should probably move onto ChangeLogEntry
41dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    def _has_valid_reviewer(self, changelog_entry):
42dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block        if changelog_entry.reviewer():
43dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block            return True
44dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block        if re.search("unreviewed", changelog_entry.contents(), re.IGNORECASE):
45dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block            return True
46dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block        if re.search("rubber[ -]stamp", changelog_entry.contents(), re.IGNORECASE):
47dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block            return True
48dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block        return False
49dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block
50dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    def run(self, state):
51dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block        # FIXME: For now we disable this check when a user is driving the script
52dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block        # this check is too draconian (and too poorly tested) to foist upon users.
53dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block        if not self._options.non_interactive:
54dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block            return
555af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke        for changelog_path in self.cached_lookup(state, "changelogs"):
56dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block            changelog_entry = ChangeLog(changelog_path).latest_entry()
57dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block            if self._has_valid_reviewer(changelog_entry):
58dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block                continue
59dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block            reviewer_text = changelog_entry.reviewer_text()
60dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block            if reviewer_text:
61dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block                log("%s found in %s does not appear to be a valid reviewer according to committers.py." % (reviewer_text, changelog_path))
62dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block            error('%s neither lists a valid reviewer nor contains the string "Unreviewed" or "Rubber stamp" (case insensitive).' % changelog_path)
63