Remove auto-branch name

The feature to configure branch names based on the presence of "bug",
"lp", "blueprint" or "bp" in the commit message is overly elaborate and
very OpenStack specific. Even with this, it hasn't been updated to keep
up with the times as many projects have migrated to Storyboard, which
isn't handled here.

Given that it frequently does the wrong thing and likely doesn't apply
to anyone outside of the OpenStack ecosystem, the wisest thing it to
simply remove the feature. This is a break in behavior but it seems
better than adding yet another flag for something that many users will
want enabled by default.

Change-Id: I82ecc1719de5c87d59bbfe73a042917e6559da1e
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Story: 1130330
Task: 566
Story: 2001247
Task: 5777
This commit is contained in:
Stephen Finucane 2018-10-15 14:20:41 +01:00
parent 56779ebe21
commit 03768832c4
3 changed files with 20 additions and 133 deletions

View File

@ -938,61 +938,21 @@ def assert_one_change(remote, branch, yes, have_hook):
sys.exit(1) sys.exit(1)
def use_topic(why, topic):
"""Inform the user about why a particular topic has been selected."""
if VERBOSE:
print(why % ('"%s"' % topic,))
return topic
def get_topic(target_branch): def get_topic(target_branch):
branch_name = get_branch_name(target_branch) branch_name = get_branch_name(target_branch)
branch_parts = branch_name.split("/") branch_parts = branch_name.split("/")
if len(branch_parts) >= 3 and branch_parts[0] == "review": if len(branch_parts) >= 3 and branch_parts[0] == "review":
return use_topic("Using change number %s " topic = "/".join(branch_parts[2:])
"for the topic of the change submitted", if VERBOSE:
"/".join(branch_parts[2:])) print("Using change number %s for the topic of the change "
"submitted" % topic)
return topic
preferred_log_format = "%B" if VERBOSE:
log_output = run_command("git log --pretty='" + preferred_log_format + print("Using local branch name %s for the topic of the change "
"' HEAD^1..HEAD") "submitted" % branch_name)
if log_output == preferred_log_format: return branch_name
# The %B format specifier is supported starting at Git v1.7.2. If it's
# not supported, we'll just get back '%B', so we try something else.
# The downside of %s is that it removes newlines in the subject.
log_output = run_command("git log --pretty='%s%n%b' HEAD^1..HEAD")
bug_re = r'''(?x) # verbose regexp
\b([Bb]ug|[Ll][Pp]) # bug or lp
[ \t\f\v]* # don't want to match newline
[:]? # separator if needed
[ \t\f\v]* # don't want to match newline
[#]? # if needed
[ \t\f\v]* # don't want to match newline
(\d+) # bug number'''
match = re.search(bug_re, log_output)
if match is not None:
return use_topic("Using bug number %s "
"for the topic of the change submitted",
"bug/%s" % match.group(2))
bp_re = r'''(?x) # verbose regexp
\b([Bb]lue[Pp]rint|[Bb][Pp]) # a blueprint or bp
[ \t\f\v]* # don't want to match newline
[#:]? # separator if needed
[ \t\f\v]* # don't want to match newline
([0-9a-zA-Z-_]+) # any identifier or number'''
match = re.search(bp_re, log_output)
if match is not None:
return use_topic("Using blueprint number %s "
"for the topic of the change submitted",
"bp/%s" % match.group(2))
return use_topic("Using local branch name %s "
"for the topic of the change submitted",
branch_name)
class CannotQueryOpenChangesets(CommandFailed): class CannotQueryOpenChangesets(CommandFailed):

View File

