• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2#
3# Copyright (C) 2011 Patrick Gansterer <paroga@paroga.com>
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8# 1.  Redistributions of source code must retain the above copyright
9#     notice, this list of conditions and the following disclaimer.
10# 2.  Redistributions in binary form must reproduce the above copyright
11#     notice, this list of conditions and the following disclaimer in the
12#     documentation and/or other materials provided with the distribution.
13#
14# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
26"""Checks WebKit style for ChangeLog files."""
27
28import re
29from common import TabChecker
30from webkitpy.common.net.bugzilla import parse_bug_id_from_changelog
31
32
33class ChangeLogChecker(object):
34
35    """Processes text lines for checking style."""
36
37    def __init__(self, file_path, handle_style_error, should_line_be_checked):
38        self.file_path = file_path
39        self.handle_style_error = handle_style_error
40        self.should_line_be_checked = should_line_be_checked
41        self._tab_checker = TabChecker(file_path, handle_style_error)
42
43    def check_entry(self, first_line_checked, entry_lines):
44        if not entry_lines:
45            return
46        for line in entry_lines:
47            if parse_bug_id_from_changelog(line):
48                break
49            if re.search("Unreviewed", line, re.IGNORECASE):
50                break
51            if re.search("build", line, re.IGNORECASE) and re.search("fix", line, re.IGNORECASE):
52                break
53        else:
54            self.handle_style_error(first_line_checked,
55                                    "changelog/bugnumber", 5,
56                                    "ChangeLog entry has no bug number")
57
58    def check(self, lines):
59        self._tab_checker.check(lines)
60        first_line_checked = 0
61        entry_lines = []
62
63        for line_index, line in enumerate(lines):
64            if not self.should_line_be_checked(line_index + 1):
65                # If we transitioned from finding changed lines to
66                # unchanged lines, then we are done.
67                if first_line_checked:
68                    break
69                continue
70            if not first_line_checked:
71                first_line_checked = line_index + 1
72            entry_lines.append(line)
73
74        self.check_entry(first_line_checked, entry_lines)
75