Extract announce info from deliverable file

There were some undocumented expectations for formatting information in
repo's README files to be extracted by the email announcement scripts
that many (most?) repos are not following. Since we have information
like the bug reporting details in the deliverable files, this attempts
to parse the info from there.

Story: #2005279
Task: #30132

Change-Id: I31643d9c4f22c199c9fc385711fdf530c2836631
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
This commit is contained in:
Sean McGinnis
2019-03-25 14:51:49 -05:00
parent ba0843c051
commit 8534d84086

View File

@@ -25,6 +25,7 @@ from reno import formatter
from reno import loader from reno import loader
from openstack_releases import rst2txt from openstack_releases import rst2txt
from openstack_releases import yamlutils
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@@ -103,7 +104,7 @@ Download the package from:
{% endif %} {% endif %}
{% if bug_url %} {% if bug_url %}
Please report issues through launchpad: Please report issues through:
{{ bug_url }} {{ bug_url }}
{% endif %} {% endif %}
@@ -158,13 +159,13 @@ cycle is available! You can find the source code tarball at:
Unless release-critical issues are found that warrant a release Unless release-critical issues are found that warrant a release
candidate respin, this candidate will be formally released as the candidate respin, this candidate will be formally released as the
final {{series|capitalize}} release. You are therefore strongly final {{series|capitalize}} release. You are therefore strongly encouraged
encouraged to test and validate this tarball! to test and validate this tarball!
Alternatively, you can directly test the stable/{{series|lower}} release Alternatively, you can directly test the stable/{{series|lower}} release
branch at: branch at:
https://git.openstack.org/cgit/openstack/{{publishing_dir_name}}/log/?h=stable/{{series|lower}} {{source_url}}/log/?h=stable/{{series|lower}}
Release notes for {{project}} can be found at: Release notes for {{project}} can be found at:
@@ -182,39 +183,46 @@ release crew's attention.
""" """
def parse_readme(repo_path): def parse_deliverable(series, repo):
"""Parse useful information out of the deliverable file.
Currently only parses the bug URL, but could potentially be expanded to get
other useful settings.
:param series: The release series being processed.
:param repo: The name of the deliverable.
"""
release_repo = os.path.realpath(
os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))
deliverable_path = os.path.join(
release_repo, 'deliverables', series.lower(), "%s.yaml" % repo)
# Hard coding source URL for now
sections = { sections = {
'bug_url': '', 'bug_url': '',
'source_url': '', 'source_url': 'https://git.openstack.org/cgit/openstack/%s' % repo,
} }
readme_formats = ['rst', 'md']
for k in readme_formats:
readme_path = os.path.join(repo_path, 'README.%s' % k)
try: try:
f = open(readme_path, 'r', encoding='utf-8') with open(deliverable_path, 'r') as d:
f.close() deliverable_info = yamlutils.loads(d)
break except Exception:
except IOError: # TODO(smcginnis): If the deliverable doesn't match the repo name, we
continue # can try to find it by loading all deliverable data and iterating on
else: # each deliverables repos to find it.
LOG.warning("No README file found in %s\n" LOG.warning('Unable to parse %s %s deliverable file', repo, series)
% repo_path)
return sections return sections
with open(readme_path, 'r', encoding='utf-8') as fh: if deliverable_info.get('launchpad'):
for line in fh: sections['bug_url'] = (
for (name, key_name) in [("Bugs:", "bug_url"), 'https://bugs.launchpad.net/%s/+bugs' %
("Source:", 'source_url')]: deliverable_info['launchpad'])
pieces = line.split(name, 1) elif deliverable_info.get('storyboard'):
if len(pieces) == 2: sections['bug_url'] = (
candidate = pieces[1].strip() 'https://storyboard.openstack.org/#!/project/%s' %
if 'http' in candidate: deliverable_info['storyboard'])
sections[key_name] = candidate
for (k, v) in sections.items():
if not v:
what = k.replace("_", " ")
LOG.warning("No %s found in '%s'\n"
% (what, readme_path))
return sections return sections
@@ -326,8 +334,8 @@ def generate_release_notes(repo, repo_path,
continue continue
diff_stats.append(line) diff_stats.append(line)
# Extract + valdiate needed sections from readme... # Extract + valdiate needed sections...
readme_sections = parse_readme(repo_path) sections = parse_deliverable(series, publishing_dir_name)
change_header = ["Changes in %s %s" % (repo_name, git_range)] change_header = ["Changes in %s %s" % (repo_name, git_range)]
change_header.append("-" * len(change_header[0])) change_header.append("-" * len(change_header[0]))
@@ -368,7 +376,7 @@ def generate_release_notes(repo, repo_path,
elif is_release_candidate: elif is_release_candidate:
email_to = 'openstack-discuss@lists.openstack.org' email_to = 'openstack-discuss@lists.openstack.org'
params = dict(readme_sections) params = dict(sections)
params.update({ params.update({
'project': repo_name, 'project': repo_name,
'description': description, 'description': description,