From 3793d87deb762f773eda1622ed87941c24bc253d Mon Sep 17 00:00:00 2001 From: Chris Dohmen Date: Fri, 3 Jun 2022 09:11:41 -0400 Subject: [PATCH] Allow leading spaces when determining symbols Update the logic that checks for sem-ver to strip out leading spaces. This helps solve an issue during automated squashes appending a tab character to the start of each line in a commit message. Closes-Bug: #1977479 Change-Id: I6f56500c366fd9610d98507f01e8af21862e4421 --- pbr/packaging.py | 2 +- pbr/tests/test_packaging.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pbr/packaging.py b/pbr/packaging.py index 8577b532..8e9c9aeb 100644 --- a/pbr/packaging.py +++ b/pbr/packaging.py @@ -694,7 +694,7 @@ def _get_increment_kwargs(git_dir, tag): git_dir) header_len = len('sem-ver:') commands = [line[header_len:].strip() for line in changelog.split('\n') - if line.lower().startswith('sem-ver:')] + if line.lower().strip().startswith('sem-ver:')] symbols = set() for command in commands: symbols.update([symbol.strip() for symbol in command.split(',')]) diff --git a/pbr/tests/test_packaging.py b/pbr/tests/test_packaging.py index c92ea9bc..346540bb 100644 --- a/pbr/tests/test_packaging.py +++ b/pbr/tests/test_packaging.py @@ -672,6 +672,20 @@ class TestVersions(base.BaseTestCase): 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') + self.repo.commit(' 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') + self.repo.commit(' ssem-ver: api-break') + version = packaging._get_version_from_git() + self.assertThat(version, matchers.StartsWith('1.2.4.dev1')) + def test_tagged_version_has_tag_version(self): self.repo.commit() self.repo.tag('1.2.3')