• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2012 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Bug module that is necessary for the layout analyzer."""
6
7import re
8
9from webkitpy.layout_tests.models.test_expectations import *
10
11
12class Bug(object):
13  """A class representing a bug.
14
15  TODO(imasaki): add more functionalities here if bug-tracker API is available.
16  For example, you can get the name of a bug owner.
17  """
18  # Type enum for the bug.
19  WEBKIT = 0
20  CHROMIUM = 1
21  OTHERS = 2
22
23  def __init__(self, bug_modifier):
24    """Initialize the object using raw bug text (such as BUGWK2322).
25
26    The bug modifier used in the test expectation file.
27
28    Args:
29      bug_modifier: a string representing a bug modifier. According to
30        http://www.chromium.org/developers/testing/webkit-layout-tests/\
31        testexpectations
32        Bug identifiers are of the form "webkit.org/b/12345", "crbug.com/12345",
33         "code.google.com/p/v8/issues/detail?id=12345" or "Bug(username)"
34    """
35    match = re.match('Bug\((\w+)\)$', bug_modifier)
36    if match:
37      self.type = self.OTHERS
38      self.url = 'mailto:%s@chromium.org' % match.group(1).lower()
39      self.bug_txt = bug_modifier
40      return
41
42    self.type = self.GetBugType(bug_modifier)
43    self.url = bug_modifier
44    self.bug_txt = bug_modifier
45
46
47  def GetBugType(self, bug_modifier):
48    """Returns type of the bug based on URL."""
49    if bug_modifier.startswith(WEBKIT_BUG_PREFIX):
50      return self.WEBKIT;
51    if bug_modifier.startswith(CHROMIUM_BUG_PREFIX):
52      return self.CHROMIUM;
53    return self.OTHERS
54
55  def __str__(self):
56    """Get a string representation of a bug object.
57
58    Returns:
59      a string for HTML link representation of a bug.
60    """
61    return '<a href="%s">%s</a>' % (self.url, self.bug_txt)
62