Skip to content

Commit

Permalink
use tagged releases to pull core porting guides
Browse files Browse the repository at this point in the history
  • Loading branch information
gotmax23 committed Aug 1, 2023
1 parent c045ab5 commit b3203f7
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 11 deletions.
5 changes: 5 additions & 0 deletions changelogs/fragments/544-porting_guide_tagged.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
minor_changes:
- Use tagged ansible-core / ansible-documentation releases to retrieve core
porting guide
(https://github.com/ansible-community/antsibull/pull/544).
21 changes: 10 additions & 11 deletions src/antsibull/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from semantic_version import Version as SemVer

from antsibull.collection_meta import CollectionsMetadata
from antsibull.utils.urls import get_documentation_repo_raw_url


class ChangelogData:
Expand Down Expand Up @@ -155,12 +156,14 @@ def matcher(filename: str) -> bool:
return read_file(tarball_path, matcher)


def get_porting_guide_filename(version: PypiVer):
if version.major == 2 and version.minor == 10:
basename = "porting_guide_base"
else:
basename = "porting_guide_core"
return f"docs/docsite/rst/porting_guides/{basename}_{version.major}.{version.minor}.rst"
def get_core_porting_guide_url(version: PypiVer):
major_minor = f"{version.major}.{version.minor}"
return (
get_documentation_repo_raw_url(version)
+ f"/v{version}"
+ "/docs/docsite/rst/porting_guides"
+ f"/porting_guide_core_{major_minor}.rst"
)


class CollectionChangelogCollector:
Expand Down Expand Up @@ -320,11 +323,7 @@ async def download_changelog(
self.changelog = ChangelogData.concatenate(changelogs)

async def download_porting_guide(self, aio_session: aiohttp.client.ClientSession):
branch_url = (
"https://raw.githubusercontent.com/ansible/ansible-documentation/devel"
)

query_url = f"{branch_url}/{get_porting_guide_filename(self.latest)}"
query_url = get_core_porting_guide_url(self.latest)
async with aio_session.get(query_url) as response:
self.porting_guide = await response.read()

Expand Down
6 changes: 6 additions & 0 deletions src/antsibull/utils/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or
# https://www.gnu.org/licenses/gpl-3.0.txt)

"""
Utilities for working with ansible URLs
"""

from __future__ import annotations

from packaging.version import Version as PypiVer

from ..constants import (
Expand Down
41 changes: 41 additions & 0 deletions tests/test_changelog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright (C) 2023 Maxwell G <[email protected]>
# SPDX-License-Identifier: GPL-3.0-or-later
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or
# https://www.gnu.org/licenses/gpl-3.0.txt)

# It doesn't make sense to split up the long URLs
# flake8: noqa E501

import pytest
from packaging.version import Version as PypiVer

from antsibull.changelog import get_core_porting_guide_url


@pytest.mark.parametrize(
"version, expected",
[
pytest.param(
PypiVer("2.12.0"),
"https://github.com/ansible/ansible/raw/v2.12.0/docs/docsite/rst/porting_guides/porting_guide_core_2.12.rst",
),
pytest.param(
PypiVer("2.13.0"),
"https://github.com/ansible/ansible/raw/v2.13.0/docs/docsite/rst/porting_guides/porting_guide_core_2.13.rst",
),
pytest.param(
PypiVer("2.13.11"),
"https://github.com/ansible/ansible-documentation/raw/v2.13.11/docs/docsite/rst/porting_guides/porting_guide_core_2.13.rst",
),
pytest.param(
PypiVer("2.14.8"),
"https://github.com/ansible/ansible-documentation/raw/v2.14.8/docs/docsite/rst/porting_guides/porting_guide_core_2.14.rst",
),
pytest.param(
PypiVer("2.16.0a1"),
"https://github.com/ansible/ansible-documentation/raw/v2.16.0a1/docs/docsite/rst/porting_guides/porting_guide_core_2.16.rst",
),
],
)
def test_get_core_porting_guide_url(version: PypiVer, expected: str):
assert get_core_porting_guide_url(version) == expected

0 comments on commit b3203f7

Please sign in to comment.