include the branch name in anchors to make them more unique
If the same version number appears in multiple output pages, sphinx reports a warning because the anchors generated by the formatter are the same. This patch adds the branch name to the anchor to make it more unique, since we should only be scanning a given branch one time in each release notes build. See http://logs.openstack.org/05/564405/1/check/build-openstack-releasenotes/b5fad95/job-output.txt.gz#_2018-04-27_06_02_12_077967 for an example of a failed build. Change-Id: I0b02e7eb319c95f885fc494977b356af71370970 Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
parent
52d4c1961d
commit
451d1ebcb9
@ -25,23 +25,26 @@ def _indent_for_list(text, prefix=' '):
|
||||
]) + '\n'
|
||||
|
||||
|
||||
def _anchor(version_title, title):
|
||||
def _anchor(version_title, title, branch):
|
||||
title = title or 'relnotes'
|
||||
return '.. _{title}_{version_title}:'.format(
|
||||
return '.. _{title}_{version_title}{branch}:'.format(
|
||||
title=title,
|
||||
version_title=version_title)
|
||||
version_title=version_title,
|
||||
branch=('_' + branch.replace('/', '_') if branch else ''),
|
||||
)
|
||||
|
||||
|
||||
def _section_anchor(section_title, version_title, title):
|
||||
def _section_anchor(section_title, version_title, title, branch):
|
||||
# Get the title and remove the trailing :
|
||||
title = _anchor(version_title, title)[:-1]
|
||||
title = _anchor(version_title, title, branch)[:-1]
|
||||
return "{title}_{section_title}:".format(
|
||||
title=title,
|
||||
section_title=section_title)
|
||||
section_title=section_title,
|
||||
)
|
||||
|
||||
|
||||
def format_report(loader, config, versions_to_include, title=None,
|
||||
show_source=True):
|
||||
show_source=True, branch=None):
|
||||
report = []
|
||||
if title:
|
||||
report.append('=' * len(title))
|
||||
@ -62,7 +65,7 @@ def format_report(loader, config, versions_to_include, title=None,
|
||||
version_title = config.unreleased_version_title or version
|
||||
else:
|
||||
version_title = version
|
||||
report.append(_anchor(version_title, title))
|
||||
report.append(_anchor(version_title, title, branch))
|
||||
report.append('')
|
||||
report.append(version_title)
|
||||
report.append('=' * len(version_title))
|
||||
@ -76,7 +79,7 @@ def format_report(loader, config, versions_to_include, title=None,
|
||||
if notefiles_with_prelude:
|
||||
prelude_title = prelude_name.replace('_', ' ').title()
|
||||
report.append(_section_anchor(
|
||||
prelude_title, version_title, title))
|
||||
prelude_title, version_title, title, branch))
|
||||
report.append('')
|
||||
report.append(prelude_title)
|
||||
report.append('-' * len(prelude_name))
|
||||
@ -98,7 +101,7 @@ def format_report(loader, config, versions_to_include, title=None,
|
||||
]
|
||||
if notes:
|
||||
report.append(_section_anchor(
|
||||
section_title, version_title, title))
|
||||
section_title, version_title, title, branch))
|
||||
report.append('')
|
||||
report.append(section_title)
|
||||
report.append('-' * len(section_title))
|
||||
|
@ -29,6 +29,7 @@ def report_cmd(args, conf):
|
||||
versions,
|
||||
title=args.title,
|
||||
show_source=args.show_source,
|
||||
branch=args.branch,
|
||||
)
|
||||
if args.output:
|
||||
with open(args.output, 'w') as f:
|
||||
|
@ -110,6 +110,7 @@ class ReleaseNotesDirective(rst.Directive):
|
||||
conf,
|
||||
versions,
|
||||
title=title,
|
||||
branch=branch,
|
||||
)
|
||||
source_name = '<%s %s>' % (__name__, branch or 'current branch')
|
||||
result = statemachine.ViewList()
|
||||
|
@ -239,3 +239,32 @@ class TestFormatterAnchors(TestFormatterBase):
|
||||
self.assertIn('.. _relnotes_0.0.0_Prelude:', result)
|
||||
self.assertIn('.. _relnotes_1.0.0:', result)
|
||||
self.assertIn('.. _relnotes_1.0.0_Known Issues:', result)
|
||||
|
||||
def test_with_branch_and_title(self):
|
||||
self.c.override(unreleased_version_title='Not Released')
|
||||
result = formatter.format_report(
|
||||
loader=self.ldr,
|
||||
config=self.c,
|
||||
versions_to_include=self.versions,
|
||||
title='This is the title',
|
||||
branch='stable/queens',
|
||||
)
|
||||
self.assertIn('.. _This is the title_0.0.0_stable_queens:', result)
|
||||
self.assertIn('.. _This is the title_0.0.0_stable_queens_Prelude:',
|
||||
result)
|
||||
self.assertIn('.. _This is the title_1.0.0_stable_queens:', result)
|
||||
self.assertIn(
|
||||
'.. _This is the title_1.0.0_stable_queens_Known Issues:',
|
||||
result)
|
||||
|
||||
def test_with_branch(self):
|
||||
result = formatter.format_report(
|
||||
loader=self.ldr,
|
||||
config=self.c,
|
||||
versions_to_include=self.versions,
|
||||
branch='stable/queens',
|
||||
)
|
||||
self.assertIn('.. _relnotes_0.0.0_stable_queens:', result)
|
||||
self.assertIn('.. _relnotes_0.0.0_stable_queens_Prelude:', result)
|
||||
self.assertIn('.. _relnotes_1.0.0_stable_queens:', result)
|
||||
self.assertIn('.. _relnotes_1.0.0_stable_queens_Known Issues:', result)
|
||||
|
Loading…
Reference in New Issue
Block a user