Fix symbol identification in multiline message

* Fix an issue where a multiline message with leading spaces would cause
  invalid symbol identification.
* Add unit-tests around multiple symbols in a single line

Sem-Ver: bugfix
Change-Id: Id799c2fd368d9df38a5c01fc2071283aecef67c6
This commit is contained in:
Chris Dohmen 2022-06-27 13:35:05 -04:00
parent 1eadf23b94
commit 0aecbea81b
3 changed files with 45 additions and 5 deletions

View File

@ -692,12 +692,14 @@ def _get_increment_kwargs(git_dir, tag):
# git log output affecting out ability to have working sem ver headers.
changelog = git._run_git_command(['log', '--pretty=%B', version_spec],
git_dir)
header_len = len('sem-ver:')
commands = [line[header_len:].strip() for line in changelog.split('\n')
if line.lower().strip().startswith('sem-ver:')]
symbols = set()
for command in commands:
symbols.update([symbol.strip() for symbol in command.split(',')])
header = 'sem-ver:'
for line in changelog.split("\n"):
line = line.lower().strip()
if not line.lower().strip().startswith(header):
continue
new_symbols = line[len(header):].strip().split(",")
symbols.update([symbol.strip() for symbol in new_symbols])
def _handle_symbol(symbol, symbols, impact):
if symbol in symbols:

View File

@ -672,6 +672,27 @@ class TestVersions(base.BaseTestCase):
version = packaging._get_version_from_git()
self.assertThat(version, matchers.StartsWith('2.0.0.dev1'))
def test_multi_inline_symbols_no_space(self):
self.repo.commit()
self.repo.tag('1.2.3')
self.repo.commit('Sem-ver: feature,api-break')
version = packaging._get_version_from_git()
self.assertThat(version, matchers.StartsWith('2.0.0.dev1'))
def test_multi_inline_symbols_spaced(self):
self.repo.commit()
self.repo.tag('1.2.3')
self.repo.commit('Sem-ver: feature, api-break')
version = packaging._get_version_from_git()
self.assertThat(version, matchers.StartsWith('2.0.0.dev1'))
def test_multi_inline_symbols_reversed(self):
self.repo.commit()
self.repo.tag('1.2.3')
self.repo.commit('Sem-ver: api-break,feature')
version = packaging._get_version_from_git()
self.assertThat(version, matchers.StartsWith('2.0.0.dev1'))
def test_leading_space(self):
self.repo.commit()
self.repo.tag('1.2.3')
@ -679,6 +700,18 @@ class TestVersions(base.BaseTestCase):
version = packaging._get_version_from_git()
self.assertThat(version, matchers.StartsWith('2.0.0.dev1'))
def test_leading_space_multiline(self):
self.repo.commit()
self.repo.tag('1.2.3')
self.repo.commit(
(
' Some cool text\n'
' sem-ver: api-break'
)
)
version = packaging._get_version_from_git()
self.assertThat(version, matchers.StartsWith('2.0.0.dev1'))
def test_leading_characters_symbol_not_found(self):
self.repo.commit()
self.repo.tag('1.2.3')

View File

@ -0,0 +1,5 @@
---
fixes:
- |
Fix an issue where symbols that were indented
would produce an incorrect version.