@ -1127,6 +1127,19 @@ class Change(object):
self . _description_without_tags = (
self . _description_without_tags = (
' \n ' . join ( description_without_tags ) . rstrip ( ) )
' \n ' . join ( description_without_tags ) . rstrip ( ) )
def AddDescriptionFooter ( self , key , value ) :
""" Adds the given footer to the change description.
Args :
key : A string with the key for the git footer . It must conform to
the git footers format ( i . e . ' List-Of-Tokens ' ) and will be case
normalized so that each token is title - cased .
value : A string with the value for the git footer .
"""
description = git_footers . add_footer (
self . FullDescriptionText ( ) , git_footers . normalize_name ( key ) , value )
self . SetDescriptionText ( description )
def RepositoryRoot ( self ) :
def RepositoryRoot ( self ) :
""" Returns the repository (checkout) root directory for this change,
""" Returns the repository (checkout) root directory for this change,
as an absolute path .
as an absolute path .
@ -1139,11 +1152,20 @@ class Change(object):
raise AttributeError ( self , attr )
raise AttributeError ( self , attr )
return self . tags . get ( attr )
return self . tags . get ( attr )
def GitFootersFromDescription ( self ) :
""" Return the git footers present in the description.
Returns :
footers : A dict of { footer : [ values ] } containing a multimap of the footers
in the change description .
"""
return git_footers . parse_footers ( self . FullDescriptionText ( ) )
def BugsFromDescription ( self ) :
def BugsFromDescription ( self ) :
""" Returns all bugs referenced in the commit description. """
""" Returns all bugs referenced in the commit description. """
tags = [ b . strip ( ) for b in self . tags . get ( ' BUG ' , ' ' ) . split ( ' , ' ) if b . strip ( ) ]
tags = [ b . strip ( ) for b in self . tags . get ( ' BUG ' , ' ' ) . split ( ' , ' ) if b . strip ( ) ]
footers = [ ]
footers = [ ]
parsed = git_footers . parse_footers ( self . _full_description )
parsed = self . GitFootersFromDescription ( )
unsplit_footers = parsed . get ( ' Bug ' , [ ] ) + parsed . get ( ' Fixed ' , [ ] )
unsplit_footers = parsed . get ( ' Bug ' , [ ] ) + parsed . get ( ' Fixed ' , [ ] )
for unsplit_footer in unsplit_footers :
for unsplit_footer in unsplit_footers :
footers + = [ b . strip ( ) for b in unsplit_footer . split ( ' , ' ) ]
footers + = [ b . strip ( ) for b in unsplit_footer . split ( ' , ' ) ]
@ -1160,7 +1182,7 @@ class Change(object):
tags = [ r . strip ( ) for r in self . tags . get ( ' TBR ' , ' ' ) . split ( ' , ' ) if r . strip ( ) ]
tags = [ r . strip ( ) for r in self . tags . get ( ' TBR ' , ' ' ) . split ( ' , ' ) if r . strip ( ) ]
# TODO(agable): Remove support for 'Tbr:' when TBRs are programmatically
# TODO(agable): Remove support for 'Tbr:' when TBRs are programmatically
# determined by self-CR+1s.
# determined by self-CR+1s.
footers = git_footers . parse_footers ( self . _full_description ) . get ( ' Tbr ' , [ ] )
footers = self . GitFootersFromDescription ( ) . get ( ' Tbr ' , [ ] )
return sorted ( set ( tags + footers ) )
return sorted ( set ( tags + footers ) )
# TODO(agable): Delete these once we're sure they're unused.
# TODO(agable): Delete these once we're sure they're unused.