Skip to content

Commit 6b99705

Browse files
authored
Merge pull request #1162 from stibus/feature/configurableHashModifier
Add configuration option for hash modifier
2 parents 31ae323 + 8ebe6e1 commit 6b99705

File tree

6 files changed

+67
-8
lines changed

6 files changed

+67
-8
lines changed

doc/configuration.rst

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,15 +1103,18 @@ Publishing configuration
11031103
11041104
Supported placeholders:
11051105

1106-
* ``{hash}`` - Create a reproducible hash given the title and location
1107-
based from the project root. Using this placeholder provides an option
1108-
for allowing pages with the same title to be pushed to the same
1109-
Confluence space without needing to manually add an index to the title.
1106+
* ``{hash}`` - Create a reproducible hash given the ``docname`` (name and
1107+
location of the document source based from the project root) and the value
1108+
of :lref:`confluence_publish_postfix_hash_modifier`. Using this
1109+
placeholder provides an option for allowing pages with the same title to
1110+
be pushed to the same Confluence space without needing to manually add an
1111+
index to the title.
11101112

11111113
By default, no postfix is used. See also:
11121114

11131115
- :lref:`confluence_ignore_titlefix_on_index`
11141116
- :lref:`confluence_publish_prefix`
1117+
- :lref:`confluence_publish_postfix_hash_modifier`
11151118

11161119
.. versionadded:: 1.2
11171120
.. versionchanged:: 1.9 Support for the ``{hash}`` placeholder.
@@ -1785,6 +1788,38 @@ Advanced publishing configuration
17851788

17861789
.. versionadded:: 2.1
17871790

1791+
.. _confluence_publish_postfix_hash_modifier:
1792+
1793+
.. confval:: confluence_publish_postfix_hash_modifier
1794+
1795+
The hash for :lref:`confluence_publish_postfix` is computed from the
1796+
``docname`` (name and location of the document source based from the
1797+
project root) and the value given here. The default value is:
1798+
1799+
.. code-block:: python
1800+
1801+
conf.confluence_publish_postfix_hash_modifier = (
1802+
str(conf.project)
1803+
+ str(conf.confluence_parent_page)
1804+
+ str(conf.confluence_publish_root)
1805+
)
1806+
1807+
Modify this value if you want the generated hashes to be independent of:
1808+
1809+
* ``project``
1810+
* :lref:`confluence_parent_page`
1811+
* :lref:`confluence_publish_root`
1812+
1813+
This can be helpful when your project name or the title of the parent page
1814+
have changed but you would like to retain the hash values. Thereby the page
1815+
contents may be updated without breaking links from other Confluence pages.
1816+
1817+
See also:
1818+
1819+
- :lref:`confluence_publish_postfix`
1820+
1821+
.. versionadded:: 3.0
1822+
17881823
.. _confluence_publish_override_api_prefix:
17891824

17901825
.. confval:: confluence_publish_override_api_prefix

sphinxcontrib/confluencebuilder/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ def setup(app):
247247
cm.add_conf_int('confluence_publish_orphan_container')
248248
# Override the path prefixes for various REST API requests.
249249
cm.add_conf('confluence_publish_override_api_prefix')
250+
# Modifier for postfix hash of published pages.
251+
cm.add_conf('confluence_publish_postfix_hash_modifier', 'confluence')
250252
# Number of attempts permitted when trying to retry a failed API request
251253
cm.add_conf('confluence_publish_retry_attempts')
252254
# Duration (in seconds) between retrying failed API requests

sphinxcontrib/confluencebuilder/config/checks.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,12 @@ def conf_translate(value):
573573

574574
# ##################################################################
575575

576+
# confluence_publish_postfix_hash_modifier
577+
validator.conf('confluence_publish_postfix_hash_modifier') \
578+
.string()
579+
580+
# ##################################################################
581+
576582
# confluence_publish_prefix
577583
validator.conf('confluence_publish_prefix') \
578584
.string()

sphinxcontrib/confluencebuilder/config/defaults.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@ def apply_defaults(app):
128128
if conf.confluence_publish_override_api_prefix is None:
129129
conf.confluence_publish_override_api_prefix = {}
130130

131+
if conf.confluence_publish_postfix_hash_modifier is None:
132+
conf.confluence_publish_postfix_hash_modifier = (
133+
str(conf.project)
134+
+ str(conf.confluence_parent_page)
135+
+ str(conf.confluence_publish_root)
136+
)
137+
131138
if conf.confluence_remove_title is None:
132139
conf.confluence_remove_title = True
133140

sphinxcontrib/confluencebuilder/state.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,5 @@ def _create_docname_unique_hash(docname: str, config) -> str:
257257
Create a unique(ish) hash for the given source file to avoid collisions
258258
when pushing pages to confluence.
259259
"""
260-
prehash = docname
261-
prehash += str(config.project)
262-
prehash += str(config.confluence_parent_page)
263-
prehash += str(config.confluence_publish_root)
260+
prehash = docname + str(config.confluence_publish_postfix_hash_modifier)
264261
return hashlib.sha1(prehash.encode()).hexdigest() # noqa: S324

tests/unit-tests/test_config_postfix_formatting.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,17 @@
1010

1111

1212
class TestCreateDocnameUniqueHash(ConfluenceTestCase):
13+
def _build_postfix_hash_modifier(self):
14+
conf = self.config
15+
conf.confluence_publish_postfix_hash_modifier = (
16+
str(conf.project)
17+
+ str(conf.confluence_parent_page)
18+
+ str(conf.confluence_publish_root)
19+
)
20+
1321
def test_no_parent_or_root_page_or_project_configured(self):
1422
test_docname = 'docs/test_file.rst'
23+
self._build_postfix_hash_modifier()
1524
hv = ConfluenceState._create_docname_unique_hash(
1625
docname=test_docname, config=self.config)
1726
self.assertEqual(hv, '75b0047d7552a5e4d91481e992f5ed339d868b3c')
@@ -20,6 +29,7 @@ def test_parent_page_configured(self):
2029
test_docname = 'docs/test_file.rst'
2130
config = self.config
2231
config['confluence_parent_page'] = 'parent_page'
32+
self._build_postfix_hash_modifier()
2333
hv = ConfluenceState._create_docname_unique_hash(
2434
docname=test_docname, config=self.config)
2535
self.assertEqual(hv, '9ca6dcc0b0e9eff175f1182ed75a2c43f359ed24')
@@ -28,6 +38,7 @@ def test_publish_root_configured(self):
2838
test_docname = 'docs/test_file.rst'
2939
config = self.config
3040
config['confluence_publish_root'] = 'publish_root'
41+
self._build_postfix_hash_modifier()
3142
hv = ConfluenceState._create_docname_unique_hash(
3243
docname=test_docname, config=self.config)
3344
self.assertEqual(hv, '02fe177ef99b746ed60cb1959d6134d3ea54fab9')
@@ -36,6 +47,7 @@ def test_project_configured(self):
3647
test_docname = 'docs/test_file.rst'
3748
config = self.config
3849
config['project'] = 'grand_project'
50+
self._build_postfix_hash_modifier()
3951
hv = ConfluenceState._create_docname_unique_hash(
4052
docname=test_docname, config=self.config)
4153
self.assertEqual(hv, '67e8ac11ab088e763c3cf2e577037b510a54ba41')

0 commit comments

Comments
 (0)