@ -389,92 +389,9 @@ class GitReviewTestCase(tests.BaseGitReviewTestCase):
self._assert_branch_would_be('master%topic=zat', self._assert_branch_would_be('master%topic=zat',
extra_args=['-t', 'zat']) extra_args=['-t', 'zat'])
def test_bug_topic(self):
self._run_git_review('-s')
self._simple_change('a change', 'new change for bug 123')
self._assert_branch_would_be('master%topic=bug/123')
def test_bug_topic_newline(self):
self._run_git_review('-s')
self._simple_change('a change', 'new change not for bug\n\n123')
self._assert_branch_would_be('master')
def test_bp_topic(self):
self._run_git_review('-s')
self._simple_change('a change', 'new change for blueprint asdf')
self._assert_branch_would_be('master%topic=bp/asdf')
def test_bp_topic_newline(self):
self._run_git_review('-s')
self._simple_change('a change', 'new change not for blueprint\n\nasdf')
self._assert_branch_would_be('master')
def test_author_name_topic_bp(self):
old_author = None
if 'GIT_AUTHOR_NAME' in os.environ:
old_author = os.environ['GIT_AUTHOR_NAME']
try:
os.environ['GIT_AUTHOR_NAME'] = 'BPNAME'
self._run_git_review('-s')
self._simple_change('a change',
'new change 1 with name but no topic')
self._assert_branch_would_be('master')
finally:
if old_author:
os.environ['GIT_AUTHOR_NAME'] = old_author
else:
del os.environ['GIT_AUTHOR_NAME']
def test_author_email_topic_bp(self):
old_author = None
if 'GIT_AUTHOR_EMAIL' in os.environ:
old_author = os.environ['GIT_AUTHOR_EMAIL']
try:
os.environ['GIT_AUTHOR_EMAIL'] = 'bpemail@example.com'
self._run_git_review('-s')
self._simple_change('a change',
'new change 1 with email but no topic')
self._assert_branch_would_be('master')
finally:
if old_author:
os.environ['GIT_AUTHOR_EMAIL'] = old_author
else:
del os.environ['GIT_AUTHOR_EMAIL']
def test_author_name_topic_bug(self):
old_author = None
if 'GIT_AUTHOR_NAME' in os.environ:
old_author = os.environ['GIT_AUTHOR_NAME']
try:
os.environ['GIT_AUTHOR_NAME'] = 'Bug: #1234'
self._run_git_review('-s')
self._simple_change('a change',
'new change 2 with name but no topic')
self._assert_branch_would_be('master')
finally:
if old_author:
os.environ['GIT_AUTHOR_NAME'] = old_author
else:
del os.environ['GIT_AUTHOR_NAME']
def test_author_email_topic_bug(self):
old_author = None
if 'GIT_AUTHOR_EMAIL' in os.environ:
old_author = os.environ['GIT_AUTHOR_EMAIL']
try:
os.environ['GIT_AUTHOR_EMAIL'] = 'bug5678@example.com'
self._run_git_review('-s')
self._simple_change('a change',
'new change 2 with email but no topic')
self._assert_branch_would_be('master')
finally:
if old_author:
os.environ['GIT_AUTHOR_EMAIL'] = old_author
else:
del os.environ['GIT_AUTHOR_EMAIL']
def test_git_review_T(self): def test_git_review_T(self):
self._run_git_review('-s') self._run_git_review('-s')
self._run_git('checkout', '-b', 'bug/456')
self._simple_change('test file modified', 'commit message for bug 456') self._simple_change('test file modified', 'commit message for bug 456')
self._assert_branch_would_be('master%topic=bug/456') self._assert_branch_would_be('master%topic=bug/456')
self._assert_branch_would_be('master', extra_args=['-T']) self._assert_branch_would_be('master', extra_args=['-T'])

View File

@ -0,0 +1,10 @@
---
upgrade:
- |
Support for auto-configuration of topic names based on the presence of
keywords in the commit message is removed. Previously, keywords such as
``bug``, ``bp`` or ``lp`` followed by a number would result in branch
names containing the associated number, e.g. ``bug/123``. This feature
was OpenStack specific, was a frequent source of bugs and clearly wasn't
being used that often, given that StoryBoard is a thing now and no one had
updated this feature to handle that metadata.