scan all changes and filter on files in reno not git log

Scanning only changes with reno files in them means we miss some of the
git tags in the repository history, so include all patches in the git
log output and then filter them in reno based on patches that include
any release notes files.

Closes-bug: #1517175
Change-Id: I36c0a54e20d47fff9af2b7f82c5380d97345a625
This commit is contained in:
Doug Hellmann 2015-11-17 19:27:04 +00:00
parent c9e19cd7a4
commit 32d475197f
3 changed files with 70 additions and 13 deletions

View File

@ -0,0 +1,5 @@
---
fixes:
- Fix `bug 1517175 <https://bugs.launchpad.net/reno/+bug/1517175>`__ to
ensure that all tagged versions are detected and that notes are associated
with the correct version numbers.

View File

@ -13,6 +13,7 @@
from __future__ import print_function
import collections
import fnmatch
import logging
import os.path
import re
@ -80,7 +81,6 @@ def _get_unique_id(filename):
# TODO(dhellmann): Add branch arg?
def get_notes_by_version(reporoot, notesdir, branch=None):
"""Return an OrderedDict mapping versions to lists of notes files.
The versions are presented in reverse chronological order.
@ -108,7 +108,6 @@ def get_notes_by_version(reporoot, notesdir, branch=None):
log_cmd = ['git', 'log', '--pretty=%x00%H %d', '--name-only']
if branch is not None:
log_cmd.append(branch)
log_cmd.extend(['--', notesdir + '/*.yaml'])
LOG.debug('running %s' % ' '.join(log_cmd))
history_results = utils.check_output(log_cmd, cwd=reporoot)
history = history_results.split('\x00')
@ -125,13 +124,22 @@ def get_notes_by_version(reporoot, notesdir, branch=None):
# include tags, the other lines are filenames.
sha = hlines[0].split(' ')[0]
tags = _TAG_PAT.findall(hlines[0])
filenames = hlines[2:]
LOG.debug('%s contains files %s' % (sha, filenames))
# Filter the files based on the notes directory we were
# given. We cannot do this in the git log command directly
# because it means we end up skipping some of the tags if the
# commits being tagged don't include any release note
# files. Even if this list ends up empty, we continue doing
# the other processing so that we record all of the known
# versions.
filenames = [
f
for f in hlines[2:]
if fnmatch.fnmatch(f, notesdir + '/*.yaml')
]
# If there are no tags in this block, assume the most recently
# seen version.
if not tags:
LOG.debug('%s is untagged, using %s' % (sha, current_version))
tags = [current_version]
else:
current_version = tags[0]
@ -143,6 +151,8 @@ def get_notes_by_version(reporoot, notesdir, branch=None):
LOG.debug('%s is a new version' % current_version)
versions.append(current_version)
LOG.debug('%s contains files %s' % (sha, filenames))
# Remember the files seen, using their UUID suffix as a unique id.
for f in filenames:
# Updated as older tags are found, handling edits to release
@ -184,7 +194,14 @@ def get_notes_by_version(reporoot, notesdir, branch=None):
uniqueid,
file=sys.stderr,
)
for version, filenames in files_and_tags.items():
files_and_tags[version] = list(reversed(filenames))
return files_and_tags
# Only return the parts of files_and_tags that actually have
# filenames associated with the versions.
trimmed = {
k: list(reversed(v))
for (k, v)
in files_and_tags.items()
if v
}
return trimmed

View File

@ -129,6 +129,11 @@ class Base(base.TestCase):
self._run_git('add', '.')
self._run_git('commit', '-m', message)
def _add_other_file(self, name):
with open(os.path.join(self.reporoot, name), 'w') as f:
f.write('adding %s\n' % name)
self._git_commit('add %s' % name)
def _add_notes_file(self, slug='slug', commit=True, legacy=False):
n = self.get_note_num()
if legacy:
@ -214,6 +219,23 @@ class BasicTest(Base):
results,
)
def test_note_before_tag(self):
filename = self._add_notes_file()
self._add_other_file('not-a-release-note.txt')
self._run_git('tag', '-s', '-m', 'first tag', '1.0.0')
raw_results = scanner.get_notes_by_version(
self.reporoot,
'releasenotes/notes',
)
results = {
k: [f for (f, n) in v]
for (k, v) in raw_results.items()
}
self.assertEqual(
{'1.0.0': [filename]},
results,
)
def test_note_commit_tagged(self):
filename = self._add_notes_file()
self._run_git('tag', '-s', '-m', 'first tag', '1.0.0')
@ -247,6 +269,24 @@ class BasicTest(Base):
results,
)
def test_other_commit_after_tag(self):
filename = self._add_notes_file()
self._add_other_file('ignore-1.txt')
self._run_git('tag', '-s', '-m', 'first tag', '1.0.0')
self._add_other_file('ignore-2.txt')
raw_results = scanner.get_notes_by_version(
self.reporoot,
'releasenotes/notes',
)
results = {
k: [f for (f, n) in v]
for (k, v) in raw_results.items()
}
self.assertEqual(
{'1.0.0': [filename]},
results,
)
def test_multiple_notes_after_tag(self):
self._make_python_package()
self._run_git('tag', '-s', '-m', 'first tag', '1.0.0')
@ -322,7 +362,6 @@ class BasicTest(Base):
}
self.assertEqual(
{'2.0.0': [f2],
'2.0.0-1': [],
},
results,
)
@ -345,7 +384,6 @@ class BasicTest(Base):
}
self.assertEqual(
{'2.0.0': [f2],
'2.0.0-1': [],
},
results,
)
@ -368,7 +406,6 @@ class BasicTest(Base):
}
self.assertEqual(
{'2.0.0': [f1],
'2.0.0-1': [],
},
results,
)
@ -391,7 +428,6 @@ class BasicTest(Base):
}
self.assertEqual(
{'2.0.0': [f2],
'2.0.0-1': [],
},
results,
)
@ -417,7 +453,6 @@ class BasicTest(Base):
}
self.assertEqual(
{'2.0.0': [f2],
'2.0.0-1': [],
},
results,
)