Home | History | Annotate | Download | only in checkout
      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 # WebKit's python module for holding information on a commit
     30 
     31 from webkitpy.common.config import urls
     32 from webkitpy.common.config.committers import CommitterList
     33 
     34 
     35 class CommitInfo(object):
     36     def __init__(self, revision, committer_email, changelog_data, committer_list=CommitterList()):
     37         self._revision = revision
     38         self._committer_email = committer_email
     39         self._bug_id = changelog_data["bug_id"]
     40         self._author_name = changelog_data["author_name"]
     41         self._author_email = changelog_data["author_email"]
     42         self._author = changelog_data["author"]
     43         self._reviewer_text = changelog_data["reviewer_text"]
     44         self._reviewer = changelog_data["reviewer"]
     45 
     46         # Derived values:
     47         self._committer = committer_list.committer_by_email(committer_email)
     48 
     49     def revision(self):
     50         return self._revision
     51 
     52     def committer(self):
     53         return self._committer  # None if committer isn't in committers.py
     54 
     55     def committer_email(self):
     56         return self._committer_email
     57 
     58     def bug_id(self):
     59         return self._bug_id  # May be None
     60 
     61     def author(self):
     62         return self._author  # May be None
     63 
     64     def author_name(self):
     65         return self._author_name
     66 
     67     def author_email(self):
     68         return self._author_email
     69 
     70     def reviewer(self):
     71         return self._reviewer # May be None
     72 
     73     def reviewer_text(self):
     74         return self._reviewer_text # May be None
     75 
     76     def responsible_parties(self):
     77         responsible_parties = [
     78             self.committer(),
     79             self.author(),
     80             self.reviewer(),
     81         ]
     82         return set([party for party in responsible_parties if party]) # Filter out None
     83 
     84     # FIXME: It is slightly lame that this "view" method is on this "model" class (in MVC terms)
     85     def blame_string(self, bugs):
     86         string = "r%s:\n" % self.revision()
     87         string += "  %s\n" % urls.view_revision_url(self.revision())
     88         string += "  Bug: %s (%s)\n" % (self.bug_id(), bugs.bug_url_for_bug_id(self.bug_id()))
     89         author_line = "\"%s\" <%s>" % (self.author_name(), self.author_email())
     90         string += "  Author: %s\n" % (self.author() or author_line)
     91         string += "  Reviewer: %s\n" % (self.reviewer() or self.reviewer_text())
     92         string += "  Committer: %s" % self.committer()
     93         return string
     94