summaryrefslogtreecommitdiff
path: root/test/lib/ansible_test/_internal/util_common.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/lib/ansible_test/_internal/util_common.py')
-rw-r--r--test/lib/ansible_test/_internal/util_common.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/lib/ansible_test/_internal/util_common.py b/test/lib/ansible_test/_internal/util_common.py
index 96beae0c11..fbd9e71d87 100644
--- a/test/lib/ansible_test/_internal/util_common.py
+++ b/test/lib/ansible_test/_internal/util_common.py
@@ -24,6 +24,7 @@ from .encoding import (
from .util import (
cache,
display,
+ get_ansible_version,
remove_tree,
MODE_DIRECTORY,
MODE_FILE_EXECUTE,
@@ -151,6 +152,31 @@ class CommonConfig:
return os.path.join(ANSIBLE_TEST_DATA_ROOT, 'ansible.cfg')
+def get_docs_url(url: str) -> str:
+ """
+ Return the given docs.ansible.com URL updated to match the running ansible-test version, if it is not a pre-release version.
+ The URL should be in the form: https://docs.ansible.com/ansible/devel/path/to/doc.html
+ Where 'devel' will be replaced with the current version, unless it is a pre-release version.
+ When run under a pre-release version, the URL will remain unchanged.
+ This serves to provide a fallback URL for pre-release versions.
+ It also makes searching the source for docs links easier, since a full URL is provided to this function.
+ """
+ url_prefix = 'https://docs.ansible.com/ansible-core/devel/'
+
+ if not url.startswith(url_prefix):
+ raise ValueError(f'URL "{url}" does not start with: {url_prefix}')
+
+ ansible_version = get_ansible_version()
+
+ if re.search(r'^[0-9.]+$', ansible_version):
+ url_version = '.'.join(ansible_version.split('.')[:2])
+ new_prefix = f'https://docs.ansible.com/ansible-core/{url_version}/'
+
+ url = url.replace(url_prefix, new_prefix)
+
+ return url
+
+
def create_result_directories(args: CommonConfig) -> None:
"""Create result directories."""
if args.explain: