Commit 57c4721d authored by Mark Mentovai's avatar Mark Mentovai Committed by Commit Bot

git-cl: Make BUG_LINE_FORMAT configurable in codereview.settings

The default BUG_LINE_FORMAT is the existing BUG=%s. Projects that wish
to begin using Gerrit-style footers like Bug: %s can now set this in
codereview.settings.

BUG=616753

Change-Id: I4470311a86db228eab2a1655ae884736cce8c380
Reviewed-on: https://chromium-review.googlesource.com/451565
Commit-Queue: Mark Mentovai <mark@chromium.org>
Reviewed-by: 's avatarAndrii Shyshkalov <tandrii@chromium.org>
parent 3e25201d
...@@ -811,6 +811,19 @@ class Settings(object): ...@@ -811,6 +811,19 @@ class Settings(object):
self.viewvc_url = self._GetRietveldConfig('viewvc-url', error_ok=True) self.viewvc_url = self._GetRietveldConfig('viewvc-url', error_ok=True)
return self.viewvc_url return self.viewvc_url
def GetBugLineFormat(self):
# rietveld.bug-line-format should have a %s where the list of bugs should
# go. This is a bit of a quirk, because normal people will always want the
# bug list to go right after a prefix like BUG= or Bug:. The %s format
# approach is used strictly because there isn't a great way to carry the
# desired space after Bug: all the way from codereview.settings to here
# without treating : specially or inventing a quoting scheme.
bug_line_format = self._GetRietveldConfig('bug-line-format', error_ok=True)
if not bug_line_format:
# TODO(tandrii): change this to 'Bug: %s' to be a proper Gerrit footer.
bug_line_format = 'BUG=%s'
return bug_line_format
def GetBugPrefix(self): def GetBugPrefix(self):
return self._GetRietveldConfig('bug-prefix', error_ok=True) return self._GetRietveldConfig('bug-prefix', error_ok=True)
...@@ -3121,9 +3134,9 @@ class ChangeDescription(object): ...@@ -3121,9 +3134,9 @@ class ChangeDescription(object):
if not any((regexp.match(line) for line in self._description_lines)): if not any((regexp.match(line) for line in self._description_lines)):
prefix = settings.GetBugPrefix() prefix = settings.GetBugPrefix()
values = list(_get_bug_line_values(prefix, bug or '')) or [prefix] values = list(_get_bug_line_values(prefix, bug or '')) or [prefix]
bug_line_format = settings.GetBugLineFormat()
for value in values: for value in values:
# TODO(tandrii): change this to 'Bug: xxx' to be a proper Gerrit footer. self.append_footer(bug_line_format % value)
self.append_footer('BUG=%s' % value)
content = gclient_utils.RunEditor(self.description, True, content = gclient_utils.RunEditor(self.description, True,
git_editor=settings.GetGitEditor()) git_editor=settings.GetGitEditor())
...@@ -3295,6 +3308,7 @@ def LoadCodereviewSettingsFromFile(fileobj): ...@@ -3295,6 +3308,7 @@ def LoadCodereviewSettingsFromFile(fileobj):
SetProperty('private', 'PRIVATE', unset_error_ok=True) SetProperty('private', 'PRIVATE', unset_error_ok=True)
SetProperty('tree-status-url', 'STATUS', unset_error_ok=True) SetProperty('tree-status-url', 'STATUS', unset_error_ok=True)
SetProperty('viewvc-url', 'VIEW_VC', unset_error_ok=True) SetProperty('viewvc-url', 'VIEW_VC', unset_error_ok=True)
SetProperty('bug-line-format', 'BUG_LINE_FORMAT', unset_error_ok=True)
SetProperty('bug-prefix', 'BUG_PREFIX', unset_error_ok=True) SetProperty('bug-prefix', 'BUG_PREFIX', unset_error_ok=True)
SetProperty('cpplint-regex', 'LINT_REGEX', unset_error_ok=True) SetProperty('cpplint-regex', 'LINT_REGEX', unset_error_ok=True)
SetProperty('cpplint-ignore-regex', 'LINT_IGNORE_REGEX', unset_error_ok=True) SetProperty('cpplint-ignore-regex', 'LINT_IGNORE_REGEX', unset_error_ok=True)
......
...@@ -501,14 +501,14 @@ class TestGitCl(TestCase): ...@@ -501,14 +501,14 @@ class TestGitCl(TestCase):
'\nIF YOU SEE THIS, READ BELOW, IT WILL SAVE YOUR TIME!\n' '\nIF YOU SEE THIS, READ BELOW, IT WILL SAVE YOUR TIME!\n'
'There are un-consumed self.calls after this test has finished.\n' 'There are un-consumed self.calls after this test has finished.\n'
'If you don\'t know which test this is, run:\n' 'If you don\'t know which test this is, run:\n'
' tests/git_cl_tests.py -v\n' ' tests/git_cl_test.py -v\n'
'\n' '\n'
'If you are already running just this single test, then **first** ' 'If you are already running just this single test, then **first** '
'fix the problem whose exception is emitted below by unittest ' 'fix the problem whose exception is emitted below by unittest '
'runner.\n' 'runner.\n'
'\n' '\n'
'Else, to be sure what\'s going on, run this test **alone** with \n' 'Else, to be sure what\'s going on, run this test **alone** with \n'
' tests/git_cl_tests.py TestGitCl.<name>\n' ' tests/git_cl_test.py TestGitCl.<name>\n'
'and follow instructions above.\n' + 'and follow instructions above.\n' +
'=' * 80) '=' * 80)
finally: finally:
...@@ -557,6 +557,7 @@ class TestGitCl(TestCase): ...@@ -557,6 +557,7 @@ class TestGitCl(TestCase):
((['git', 'config', '--unset-all', 'rietveld.private'],), CERR1), ((['git', 'config', '--unset-all', 'rietveld.private'],), CERR1),
((['git', 'config', '--unset-all', 'rietveld.tree-status-url'],), CERR1), ((['git', 'config', '--unset-all', 'rietveld.tree-status-url'],), CERR1),
((['git', 'config', '--unset-all', 'rietveld.viewvc-url'],), CERR1), ((['git', 'config', '--unset-all', 'rietveld.viewvc-url'],), CERR1),
((['git', 'config', '--unset-all', 'rietveld.bug-line-format'],), CERR1),
((['git', 'config', '--unset-all', 'rietveld.bug-prefix'],), CERR1), ((['git', 'config', '--unset-all', 'rietveld.bug-prefix'],), CERR1),
((['git', 'config', '--unset-all', 'rietveld.cpplint-regex'],), CERR1), ((['git', 'config', '--unset-all', 'rietveld.cpplint-regex'],), CERR1),
((['git', 'config', '--unset-all', 'rietveld.cpplint-ignore-regex'],), ((['git', 'config', '--unset-all', 'rietveld.cpplint-ignore-regex'],),
...@@ -640,7 +641,8 @@ class TestGitCl(TestCase): ...@@ -640,7 +641,8 @@ class TestGitCl(TestCase):
((['git', 'log', '--pretty=format:%s\n\n%b', ((['git', 'log', '--pretty=format:%s\n\n%b',
'fake_ancestor_sha..HEAD'],), 'fake_ancestor_sha..HEAD'],),
'desc\n'), 'desc\n'),
((['git', 'config', 'rietveld.bug-prefix'],), ''), ((['git', 'config', 'rietveld.bug-prefix'],), CERR1),
((['git', 'config', 'rietveld.bug-line-format'],), CERR1),
] ]
@classmethod @classmethod
...@@ -2157,6 +2159,7 @@ class TestGitCl(TestCase): ...@@ -2157,6 +2159,7 @@ class TestGitCl(TestCase):
((['git', 'config', 'branch.feature.gerritissue'],), '123'), ((['git', 'config', 'branch.feature.gerritissue'],), '123'),
((['git', 'config', 'rietveld.autoupdate'],), CERR1), ((['git', 'config', 'rietveld.autoupdate'],), CERR1),
((['git', 'config', 'rietveld.bug-prefix'],), CERR1), ((['git', 'config', 'rietveld.bug-prefix'],), CERR1),
((['git', 'config', 'rietveld.bug-line-format'],), CERR1),
((['git', 'config', 'core.editor'],), 'vi'), ((['git', 'config', 'core.editor'],), 'vi'),
] ]
self.assertEqual(0, git_cl.main(['description', '--gerrit'])) self.assertEqual(0, git_cl.main(['description', '--gerrit']))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment